mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-20 09:04:42 +01:00
move book support into the core
This commit is contained in:
@@ -84,6 +84,9 @@ namespace Emby.Server.Implementations.Activity
|
||||
{
|
||||
using (var connection = CreateConnection(true))
|
||||
{
|
||||
var list = new List<ActivityLogEntry>();
|
||||
int totalRecordCount = 0;
|
||||
|
||||
var commandText = BaseActivitySelectText;
|
||||
var whereClauses = new List<string>();
|
||||
|
||||
@@ -120,32 +123,37 @@ namespace Emby.Server.Implementations.Activity
|
||||
commandText += " LIMIT " + limit.Value.ToString(_usCulture);
|
||||
}
|
||||
|
||||
var list = new List<ActivityLogEntry>();
|
||||
var statementTexts = new List<string>();
|
||||
statementTexts.Add(commandText);
|
||||
statementTexts.Add("select count (Id) from ActivityLogEntries" + whereTextWithoutPaging);
|
||||
|
||||
using (var statement = connection.PrepareStatement(commandText))
|
||||
connection.RunInTransaction(db =>
|
||||
{
|
||||
if (minDate.HasValue)
|
||||
var statements = PrepareAllSafe(db, string.Join(";", statementTexts.ToArray())).ToList();
|
||||
|
||||
using (var statement = statements[0])
|
||||
{
|
||||
statement.TryBind("@DateCreated", minDate.Value.ToDateTimeParamValue());
|
||||
if (minDate.HasValue)
|
||||
{
|
||||
statement.TryBind("@DateCreated", minDate.Value.ToDateTimeParamValue());
|
||||
}
|
||||
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
{
|
||||
list.Add(GetEntry(row));
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
using (var statement = statements[1])
|
||||
{
|
||||
list.Add(GetEntry(row));
|
||||
if (minDate.HasValue)
|
||||
{
|
||||
statement.TryBind("@DateCreated", minDate.Value.ToDateTimeParamValue());
|
||||
}
|
||||
|
||||
totalRecordCount = statement.ExecuteQuery().SelectScalarInt().First();
|
||||
}
|
||||
}
|
||||
|
||||
int totalRecordCount;
|
||||
|
||||
using (var statement = connection.PrepareStatement("select count (Id) from ActivityLogEntries" + whereTextWithoutPaging))
|
||||
{
|
||||
if (minDate.HasValue)
|
||||
{
|
||||
statement.TryBind("@DateCreated", minDate.Value.ToDateTimeParamValue());
|
||||
}
|
||||
|
||||
totalRecordCount = statement.ExecuteQuery().SelectScalarInt().First();
|
||||
}
|
||||
}, ReadTransactionMode);
|
||||
|
||||
return new QueryResult<ActivityLogEntry>()
|
||||
{
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace Emby.Server.Implementations.Data
|
||||
connectionFlags |= ConnectionFlags.ReadWrite;
|
||||
}
|
||||
|
||||
//connectionFlags |= ConnectionFlags.SharedCached;
|
||||
connectionFlags |= ConnectionFlags.SharedCached;
|
||||
connectionFlags |= ConnectionFlags.NoMutex;
|
||||
|
||||
var db = SQLite3.Open(DbFilePath, connectionFlags, null);
|
||||
|
||||
@@ -123,17 +123,10 @@ namespace Emby.Server.Implementations.Data
|
||||
}
|
||||
}
|
||||
|
||||
private SQLiteDatabaseConnection _backgroundConnection;
|
||||
protected override void CloseConnection()
|
||||
{
|
||||
base.CloseConnection();
|
||||
|
||||
if (_backgroundConnection != null)
|
||||
{
|
||||
_backgroundConnection.Dispose();
|
||||
_backgroundConnection = null;
|
||||
}
|
||||
|
||||
if (_shrinkMemoryTimer != null)
|
||||
{
|
||||
_shrinkMemoryTimer.Dispose();
|
||||
@@ -379,8 +372,6 @@ namespace Emby.Server.Implementations.Data
|
||||
|
||||
userDataRepo.Initialize(WriteLock);
|
||||
|
||||
//_backgroundConnection = CreateConnection(true);
|
||||
|
||||
_shrinkMemoryTimer = _timerFactory.Create(OnShrinkMemoryTimerCallback, null, TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(30));
|
||||
}
|
||||
|
||||
@@ -1370,6 +1361,10 @@ namespace Emby.Server.Implementations.Data
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (type == typeof(AudioBook))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (type == typeof(MusicAlbum))
|
||||
{
|
||||
return false;
|
||||
@@ -2691,51 +2686,55 @@ namespace Emby.Server.Implementations.Data
|
||||
{
|
||||
using (var connection = CreateConnection(true))
|
||||
{
|
||||
var statements = PrepareAllSafe(connection, string.Join(";", statementTexts.ToArray()))
|
||||
.ToList();
|
||||
|
||||
if (!isReturningZeroItems)
|
||||
connection.RunInTransaction(db =>
|
||||
{
|
||||
using (var statement = statements[0])
|
||||
var statements = PrepareAllSafe(db, string.Join(";", statementTexts.ToArray()))
|
||||
.ToList();
|
||||
|
||||
if (!isReturningZeroItems)
|
||||
{
|
||||
if (EnableJoinUserData(query))
|
||||
using (var statement = statements[0])
|
||||
{
|
||||
statement.TryBind("@UserId", query.User.Id);
|
||||
if (EnableJoinUserData(query))
|
||||
{
|
||||
statement.TryBind("@UserId", query.User.Id);
|
||||
}
|
||||
|
||||
BindSimilarParams(query, statement);
|
||||
|
||||
// Running this again will bind the params
|
||||
GetWhereClauses(query, statement);
|
||||
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
{
|
||||
var item = GetItem(row, query);
|
||||
if (item != null)
|
||||
{
|
||||
list.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BindSimilarParams(query, statement);
|
||||
|
||||
// Running this again will bind the params
|
||||
GetWhereClauses(query, statement);
|
||||
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
if (query.EnableTotalRecordCount)
|
||||
{
|
||||
var item = GetItem(row, query);
|
||||
if (item != null)
|
||||
using (var statement = statements[statements.Count - 1])
|
||||
{
|
||||
list.Add(item);
|
||||
if (EnableJoinUserData(query))
|
||||
{
|
||||
statement.TryBind("@UserId", query.User.Id);
|
||||
}
|
||||
|
||||
BindSimilarParams(query, statement);
|
||||
|
||||
// Running this again will bind the params
|
||||
GetWhereClauses(query, statement);
|
||||
|
||||
totalRecordCount = statement.ExecuteQuery().SelectScalarInt().First();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (query.EnableTotalRecordCount)
|
||||
{
|
||||
using (var statement = statements[statements.Count - 1])
|
||||
{
|
||||
if (EnableJoinUserData(query))
|
||||
{
|
||||
statement.TryBind("@UserId", query.User.Id);
|
||||
}
|
||||
|
||||
BindSimilarParams(query, statement);
|
||||
|
||||
// Running this again will bind the params
|
||||
GetWhereClauses(query, statement);
|
||||
|
||||
totalRecordCount = statement.ExecuteQuery().SelectScalarInt().First();
|
||||
}
|
||||
}
|
||||
}, ReadTransactionMode);
|
||||
|
||||
LogQueryTime("GetItems", commandText, now);
|
||||
|
||||
@@ -3095,49 +3094,53 @@ namespace Emby.Server.Implementations.Data
|
||||
{
|
||||
using (var connection = CreateConnection(true))
|
||||
{
|
||||
var statements = PrepareAllSafe(connection, string.Join(";", statementTexts.ToArray()))
|
||||
.ToList();
|
||||
|
||||
var totalRecordCount = 0;
|
||||
|
||||
if (!isReturningZeroItems)
|
||||
connection.RunInTransaction(db =>
|
||||
{
|
||||
using (var statement = statements[0])
|
||||
var statements = PrepareAllSafe(db, string.Join(";", statementTexts.ToArray()))
|
||||
.ToList();
|
||||
|
||||
if (!isReturningZeroItems)
|
||||
{
|
||||
if (EnableJoinUserData(query))
|
||||
using (var statement = statements[0])
|
||||
{
|
||||
statement.TryBind("@UserId", query.User.Id);
|
||||
}
|
||||
if (EnableJoinUserData(query))
|
||||
{
|
||||
statement.TryBind("@UserId", query.User.Id);
|
||||
}
|
||||
|
||||
BindSimilarParams(query, statement);
|
||||
BindSimilarParams(query, statement);
|
||||
|
||||
// Running this again will bind the params
|
||||
GetWhereClauses(query, statement);
|
||||
// Running this again will bind the params
|
||||
GetWhereClauses(query, statement);
|
||||
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
{
|
||||
list.Add(row[0].ReadGuid());
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
{
|
||||
list.Add(row[0].ReadGuid());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (query.EnableTotalRecordCount)
|
||||
{
|
||||
using (var statement = statements[statements.Count - 1])
|
||||
if (query.EnableTotalRecordCount)
|
||||
{
|
||||
if (EnableJoinUserData(query))
|
||||
using (var statement = statements[statements.Count - 1])
|
||||
{
|
||||
statement.TryBind("@UserId", query.User.Id);
|
||||
if (EnableJoinUserData(query))
|
||||
{
|
||||
statement.TryBind("@UserId", query.User.Id);
|
||||
}
|
||||
|
||||
BindSimilarParams(query, statement);
|
||||
|
||||
// Running this again will bind the params
|
||||
GetWhereClauses(query, statement);
|
||||
|
||||
totalRecordCount = statement.ExecuteQuery().SelectScalarInt().First();
|
||||
}
|
||||
|
||||
BindSimilarParams(query, statement);
|
||||
|
||||
// Running this again will bind the params
|
||||
GetWhereClauses(query, statement);
|
||||
|
||||
totalRecordCount = statement.ExecuteQuery().SelectScalarInt().First();
|
||||
}
|
||||
}
|
||||
|
||||
}, ReadTransactionMode);
|
||||
|
||||
LogQueryTime("GetItemIds", commandText, now);
|
||||
|
||||
@@ -4426,6 +4429,7 @@ namespace Emby.Server.Implementations.Data
|
||||
typeof(Movie),
|
||||
typeof(Playlist),
|
||||
typeof(AudioPodcast),
|
||||
typeof(AudioBook),
|
||||
typeof(Trailer),
|
||||
typeof(BoxSet),
|
||||
typeof(Episode),
|
||||
@@ -4594,21 +4598,23 @@ namespace Emby.Server.Implementations.Data
|
||||
commandText += " order by ListOrder";
|
||||
|
||||
var list = new List<string>();
|
||||
|
||||
using (WriteLock.Read())
|
||||
{
|
||||
using (var connection = CreateConnection(true))
|
||||
{
|
||||
using (var statement = PrepareStatementSafe(connection, commandText))
|
||||
connection.RunInTransaction(db =>
|
||||
{
|
||||
// Run this again to bind the params
|
||||
GetPeopleWhereClauses(query, statement);
|
||||
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
using (var statement = PrepareStatementSafe(db, commandText))
|
||||
{
|
||||
list.Add(row.GetString(0));
|
||||
// Run this again to bind the params
|
||||
GetPeopleWhereClauses(query, statement);
|
||||
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
{
|
||||
list.Add(row.GetString(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}, ReadTransactionMode);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
@@ -4640,16 +4646,19 @@ namespace Emby.Server.Implementations.Data
|
||||
{
|
||||
using (var connection = CreateConnection(true))
|
||||
{
|
||||
using (var statement = PrepareStatementSafe(connection, commandText))
|
||||
connection.RunInTransaction(db =>
|
||||
{
|
||||
// Run this again to bind the params
|
||||
GetPeopleWhereClauses(query, statement);
|
||||
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
using (var statement = PrepareStatementSafe(db, commandText))
|
||||
{
|
||||
list.Add(GetPerson(row));
|
||||
// Run this again to bind the params
|
||||
GetPeopleWhereClauses(query, statement);
|
||||
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
{
|
||||
list.Add(GetPerson(row));
|
||||
}
|
||||
}
|
||||
}
|
||||
}, ReadTransactionMode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4855,16 +4864,19 @@ namespace Emby.Server.Implementations.Data
|
||||
{
|
||||
using (var connection = CreateConnection(true))
|
||||
{
|
||||
using (var statement = PrepareStatementSafe(connection, commandText))
|
||||
connection.RunInTransaction(db =>
|
||||
{
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
using (var statement = PrepareStatementSafe(db, commandText))
|
||||
{
|
||||
if (!row.IsDBNull(0))
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
{
|
||||
list.Add(row.GetString(0));
|
||||
if (!row.IsDBNull(0))
|
||||
{
|
||||
list.Add(row.GetString(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, ReadTransactionMode);
|
||||
}
|
||||
}
|
||||
LogQueryTime("GetItemValueNames", commandText, now);
|
||||
@@ -5034,69 +5046,72 @@ namespace Emby.Server.Implementations.Data
|
||||
{
|
||||
using (var connection = CreateConnection(true))
|
||||
{
|
||||
var statements = PrepareAllSafe(connection, string.Join(";", statementTexts.ToArray())).ToList();
|
||||
|
||||
if (!isReturningZeroItems)
|
||||
connection.RunInTransaction(db =>
|
||||
{
|
||||
using (var statement = statements[0])
|
||||
var statements = PrepareAllSafe(db, string.Join(";", statementTexts.ToArray())).ToList();
|
||||
|
||||
if (!isReturningZeroItems)
|
||||
{
|
||||
statement.TryBind("@SelectType", returnType);
|
||||
if (EnableJoinUserData(query))
|
||||
using (var statement = statements[0])
|
||||
{
|
||||
statement.TryBind("@UserId", query.User.Id);
|
||||
}
|
||||
|
||||
if (typeSubQuery != null)
|
||||
{
|
||||
GetWhereClauses(typeSubQuery, null, "itemTypes");
|
||||
}
|
||||
BindSimilarParams(query, statement);
|
||||
GetWhereClauses(innerQuery, statement);
|
||||
GetWhereClauses(outerQuery, statement);
|
||||
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
{
|
||||
var item = GetItem(row);
|
||||
if (item != null)
|
||||
statement.TryBind("@SelectType", returnType);
|
||||
if (EnableJoinUserData(query))
|
||||
{
|
||||
var countStartColumn = columns.Count - 1;
|
||||
|
||||
list.Add(new Tuple<BaseItem, ItemCounts>(item, GetItemCounts(row, countStartColumn, typesToCount)));
|
||||
statement.TryBind("@UserId", query.User.Id);
|
||||
}
|
||||
|
||||
if (typeSubQuery != null)
|
||||
{
|
||||
GetWhereClauses(typeSubQuery, null, "itemTypes");
|
||||
}
|
||||
BindSimilarParams(query, statement);
|
||||
GetWhereClauses(innerQuery, statement);
|
||||
GetWhereClauses(outerQuery, statement);
|
||||
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
{
|
||||
var item = GetItem(row);
|
||||
if (item != null)
|
||||
{
|
||||
var countStartColumn = columns.Count - 1;
|
||||
|
||||
list.Add(new Tuple<BaseItem, ItemCounts>(item, GetItemCounts(row, countStartColumn, typesToCount)));
|
||||
}
|
||||
}
|
||||
|
||||
LogQueryTime("GetItemValues", commandText, now);
|
||||
}
|
||||
|
||||
LogQueryTime("GetItemValues", commandText, now);
|
||||
}
|
||||
}
|
||||
|
||||
if (query.EnableTotalRecordCount)
|
||||
{
|
||||
commandText = "select count (distinct PresentationUniqueKey)" + GetFromText();
|
||||
|
||||
commandText += GetJoinUserDataText(query);
|
||||
commandText += whereText;
|
||||
|
||||
using (var statement = statements[statements.Count - 1])
|
||||
if (query.EnableTotalRecordCount)
|
||||
{
|
||||
statement.TryBind("@SelectType", returnType);
|
||||
if (EnableJoinUserData(query))
|
||||
commandText = "select count (distinct PresentationUniqueKey)" + GetFromText();
|
||||
|
||||
commandText += GetJoinUserDataText(query);
|
||||
commandText += whereText;
|
||||
|
||||
using (var statement = statements[statements.Count - 1])
|
||||
{
|
||||
statement.TryBind("@UserId", query.User.Id);
|
||||
statement.TryBind("@SelectType", returnType);
|
||||
if (EnableJoinUserData(query))
|
||||
{
|
||||
statement.TryBind("@UserId", query.User.Id);
|
||||
}
|
||||
|
||||
if (typeSubQuery != null)
|
||||
{
|
||||
GetWhereClauses(typeSubQuery, null, "itemTypes");
|
||||
}
|
||||
BindSimilarParams(query, statement);
|
||||
GetWhereClauses(innerQuery, statement);
|
||||
GetWhereClauses(outerQuery, statement);
|
||||
|
||||
count = statement.ExecuteQuery().SelectScalarInt().First();
|
||||
|
||||
LogQueryTime("GetItemValues", commandText, now);
|
||||
}
|
||||
|
||||
if (typeSubQuery != null)
|
||||
{
|
||||
GetWhereClauses(typeSubQuery, null, "itemTypes");
|
||||
}
|
||||
BindSimilarParams(query, statement);
|
||||
GetWhereClauses(innerQuery, statement);
|
||||
GetWhereClauses(outerQuery, statement);
|
||||
|
||||
count = statement.ExecuteQuery().SelectScalarInt().First();
|
||||
|
||||
LogQueryTime("GetItemValues", commandText, now);
|
||||
}
|
||||
}
|
||||
}, ReadTransactionMode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5344,25 +5359,28 @@ namespace Emby.Server.Implementations.Data
|
||||
{
|
||||
using (var connection = CreateConnection(true))
|
||||
{
|
||||
using (var statement = PrepareStatementSafe(connection, cmdText))
|
||||
connection.RunInTransaction(db =>
|
||||
{
|
||||
statement.TryBind("@ItemId", query.ItemId.ToGuidParamValue());
|
||||
|
||||
if (query.Type.HasValue)
|
||||
using (var statement = PrepareStatementSafe(db, cmdText))
|
||||
{
|
||||
statement.TryBind("@StreamType", query.Type.Value.ToString());
|
||||
}
|
||||
statement.TryBind("@ItemId", query.ItemId.ToGuidParamValue());
|
||||
|
||||
if (query.Index.HasValue)
|
||||
{
|
||||
statement.TryBind("@StreamIndex", query.Index.Value);
|
||||
}
|
||||
if (query.Type.HasValue)
|
||||
{
|
||||
statement.TryBind("@StreamType", query.Type.Value.ToString());
|
||||
}
|
||||
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
{
|
||||
list.Add(GetMediaStream(row));
|
||||
if (query.Index.HasValue)
|
||||
{
|
||||
statement.TryBind("@StreamIndex", query.Index.Value);
|
||||
}
|
||||
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
{
|
||||
list.Add(GetMediaStream(row));
|
||||
}
|
||||
}
|
||||
}
|
||||
}, ReadTransactionMode);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -300,20 +300,26 @@ namespace Emby.Server.Implementations.Data
|
||||
{
|
||||
using (var connection = CreateConnection(true))
|
||||
{
|
||||
using (var statement = connection.PrepareStatement("select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where key =@Key and userId=@UserId"))
|
||||
{
|
||||
statement.TryBind("@UserId", userId.ToGuidParamValue());
|
||||
statement.TryBind("@Key", key);
|
||||
UserItemData result = null;
|
||||
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
connection.RunInTransaction(db =>
|
||||
{
|
||||
using (var statement = db.PrepareStatement("select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where key =@Key and userId=@UserId"))
|
||||
{
|
||||
return ReadRow(row);
|
||||
statement.TryBind("@UserId", userId.ToGuidParamValue());
|
||||
statement.TryBind("@Key", key);
|
||||
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
{
|
||||
result = ReadRow(row);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}, ReadTransactionMode);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public UserItemData GetUserData(Guid userId, List<string> keys)
|
||||
|
||||
@@ -119,6 +119,7 @@
|
||||
<Compile Include="Library\Resolvers\Audio\MusicAlbumResolver.cs" />
|
||||
<Compile Include="Library\Resolvers\Audio\MusicArtistResolver.cs" />
|
||||
<Compile Include="Library\Resolvers\BaseVideoResolver.cs" />
|
||||
<Compile Include="Library\Resolvers\Books\BookResolver.cs" />
|
||||
<Compile Include="Library\Resolvers\FolderResolver.cs" />
|
||||
<Compile Include="Library\Resolvers\ItemResolver.cs" />
|
||||
<Compile Include="Library\Resolvers\Movies\BoxSetResolver.cs" />
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using MediaBrowser.Controller.Resolvers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using System;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
|
||||
namespace Emby.Server.Implementations.Library.Resolvers.Audio
|
||||
{
|
||||
@@ -59,6 +60,11 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio
|
||||
{
|
||||
return new MediaBrowser.Controller.Entities.Audio.Audio();
|
||||
}
|
||||
|
||||
if (string.Equals(collectionType, CollectionType.Books, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return new AudioBook();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Model.Entities;
|
||||
|
||||
namespace Emby.Server.Implementations.Library.Resolvers.Books
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class BookResolver : MediaBrowser.Controller.Resolvers.ItemResolver<Book>
|
||||
{
|
||||
private readonly string[] _validExtensions = {".pdf", ".epub", ".mobi", ".cbr", ".cbz"};
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
/// <returns></returns>
|
||||
protected override Book Resolve(ItemResolveArgs args)
|
||||
{
|
||||
var collectionType = args.GetCollectionType();
|
||||
|
||||
// Only process items that are in a collection folder containing books
|
||||
if (!string.Equals(collectionType, CollectionType.Books, StringComparison.OrdinalIgnoreCase))
|
||||
return null;
|
||||
|
||||
if (args.IsDirectory)
|
||||
{
|
||||
return GetBook(args);
|
||||
}
|
||||
|
||||
var extension = Path.GetExtension(args.Path);
|
||||
|
||||
if (extension != null && _validExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
// It's a book
|
||||
return new Book
|
||||
{
|
||||
Path = args.Path,
|
||||
IsInMixedFolder = true
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="args"></param>
|
||||
/// <returns></returns>
|
||||
private Book GetBook(ItemResolveArgs args)
|
||||
{
|
||||
var bookFiles = args.FileSystemChildren.Where(f =>
|
||||
{
|
||||
var fileExtension = Path.GetExtension(f.FullName) ??
|
||||
string.Empty;
|
||||
|
||||
return _validExtensions.Contains(fileExtension,
|
||||
StringComparer
|
||||
.OrdinalIgnoreCase);
|
||||
}).ToList();
|
||||
|
||||
// Don't return a Book if there is more (or less) than one document in the directory
|
||||
if (bookFiles.Count != 1)
|
||||
return null;
|
||||
|
||||
return new Book
|
||||
{
|
||||
Path = bookFiles[0].FullName
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -274,7 +274,7 @@ namespace Emby.Server.Implementations.Library
|
||||
positionTicks = 0;
|
||||
data.Played = false;
|
||||
}
|
||||
if (item is Audio)
|
||||
if (!item.SupportsPositionTicksResume)
|
||||
{
|
||||
positionTicks = 0;
|
||||
}
|
||||
|
||||
@@ -201,35 +201,47 @@ namespace Emby.Server.Implementations.Security
|
||||
}
|
||||
|
||||
var list = new List<AuthenticationInfo>();
|
||||
int totalRecordCount = 0;
|
||||
|
||||
using (WriteLock.Read())
|
||||
{
|
||||
using (var connection = CreateConnection(true))
|
||||
{
|
||||
using (var statement = connection.PrepareStatement(commandText))
|
||||
connection.RunInTransaction(db =>
|
||||
{
|
||||
BindAuthenticationQueryParams(query, statement);
|
||||
var statementTexts = new List<string>();
|
||||
statementTexts.Add(commandText);
|
||||
statementTexts.Add("select count (Id) from AccessTokens" + whereTextWithoutPaging);
|
||||
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
var statements = PrepareAllSafe(db, string.Join(";", statementTexts.ToArray()))
|
||||
.ToList();
|
||||
|
||||
using (var statement = statements[0])
|
||||
{
|
||||
list.Add(Get(row));
|
||||
}
|
||||
BindAuthenticationQueryParams(query, statement);
|
||||
|
||||
using (var totalCountStatement = connection.PrepareStatement("select count (Id) from AccessTokens" + whereTextWithoutPaging))
|
||||
{
|
||||
BindAuthenticationQueryParams(query, totalCountStatement);
|
||||
|
||||
var count = totalCountStatement.ExecuteQuery()
|
||||
.SelectScalarInt()
|
||||
.First();
|
||||
|
||||
return new QueryResult<AuthenticationInfo>()
|
||||
foreach (var row in statement.ExecuteQuery())
|
||||
{
|
||||
Items = list.ToArray(),
|
||||
TotalRecordCount = count
|
||||
};
|
||||
list.Add(Get(row));
|
||||
}
|
||||
|
||||
using (var totalCountStatement = statements[1])
|
||||
{
|
||||
BindAuthenticationQueryParams(query, totalCountStatement);
|
||||
|
||||
totalRecordCount = totalCountStatement.ExecuteQuery()
|
||||
.SelectScalarInt()
|
||||
.First();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}, ReadTransactionMode);
|
||||
|
||||
return new QueryResult<AuthenticationInfo>()
|
||||
{
|
||||
Items = list.ToArray(),
|
||||
TotalRecordCount = totalRecordCount
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,14 @@ namespace Emby.Server.Implementations.TV
|
||||
PresentationUniqueKey = presentationUniqueKey,
|
||||
Limit = limit,
|
||||
ParentId = parentIdGuid,
|
||||
Recursive = true
|
||||
Recursive = true,
|
||||
DtoOptions = new MediaBrowser.Controller.Dto.DtoOptions
|
||||
{
|
||||
Fields = new List<ItemFields>
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}).Cast<Series>();
|
||||
|
||||
@@ -104,7 +111,15 @@ namespace Emby.Server.Implementations.TV
|
||||
IncludeItemTypes = new[] { typeof(Series).Name },
|
||||
SortOrder = SortOrder.Ascending,
|
||||
PresentationUniqueKey = presentationUniqueKey,
|
||||
Limit = limit
|
||||
Limit = limit,
|
||||
DtoOptions = new MediaBrowser.Controller.Dto.DtoOptions
|
||||
{
|
||||
Fields = new List<ItemFields>
|
||||
{
|
||||
|
||||
},
|
||||
EnableImages = false
|
||||
}
|
||||
|
||||
}, parentsFolders.Cast<BaseItem>().ToList()).Cast<Series>();
|
||||
|
||||
@@ -120,26 +135,32 @@ namespace Emby.Server.Implementations.TV
|
||||
var currentUser = user;
|
||||
|
||||
var allNextUp = series
|
||||
.Select(i => GetNextUp(i, currentUser))
|
||||
.Select(i => GetNextUp(GetUniqueSeriesKey(i), currentUser))
|
||||
// Include if an episode was found, and either the series is not unwatched or the specific series was requested
|
||||
.OrderByDescending(i => i.Item1)
|
||||
.ToList();
|
||||
.OrderByDescending(i => i.Item1);
|
||||
|
||||
// If viewing all next up for all series, remove first episodes
|
||||
if (string.IsNullOrWhiteSpace(request.SeriesId))
|
||||
{
|
||||
var withoutFirstEpisode = allNextUp
|
||||
.Where(i => i.Item1 != DateTime.MinValue)
|
||||
.ToList();
|
||||
|
||||
// But if that returns empty, keep those first episodes (avoid completely empty view)
|
||||
if (withoutFirstEpisode.Count > 0)
|
||||
{
|
||||
allNextUp = withoutFirstEpisode;
|
||||
}
|
||||
}
|
||||
// But if that returns empty, keep those first episodes (avoid completely empty view)
|
||||
var alwaysEnableFirstEpisode = string.IsNullOrWhiteSpace(request.SeriesId);
|
||||
var isFirstItemAFirstEpisode = true;
|
||||
|
||||
return allNextUp
|
||||
.Where(i =>
|
||||
{
|
||||
if (alwaysEnableFirstEpisode || i.Item1 != DateTime.MinValue)
|
||||
{
|
||||
isFirstItemAFirstEpisode = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isFirstItemAFirstEpisode)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
})
|
||||
.Take(request.Limit.HasValue ? (request.Limit.Value * 2) : int.MaxValue)
|
||||
.Select(i => i.Item2())
|
||||
.Where(i => i != null)
|
||||
.Take(request.Limit ?? int.MaxValue);
|
||||
@@ -153,13 +174,10 @@ namespace Emby.Server.Implementations.TV
|
||||
/// <summary>
|
||||
/// Gets the next up.
|
||||
/// </summary>
|
||||
/// <param name="series">The series.</param>
|
||||
/// <param name="user">The user.</param>
|
||||
/// <returns>Task{Episode}.</returns>
|
||||
private Tuple<DateTime, Func<Episode>> GetNextUp(Series series, User user)
|
||||
private Tuple<DateTime, Func<Episode>> GetNextUp(string seriesKey, User user)
|
||||
{
|
||||
var enableSeriesPresentationKey = _config.Configuration.EnableSeriesPresentationUniqueKey;
|
||||
var seriesKey = GetUniqueSeriesKey(series);
|
||||
|
||||
var lastWatchedEpisode = _libraryManager.GetItemList(new InternalItemsQuery(user)
|
||||
{
|
||||
@@ -170,7 +188,15 @@ namespace Emby.Server.Implementations.TV
|
||||
SortOrder = SortOrder.Descending,
|
||||
IsPlayed = true,
|
||||
Limit = 1,
|
||||
ParentIndexNumberNotEquals = 0
|
||||
ParentIndexNumberNotEquals = 0,
|
||||
DtoOptions = new MediaBrowser.Controller.Dto.DtoOptions
|
||||
{
|
||||
Fields = new List<ItemFields>
|
||||
{
|
||||
|
||||
},
|
||||
EnableImages = false
|
||||
}
|
||||
|
||||
}).FirstOrDefault();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user