| | 1 | | #pragma warning disable RS0030 // Do not use banned APIs |
| | 2 | | // Do not enforce that because EFCore cannot deal with cultures well. |
| | 3 | | #pragma warning disable CA1304 // Specify CultureInfo |
| | 4 | | #pragma warning disable CA1311 // Specify a culture or use an invariant version |
| | 5 | | #pragma warning disable CA1862 // Use the 'StringComparison' method overloads to perform case-insensitive string compari |
| | 6 | |
|
| | 7 | | using System; |
| | 8 | | using System.Collections.Concurrent; |
| | 9 | | using System.Collections.Generic; |
| | 10 | | using System.Globalization; |
| | 11 | | using System.Linq; |
| | 12 | | using System.Linq.Expressions; |
| | 13 | | using System.Reflection; |
| | 14 | | using System.Text; |
| | 15 | | using System.Text.Json; |
| | 16 | | using System.Threading; |
| | 17 | | using System.Threading.Tasks; |
| | 18 | | using Jellyfin.Data.Enums; |
| | 19 | | using Jellyfin.Database.Implementations; |
| | 20 | | using Jellyfin.Database.Implementations.Entities; |
| | 21 | | using Jellyfin.Database.Implementations.Enums; |
| | 22 | | using Jellyfin.Extensions; |
| | 23 | | using Jellyfin.Extensions.Json; |
| | 24 | | using Jellyfin.Server.Implementations.Extensions; |
| | 25 | | using MediaBrowser.Common; |
| | 26 | | using MediaBrowser.Controller; |
| | 27 | | using MediaBrowser.Controller.Channels; |
| | 28 | | using MediaBrowser.Controller.Configuration; |
| | 29 | | using MediaBrowser.Controller.Entities; |
| | 30 | | using MediaBrowser.Controller.Entities.Audio; |
| | 31 | | using MediaBrowser.Controller.Entities.TV; |
| | 32 | | using MediaBrowser.Controller.LiveTv; |
| | 33 | | using MediaBrowser.Controller.Persistence; |
| | 34 | | using MediaBrowser.Model.Dto; |
| | 35 | | using MediaBrowser.Model.Entities; |
| | 36 | | using MediaBrowser.Model.LiveTv; |
| | 37 | | using MediaBrowser.Model.Querying; |
| | 38 | | using Microsoft.EntityFrameworkCore; |
| | 39 | | using Microsoft.Extensions.Logging; |
| | 40 | | using BaseItemDto = MediaBrowser.Controller.Entities.BaseItem; |
| | 41 | | using BaseItemEntity = Jellyfin.Database.Implementations.Entities.BaseItemEntity; |
| | 42 | |
|
| | 43 | | namespace Jellyfin.Server.Implementations.Item; |
| | 44 | |
|
| | 45 | | /* |
| | 46 | | All queries in this class and all other nullable enabled EFCore repository classes will make liberal use of the null |
| | 47 | | This is done as the code isn't actually executed client side, but only the expressions are interpret and the compile |
| | 48 | | This is your only warning/message regarding this topic. |
| | 49 | | */ |
| | 50 | |
|
| | 51 | | /// <summary> |
| | 52 | | /// Handles all storage logic for BaseItems. |
| | 53 | | /// </summary> |
| | 54 | | public sealed class BaseItemRepository |
| | 55 | | : IItemRepository |
| | 56 | | { |
| | 57 | | /// <summary> |
| | 58 | | /// Gets the placeholder id for UserData detached items. |
| | 59 | | /// </summary> |
| 1 | 60 | | public static readonly Guid PlaceholderId = Guid.Parse("00000000-0000-0000-0000-000000000001"); |
| | 61 | |
|
| | 62 | | /// <summary> |
| | 63 | | /// This holds all the types in the running assemblies |
| | 64 | | /// so that we can de-serialize properly when we don't have strong types. |
| | 65 | | /// </summary> |
| 1 | 66 | | private static readonly ConcurrentDictionary<string, Type?> _typeMap = new ConcurrentDictionary<string, Type?>(); |
| | 67 | | private readonly IDbContextFactory<JellyfinDbContext> _dbProvider; |
| | 68 | | private readonly IServerApplicationHost _appHost; |
| | 69 | | private readonly IItemTypeLookup _itemTypeLookup; |
| | 70 | | private readonly IServerConfigurationManager _serverConfigurationManager; |
| | 71 | | private readonly ILogger<BaseItemRepository> _logger; |
| | 72 | |
|
| 1 | 73 | | private static readonly IReadOnlyList<ItemValueType> _getAllArtistsValueTypes = [ItemValueType.Artist, ItemValueType |
| 1 | 74 | | private static readonly IReadOnlyList<ItemValueType> _getArtistValueTypes = [ItemValueType.Artist]; |
| 1 | 75 | | private static readonly IReadOnlyList<ItemValueType> _getAlbumArtistValueTypes = [ItemValueType.AlbumArtist]; |
| 1 | 76 | | private static readonly IReadOnlyList<ItemValueType> _getStudiosValueTypes = [ItemValueType.Studios]; |
| 1 | 77 | | private static readonly IReadOnlyList<ItemValueType> _getGenreValueTypes = [ItemValueType.Genre]; |
| | 78 | |
|
| | 79 | | /// <summary> |
| | 80 | | /// Initializes a new instance of the <see cref="BaseItemRepository"/> class. |
| | 81 | | /// </summary> |
| | 82 | | /// <param name="dbProvider">The db factory.</param> |
| | 83 | | /// <param name="appHost">The Application host.</param> |
| | 84 | | /// <param name="itemTypeLookup">The static type lookup.</param> |
| | 85 | | /// <param name="serverConfigurationManager">The server Configuration manager.</param> |
| | 86 | | /// <param name="logger">System logger.</param> |
| | 87 | | public BaseItemRepository( |
| | 88 | | IDbContextFactory<JellyfinDbContext> dbProvider, |
| | 89 | | IServerApplicationHost appHost, |
| | 90 | | IItemTypeLookup itemTypeLookup, |
| | 91 | | IServerConfigurationManager serverConfigurationManager, |
| | 92 | | ILogger<BaseItemRepository> logger) |
| | 93 | | { |
| 21 | 94 | | _dbProvider = dbProvider; |
| 21 | 95 | | _appHost = appHost; |
| 21 | 96 | | _itemTypeLookup = itemTypeLookup; |
| 21 | 97 | | _serverConfigurationManager = serverConfigurationManager; |
| 21 | 98 | | _logger = logger; |
| 21 | 99 | | } |
| | 100 | |
|
| | 101 | | /// <inheritdoc /> |
| | 102 | | public void DeleteItem(Guid id) |
| | 103 | | { |
| 3 | 104 | | if (id.IsEmpty() || id.Equals(PlaceholderId)) |
| | 105 | | { |
| 0 | 106 | | throw new ArgumentException("Guid can't be empty or the placeholder id.", nameof(id)); |
| | 107 | | } |
| | 108 | |
|
| 3 | 109 | | using var context = _dbProvider.CreateDbContext(); |
| 3 | 110 | | using var transaction = context.Database.BeginTransaction(); |
| | 111 | |
|
| 3 | 112 | | var date = (DateTime?)DateTime.UtcNow; |
| | 113 | |
|
| | 114 | | // Remove any UserData entries for the placeholder item that would conflict with the UserData |
| | 115 | | // being detached from the item being deleted. This is necessary because, during an update, |
| | 116 | | // UserData may be reattached to a new entry, but some entries can be left behind. |
| | 117 | | // Ensures there are no duplicate UserId/CustomDataKey combinations for the placeholder. |
| 3 | 118 | | context.UserData |
| 3 | 119 | | .Join( |
| 3 | 120 | | context.UserData.Where(e => e.ItemId == id), |
| 3 | 121 | | placeholder => new { placeholder.UserId, placeholder.CustomDataKey }, |
| 3 | 122 | | userData => new { userData.UserId, userData.CustomDataKey }, |
| 3 | 123 | | (placeholder, userData) => placeholder) |
| 3 | 124 | | .Where(e => e.ItemId == PlaceholderId) |
| 3 | 125 | | .ExecuteDelete(); |
| | 126 | |
|
| | 127 | | // Detach all user watch data |
| 3 | 128 | | context.UserData.Where(e => e.ItemId == id) |
| 3 | 129 | | .ExecuteUpdate(e => e |
| 3 | 130 | | .SetProperty(f => f.RetentionDate, date) |
| 3 | 131 | | .SetProperty(f => f.ItemId, PlaceholderId)); |
| | 132 | |
|
| 3 | 133 | | context.AncestorIds.Where(e => e.ItemId == id || e.ParentItemId == id).ExecuteDelete(); |
| 3 | 134 | | context.AttachmentStreamInfos.Where(e => e.ItemId == id).ExecuteDelete(); |
| 3 | 135 | | context.BaseItemImageInfos.Where(e => e.ItemId == id).ExecuteDelete(); |
| 3 | 136 | | context.BaseItemMetadataFields.Where(e => e.ItemId == id).ExecuteDelete(); |
| 3 | 137 | | context.BaseItemProviders.Where(e => e.ItemId == id).ExecuteDelete(); |
| 3 | 138 | | context.BaseItemTrailerTypes.Where(e => e.ItemId == id).ExecuteDelete(); |
| 3 | 139 | | context.BaseItems.Where(e => e.Id == id).ExecuteDelete(); |
| 3 | 140 | | context.Chapters.Where(e => e.ItemId == id).ExecuteDelete(); |
| 3 | 141 | | context.CustomItemDisplayPreferences.Where(e => e.ItemId == id).ExecuteDelete(); |
| 3 | 142 | | context.ItemDisplayPreferences.Where(e => e.ItemId == id).ExecuteDelete(); |
| 3 | 143 | | context.ItemValues.Where(e => e.BaseItemsMap!.Count == 0).ExecuteDelete(); |
| 3 | 144 | | context.ItemValuesMap.Where(e => e.ItemId == id).ExecuteDelete(); |
| 3 | 145 | | context.KeyframeData.Where(e => e.ItemId == id).ExecuteDelete(); |
| 3 | 146 | | context.MediaSegments.Where(e => e.ItemId == id).ExecuteDelete(); |
| 3 | 147 | | context.MediaStreamInfos.Where(e => e.ItemId == id).ExecuteDelete(); |
| 3 | 148 | | context.PeopleBaseItemMap.Where(e => e.ItemId == id).ExecuteDelete(); |
| 3 | 149 | | context.Peoples.Where(e => e.BaseItems!.Count == 0).ExecuteDelete(); |
| 3 | 150 | | context.TrickplayInfos.Where(e => e.ItemId == id).ExecuteDelete(); |
| 3 | 151 | | context.SaveChanges(); |
| 3 | 152 | | transaction.Commit(); |
| 6 | 153 | | } |
| | 154 | |
|
| | 155 | | /// <inheritdoc /> |
| | 156 | | public void UpdateInheritedValues() |
| | 157 | | { |
| 9 | 158 | | using var context = _dbProvider.CreateDbContext(); |
| 9 | 159 | | using var transaction = context.Database.BeginTransaction(); |
| | 160 | |
|
| 9 | 161 | | context.ItemValuesMap.Where(e => e.ItemValue.Type == ItemValueType.InheritedTags).ExecuteDelete(); |
| | 162 | | // ItemValue Inheritance is now correctly mapped via AncestorId on demand |
| 9 | 163 | | context.SaveChanges(); |
| | 164 | |
|
| 9 | 165 | | transaction.Commit(); |
| 18 | 166 | | } |
| | 167 | |
|
| | 168 | | /// <inheritdoc /> |
| | 169 | | public IReadOnlyList<Guid> GetItemIdsList(InternalItemsQuery filter) |
| | 170 | | { |
| 9 | 171 | | ArgumentNullException.ThrowIfNull(filter); |
| 9 | 172 | | PrepareFilterQuery(filter); |
| | 173 | |
|
| 9 | 174 | | using var context = _dbProvider.CreateDbContext(); |
| 9 | 175 | | return ApplyQueryFilter(context.BaseItems.AsNoTracking().Where(e => e.Id != EF.Constant(PlaceholderId)), context |
| 9 | 176 | | } |
| | 177 | |
|
| | 178 | | /// <inheritdoc /> |
| | 179 | | public QueryResult<(BaseItemDto Item, ItemCounts? ItemCounts)> GetAllArtists(InternalItemsQuery filter) |
| | 180 | | { |
| 0 | 181 | | return GetItemValues(filter, _getAllArtistsValueTypes, _itemTypeLookup.BaseItemKindNames[BaseItemKind.MusicArtis |
| | 182 | | } |
| | 183 | |
|
| | 184 | | /// <inheritdoc /> |
| | 185 | | public QueryResult<(BaseItemDto Item, ItemCounts? ItemCounts)> GetArtists(InternalItemsQuery filter) |
| | 186 | | { |
| 0 | 187 | | return GetItemValues(filter, _getArtistValueTypes, _itemTypeLookup.BaseItemKindNames[BaseItemKind.MusicArtist]); |
| | 188 | | } |
| | 189 | |
|
| | 190 | | /// <inheritdoc /> |
| | 191 | | public QueryResult<(BaseItemDto Item, ItemCounts? ItemCounts)> GetAlbumArtists(InternalItemsQuery filter) |
| | 192 | | { |
| 0 | 193 | | return GetItemValues(filter, _getAlbumArtistValueTypes, _itemTypeLookup.BaseItemKindNames[BaseItemKind.MusicArti |
| | 194 | | } |
| | 195 | |
|
| | 196 | | /// <inheritdoc /> |
| | 197 | | public QueryResult<(BaseItemDto Item, ItemCounts? ItemCounts)> GetStudios(InternalItemsQuery filter) |
| | 198 | | { |
| 0 | 199 | | return GetItemValues(filter, _getStudiosValueTypes, _itemTypeLookup.BaseItemKindNames[BaseItemKind.Studio]); |
| | 200 | | } |
| | 201 | |
|
| | 202 | | /// <inheritdoc /> |
| | 203 | | public QueryResult<(BaseItemDto Item, ItemCounts? ItemCounts)> GetGenres(InternalItemsQuery filter) |
| | 204 | | { |
| 0 | 205 | | return GetItemValues(filter, _getGenreValueTypes, _itemTypeLookup.BaseItemKindNames[BaseItemKind.Genre]); |
| | 206 | | } |
| | 207 | |
|
| | 208 | | /// <inheritdoc /> |
| | 209 | | public QueryResult<(BaseItemDto Item, ItemCounts? ItemCounts)> GetMusicGenres(InternalItemsQuery filter) |
| | 210 | | { |
| 0 | 211 | | return GetItemValues(filter, _getGenreValueTypes, _itemTypeLookup.BaseItemKindNames[BaseItemKind.MusicGenre]); |
| | 212 | | } |
| | 213 | |
|
| | 214 | | /// <inheritdoc /> |
| | 215 | | public IReadOnlyList<string> GetStudioNames() |
| | 216 | | { |
| 9 | 217 | | return GetItemValueNames(_getStudiosValueTypes, [], []); |
| | 218 | | } |
| | 219 | |
|
| | 220 | | /// <inheritdoc /> |
| | 221 | | public IReadOnlyList<string> GetAllArtistNames() |
| | 222 | | { |
| 9 | 223 | | return GetItemValueNames(_getAllArtistsValueTypes, [], []); |
| | 224 | | } |
| | 225 | |
|
| | 226 | | /// <inheritdoc /> |
| | 227 | | public IReadOnlyList<string> GetMusicGenreNames() |
| | 228 | | { |
| 9 | 229 | | return GetItemValueNames( |
| 9 | 230 | | _getGenreValueTypes, |
| 9 | 231 | | _itemTypeLookup.MusicGenreTypes, |
| 9 | 232 | | []); |
| | 233 | | } |
| | 234 | |
|
| | 235 | | /// <inheritdoc /> |
| | 236 | | public IReadOnlyList<string> GetGenreNames() |
| | 237 | | { |
| 9 | 238 | | return GetItemValueNames( |
| 9 | 239 | | _getGenreValueTypes, |
| 9 | 240 | | [], |
| 9 | 241 | | _itemTypeLookup.MusicGenreTypes); |
| | 242 | | } |
| | 243 | |
|
| | 244 | | /// <inheritdoc /> |
| | 245 | | public QueryResult<BaseItemDto> GetItems(InternalItemsQuery filter) |
| | 246 | | { |
| 1 | 247 | | ArgumentNullException.ThrowIfNull(filter); |
| 1 | 248 | | if (!filter.EnableTotalRecordCount || (!filter.Limit.HasValue && (filter.StartIndex ?? 0) == 0)) |
| | 249 | | { |
| 1 | 250 | | var returnList = GetItemList(filter); |
| 1 | 251 | | return new QueryResult<BaseItemDto>( |
| 1 | 252 | | filter.StartIndex, |
| 1 | 253 | | returnList.Count, |
| 1 | 254 | | returnList); |
| | 255 | | } |
| | 256 | |
|
| 0 | 257 | | PrepareFilterQuery(filter); |
| 0 | 258 | | var result = new QueryResult<BaseItemDto>(); |
| | 259 | |
|
| 0 | 260 | | using var context = _dbProvider.CreateDbContext(); |
| | 261 | |
|
| 0 | 262 | | IQueryable<BaseItemEntity> dbQuery = PrepareItemQuery(context, filter); |
| | 263 | |
|
| 0 | 264 | | dbQuery = TranslateQuery(dbQuery, context, filter); |
| 0 | 265 | | if (filter.EnableTotalRecordCount) |
| | 266 | | { |
| 0 | 267 | | result.TotalRecordCount = dbQuery.Count(); |
| | 268 | | } |
| | 269 | |
|
| 0 | 270 | | dbQuery = ApplyGroupingFilter(dbQuery, filter); |
| 0 | 271 | | dbQuery = ApplyQueryPaging(dbQuery, filter); |
| | 272 | |
|
| 0 | 273 | | result.Items = dbQuery.AsEnumerable().Where(e => e is not null).Select(w => DeserializeBaseItem(w, filter.SkipDe |
| 0 | 274 | | result.StartIndex = filter.StartIndex ?? 0; |
| 0 | 275 | | return result; |
| 0 | 276 | | } |
| | 277 | |
|
| | 278 | | /// <inheritdoc /> |
| | 279 | | public IReadOnlyList<BaseItemDto> GetItemList(InternalItemsQuery filter) |
| | 280 | | { |
| 273 | 281 | | ArgumentNullException.ThrowIfNull(filter); |
| 273 | 282 | | PrepareFilterQuery(filter); |
| | 283 | |
|
| 273 | 284 | | using var context = _dbProvider.CreateDbContext(); |
| 272 | 285 | | IQueryable<BaseItemEntity> dbQuery = PrepareItemQuery(context, filter); |
| | 286 | |
|
| 272 | 287 | | dbQuery = TranslateQuery(dbQuery, context, filter); |
| | 288 | |
|
| 272 | 289 | | dbQuery = ApplyGroupingFilter(dbQuery, filter); |
| 272 | 290 | | dbQuery = ApplyQueryPaging(dbQuery, filter); |
| | 291 | |
|
| 272 | 292 | | return dbQuery.AsEnumerable().Where(e => e is not null).Select(w => DeserializeBaseItem(w, filter.SkipDeserializ |
| 272 | 293 | | } |
| | 294 | |
|
| | 295 | | /// <inheritdoc/> |
| | 296 | | public IReadOnlyList<BaseItem> GetLatestItemList(InternalItemsQuery filter, CollectionType collectionType) |
| | 297 | | { |
| 0 | 298 | | ArgumentNullException.ThrowIfNull(filter); |
| 0 | 299 | | PrepareFilterQuery(filter); |
| | 300 | |
|
| | 301 | | // Early exit if collection type is not tvshows or music |
| 0 | 302 | | if (collectionType != CollectionType.tvshows && collectionType != CollectionType.music) |
| | 303 | | { |
| 0 | 304 | | return Array.Empty<BaseItem>(); |
| | 305 | | } |
| | 306 | |
|
| 0 | 307 | | using var context = _dbProvider.CreateDbContext(); |
| | 308 | |
|
| | 309 | | // Subquery to group by SeriesNames/Album and get the max Date Created for each group. |
| 0 | 310 | | var subquery = PrepareItemQuery(context, filter); |
| 0 | 311 | | subquery = TranslateQuery(subquery, context, filter); |
| 0 | 312 | | var subqueryGrouped = subquery.GroupBy(g => collectionType == CollectionType.tvshows ? g.SeriesName : g.Album) |
| 0 | 313 | | .Select(g => new |
| 0 | 314 | | { |
| 0 | 315 | | Key = g.Key, |
| 0 | 316 | | MaxDateCreated = g.Max(a => a.DateCreated) |
| 0 | 317 | | }) |
| 0 | 318 | | .OrderByDescending(g => g.MaxDateCreated) |
| 0 | 319 | | .Select(g => g); |
| | 320 | |
|
| 0 | 321 | | if (filter.Limit.HasValue) |
| | 322 | | { |
| 0 | 323 | | subqueryGrouped = subqueryGrouped.Take(filter.Limit.Value); |
| | 324 | | } |
| | 325 | |
|
| 0 | 326 | | filter.Limit = null; |
| | 327 | |
|
| 0 | 328 | | var mainquery = PrepareItemQuery(context, filter); |
| 0 | 329 | | mainquery = TranslateQuery(mainquery, context, filter); |
| 0 | 330 | | mainquery = mainquery.Where(g => g.DateCreated >= subqueryGrouped.Min(s => s.MaxDateCreated)); |
| 0 | 331 | | mainquery = ApplyGroupingFilter(mainquery, filter); |
| 0 | 332 | | mainquery = ApplyQueryPaging(mainquery, filter); |
| | 333 | |
|
| 0 | 334 | | return mainquery.AsEnumerable().Where(e => e is not null).Select(w => DeserializeBaseItem(w, filter.SkipDeserial |
| 0 | 335 | | } |
| | 336 | |
|
| | 337 | | /// <inheritdoc /> |
| | 338 | | public IReadOnlyList<string> GetNextUpSeriesKeys(InternalItemsQuery filter, DateTime dateCutoff) |
| | 339 | | { |
| 0 | 340 | | ArgumentNullException.ThrowIfNull(filter); |
| 0 | 341 | | ArgumentNullException.ThrowIfNull(filter.User); |
| | 342 | |
|
| 0 | 343 | | using var context = _dbProvider.CreateDbContext(); |
| | 344 | |
|
| 0 | 345 | | var query = context.BaseItems |
| 0 | 346 | | .AsNoTracking() |
| 0 | 347 | | .Where(i => filter.TopParentIds.Contains(i.TopParentId!.Value)) |
| 0 | 348 | | .Where(i => i.Type == _itemTypeLookup.BaseItemKindNames[BaseItemKind.Episode]) |
| 0 | 349 | | .Join( |
| 0 | 350 | | context.UserData.AsNoTracking().Where(e => e.ItemId != EF.Constant(PlaceholderId)), |
| 0 | 351 | | i => new { UserId = filter.User.Id, ItemId = i.Id }, |
| 0 | 352 | | u => new { UserId = u.UserId, ItemId = u.ItemId }, |
| 0 | 353 | | (entity, data) => new { Item = entity, UserData = data }) |
| 0 | 354 | | .GroupBy(g => g.Item.SeriesPresentationUniqueKey) |
| 0 | 355 | | .Select(g => new { g.Key, LastPlayedDate = g.Max(u => u.UserData.LastPlayedDate) }) |
| 0 | 356 | | .Where(g => g.Key != null && g.LastPlayedDate != null && g.LastPlayedDate >= dateCutoff) |
| 0 | 357 | | .OrderByDescending(g => g.LastPlayedDate) |
| 0 | 358 | | .Select(g => g.Key!); |
| | 359 | |
|
| 0 | 360 | | if (filter.Limit.HasValue) |
| | 361 | | { |
| 0 | 362 | | query = query.Take(filter.Limit.Value); |
| | 363 | | } |
| | 364 | |
|
| 0 | 365 | | return query.ToArray(); |
| 0 | 366 | | } |
| | 367 | |
|
| | 368 | | private IQueryable<BaseItemEntity> ApplyGroupingFilter(IQueryable<BaseItemEntity> dbQuery, InternalItemsQuery filter |
| | 369 | | { |
| | 370 | | // This whole block is needed to filter duplicate entries on request |
| | 371 | | // for the time being it cannot be used because it would destroy the ordering |
| | 372 | | // this results in "duplicate" responses for queries that try to lookup individual series or multiple versions b |
| | 373 | | // for that case the invoker has to run a DistinctBy(e => e.PresentationUniqueKey) on their own |
| | 374 | |
|
| | 375 | | // var enableGroupByPresentationUniqueKey = EnableGroupByPresentationUniqueKey(filter); |
| | 376 | | // if (enableGroupByPresentationUniqueKey && filter.GroupBySeriesPresentationUniqueKey) |
| | 377 | | // { |
| | 378 | | // dbQuery = ApplyOrder(dbQuery, filter); |
| | 379 | | // dbQuery = dbQuery.GroupBy(e => new { e.PresentationUniqueKey, e.SeriesPresentationUniqueKey }).Select(e = |
| | 380 | | // } |
| | 381 | | // else if (enableGroupByPresentationUniqueKey) |
| | 382 | | // { |
| | 383 | | // dbQuery = ApplyOrder(dbQuery, filter); |
| | 384 | | // dbQuery = dbQuery.GroupBy(e => e.PresentationUniqueKey).Select(e => e.First()); |
| | 385 | | // } |
| | 386 | | // else if (filter.GroupBySeriesPresentationUniqueKey) |
| | 387 | | // { |
| | 388 | | // dbQuery = ApplyOrder(dbQuery, filter); |
| | 389 | | // dbQuery = dbQuery.GroupBy(e => e.SeriesPresentationUniqueKey).Select(e => e.First()); |
| | 390 | | // } |
| | 391 | | // else |
| | 392 | | // { |
| | 393 | | // dbQuery = dbQuery.Distinct(); |
| | 394 | | // dbQuery = ApplyOrder(dbQuery, filter); |
| | 395 | | // } |
| 281 | 396 | | dbQuery = dbQuery.Distinct(); |
| 281 | 397 | | dbQuery = ApplyOrder(dbQuery, filter); |
| | 398 | |
|
| 281 | 399 | | return dbQuery; |
| | 400 | | } |
| | 401 | |
|
| | 402 | | private IQueryable<BaseItemEntity> ApplyQueryPaging(IQueryable<BaseItemEntity> dbQuery, InternalItemsQuery filter) |
| | 403 | | { |
| 281 | 404 | | if (filter.Limit.HasValue || filter.StartIndex.HasValue) |
| | 405 | | { |
| 80 | 406 | | var offset = filter.StartIndex ?? 0; |
| | 407 | |
|
| 80 | 408 | | if (offset > 0) |
| | 409 | | { |
| 0 | 410 | | dbQuery = dbQuery.Skip(offset); |
| | 411 | | } |
| | 412 | |
|
| 80 | 413 | | if (filter.Limit.HasValue) |
| | 414 | | { |
| 80 | 415 | | dbQuery = dbQuery.Take(filter.Limit.Value); |
| | 416 | | } |
| | 417 | | } |
| | 418 | |
|
| 281 | 419 | | return dbQuery; |
| | 420 | | } |
| | 421 | |
|
| | 422 | | private IQueryable<BaseItemEntity> ApplyQueryFilter(IQueryable<BaseItemEntity> dbQuery, JellyfinDbContext context, I |
| | 423 | | { |
| 9 | 424 | | dbQuery = TranslateQuery(dbQuery, context, filter); |
| 9 | 425 | | dbQuery = ApplyOrder(dbQuery, filter); |
| 9 | 426 | | dbQuery = ApplyGroupingFilter(dbQuery, filter); |
| 9 | 427 | | dbQuery = ApplyQueryPaging(dbQuery, filter); |
| 9 | 428 | | return dbQuery; |
| | 429 | | } |
| | 430 | |
|
| | 431 | | private IQueryable<BaseItemEntity> PrepareItemQuery(JellyfinDbContext context, InternalItemsQuery filter) |
| | 432 | | { |
| 488 | 433 | | IQueryable<BaseItemEntity> dbQuery = context.BaseItems.AsNoTracking(); |
| 488 | 434 | | dbQuery = dbQuery.AsSingleQuery() |
| 488 | 435 | | .Include(e => e.TrailerTypes) |
| 488 | 436 | | .Include(e => e.Provider) |
| 488 | 437 | | .Include(e => e.LockedFields); |
| | 438 | |
|
| 488 | 439 | | if (filter.DtoOptions.EnableImages) |
| | 440 | | { |
| 488 | 441 | | dbQuery = dbQuery.Include(e => e.Images); |
| | 442 | | } |
| | 443 | |
|
| 488 | 444 | | return dbQuery; |
| | 445 | | } |
| | 446 | |
|
| | 447 | | /// <inheritdoc/> |
| | 448 | | public int GetCount(InternalItemsQuery filter) |
| | 449 | | { |
| 0 | 450 | | ArgumentNullException.ThrowIfNull(filter); |
| | 451 | | // Hack for right now since we currently don't support filtering out these duplicates within a query |
| 0 | 452 | | PrepareFilterQuery(filter); |
| | 453 | |
|
| 0 | 454 | | using var context = _dbProvider.CreateDbContext(); |
| 0 | 455 | | var dbQuery = TranslateQuery(context.BaseItems.AsNoTracking(), context, filter); |
| | 456 | |
|
| 0 | 457 | | return dbQuery.Count(); |
| 0 | 458 | | } |
| | 459 | |
|
| | 460 | | /// <inheritdoc /> |
| | 461 | | public ItemCounts GetItemCounts(InternalItemsQuery filter) |
| | 462 | | { |
| 0 | 463 | | ArgumentNullException.ThrowIfNull(filter); |
| | 464 | | // Hack for right now since we currently don't support filtering out these duplicates within a query |
| 0 | 465 | | PrepareFilterQuery(filter); |
| | 466 | |
|
| 0 | 467 | | using var context = _dbProvider.CreateDbContext(); |
| 0 | 468 | | var dbQuery = TranslateQuery(context.BaseItems.AsNoTracking(), context, filter); |
| | 469 | |
|
| 0 | 470 | | var counts = dbQuery |
| 0 | 471 | | .GroupBy(x => x.Type) |
| 0 | 472 | | .Select(x => new { x.Key, Count = x.Count() }) |
| 0 | 473 | | .AsEnumerable(); |
| | 474 | |
|
| 0 | 475 | | var lookup = _itemTypeLookup.BaseItemKindNames; |
| 0 | 476 | | var result = new ItemCounts(); |
| 0 | 477 | | foreach (var count in counts) |
| | 478 | | { |
| 0 | 479 | | if (string.Equals(count.Key, lookup[BaseItemKind.MusicAlbum], StringComparison.Ordinal)) |
| | 480 | | { |
| 0 | 481 | | result.AlbumCount = count.Count; |
| | 482 | | } |
| 0 | 483 | | else if (string.Equals(count.Key, lookup[BaseItemKind.MusicArtist], StringComparison.Ordinal)) |
| | 484 | | { |
| 0 | 485 | | result.ArtistCount = count.Count; |
| | 486 | | } |
| 0 | 487 | | else if (string.Equals(count.Key, lookup[BaseItemKind.Episode], StringComparison.Ordinal)) |
| | 488 | | { |
| 0 | 489 | | result.EpisodeCount = count.Count; |
| | 490 | | } |
| 0 | 491 | | else if (string.Equals(count.Key, lookup[BaseItemKind.Movie], StringComparison.Ordinal)) |
| | 492 | | { |
| 0 | 493 | | result.MovieCount = count.Count; |
| | 494 | | } |
| 0 | 495 | | else if (string.Equals(count.Key, lookup[BaseItemKind.MusicVideo], StringComparison.Ordinal)) |
| | 496 | | { |
| 0 | 497 | | result.MusicVideoCount = count.Count; |
| | 498 | | } |
| 0 | 499 | | else if (string.Equals(count.Key, lookup[BaseItemKind.LiveTvProgram], StringComparison.Ordinal)) |
| | 500 | | { |
| 0 | 501 | | result.ProgramCount = count.Count; |
| | 502 | | } |
| 0 | 503 | | else if (string.Equals(count.Key, lookup[BaseItemKind.Series], StringComparison.Ordinal)) |
| | 504 | | { |
| 0 | 505 | | result.SeriesCount = count.Count; |
| | 506 | | } |
| 0 | 507 | | else if (string.Equals(count.Key, lookup[BaseItemKind.Audio], StringComparison.Ordinal)) |
| | 508 | | { |
| 0 | 509 | | result.SongCount = count.Count; |
| | 510 | | } |
| 0 | 511 | | else if (string.Equals(count.Key, lookup[BaseItemKind.Trailer], StringComparison.Ordinal)) |
| | 512 | | { |
| 0 | 513 | | result.TrailerCount = count.Count; |
| | 514 | | } |
| | 515 | | } |
| | 516 | |
|
| 0 | 517 | | return result; |
| 0 | 518 | | } |
| | 519 | |
|
| | 520 | | #pragma warning disable CA1307 // Specify StringComparison for clarity |
| | 521 | | /// <summary> |
| | 522 | | /// Gets the type. |
| | 523 | | /// </summary> |
| | 524 | | /// <param name="typeName">Name of the type.</param> |
| | 525 | | /// <returns>Type.</returns> |
| | 526 | | /// <exception cref="ArgumentNullException"><c>typeName</c> is null.</exception> |
| | 527 | | private static Type? GetType(string typeName) |
| | 528 | | { |
| 176 | 529 | | ArgumentException.ThrowIfNullOrEmpty(typeName); |
| | 530 | |
|
| | 531 | | // TODO: this isn't great. Refactor later to be both globally handled by a dedicated service not just an static |
| | 532 | | // currently this is done so that plugins may introduce their own type of baseitems as we dont know when we are |
| 176 | 533 | | return _typeMap.GetOrAdd(typeName, k => AppDomain.CurrentDomain.GetAssemblies() |
| 176 | 534 | | .Select(a => a.GetType(k)) |
| 176 | 535 | | .FirstOrDefault(t => t is not null)); |
| | 536 | | } |
| | 537 | |
|
| | 538 | | /// <inheritdoc /> |
| | 539 | | public void SaveImages(BaseItemDto item) |
| | 540 | | { |
| 0 | 541 | | ArgumentNullException.ThrowIfNull(item); |
| | 542 | |
|
| 0 | 543 | | var images = item.ImageInfos.Select(e => Map(item.Id, e)); |
| 0 | 544 | | using var context = _dbProvider.CreateDbContext(); |
| | 545 | |
|
| 0 | 546 | | if (!context.BaseItems.Any(bi => bi.Id == item.Id)) |
| | 547 | | { |
| 0 | 548 | | _logger.LogWarning("Unable to save ImageInfo for non existing BaseItem"); |
| 0 | 549 | | return; |
| | 550 | | } |
| | 551 | |
|
| 0 | 552 | | context.BaseItemImageInfos.Where(e => e.ItemId == item.Id).ExecuteDelete(); |
| 0 | 553 | | context.BaseItemImageInfos.AddRange(images); |
| 0 | 554 | | context.SaveChanges(); |
| 0 | 555 | | } |
| | 556 | |
|
| | 557 | | /// <inheritdoc /> |
| | 558 | | public void SaveItems(IReadOnlyList<BaseItemDto> items, CancellationToken cancellationToken) |
| | 559 | | { |
| 87 | 560 | | UpdateOrInsertItems(items, cancellationToken); |
| 85 | 561 | | } |
| | 562 | |
|
| | 563 | | /// <inheritdoc cref="IItemRepository"/> |
| | 564 | | public void UpdateOrInsertItems(IReadOnlyList<BaseItemDto> items, CancellationToken cancellationToken) |
| | 565 | | { |
| 87 | 566 | | ArgumentNullException.ThrowIfNull(items); |
| 87 | 567 | | cancellationToken.ThrowIfCancellationRequested(); |
| | 568 | |
|
| 85 | 569 | | var tuples = new List<(BaseItemDto Item, List<Guid>? AncestorIds, BaseItemDto TopParent, IEnumerable<string> Use |
| 340 | 570 | | foreach (var item in items.GroupBy(e => e.Id).Select(e => e.Last()).Where(e => e.Id != PlaceholderId)) |
| | 571 | | { |
| 85 | 572 | | var ancestorIds = item.SupportsAncestors ? |
| 85 | 573 | | item.GetAncestorIds().Distinct().ToList() : |
| 85 | 574 | | null; |
| | 575 | |
|
| 85 | 576 | | var topParent = item.GetTopParent(); |
| | 577 | |
|
| 85 | 578 | | var userdataKey = item.GetUserDataKeys(); |
| 85 | 579 | | var inheritedTags = item.GetInheritedTags(); |
| | 580 | |
|
| 85 | 581 | | tuples.Add((item, ancestorIds, topParent, userdataKey, inheritedTags)); |
| | 582 | | } |
| | 583 | |
|
| 85 | 584 | | using var context = _dbProvider.CreateDbContext(); |
| 85 | 585 | | using var transaction = context.Database.BeginTransaction(); |
| | 586 | |
|
| 85 | 587 | | var ids = tuples.Select(f => f.Item.Id).ToArray(); |
| 85 | 588 | | var existingItems = context.BaseItems.Where(e => ids.Contains(e.Id)).Select(f => f.Id).ToArray(); |
| 85 | 589 | | var newItems = tuples.Where(e => !existingItems.Contains(e.Item.Id)).ToArray(); |
| | 590 | |
|
| 340 | 591 | | foreach (var item in tuples) |
| | 592 | | { |
| 85 | 593 | | var entity = Map(item.Item); |
| | 594 | | // TODO: refactor this "inconsistency" |
| 85 | 595 | | entity.TopParentId = item.TopParent?.Id; |
| | 596 | |
|
| 85 | 597 | | if (!existingItems.Any(e => e == entity.Id)) |
| | 598 | | { |
| 49 | 599 | | context.BaseItems.Add(entity); |
| | 600 | | } |
| | 601 | | else |
| | 602 | | { |
| 36 | 603 | | context.BaseItemProviders.Where(e => e.ItemId == entity.Id).ExecuteDelete(); |
| 36 | 604 | | context.BaseItems.Attach(entity).State = EntityState.Modified; |
| | 605 | | } |
| | 606 | | } |
| | 607 | |
|
| 85 | 608 | | context.SaveChanges(); |
| | 609 | |
|
| 268 | 610 | | foreach (var item in newItems) |
| | 611 | | { |
| | 612 | | // reattach old userData entries |
| 49 | 613 | | var userKeys = item.UserDataKey.ToArray(); |
| 49 | 614 | | var retentionDate = (DateTime?)null; |
| 49 | 615 | | context.UserData |
| 49 | 616 | | .Where(e => e.ItemId == PlaceholderId) |
| 49 | 617 | | .Where(e => userKeys.Contains(e.CustomDataKey)) |
| 49 | 618 | | .ExecuteUpdate(e => e |
| 49 | 619 | | .SetProperty(f => f.ItemId, item.Item.Id) |
| 49 | 620 | | .SetProperty(f => f.RetentionDate, retentionDate)); |
| | 621 | | } |
| | 622 | |
|
| 85 | 623 | | var itemValueMaps = tuples |
| 85 | 624 | | .Select(e => (e.Item, Values: GetItemValuesToSave(e.Item, e.InheritedTags))) |
| 85 | 625 | | .ToArray(); |
| 85 | 626 | | var allListedItemValues = itemValueMaps |
| 85 | 627 | | .SelectMany(f => f.Values) |
| 85 | 628 | | .Distinct() |
| 85 | 629 | | .ToArray(); |
| 85 | 630 | | var existingValues = context.ItemValues |
| 85 | 631 | | .Select(e => new |
| 85 | 632 | | { |
| 85 | 633 | | item = e, |
| 85 | 634 | | Key = e.Type + "+" + e.Value |
| 85 | 635 | | }) |
| 85 | 636 | | .Where(f => allListedItemValues.Select(e => $"{(int)e.MagicNumber}+{e.Value}").Contains(f.Key)) |
| 85 | 637 | | .Select(e => e.item) |
| 85 | 638 | | .ToArray(); |
| 85 | 639 | | var missingItemValues = allListedItemValues.Except(existingValues.Select(f => (MagicNumber: f.Type, f.Value))).S |
| 85 | 640 | | { |
| 85 | 641 | | CleanValue = GetCleanValue(f.Value), |
| 85 | 642 | | ItemValueId = Guid.NewGuid(), |
| 85 | 643 | | Type = f.MagicNumber, |
| 85 | 644 | | Value = f.Value |
| 85 | 645 | | }).ToArray(); |
| 85 | 646 | | context.ItemValues.AddRange(missingItemValues); |
| 85 | 647 | | context.SaveChanges(); |
| | 648 | |
|
| 85 | 649 | | var itemValuesStore = existingValues.Concat(missingItemValues).ToArray(); |
| 85 | 650 | | var valueMap = itemValueMaps |
| 85 | 651 | | .Select(f => (f.Item, Values: f.Values.Select(e => itemValuesStore.First(g => g.Value == e.Value && g.Type = |
| 85 | 652 | | .ToArray(); |
| | 653 | |
|
| 85 | 654 | | var mappedValues = context.ItemValuesMap.Where(e => ids.Contains(e.ItemId)).ToList(); |
| | 655 | |
|
| 340 | 656 | | foreach (var item in valueMap) |
| | 657 | | { |
| 85 | 658 | | var itemMappedValues = mappedValues.Where(e => e.ItemId == item.Item.Id).ToList(); |
| 170 | 659 | | foreach (var itemValue in item.Values) |
| | 660 | | { |
| 0 | 661 | | var existingItem = itemMappedValues.FirstOrDefault(f => f.ItemValueId == itemValue.ItemValueId); |
| 0 | 662 | | if (existingItem is null) |
| | 663 | | { |
| 0 | 664 | | context.ItemValuesMap.Add(new ItemValueMap() |
| 0 | 665 | | { |
| 0 | 666 | | Item = null!, |
| 0 | 667 | | ItemId = item.Item.Id, |
| 0 | 668 | | ItemValue = null!, |
| 0 | 669 | | ItemValueId = itemValue.ItemValueId |
| 0 | 670 | | }); |
| | 671 | | } |
| | 672 | | else |
| | 673 | | { |
| | 674 | | // map exists, remove from list so its been handled. |
| 0 | 675 | | itemMappedValues.Remove(existingItem); |
| | 676 | | } |
| | 677 | | } |
| | 678 | |
|
| | 679 | | // all still listed values are not in the new list so remove them. |
| 85 | 680 | | context.ItemValuesMap.RemoveRange(itemMappedValues); |
| | 681 | | } |
| | 682 | |
|
| 85 | 683 | | context.SaveChanges(); |
| | 684 | |
|
| 340 | 685 | | foreach (var item in tuples) |
| | 686 | | { |
| 85 | 687 | | if (item.Item.SupportsAncestors && item.AncestorIds != null) |
| | 688 | | { |
| 85 | 689 | | var existingAncestorIds = context.AncestorIds.Where(e => e.ItemId == item.Item.Id).ToList(); |
| 85 | 690 | | var validAncestorIds = context.BaseItems.Where(e => item.AncestorIds.Contains(e.Id)).Select(f => f.Id).T |
| 190 | 691 | | foreach (var ancestorId in validAncestorIds) |
| | 692 | | { |
| 10 | 693 | | var existingAncestorId = existingAncestorIds.FirstOrDefault(e => e.ParentItemId == ancestorId); |
| 10 | 694 | | if (existingAncestorId is null) |
| | 695 | | { |
| 2 | 696 | | context.AncestorIds.Add(new AncestorId() |
| 2 | 697 | | { |
| 2 | 698 | | ParentItemId = ancestorId, |
| 2 | 699 | | ItemId = item.Item.Id, |
| 2 | 700 | | Item = null!, |
| 2 | 701 | | ParentItem = null! |
| 2 | 702 | | }); |
| | 703 | | } |
| | 704 | | else |
| | 705 | | { |
| 8 | 706 | | existingAncestorIds.Remove(existingAncestorId); |
| | 707 | | } |
| | 708 | | } |
| | 709 | |
|
| 85 | 710 | | context.AncestorIds.RemoveRange(existingAncestorIds); |
| | 711 | | } |
| | 712 | | } |
| | 713 | |
|
| 85 | 714 | | context.SaveChanges(); |
| 85 | 715 | | transaction.Commit(); |
| 170 | 716 | | } |
| | 717 | |
|
| | 718 | | /// <inheritdoc /> |
| | 719 | | public BaseItemDto? RetrieveItem(Guid id) |
| | 720 | | { |
| 216 | 721 | | if (id.IsEmpty()) |
| | 722 | | { |
| 0 | 723 | | throw new ArgumentException("Guid can't be empty", nameof(id)); |
| | 724 | | } |
| | 725 | |
|
| 216 | 726 | | using var context = _dbProvider.CreateDbContext(); |
| 216 | 727 | | var item = PrepareItemQuery(context, new() |
| 216 | 728 | | { |
| 216 | 729 | | DtoOptions = new() |
| 216 | 730 | | { |
| 216 | 731 | | EnableImages = true |
| 216 | 732 | | } |
| 216 | 733 | | }).FirstOrDefault(e => e.Id == id); |
| 216 | 734 | | if (item is null) |
| | 735 | | { |
| 216 | 736 | | return null; |
| | 737 | | } |
| | 738 | |
|
| 0 | 739 | | return DeserializeBaseItem(item); |
| 216 | 740 | | } |
| | 741 | |
|
| | 742 | | /// <summary> |
| | 743 | | /// Maps a Entity to the DTO. |
| | 744 | | /// </summary> |
| | 745 | | /// <param name="entity">The entity.</param> |
| | 746 | | /// <param name="dto">The dto base instance.</param> |
| | 747 | | /// <param name="appHost">The Application server Host.</param> |
| | 748 | | /// <returns>The dto to map.</returns> |
| | 749 | | public static BaseItemDto Map(BaseItemEntity entity, BaseItemDto dto, IServerApplicationHost? appHost) |
| | 750 | | { |
| 88 | 751 | | dto.Id = entity.Id; |
| 88 | 752 | | dto.ParentId = entity.ParentId.GetValueOrDefault(); |
| 88 | 753 | | dto.Path = appHost?.ExpandVirtualPath(entity.Path) ?? entity.Path; |
| 88 | 754 | | dto.EndDate = entity.EndDate; |
| 88 | 755 | | dto.CommunityRating = entity.CommunityRating; |
| 88 | 756 | | dto.CustomRating = entity.CustomRating; |
| 88 | 757 | | dto.IndexNumber = entity.IndexNumber; |
| 88 | 758 | | dto.IsLocked = entity.IsLocked; |
| 88 | 759 | | dto.Name = entity.Name; |
| 88 | 760 | | dto.OfficialRating = entity.OfficialRating; |
| 88 | 761 | | dto.Overview = entity.Overview; |
| 88 | 762 | | dto.ParentIndexNumber = entity.ParentIndexNumber; |
| 88 | 763 | | dto.PremiereDate = entity.PremiereDate; |
| 88 | 764 | | dto.ProductionYear = entity.ProductionYear; |
| 88 | 765 | | dto.SortName = entity.SortName; |
| 88 | 766 | | dto.ForcedSortName = entity.ForcedSortName; |
| 88 | 767 | | dto.RunTimeTicks = entity.RunTimeTicks; |
| 88 | 768 | | dto.PreferredMetadataLanguage = entity.PreferredMetadataLanguage; |
| 88 | 769 | | dto.PreferredMetadataCountryCode = entity.PreferredMetadataCountryCode; |
| 88 | 770 | | dto.IsInMixedFolder = entity.IsInMixedFolder; |
| 88 | 771 | | dto.InheritedParentalRatingValue = entity.InheritedParentalRatingValue; |
| 88 | 772 | | dto.InheritedParentalRatingSubValue = entity.InheritedParentalRatingSubValue; |
| 88 | 773 | | dto.CriticRating = entity.CriticRating; |
| 88 | 774 | | dto.PresentationUniqueKey = entity.PresentationUniqueKey; |
| 88 | 775 | | dto.OriginalTitle = entity.OriginalTitle; |
| 88 | 776 | | dto.Album = entity.Album; |
| 88 | 777 | | dto.LUFS = entity.LUFS; |
| 88 | 778 | | dto.NormalizationGain = entity.NormalizationGain; |
| 88 | 779 | | dto.IsVirtualItem = entity.IsVirtualItem; |
| 88 | 780 | | dto.ExternalSeriesId = entity.ExternalSeriesId; |
| 88 | 781 | | dto.Tagline = entity.Tagline; |
| 88 | 782 | | dto.TotalBitrate = entity.TotalBitrate; |
| 88 | 783 | | dto.ExternalId = entity.ExternalId; |
| 88 | 784 | | dto.Size = entity.Size; |
| 88 | 785 | | dto.Genres = string.IsNullOrWhiteSpace(entity.Genres) ? [] : entity.Genres.Split('|'); |
| 88 | 786 | | dto.DateCreated = entity.DateCreated ?? DateTime.SpecifyKind(DateTime.MinValue, DateTimeKind.Utc); |
| 88 | 787 | | dto.DateModified = entity.DateModified ?? DateTime.SpecifyKind(DateTime.MinValue, DateTimeKind.Utc); |
| 88 | 788 | | dto.ChannelId = entity.ChannelId ?? Guid.Empty; |
| 88 | 789 | | dto.DateLastRefreshed = entity.DateLastRefreshed ?? DateTime.SpecifyKind(DateTime.MinValue, DateTimeKind.Utc); |
| 88 | 790 | | dto.DateLastSaved = entity.DateLastSaved ?? DateTime.SpecifyKind(DateTime.MinValue, DateTimeKind.Utc); |
| 88 | 791 | | dto.OwnerId = string.IsNullOrWhiteSpace(entity.OwnerId) ? Guid.Empty : (Guid.TryParse(entity.OwnerId, out var ow |
| 88 | 792 | | dto.Width = entity.Width.GetValueOrDefault(); |
| 88 | 793 | | dto.Height = entity.Height.GetValueOrDefault(); |
| 88 | 794 | | if (entity.Provider is not null) |
| | 795 | | { |
| 88 | 796 | | dto.ProviderIds = entity.Provider.ToDictionary(e => e.ProviderId, e => e.ProviderValue); |
| | 797 | | } |
| | 798 | |
|
| 88 | 799 | | if (entity.ExtraType is not null) |
| | 800 | | { |
| 0 | 801 | | dto.ExtraType = (ExtraType)entity.ExtraType; |
| | 802 | | } |
| | 803 | |
|
| 88 | 804 | | if (entity.LockedFields is not null) |
| | 805 | | { |
| 88 | 806 | | dto.LockedFields = entity.LockedFields?.Select(e => (MetadataField)e.Id).ToArray() ?? []; |
| | 807 | | } |
| | 808 | |
|
| 88 | 809 | | if (entity.Audio is not null) |
| | 810 | | { |
| 0 | 811 | | dto.Audio = (ProgramAudio)entity.Audio; |
| | 812 | | } |
| | 813 | |
|
| 88 | 814 | | dto.ExtraIds = string.IsNullOrWhiteSpace(entity.ExtraIds) ? [] : entity.ExtraIds.Split('|').Select(e => Guid.Par |
| 88 | 815 | | dto.ProductionLocations = entity.ProductionLocations?.Split('|') ?? []; |
| 88 | 816 | | dto.Studios = entity.Studios?.Split('|') ?? []; |
| 88 | 817 | | dto.Tags = string.IsNullOrWhiteSpace(entity.Tags) ? [] : entity.Tags.Split('|'); |
| | 818 | |
|
| 88 | 819 | | if (dto is IHasProgramAttributes hasProgramAttributes) |
| | 820 | | { |
| 0 | 821 | | hasProgramAttributes.IsMovie = entity.IsMovie; |
| 0 | 822 | | hasProgramAttributes.IsSeries = entity.IsSeries; |
| 0 | 823 | | hasProgramAttributes.EpisodeTitle = entity.EpisodeTitle; |
| 0 | 824 | | hasProgramAttributes.IsRepeat = entity.IsRepeat; |
| | 825 | | } |
| | 826 | |
|
| 88 | 827 | | if (dto is LiveTvChannel liveTvChannel) |
| | 828 | | { |
| 0 | 829 | | liveTvChannel.ServiceName = entity.ExternalServiceId; |
| | 830 | | } |
| | 831 | |
|
| 88 | 832 | | if (dto is Trailer trailer) |
| | 833 | | { |
| 0 | 834 | | trailer.TrailerTypes = entity.TrailerTypes?.Select(e => (TrailerType)e.Id).ToArray() ?? []; |
| | 835 | | } |
| | 836 | |
|
| 88 | 837 | | if (dto is Video video) |
| | 838 | | { |
| 0 | 839 | | video.PrimaryVersionId = entity.PrimaryVersionId; |
| | 840 | | } |
| | 841 | |
|
| 88 | 842 | | if (dto is IHasSeries hasSeriesName) |
| | 843 | | { |
| 0 | 844 | | hasSeriesName.SeriesName = entity.SeriesName; |
| 0 | 845 | | hasSeriesName.SeriesId = entity.SeriesId.GetValueOrDefault(); |
| 0 | 846 | | hasSeriesName.SeriesPresentationUniqueKey = entity.SeriesPresentationUniqueKey; |
| | 847 | | } |
| | 848 | |
|
| 88 | 849 | | if (dto is Episode episode) |
| | 850 | | { |
| 0 | 851 | | episode.SeasonName = entity.SeasonName; |
| 0 | 852 | | episode.SeasonId = entity.SeasonId.GetValueOrDefault(); |
| | 853 | | } |
| | 854 | |
|
| 88 | 855 | | if (dto is IHasArtist hasArtists) |
| | 856 | | { |
| 0 | 857 | | hasArtists.Artists = entity.Artists?.Split('|', StringSplitOptions.RemoveEmptyEntries) ?? []; |
| | 858 | | } |
| | 859 | |
|
| 88 | 860 | | if (dto is IHasAlbumArtist hasAlbumArtists) |
| | 861 | | { |
| 0 | 862 | | hasAlbumArtists.AlbumArtists = entity.AlbumArtists?.Split('|', StringSplitOptions.RemoveEmptyEntries) ?? []; |
| | 863 | | } |
| | 864 | |
|
| 88 | 865 | | if (dto is LiveTvProgram program) |
| | 866 | | { |
| 0 | 867 | | program.ShowId = entity.ShowId; |
| | 868 | | } |
| | 869 | |
|
| 88 | 870 | | if (entity.Images is not null) |
| | 871 | | { |
| 88 | 872 | | dto.ImageInfos = entity.Images.Select(e => Map(e, appHost)).ToArray(); |
| | 873 | | } |
| | 874 | |
|
| | 875 | | // dto.Type = entity.Type; |
| | 876 | | // dto.Data = entity.Data; |
| | 877 | | // dto.MediaType = Enum.TryParse<MediaType>(entity.MediaType); |
| 88 | 878 | | if (dto is IHasStartDate hasStartDate) |
| | 879 | | { |
| 0 | 880 | | hasStartDate.StartDate = entity.StartDate.GetValueOrDefault(); |
| | 881 | | } |
| | 882 | |
|
| | 883 | | // Fields that are present in the DB but are never actually used |
| | 884 | | // dto.UnratedType = entity.UnratedType; |
| | 885 | | // dto.TopParentId = entity.TopParentId; |
| | 886 | | // dto.CleanName = entity.CleanName; |
| | 887 | | // dto.UserDataKey = entity.UserDataKey; |
| | 888 | |
|
| 88 | 889 | | if (dto is Folder folder) |
| | 890 | | { |
| 88 | 891 | | folder.DateLastMediaAdded = entity.DateLastMediaAdded ?? DateTime.SpecifyKind(DateTime.MinValue, DateTimeKin |
| | 892 | | } |
| | 893 | |
|
| 88 | 894 | | return dto; |
| | 895 | | } |
| | 896 | |
|
| | 897 | | /// <summary> |
| | 898 | | /// Maps a Entity to the DTO. |
| | 899 | | /// </summary> |
| | 900 | | /// <param name="dto">The entity.</param> |
| | 901 | | /// <returns>The dto to map.</returns> |
| | 902 | | public BaseItemEntity Map(BaseItemDto dto) |
| | 903 | | { |
| 85 | 904 | | var dtoType = dto.GetType(); |
| 85 | 905 | | var entity = new BaseItemEntity() |
| 85 | 906 | | { |
| 85 | 907 | | Type = dtoType.ToString(), |
| 85 | 908 | | Id = dto.Id |
| 85 | 909 | | }; |
| | 910 | |
|
| 85 | 911 | | if (TypeRequiresDeserialization(dtoType)) |
| | 912 | | { |
| 64 | 913 | | entity.Data = JsonSerializer.Serialize(dto, dtoType, JsonDefaults.Options); |
| | 914 | | } |
| | 915 | |
|
| 85 | 916 | | entity.ParentId = !dto.ParentId.IsEmpty() ? dto.ParentId : null; |
| 85 | 917 | | entity.Path = GetPathToSave(dto.Path); |
| 85 | 918 | | entity.EndDate = dto.EndDate; |
| 85 | 919 | | entity.CommunityRating = dto.CommunityRating; |
| 85 | 920 | | entity.CustomRating = dto.CustomRating; |
| 85 | 921 | | entity.IndexNumber = dto.IndexNumber; |
| 85 | 922 | | entity.IsLocked = dto.IsLocked; |
| 85 | 923 | | entity.Name = dto.Name; |
| 85 | 924 | | entity.CleanName = GetCleanValue(dto.Name); |
| 85 | 925 | | entity.OfficialRating = dto.OfficialRating; |
| 85 | 926 | | entity.Overview = dto.Overview; |
| 85 | 927 | | entity.ParentIndexNumber = dto.ParentIndexNumber; |
| 85 | 928 | | entity.PremiereDate = dto.PremiereDate; |
| 85 | 929 | | entity.ProductionYear = dto.ProductionYear; |
| 85 | 930 | | entity.SortName = dto.SortName; |
| 85 | 931 | | entity.ForcedSortName = dto.ForcedSortName; |
| 85 | 932 | | entity.RunTimeTicks = dto.RunTimeTicks; |
| 85 | 933 | | entity.PreferredMetadataLanguage = dto.PreferredMetadataLanguage; |
| 85 | 934 | | entity.PreferredMetadataCountryCode = dto.PreferredMetadataCountryCode; |
| 85 | 935 | | entity.IsInMixedFolder = dto.IsInMixedFolder; |
| 85 | 936 | | entity.InheritedParentalRatingValue = dto.InheritedParentalRatingValue; |
| 85 | 937 | | entity.InheritedParentalRatingSubValue = dto.InheritedParentalRatingSubValue; |
| 85 | 938 | | entity.CriticRating = dto.CriticRating; |
| 85 | 939 | | entity.PresentationUniqueKey = dto.PresentationUniqueKey; |
| 85 | 940 | | entity.OriginalTitle = dto.OriginalTitle; |
| 85 | 941 | | entity.Album = dto.Album; |
| 85 | 942 | | entity.LUFS = dto.LUFS; |
| 85 | 943 | | entity.NormalizationGain = dto.NormalizationGain; |
| 85 | 944 | | entity.IsVirtualItem = dto.IsVirtualItem; |
| 85 | 945 | | entity.ExternalSeriesId = dto.ExternalSeriesId; |
| 85 | 946 | | entity.Tagline = dto.Tagline; |
| 85 | 947 | | entity.TotalBitrate = dto.TotalBitrate; |
| 85 | 948 | | entity.ExternalId = dto.ExternalId; |
| 85 | 949 | | entity.Size = dto.Size; |
| 85 | 950 | | entity.Genres = string.Join('|', dto.Genres); |
| 85 | 951 | | entity.DateCreated = dto.DateCreated == DateTime.MinValue ? null : dto.DateCreated; |
| 85 | 952 | | entity.DateModified = dto.DateModified == DateTime.MinValue ? null : dto.DateModified; |
| 85 | 953 | | entity.ChannelId = dto.ChannelId; |
| 85 | 954 | | entity.DateLastRefreshed = dto.DateLastRefreshed == DateTime.MinValue ? null : dto.DateLastRefreshed; |
| 85 | 955 | | entity.DateLastSaved = dto.DateLastSaved == DateTime.MinValue ? null : dto.DateLastSaved; |
| 85 | 956 | | entity.OwnerId = dto.OwnerId.ToString(); |
| 85 | 957 | | entity.Width = dto.Width; |
| 85 | 958 | | entity.Height = dto.Height; |
| 85 | 959 | | entity.Provider = dto.ProviderIds.Select(e => new BaseItemProvider() |
| 85 | 960 | | { |
| 85 | 961 | | Item = entity, |
| 85 | 962 | | ProviderId = e.Key, |
| 85 | 963 | | ProviderValue = e.Value |
| 85 | 964 | | }).ToList(); |
| | 965 | |
|
| 85 | 966 | | if (dto.Audio.HasValue) |
| | 967 | | { |
| 0 | 968 | | entity.Audio = (ProgramAudioEntity)dto.Audio; |
| | 969 | | } |
| | 970 | |
|
| 85 | 971 | | if (dto.ExtraType.HasValue) |
| | 972 | | { |
| 0 | 973 | | entity.ExtraType = (BaseItemExtraType)dto.ExtraType; |
| | 974 | | } |
| | 975 | |
|
| 85 | 976 | | entity.ExtraIds = dto.ExtraIds is not null ? string.Join('|', dto.ExtraIds) : null; |
| 85 | 977 | | entity.ProductionLocations = dto.ProductionLocations is not null ? string.Join('|', dto.ProductionLocations) : n |
| 85 | 978 | | entity.Studios = dto.Studios is not null ? string.Join('|', dto.Studios) : null; |
| 85 | 979 | | entity.Tags = dto.Tags is not null ? string.Join('|', dto.Tags) : null; |
| 85 | 980 | | entity.LockedFields = dto.LockedFields is not null ? dto.LockedFields |
| 85 | 981 | | .Select(e => new BaseItemMetadataField() |
| 85 | 982 | | { |
| 85 | 983 | | Id = (int)e, |
| 85 | 984 | | Item = entity, |
| 85 | 985 | | ItemId = entity.Id |
| 85 | 986 | | }) |
| 85 | 987 | | .ToArray() : null; |
| | 988 | |
|
| 85 | 989 | | if (dto is IHasProgramAttributes hasProgramAttributes) |
| | 990 | | { |
| 0 | 991 | | entity.IsMovie = hasProgramAttributes.IsMovie; |
| 0 | 992 | | entity.IsSeries = hasProgramAttributes.IsSeries; |
| 0 | 993 | | entity.EpisodeTitle = hasProgramAttributes.EpisodeTitle; |
| 0 | 994 | | entity.IsRepeat = hasProgramAttributes.IsRepeat; |
| | 995 | | } |
| | 996 | |
|
| 85 | 997 | | if (dto is LiveTvChannel liveTvChannel) |
| | 998 | | { |
| 0 | 999 | | entity.ExternalServiceId = liveTvChannel.ServiceName; |
| | 1000 | | } |
| | 1001 | |
|
| 85 | 1002 | | if (dto is Video video) |
| | 1003 | | { |
| 0 | 1004 | | entity.PrimaryVersionId = video.PrimaryVersionId; |
| | 1005 | | } |
| | 1006 | |
|
| 85 | 1007 | | if (dto is IHasSeries hasSeriesName) |
| | 1008 | | { |
| 0 | 1009 | | entity.SeriesName = hasSeriesName.SeriesName; |
| 0 | 1010 | | entity.SeriesId = hasSeriesName.SeriesId; |
| 0 | 1011 | | entity.SeriesPresentationUniqueKey = hasSeriesName.SeriesPresentationUniqueKey; |
| | 1012 | | } |
| | 1013 | |
|
| 85 | 1014 | | if (dto is Episode episode) |
| | 1015 | | { |
| 0 | 1016 | | entity.SeasonName = episode.SeasonName; |
| 0 | 1017 | | entity.SeasonId = episode.SeasonId; |
| | 1018 | | } |
| | 1019 | |
|
| 85 | 1020 | | if (dto is IHasArtist hasArtists) |
| | 1021 | | { |
| 0 | 1022 | | entity.Artists = hasArtists.Artists is not null ? string.Join('|', hasArtists.Artists) : null; |
| | 1023 | | } |
| | 1024 | |
|
| 85 | 1025 | | if (dto is IHasAlbumArtist hasAlbumArtists) |
| | 1026 | | { |
| 0 | 1027 | | entity.AlbumArtists = hasAlbumArtists.AlbumArtists is not null ? string.Join('|', hasAlbumArtists.AlbumArtis |
| | 1028 | | } |
| | 1029 | |
|
| 85 | 1030 | | if (dto is LiveTvProgram program) |
| | 1031 | | { |
| 0 | 1032 | | entity.ShowId = program.ShowId; |
| | 1033 | | } |
| | 1034 | |
|
| 85 | 1035 | | if (dto.ImageInfos is not null) |
| | 1036 | | { |
| 85 | 1037 | | entity.Images = dto.ImageInfos.Select(f => Map(dto.Id, f)).ToArray(); |
| | 1038 | | } |
| | 1039 | |
|
| 85 | 1040 | | if (dto is Trailer trailer) |
| | 1041 | | { |
| 0 | 1042 | | entity.TrailerTypes = trailer.TrailerTypes?.Select(e => new BaseItemTrailerType() |
| 0 | 1043 | | { |
| 0 | 1044 | | Id = (int)e, |
| 0 | 1045 | | Item = entity, |
| 0 | 1046 | | ItemId = entity.Id |
| 0 | 1047 | | }).ToArray() ?? []; |
| | 1048 | | } |
| | 1049 | |
|
| | 1050 | | // dto.Type = entity.Type; |
| | 1051 | | // dto.Data = entity.Data; |
| 85 | 1052 | | entity.MediaType = dto.MediaType.ToString(); |
| 85 | 1053 | | if (dto is IHasStartDate hasStartDate) |
| | 1054 | | { |
| 0 | 1055 | | entity.StartDate = hasStartDate.StartDate; |
| | 1056 | | } |
| | 1057 | |
|
| 85 | 1058 | | entity.UnratedType = dto.GetBlockUnratedType().ToString(); |
| | 1059 | |
|
| | 1060 | | // Fields that are present in the DB but are never actually used |
| | 1061 | | // dto.UserDataKey = entity.UserDataKey; |
| | 1062 | |
|
| 85 | 1063 | | if (dto is Folder folder) |
| | 1064 | | { |
| 85 | 1065 | | entity.DateLastMediaAdded = folder.DateLastMediaAdded == DateTime.MinValue ? null : folder.DateLastMediaAdde |
| 85 | 1066 | | entity.IsFolder = folder.IsFolder; |
| | 1067 | | } |
| | 1068 | |
|
| 85 | 1069 | | return entity; |
| | 1070 | | } |
| | 1071 | |
|
| | 1072 | | private string[] GetItemValueNames(IReadOnlyList<ItemValueType> itemValueTypes, IReadOnlyList<string> withItemTypes, |
| | 1073 | | { |
| 36 | 1074 | | using var context = _dbProvider.CreateDbContext(); |
| | 1075 | |
|
| 36 | 1076 | | var query = context.ItemValuesMap |
| 36 | 1077 | | .AsNoTracking() |
| 36 | 1078 | | .Where(e => itemValueTypes.Any(w => (ItemValueType)w == e.ItemValue.Type)); |
| 36 | 1079 | | if (withItemTypes.Count > 0) |
| | 1080 | | { |
| 9 | 1081 | | query = query.Where(e => withItemTypes.Contains(e.Item.Type)); |
| | 1082 | | } |
| | 1083 | |
|
| 36 | 1084 | | if (excludeItemTypes.Count > 0) |
| | 1085 | | { |
| 9 | 1086 | | query = query.Where(e => !excludeItemTypes.Contains(e.Item.Type)); |
| | 1087 | | } |
| | 1088 | |
|
| | 1089 | | // query = query.DistinctBy(e => e.CleanValue); |
| 36 | 1090 | | return query.Select(e => e.ItemValue) |
| 36 | 1091 | | .GroupBy(e => e.CleanValue) |
| 36 | 1092 | | .Select(e => e.First().Value) |
| 36 | 1093 | | .ToArray(); |
| 36 | 1094 | | } |
| | 1095 | |
|
| | 1096 | | private static bool TypeRequiresDeserialization(Type type) |
| | 1097 | | { |
| 173 | 1098 | | return type.GetCustomAttribute<RequiresSourceSerialisationAttribute>() == null; |
| | 1099 | | } |
| | 1100 | |
|
| | 1101 | | private BaseItemDto DeserializeBaseItem(BaseItemEntity baseItemEntity, bool skipDeserialization = false) |
| | 1102 | | { |
| 88 | 1103 | | ArgumentNullException.ThrowIfNull(baseItemEntity, nameof(baseItemEntity)); |
| 88 | 1104 | | if (_serverConfigurationManager?.Configuration is null) |
| | 1105 | | { |
| 0 | 1106 | | throw new InvalidOperationException("Server Configuration manager or configuration is null"); |
| | 1107 | | } |
| | 1108 | |
|
| 88 | 1109 | | var typeToSerialise = GetType(baseItemEntity.Type); |
| 88 | 1110 | | return BaseItemRepository.DeserializeBaseItem( |
| 88 | 1111 | | baseItemEntity, |
| 88 | 1112 | | _logger, |
| 88 | 1113 | | _appHost, |
| 88 | 1114 | | skipDeserialization || (_serverConfigurationManager.Configuration.SkipDeserializationForBasicTypes && (typeT |
| | 1115 | | } |
| | 1116 | |
|
| | 1117 | | /// <summary> |
| | 1118 | | /// Deserializes a BaseItemEntity and sets all properties. |
| | 1119 | | /// </summary> |
| | 1120 | | /// <param name="baseItemEntity">The DB entity.</param> |
| | 1121 | | /// <param name="logger">Logger.</param> |
| | 1122 | | /// <param name="appHost">The application server Host.</param> |
| | 1123 | | /// <param name="skipDeserialization">If only mapping should be processed.</param> |
| | 1124 | | /// <returns>A mapped BaseItem.</returns> |
| | 1125 | | /// <exception cref="InvalidOperationException">Will be thrown if an invalid serialisation is requested.</exception> |
| | 1126 | | public static BaseItemDto DeserializeBaseItem(BaseItemEntity baseItemEntity, ILogger logger, IServerApplicationHost? |
| | 1127 | | { |
| 88 | 1128 | | var type = GetType(baseItemEntity.Type) ?? throw new InvalidOperationException("Cannot deserialize unknown type. |
| 88 | 1129 | | BaseItemDto? dto = null; |
| 88 | 1130 | | if (TypeRequiresDeserialization(type) && baseItemEntity.Data is not null && !skipDeserialization) |
| | 1131 | | { |
| | 1132 | | try |
| | 1133 | | { |
| 23 | 1134 | | dto = JsonSerializer.Deserialize(baseItemEntity.Data, type, JsonDefaults.Options) as BaseItemDto; |
| 23 | 1135 | | } |
| 0 | 1136 | | catch (JsonException ex) |
| | 1137 | | { |
| 0 | 1138 | | logger.LogError(ex, "Error deserializing item with JSON: {Data}", baseItemEntity.Data); |
| 0 | 1139 | | } |
| | 1140 | | } |
| | 1141 | |
|
| 88 | 1142 | | if (dto is null) |
| | 1143 | | { |
| 65 | 1144 | | dto = Activator.CreateInstance(type) as BaseItemDto ?? throw new InvalidOperationException("Cannot deseriali |
| | 1145 | | } |
| | 1146 | |
|
| 88 | 1147 | | return Map(baseItemEntity, dto, appHost); |
| | 1148 | | } |
| | 1149 | |
|
| | 1150 | | private QueryResult<(BaseItemDto Item, ItemCounts? ItemCounts)> GetItemValues(InternalItemsQuery filter, IReadOnlyLi |
| | 1151 | | { |
| 0 | 1152 | | ArgumentNullException.ThrowIfNull(filter); |
| | 1153 | |
|
| 0 | 1154 | | if (!filter.Limit.HasValue) |
| | 1155 | | { |
| 0 | 1156 | | filter.EnableTotalRecordCount = false; |
| | 1157 | | } |
| | 1158 | |
|
| 0 | 1159 | | using var context = _dbProvider.CreateDbContext(); |
| | 1160 | |
|
| 0 | 1161 | | var innerQueryFilter = TranslateQuery(context.BaseItems.Where(e => e.Id != EF.Constant(PlaceholderId)), context, |
| 0 | 1162 | | { |
| 0 | 1163 | | ExcludeItemTypes = filter.ExcludeItemTypes, |
| 0 | 1164 | | IncludeItemTypes = filter.IncludeItemTypes, |
| 0 | 1165 | | MediaTypes = filter.MediaTypes, |
| 0 | 1166 | | AncestorIds = filter.AncestorIds, |
| 0 | 1167 | | ItemIds = filter.ItemIds, |
| 0 | 1168 | | TopParentIds = filter.TopParentIds, |
| 0 | 1169 | | ParentId = filter.ParentId, |
| 0 | 1170 | | IsAiring = filter.IsAiring, |
| 0 | 1171 | | IsMovie = filter.IsMovie, |
| 0 | 1172 | | IsSports = filter.IsSports, |
| 0 | 1173 | | IsKids = filter.IsKids, |
| 0 | 1174 | | IsNews = filter.IsNews, |
| 0 | 1175 | | IsSeries = filter.IsSeries |
| 0 | 1176 | | }); |
| | 1177 | |
|
| 0 | 1178 | | var itemValuesQuery = context.ItemValues |
| 0 | 1179 | | .Where(f => itemValueTypes.Contains(f.Type)) |
| 0 | 1180 | | .SelectMany(f => f.BaseItemsMap!, (f, w) => new { f, w }) |
| 0 | 1181 | | .Join( |
| 0 | 1182 | | innerQueryFilter, |
| 0 | 1183 | | fw => fw.w.ItemId, |
| 0 | 1184 | | g => g.Id, |
| 0 | 1185 | | (fw, g) => fw.f.CleanValue); |
| | 1186 | |
|
| 0 | 1187 | | var innerQuery = PrepareItemQuery(context, filter) |
| 0 | 1188 | | .Where(e => e.Type == returnType) |
| 0 | 1189 | | .Where(e => itemValuesQuery.Contains(e.CleanName)); |
| | 1190 | |
|
| 0 | 1191 | | var outerQueryFilter = new InternalItemsQuery(filter.User) |
| 0 | 1192 | | { |
| 0 | 1193 | | IsPlayed = filter.IsPlayed, |
| 0 | 1194 | | IsFavorite = filter.IsFavorite, |
| 0 | 1195 | | IsFavoriteOrLiked = filter.IsFavoriteOrLiked, |
| 0 | 1196 | | IsLiked = filter.IsLiked, |
| 0 | 1197 | | IsLocked = filter.IsLocked, |
| 0 | 1198 | | NameLessThan = filter.NameLessThan, |
| 0 | 1199 | | NameStartsWith = filter.NameStartsWith, |
| 0 | 1200 | | NameStartsWithOrGreater = filter.NameStartsWithOrGreater, |
| 0 | 1201 | | Tags = filter.Tags, |
| 0 | 1202 | | OfficialRatings = filter.OfficialRatings, |
| 0 | 1203 | | StudioIds = filter.StudioIds, |
| 0 | 1204 | | GenreIds = filter.GenreIds, |
| 0 | 1205 | | Genres = filter.Genres, |
| 0 | 1206 | | Years = filter.Years, |
| 0 | 1207 | | NameContains = filter.NameContains, |
| 0 | 1208 | | SearchTerm = filter.SearchTerm, |
| 0 | 1209 | | ExcludeItemIds = filter.ExcludeItemIds |
| 0 | 1210 | | }; |
| | 1211 | |
|
| 0 | 1212 | | var query = TranslateQuery(innerQuery, context, outerQueryFilter) |
| 0 | 1213 | | .GroupBy(e => e.PresentationUniqueKey); |
| | 1214 | |
|
| 0 | 1215 | | var result = new QueryResult<(BaseItemDto, ItemCounts?)>(); |
| 0 | 1216 | | if (filter.EnableTotalRecordCount) |
| | 1217 | | { |
| 0 | 1218 | | result.TotalRecordCount = query.Count(); |
| | 1219 | | } |
| | 1220 | |
|
| 0 | 1221 | | if (filter.Limit.HasValue || filter.StartIndex.HasValue) |
| | 1222 | | { |
| 0 | 1223 | | var offset = filter.StartIndex ?? 0; |
| | 1224 | |
|
| 0 | 1225 | | if (offset > 0) |
| | 1226 | | { |
| 0 | 1227 | | query = query.Skip(offset); |
| | 1228 | | } |
| | 1229 | |
|
| 0 | 1230 | | if (filter.Limit.HasValue) |
| | 1231 | | { |
| 0 | 1232 | | query = query.Take(filter.Limit.Value); |
| | 1233 | | } |
| | 1234 | | } |
| | 1235 | |
|
| 0 | 1236 | | IQueryable<BaseItemEntity>? itemCountQuery = null; |
| | 1237 | |
|
| 0 | 1238 | | if (filter.IncludeItemTypes.Length > 0) |
| | 1239 | | { |
| | 1240 | | // if we are to include more then one type, sub query those items beforehand. |
| | 1241 | |
|
| 0 | 1242 | | var typeSubQuery = new InternalItemsQuery(filter.User) |
| 0 | 1243 | | { |
| 0 | 1244 | | ExcludeItemTypes = filter.ExcludeItemTypes, |
| 0 | 1245 | | IncludeItemTypes = filter.IncludeItemTypes, |
| 0 | 1246 | | MediaTypes = filter.MediaTypes, |
| 0 | 1247 | | AncestorIds = filter.AncestorIds, |
| 0 | 1248 | | ExcludeItemIds = filter.ExcludeItemIds, |
| 0 | 1249 | | ItemIds = filter.ItemIds, |
| 0 | 1250 | | TopParentIds = filter.TopParentIds, |
| 0 | 1251 | | ParentId = filter.ParentId, |
| 0 | 1252 | | IsPlayed = filter.IsPlayed |
| 0 | 1253 | | }; |
| | 1254 | |
|
| 0 | 1255 | | itemCountQuery = TranslateQuery(context.BaseItems.AsNoTracking().Where(e => e.Id != EF.Constant(PlaceholderI |
| 0 | 1256 | | .Where(e => e.ItemValues!.Any(f => itemValueTypes!.Contains(f.ItemValue.Type))); |
| | 1257 | |
|
| 0 | 1258 | | var seriesTypeName = _itemTypeLookup.BaseItemKindNames[BaseItemKind.Series]; |
| 0 | 1259 | | var movieTypeName = _itemTypeLookup.BaseItemKindNames[BaseItemKind.Movie]; |
| 0 | 1260 | | var episodeTypeName = _itemTypeLookup.BaseItemKindNames[BaseItemKind.Episode]; |
| 0 | 1261 | | var musicAlbumTypeName = _itemTypeLookup.BaseItemKindNames[BaseItemKind.MusicAlbum]; |
| 0 | 1262 | | var musicArtistTypeName = _itemTypeLookup.BaseItemKindNames[BaseItemKind.MusicArtist]; |
| 0 | 1263 | | var audioTypeName = _itemTypeLookup.BaseItemKindNames[BaseItemKind.Audio]; |
| 0 | 1264 | | var trailerTypeName = _itemTypeLookup.BaseItemKindNames[BaseItemKind.Trailer]; |
| | 1265 | |
|
| 0 | 1266 | | var resultQuery = query.Select(e => new |
| 0 | 1267 | | { |
| 0 | 1268 | | item = e.AsQueryable() |
| 0 | 1269 | | .Include(e => e.TrailerTypes) |
| 0 | 1270 | | .Include(e => e.Provider) |
| 0 | 1271 | | .Include(e => e.LockedFields) |
| 0 | 1272 | | .Include(e => e.Images) |
| 0 | 1273 | | .AsSingleQuery().First(), |
| 0 | 1274 | | // TODO: This is bad refactor! |
| 0 | 1275 | | itemCount = new ItemCounts() |
| 0 | 1276 | | { |
| 0 | 1277 | | SeriesCount = itemCountQuery!.Count(f => f.Type == seriesTypeName), |
| 0 | 1278 | | EpisodeCount = itemCountQuery!.Count(f => f.Type == episodeTypeName), |
| 0 | 1279 | | MovieCount = itemCountQuery!.Count(f => f.Type == movieTypeName), |
| 0 | 1280 | | AlbumCount = itemCountQuery!.Count(f => f.Type == musicAlbumTypeName), |
| 0 | 1281 | | ArtistCount = itemCountQuery!.Count(f => f.Type == musicArtistTypeName), |
| 0 | 1282 | | SongCount = itemCountQuery!.Count(f => f.Type == audioTypeName), |
| 0 | 1283 | | TrailerCount = itemCountQuery!.Count(f => f.Type == trailerTypeName), |
| 0 | 1284 | | } |
| 0 | 1285 | | }); |
| | 1286 | |
|
| 0 | 1287 | | result.StartIndex = filter.StartIndex ?? 0; |
| 0 | 1288 | | result.Items = |
| 0 | 1289 | | [ |
| 0 | 1290 | | .. resultQuery |
| 0 | 1291 | | .AsEnumerable() |
| 0 | 1292 | | .Where(e => e is not null) |
| 0 | 1293 | | .Select(e => |
| 0 | 1294 | | { |
| 0 | 1295 | | return (DeserializeBaseItem(e.item, filter.SkipDeserialization), e.itemCount); |
| 0 | 1296 | | }) |
| 0 | 1297 | | ]; |
| | 1298 | | } |
| | 1299 | | else |
| | 1300 | | { |
| 0 | 1301 | | result.StartIndex = filter.StartIndex ?? 0; |
| 0 | 1302 | | result.Items = |
| 0 | 1303 | | [ |
| 0 | 1304 | | .. query |
| 0 | 1305 | | .Select(e => e.First()) |
| 0 | 1306 | | .AsEnumerable() |
| 0 | 1307 | | .Where(e => e is not null) |
| 0 | 1308 | | .Select<BaseItemEntity, (BaseItemDto, ItemCounts?)>(e => |
| 0 | 1309 | | { |
| 0 | 1310 | | return (DeserializeBaseItem(e, filter.SkipDeserialization), null); |
| 0 | 1311 | | }) |
| 0 | 1312 | | ]; |
| | 1313 | | } |
| | 1314 | |
|
| 0 | 1315 | | return result; |
| 0 | 1316 | | } |
| | 1317 | |
|
| | 1318 | | private static void PrepareFilterQuery(InternalItemsQuery query) |
| | 1319 | | { |
| 282 | 1320 | | if (query.Limit.HasValue && query.EnableGroupByMetadataKey) |
| | 1321 | | { |
| 0 | 1322 | | query.Limit = query.Limit.Value + 4; |
| | 1323 | | } |
| | 1324 | |
|
| 282 | 1325 | | if (query.IsResumable ?? false) |
| | 1326 | | { |
| 1 | 1327 | | query.IsVirtualItem = false; |
| | 1328 | | } |
| 282 | 1329 | | } |
| | 1330 | |
|
| | 1331 | | private string GetCleanValue(string value) |
| | 1332 | | { |
| 88 | 1333 | | if (string.IsNullOrWhiteSpace(value)) |
| | 1334 | | { |
| 0 | 1335 | | return value; |
| | 1336 | | } |
| | 1337 | |
|
| 88 | 1338 | | return value.RemoveDiacritics().ToLowerInvariant(); |
| | 1339 | | } |
| | 1340 | |
|
| | 1341 | | private List<(ItemValueType MagicNumber, string Value)> GetItemValuesToSave(BaseItemDto item, List<string> inherited |
| | 1342 | | { |
| 85 | 1343 | | var list = new List<(ItemValueType, string)>(); |
| | 1344 | |
|
| 85 | 1345 | | if (item is IHasArtist hasArtist) |
| | 1346 | | { |
| 0 | 1347 | | list.AddRange(hasArtist.Artists.Select(i => ((ItemValueType)0, i))); |
| | 1348 | | } |
| | 1349 | |
|
| 85 | 1350 | | if (item is IHasAlbumArtist hasAlbumArtist) |
| | 1351 | | { |
| 0 | 1352 | | list.AddRange(hasAlbumArtist.AlbumArtists.Select(i => (ItemValueType.AlbumArtist, i))); |
| | 1353 | | } |
| | 1354 | |
|
| 85 | 1355 | | list.AddRange(item.Genres.Select(i => (ItemValueType.Genre, i))); |
| 85 | 1356 | | list.AddRange(item.Studios.Select(i => (ItemValueType.Studios, i))); |
| 85 | 1357 | | list.AddRange(item.Tags.Select(i => (ItemValueType.Tags, i))); |
| | 1358 | |
|
| | 1359 | | // keywords was 5 |
| | 1360 | |
|
| 85 | 1361 | | list.AddRange(inheritedTags.Select(i => (ItemValueType.InheritedTags, i))); |
| | 1362 | |
|
| | 1363 | | // Remove all invalid values. |
| 85 | 1364 | | list.RemoveAll(i => string.IsNullOrWhiteSpace(i.Item2)); |
| | 1365 | |
|
| 85 | 1366 | | return list; |
| | 1367 | | } |
| | 1368 | |
|
| | 1369 | | private static BaseItemImageInfo Map(Guid baseItemId, ItemImageInfo e) |
| | 1370 | | { |
| 0 | 1371 | | return new BaseItemImageInfo() |
| 0 | 1372 | | { |
| 0 | 1373 | | ItemId = baseItemId, |
| 0 | 1374 | | Id = Guid.NewGuid(), |
| 0 | 1375 | | Path = e.Path, |
| 0 | 1376 | | Blurhash = e.BlurHash is null ? null : Encoding.UTF8.GetBytes(e.BlurHash), |
| 0 | 1377 | | DateModified = e.DateModified, |
| 0 | 1378 | | Height = e.Height, |
| 0 | 1379 | | Width = e.Width, |
| 0 | 1380 | | ImageType = (ImageInfoImageType)e.Type, |
| 0 | 1381 | | Item = null! |
| 0 | 1382 | | }; |
| | 1383 | | } |
| | 1384 | |
|
| | 1385 | | private static ItemImageInfo Map(BaseItemImageInfo e, IServerApplicationHost? appHost) |
| | 1386 | | { |
| 0 | 1387 | | return new ItemImageInfo() |
| 0 | 1388 | | { |
| 0 | 1389 | | Path = appHost?.ExpandVirtualPath(e.Path) ?? e.Path, |
| 0 | 1390 | | BlurHash = e.Blurhash is null ? null : Encoding.UTF8.GetString(e.Blurhash), |
| 0 | 1391 | | DateModified = e.DateModified ?? DateTime.SpecifyKind(DateTime.MinValue, DateTimeKind.Utc), |
| 0 | 1392 | | Height = e.Height, |
| 0 | 1393 | | Width = e.Width, |
| 0 | 1394 | | Type = (ImageType)e.ImageType |
| 0 | 1395 | | }; |
| | 1396 | | } |
| | 1397 | |
|
| | 1398 | | private string? GetPathToSave(string path) |
| | 1399 | | { |
| 85 | 1400 | | if (path is null) |
| | 1401 | | { |
| 0 | 1402 | | return null; |
| | 1403 | | } |
| | 1404 | |
|
| 85 | 1405 | | return _appHost.ReverseVirtualPath(path); |
| | 1406 | | } |
| | 1407 | |
|
| | 1408 | | private List<string> GetItemByNameTypesInQuery(InternalItemsQuery query) |
| | 1409 | | { |
| 17 | 1410 | | var list = new List<string>(); |
| | 1411 | |
|
| 17 | 1412 | | if (IsTypeInQuery(BaseItemKind.Person, query)) |
| | 1413 | | { |
| 1 | 1414 | | list.Add(_itemTypeLookup.BaseItemKindNames[BaseItemKind.Person]!); |
| | 1415 | | } |
| | 1416 | |
|
| 17 | 1417 | | if (IsTypeInQuery(BaseItemKind.Genre, query)) |
| | 1418 | | { |
| 1 | 1419 | | list.Add(_itemTypeLookup.BaseItemKindNames[BaseItemKind.Genre]!); |
| | 1420 | | } |
| | 1421 | |
|
| 17 | 1422 | | if (IsTypeInQuery(BaseItemKind.MusicGenre, query)) |
| | 1423 | | { |
| 1 | 1424 | | list.Add(_itemTypeLookup.BaseItemKindNames[BaseItemKind.MusicGenre]!); |
| | 1425 | | } |
| | 1426 | |
|
| 17 | 1427 | | if (IsTypeInQuery(BaseItemKind.MusicArtist, query)) |
| | 1428 | | { |
| 1 | 1429 | | list.Add(_itemTypeLookup.BaseItemKindNames[BaseItemKind.MusicArtist]!); |
| | 1430 | | } |
| | 1431 | |
|
| 17 | 1432 | | if (IsTypeInQuery(BaseItemKind.Studio, query)) |
| | 1433 | | { |
| 1 | 1434 | | list.Add(_itemTypeLookup.BaseItemKindNames[BaseItemKind.Studio]!); |
| | 1435 | | } |
| | 1436 | |
|
| 17 | 1437 | | return list; |
| | 1438 | | } |
| | 1439 | |
|
| | 1440 | | private bool IsTypeInQuery(BaseItemKind type, InternalItemsQuery query) |
| | 1441 | | { |
| 85 | 1442 | | if (query.ExcludeItemTypes.Contains(type)) |
| | 1443 | | { |
| 0 | 1444 | | return false; |
| | 1445 | | } |
| | 1446 | |
|
| 85 | 1447 | | return query.IncludeItemTypes.Length == 0 || query.IncludeItemTypes.Contains(type); |
| | 1448 | | } |
| | 1449 | |
|
| | 1450 | | private bool EnableGroupByPresentationUniqueKey(InternalItemsQuery query) |
| | 1451 | | { |
| 0 | 1452 | | if (!query.GroupByPresentationUniqueKey) |
| | 1453 | | { |
| 0 | 1454 | | return false; |
| | 1455 | | } |
| | 1456 | |
|
| 0 | 1457 | | if (query.GroupBySeriesPresentationUniqueKey) |
| | 1458 | | { |
| 0 | 1459 | | return false; |
| | 1460 | | } |
| | 1461 | |
|
| 0 | 1462 | | if (!string.IsNullOrWhiteSpace(query.PresentationUniqueKey)) |
| | 1463 | | { |
| 0 | 1464 | | return false; |
| | 1465 | | } |
| | 1466 | |
|
| 0 | 1467 | | if (query.User is null) |
| | 1468 | | { |
| 0 | 1469 | | return false; |
| | 1470 | | } |
| | 1471 | |
|
| 0 | 1472 | | if (query.IncludeItemTypes.Length == 0) |
| | 1473 | | { |
| 0 | 1474 | | return true; |
| | 1475 | | } |
| | 1476 | |
|
| 0 | 1477 | | return query.IncludeItemTypes.Contains(BaseItemKind.Episode) |
| 0 | 1478 | | || query.IncludeItemTypes.Contains(BaseItemKind.Video) |
| 0 | 1479 | | || query.IncludeItemTypes.Contains(BaseItemKind.Movie) |
| 0 | 1480 | | || query.IncludeItemTypes.Contains(BaseItemKind.MusicVideo) |
| 0 | 1481 | | || query.IncludeItemTypes.Contains(BaseItemKind.Series) |
| 0 | 1482 | | || query.IncludeItemTypes.Contains(BaseItemKind.Season); |
| | 1483 | | } |
| | 1484 | |
|
| | 1485 | | private IQueryable<BaseItemEntity> ApplyOrder(IQueryable<BaseItemEntity> query, InternalItemsQuery filter) |
| | 1486 | | { |
| 290 | 1487 | | var orderBy = filter.OrderBy; |
| 290 | 1488 | | var hasSearch = !string.IsNullOrEmpty(filter.SearchTerm); |
| | 1489 | |
|
| 290 | 1490 | | if (hasSearch) |
| | 1491 | | { |
| 0 | 1492 | | orderBy = filter.OrderBy = [(ItemSortBy.SortName, SortOrder.Ascending), .. orderBy]; |
| | 1493 | | } |
| 290 | 1494 | | else if (orderBy.Count == 0) |
| | 1495 | | { |
| 209 | 1496 | | return query.OrderBy(e => e.SortName); |
| | 1497 | | } |
| | 1498 | |
|
| 81 | 1499 | | IOrderedQueryable<BaseItemEntity>? orderedQuery = null; |
| | 1500 | |
|
| 81 | 1501 | | var firstOrdering = orderBy.FirstOrDefault(); |
| 81 | 1502 | | if (firstOrdering != default) |
| | 1503 | | { |
| 81 | 1504 | | var expression = OrderMapper.MapOrderByField(firstOrdering.OrderBy, filter); |
| 81 | 1505 | | if (firstOrdering.SortOrder == SortOrder.Ascending) |
| | 1506 | | { |
| 80 | 1507 | | orderedQuery = query.OrderBy(expression); |
| | 1508 | | } |
| | 1509 | | else |
| | 1510 | | { |
| 1 | 1511 | | orderedQuery = query.OrderByDescending(expression); |
| | 1512 | | } |
| | 1513 | |
|
| 81 | 1514 | | if (firstOrdering.OrderBy is ItemSortBy.Default or ItemSortBy.SortName) |
| | 1515 | | { |
| 0 | 1516 | | if (firstOrdering.SortOrder is SortOrder.Ascending) |
| | 1517 | | { |
| 0 | 1518 | | orderedQuery = orderedQuery.ThenBy(e => e.Name); |
| | 1519 | | } |
| | 1520 | | else |
| | 1521 | | { |
| 0 | 1522 | | orderedQuery = orderedQuery.ThenByDescending(e => e.Name); |
| | 1523 | | } |
| | 1524 | | } |
| | 1525 | | } |
| | 1526 | |
|
| 236 | 1527 | | foreach (var item in orderBy.Skip(1)) |
| | 1528 | | { |
| 37 | 1529 | | var expression = OrderMapper.MapOrderByField(item.OrderBy, filter); |
| 37 | 1530 | | if (item.SortOrder == SortOrder.Ascending) |
| | 1531 | | { |
| 37 | 1532 | | orderedQuery = orderedQuery!.ThenBy(expression); |
| | 1533 | | } |
| | 1534 | | else |
| | 1535 | | { |
| 0 | 1536 | | orderedQuery = orderedQuery!.ThenByDescending(expression); |
| | 1537 | | } |
| | 1538 | | } |
| | 1539 | |
|
| 81 | 1540 | | return orderedQuery ?? query; |
| | 1541 | | } |
| | 1542 | |
|
| | 1543 | | private IQueryable<BaseItemEntity> TranslateQuery( |
| | 1544 | | IQueryable<BaseItemEntity> baseQuery, |
| | 1545 | | JellyfinDbContext context, |
| | 1546 | | InternalItemsQuery filter) |
| | 1547 | | { |
| | 1548 | | const int HDWidth = 1200; |
| | 1549 | | const int UHDWidth = 3800; |
| | 1550 | | const int UHDHeight = 2100; |
| | 1551 | |
|
| 281 | 1552 | | var minWidth = filter.MinWidth; |
| 281 | 1553 | | var maxWidth = filter.MaxWidth; |
| 281 | 1554 | | var now = DateTime.UtcNow; |
| | 1555 | |
|
| 281 | 1556 | | if (filter.IsHD.HasValue || filter.Is4K.HasValue) |
| | 1557 | | { |
| 0 | 1558 | | bool includeSD = false; |
| 0 | 1559 | | bool includeHD = false; |
| 0 | 1560 | | bool include4K = false; |
| | 1561 | |
|
| 0 | 1562 | | if (filter.IsHD.HasValue && !filter.IsHD.Value) |
| | 1563 | | { |
| 0 | 1564 | | includeSD = true; |
| | 1565 | | } |
| | 1566 | |
|
| 0 | 1567 | | if (filter.IsHD.HasValue && filter.IsHD.Value) |
| | 1568 | | { |
| 0 | 1569 | | includeHD = true; |
| | 1570 | | } |
| | 1571 | |
|
| 0 | 1572 | | if (filter.Is4K.HasValue && filter.Is4K.Value) |
| | 1573 | | { |
| 0 | 1574 | | include4K = true; |
| | 1575 | | } |
| | 1576 | |
|
| 0 | 1577 | | baseQuery = baseQuery.Where(e => |
| 0 | 1578 | | (includeSD && e.Width < HDWidth) || |
| 0 | 1579 | | (includeHD && e.Width >= HDWidth && !(e.Width >= UHDWidth || e.Height >= UHDHeight)) || |
| 0 | 1580 | | (include4K && (e.Width >= UHDWidth || e.Height >= UHDHeight))); |
| | 1581 | | } |
| | 1582 | |
|
| 281 | 1583 | | if (minWidth.HasValue) |
| | 1584 | | { |
| 0 | 1585 | | baseQuery = baseQuery.Where(e => e.Width >= minWidth); |
| | 1586 | | } |
| | 1587 | |
|
| 281 | 1588 | | if (filter.MinHeight.HasValue) |
| | 1589 | | { |
| 0 | 1590 | | baseQuery = baseQuery.Where(e => e.Height >= filter.MinHeight); |
| | 1591 | | } |
| | 1592 | |
|
| 281 | 1593 | | if (maxWidth.HasValue) |
| | 1594 | | { |
| 0 | 1595 | | baseQuery = baseQuery.Where(e => e.Width <= maxWidth); |
| | 1596 | | } |
| | 1597 | |
|
| 281 | 1598 | | if (filter.MaxHeight.HasValue) |
| | 1599 | | { |
| 0 | 1600 | | baseQuery = baseQuery.Where(e => e.Height <= filter.MaxHeight); |
| | 1601 | | } |
| | 1602 | |
|
| 281 | 1603 | | if (filter.IsLocked.HasValue) |
| | 1604 | | { |
| 27 | 1605 | | baseQuery = baseQuery.Where(e => e.IsLocked == filter.IsLocked); |
| | 1606 | | } |
| | 1607 | |
|
| 281 | 1608 | | var tags = filter.Tags.ToList(); |
| 281 | 1609 | | var excludeTags = filter.ExcludeTags.ToList(); |
| | 1610 | |
|
| 281 | 1611 | | if (filter.IsMovie == true) |
| | 1612 | | { |
| 0 | 1613 | | if (filter.IncludeItemTypes.Length == 0 |
| 0 | 1614 | | || filter.IncludeItemTypes.Contains(BaseItemKind.Movie) |
| 0 | 1615 | | || filter.IncludeItemTypes.Contains(BaseItemKind.Trailer)) |
| | 1616 | | { |
| 0 | 1617 | | baseQuery = baseQuery.Where(e => e.IsMovie); |
| | 1618 | | } |
| | 1619 | | } |
| 281 | 1620 | | else if (filter.IsMovie.HasValue) |
| | 1621 | | { |
| 0 | 1622 | | baseQuery = baseQuery.Where(e => e.IsMovie == filter.IsMovie); |
| | 1623 | | } |
| | 1624 | |
|
| 281 | 1625 | | if (filter.IsSeries.HasValue) |
| | 1626 | | { |
| 0 | 1627 | | baseQuery = baseQuery.Where(e => e.IsSeries == filter.IsSeries); |
| | 1628 | | } |
| | 1629 | |
|
| 281 | 1630 | | if (filter.IsSports.HasValue) |
| | 1631 | | { |
| 0 | 1632 | | if (filter.IsSports.Value) |
| | 1633 | | { |
| 0 | 1634 | | tags.Add("Sports"); |
| | 1635 | | } |
| | 1636 | | else |
| | 1637 | | { |
| 0 | 1638 | | excludeTags.Add("Sports"); |
| | 1639 | | } |
| | 1640 | | } |
| | 1641 | |
|
| 281 | 1642 | | if (filter.IsNews.HasValue) |
| | 1643 | | { |
| 0 | 1644 | | if (filter.IsNews.Value) |
| | 1645 | | { |
| 0 | 1646 | | tags.Add("News"); |
| | 1647 | | } |
| | 1648 | | else |
| | 1649 | | { |
| 0 | 1650 | | excludeTags.Add("News"); |
| | 1651 | | } |
| | 1652 | | } |
| | 1653 | |
|
| 281 | 1654 | | if (filter.IsKids.HasValue) |
| | 1655 | | { |
| 0 | 1656 | | if (filter.IsKids.Value) |
| | 1657 | | { |
| 0 | 1658 | | tags.Add("Kids"); |
| | 1659 | | } |
| | 1660 | | else |
| | 1661 | | { |
| 0 | 1662 | | excludeTags.Add("Kids"); |
| | 1663 | | } |
| | 1664 | | } |
| | 1665 | |
|
| 281 | 1666 | | if (!string.IsNullOrEmpty(filter.SearchTerm)) |
| | 1667 | | { |
| 0 | 1668 | | var searchTerm = filter.SearchTerm.ToLower(); |
| 0 | 1669 | | baseQuery = baseQuery.Where(e => e.CleanName!.ToLower().Contains(searchTerm) || (e.OriginalTitle != null && |
| | 1670 | | } |
| | 1671 | |
|
| 281 | 1672 | | if (filter.IsFolder.HasValue) |
| | 1673 | | { |
| 21 | 1674 | | baseQuery = baseQuery.Where(e => e.IsFolder == filter.IsFolder); |
| | 1675 | | } |
| | 1676 | |
|
| 281 | 1677 | | var includeTypes = filter.IncludeItemTypes; |
| | 1678 | |
|
| | 1679 | | // Only specify excluded types if no included types are specified |
| 281 | 1680 | | if (filter.IncludeItemTypes.Length == 0) |
| | 1681 | | { |
| 207 | 1682 | | var excludeTypes = filter.ExcludeItemTypes; |
| 207 | 1683 | | if (excludeTypes.Length == 1) |
| | 1684 | | { |
| 0 | 1685 | | if (_itemTypeLookup.BaseItemKindNames.TryGetValue(excludeTypes[0], out var excludeTypeName)) |
| | 1686 | | { |
| 0 | 1687 | | baseQuery = baseQuery.Where(e => e.Type != excludeTypeName); |
| | 1688 | | } |
| | 1689 | | } |
| 207 | 1690 | | else if (excludeTypes.Length > 1) |
| | 1691 | | { |
| 0 | 1692 | | var excludeTypeName = new List<string>(); |
| 0 | 1693 | | foreach (var excludeType in excludeTypes) |
| | 1694 | | { |
| 0 | 1695 | | if (_itemTypeLookup.BaseItemKindNames.TryGetValue(excludeType, out var baseItemKindName)) |
| | 1696 | | { |
| 0 | 1697 | | excludeTypeName.Add(baseItemKindName!); |
| | 1698 | | } |
| | 1699 | | } |
| | 1700 | |
|
| 0 | 1701 | | baseQuery = baseQuery.Where(e => !excludeTypeName.Contains(e.Type)); |
| | 1702 | | } |
| | 1703 | | } |
| | 1704 | | else |
| | 1705 | | { |
| 74 | 1706 | | string[] types = includeTypes.Select(f => _itemTypeLookup.BaseItemKindNames.GetValueOrDefault(f)).Where(e => |
| 74 | 1707 | | baseQuery = baseQuery.WhereOneOrMany(types, f => f.Type); |
| | 1708 | | } |
| | 1709 | |
|
| 281 | 1710 | | if (filter.ChannelIds.Count > 0) |
| | 1711 | | { |
| 0 | 1712 | | baseQuery = baseQuery.Where(e => e.ChannelId != null && filter.ChannelIds.Contains(e.ChannelId.Value)); |
| | 1713 | | } |
| | 1714 | |
|
| 281 | 1715 | | if (!filter.ParentId.IsEmpty()) |
| | 1716 | | { |
| 139 | 1717 | | baseQuery = baseQuery.Where(e => e.ParentId!.Value == filter.ParentId); |
| | 1718 | | } |
| | 1719 | |
|
| 281 | 1720 | | if (!string.IsNullOrWhiteSpace(filter.Path)) |
| | 1721 | | { |
| 0 | 1722 | | baseQuery = baseQuery.Where(e => e.Path == filter.Path); |
| | 1723 | | } |
| | 1724 | |
|
| 281 | 1725 | | if (!string.IsNullOrWhiteSpace(filter.PresentationUniqueKey)) |
| | 1726 | | { |
| 0 | 1727 | | baseQuery = baseQuery.Where(e => e.PresentationUniqueKey == filter.PresentationUniqueKey); |
| | 1728 | | } |
| | 1729 | |
|
| 281 | 1730 | | if (filter.MinCommunityRating.HasValue) |
| | 1731 | | { |
| 0 | 1732 | | baseQuery = baseQuery.Where(e => e.CommunityRating >= filter.MinCommunityRating); |
| | 1733 | | } |
| | 1734 | |
|
| 281 | 1735 | | if (filter.MinIndexNumber.HasValue) |
| | 1736 | | { |
| 0 | 1737 | | baseQuery = baseQuery.Where(e => e.IndexNumber >= filter.MinIndexNumber); |
| | 1738 | | } |
| | 1739 | |
|
| 281 | 1740 | | if (filter.MinParentAndIndexNumber.HasValue) |
| | 1741 | | { |
| 0 | 1742 | | baseQuery = baseQuery |
| 0 | 1743 | | .Where(e => (e.ParentIndexNumber == filter.MinParentAndIndexNumber.Value.ParentIndexNumber && e.IndexNum |
| | 1744 | | } |
| | 1745 | |
|
| 281 | 1746 | | if (filter.MinDateCreated.HasValue) |
| | 1747 | | { |
| 0 | 1748 | | baseQuery = baseQuery.Where(e => e.DateCreated >= filter.MinDateCreated); |
| | 1749 | | } |
| | 1750 | |
|
| 281 | 1751 | | if (filter.MinDateLastSaved.HasValue) |
| | 1752 | | { |
| 0 | 1753 | | baseQuery = baseQuery.Where(e => e.DateLastSaved != null && e.DateLastSaved >= filter.MinDateLastSaved.Value |
| | 1754 | | } |
| | 1755 | |
|
| 281 | 1756 | | if (filter.MinDateLastSavedForUser.HasValue) |
| | 1757 | | { |
| 0 | 1758 | | baseQuery = baseQuery.Where(e => e.DateLastSaved != null && e.DateLastSaved >= filter.MinDateLastSavedForUse |
| | 1759 | | } |
| | 1760 | |
|
| 281 | 1761 | | if (filter.IndexNumber.HasValue) |
| | 1762 | | { |
| 0 | 1763 | | baseQuery = baseQuery.Where(e => e.IndexNumber == filter.IndexNumber.Value); |
| | 1764 | | } |
| | 1765 | |
|
| 281 | 1766 | | if (filter.ParentIndexNumber.HasValue) |
| | 1767 | | { |
| 0 | 1768 | | baseQuery = baseQuery.Where(e => e.ParentIndexNumber == filter.ParentIndexNumber.Value); |
| | 1769 | | } |
| | 1770 | |
|
| 281 | 1771 | | if (filter.ParentIndexNumberNotEquals.HasValue) |
| | 1772 | | { |
| 0 | 1773 | | baseQuery = baseQuery.Where(e => e.ParentIndexNumber != filter.ParentIndexNumberNotEquals.Value || e.ParentI |
| | 1774 | | } |
| | 1775 | |
|
| 281 | 1776 | | var minEndDate = filter.MinEndDate; |
| 281 | 1777 | | var maxEndDate = filter.MaxEndDate; |
| | 1778 | |
|
| 281 | 1779 | | if (filter.HasAired.HasValue) |
| | 1780 | | { |
| 0 | 1781 | | if (filter.HasAired.Value) |
| | 1782 | | { |
| 0 | 1783 | | maxEndDate = DateTime.UtcNow; |
| | 1784 | | } |
| | 1785 | | else |
| | 1786 | | { |
| 0 | 1787 | | minEndDate = DateTime.UtcNow; |
| | 1788 | | } |
| | 1789 | | } |
| | 1790 | |
|
| 281 | 1791 | | if (minEndDate.HasValue) |
| | 1792 | | { |
| 0 | 1793 | | baseQuery = baseQuery.Where(e => e.EndDate >= minEndDate); |
| | 1794 | | } |
| | 1795 | |
|
| 281 | 1796 | | if (maxEndDate.HasValue) |
| | 1797 | | { |
| 0 | 1798 | | baseQuery = baseQuery.Where(e => e.EndDate <= maxEndDate); |
| | 1799 | | } |
| | 1800 | |
|
| 281 | 1801 | | if (filter.MinStartDate.HasValue) |
| | 1802 | | { |
| 0 | 1803 | | baseQuery = baseQuery.Where(e => e.StartDate >= filter.MinStartDate.Value); |
| | 1804 | | } |
| | 1805 | |
|
| 281 | 1806 | | if (filter.MaxStartDate.HasValue) |
| | 1807 | | { |
| 0 | 1808 | | baseQuery = baseQuery.Where(e => e.StartDate <= filter.MaxStartDate.Value); |
| | 1809 | | } |
| | 1810 | |
|
| 281 | 1811 | | if (filter.MinPremiereDate.HasValue) |
| | 1812 | | { |
| 0 | 1813 | | baseQuery = baseQuery.Where(e => e.PremiereDate >= filter.MinPremiereDate.Value); |
| | 1814 | | } |
| | 1815 | |
|
| 281 | 1816 | | if (filter.MaxPremiereDate.HasValue) |
| | 1817 | | { |
| 0 | 1818 | | baseQuery = baseQuery.Where(e => e.PremiereDate <= filter.MaxPremiereDate.Value); |
| | 1819 | | } |
| | 1820 | |
|
| 281 | 1821 | | if (filter.TrailerTypes.Length > 0) |
| | 1822 | | { |
| 0 | 1823 | | var trailerTypes = filter.TrailerTypes.Select(e => (int)e).ToArray(); |
| 0 | 1824 | | baseQuery = baseQuery.Where(e => trailerTypes.Any(f => e.TrailerTypes!.Any(w => w.Id == f))); |
| | 1825 | | } |
| | 1826 | |
|
| 281 | 1827 | | if (filter.IsAiring.HasValue) |
| | 1828 | | { |
| 0 | 1829 | | if (filter.IsAiring.Value) |
| | 1830 | | { |
| 0 | 1831 | | baseQuery = baseQuery.Where(e => e.StartDate <= now && e.EndDate >= now); |
| | 1832 | | } |
| | 1833 | | else |
| | 1834 | | { |
| 0 | 1835 | | baseQuery = baseQuery.Where(e => e.StartDate > now && e.EndDate < now); |
| | 1836 | | } |
| | 1837 | | } |
| | 1838 | |
|
| 281 | 1839 | | if (filter.PersonIds.Length > 0) |
| | 1840 | | { |
| 0 | 1841 | | baseQuery = baseQuery |
| 0 | 1842 | | .Where(e => |
| 0 | 1843 | | context.PeopleBaseItemMap.Where(w => context.BaseItems.Where(r => filter.PersonIds.Contains(r.Id)).A |
| 0 | 1844 | | .Any(f => f.ItemId == e.Id)); |
| | 1845 | | } |
| | 1846 | |
|
| 281 | 1847 | | if (!string.IsNullOrWhiteSpace(filter.Person)) |
| | 1848 | | { |
| 0 | 1849 | | baseQuery = baseQuery.Where(e => e.Peoples!.Any(f => f.People.Name == filter.Person)); |
| | 1850 | | } |
| | 1851 | |
|
| 281 | 1852 | | if (!string.IsNullOrWhiteSpace(filter.MinSortName)) |
| | 1853 | | { |
| | 1854 | | // this does not makes sense. |
| | 1855 | | // baseQuery = baseQuery.Where(e => e.SortName >= query.MinSortName); |
| | 1856 | | // whereClauses.Add("SortName>=@MinSortName"); |
| | 1857 | | // statement?.TryBind("@MinSortName", query.MinSortName); |
| | 1858 | | } |
| | 1859 | |
|
| 281 | 1860 | | if (!string.IsNullOrWhiteSpace(filter.ExternalSeriesId)) |
| | 1861 | | { |
| 0 | 1862 | | baseQuery = baseQuery.Where(e => e.ExternalSeriesId == filter.ExternalSeriesId); |
| | 1863 | | } |
| | 1864 | |
|
| 281 | 1865 | | if (!string.IsNullOrWhiteSpace(filter.ExternalId)) |
| | 1866 | | { |
| 0 | 1867 | | baseQuery = baseQuery.Where(e => e.ExternalId == filter.ExternalId); |
| | 1868 | | } |
| | 1869 | |
|
| 281 | 1870 | | if (!string.IsNullOrWhiteSpace(filter.Name)) |
| | 1871 | | { |
| 3 | 1872 | | var cleanName = GetCleanValue(filter.Name); |
| 3 | 1873 | | baseQuery = baseQuery.Where(e => e.CleanName == cleanName); |
| | 1874 | | } |
| | 1875 | |
|
| | 1876 | | // These are the same, for now |
| 281 | 1877 | | var nameContains = filter.NameContains; |
| 281 | 1878 | | if (!string.IsNullOrWhiteSpace(nameContains)) |
| | 1879 | | { |
| 0 | 1880 | | baseQuery = baseQuery.Where(e => |
| 0 | 1881 | | e.CleanName!.Contains(nameContains) |
| 0 | 1882 | | || e.OriginalTitle!.ToLower().Contains(nameContains!)); |
| | 1883 | | } |
| | 1884 | |
|
| 281 | 1885 | | if (!string.IsNullOrWhiteSpace(filter.NameStartsWith)) |
| | 1886 | | { |
| 0 | 1887 | | baseQuery = baseQuery.Where(e => e.SortName!.StartsWith(filter.NameStartsWith) || e.Name!.StartsWith(filter. |
| | 1888 | | } |
| | 1889 | |
|
| 281 | 1890 | | if (!string.IsNullOrWhiteSpace(filter.NameStartsWithOrGreater)) |
| | 1891 | | { |
| | 1892 | | // i hate this |
| 0 | 1893 | | baseQuery = baseQuery.Where(e => e.SortName!.FirstOrDefault() > filter.NameStartsWithOrGreater[0] || e.Name! |
| | 1894 | | } |
| | 1895 | |
|
| 281 | 1896 | | if (!string.IsNullOrWhiteSpace(filter.NameLessThan)) |
| | 1897 | | { |
| | 1898 | | // i hate this |
| 0 | 1899 | | baseQuery = baseQuery.Where(e => e.SortName!.FirstOrDefault() < filter.NameLessThan[0] || e.Name!.FirstOrDef |
| | 1900 | | } |
| | 1901 | |
|
| 281 | 1902 | | if (filter.ImageTypes.Length > 0) |
| | 1903 | | { |
| 80 | 1904 | | var imgTypes = filter.ImageTypes.Select(e => (ImageInfoImageType)e).ToArray(); |
| 80 | 1905 | | baseQuery = baseQuery.Where(e => imgTypes.Any(f => e.Images!.Any(w => w.ImageType == f))); |
| | 1906 | | } |
| | 1907 | |
|
| 281 | 1908 | | if (filter.IsLiked.HasValue) |
| | 1909 | | { |
| 0 | 1910 | | baseQuery = baseQuery |
| 0 | 1911 | | .Where(e => e.UserData!.FirstOrDefault(f => f.UserId == filter.User!.Id)!.Rating >= UserItemData.MinLike |
| | 1912 | | } |
| | 1913 | |
|
| 281 | 1914 | | if (filter.IsFavoriteOrLiked.HasValue) |
| | 1915 | | { |
| 0 | 1916 | | baseQuery = baseQuery |
| 0 | 1917 | | .Where(e => e.UserData!.FirstOrDefault(f => f.UserId == filter.User!.Id)!.IsFavorite == filter.IsFavorit |
| | 1918 | | } |
| | 1919 | |
|
| 281 | 1920 | | if (filter.IsFavorite.HasValue) |
| | 1921 | | { |
| 0 | 1922 | | baseQuery = baseQuery |
| 0 | 1923 | | .Where(e => e.UserData!.FirstOrDefault(f => f.UserId == filter.User!.Id)!.IsFavorite == filter.IsFavorit |
| | 1924 | | } |
| | 1925 | |
|
| 281 | 1926 | | if (filter.IsPlayed.HasValue) |
| | 1927 | | { |
| | 1928 | | // We should probably figure this out for all folders, but for right now, this is the only place where we ne |
| 0 | 1929 | | if (filter.IncludeItemTypes.Length == 1 && filter.IncludeItemTypes[0] == BaseItemKind.Series) |
| | 1930 | | { |
| 0 | 1931 | | baseQuery = baseQuery.Where(e => context.BaseItems.Where(e => e.Id != EF.Constant(PlaceholderId)) |
| 0 | 1932 | | .Where(e => e.IsFolder == false && e.IsVirtualItem == false) |
| 0 | 1933 | | .Where(f => f.UserData!.FirstOrDefault(e => e.UserId == filter.User!.Id && e.Played)!.Played) |
| 0 | 1934 | | .Any(f => f.SeriesPresentationUniqueKey == e.PresentationUniqueKey) == filter.IsPlayed); |
| | 1935 | | } |
| | 1936 | | else |
| | 1937 | | { |
| 0 | 1938 | | baseQuery = baseQuery |
| 0 | 1939 | | .Select(e => new |
| 0 | 1940 | | { |
| 0 | 1941 | | IsPlayed = e.UserData!.Where(f => f.UserId == filter.User!.Id).Select(f => (bool?)f.Played).Firs |
| 0 | 1942 | | Item = e |
| 0 | 1943 | | }) |
| 0 | 1944 | | .Where(e => e.IsPlayed == filter.IsPlayed) |
| 0 | 1945 | | .Select(f => f.Item); |
| | 1946 | | } |
| | 1947 | | } |
| | 1948 | |
|
| 281 | 1949 | | if (filter.IsResumable.HasValue) |
| | 1950 | | { |
| 1 | 1951 | | if (filter.IsResumable.Value) |
| | 1952 | | { |
| 1 | 1953 | | baseQuery = baseQuery |
| 1 | 1954 | | .Where(e => e.UserData!.FirstOrDefault(f => f.UserId == filter.User!.Id)!.PlaybackPositionTicks > |
| | 1955 | | } |
| | 1956 | | else |
| | 1957 | | { |
| 0 | 1958 | | baseQuery = baseQuery |
| 0 | 1959 | | .Where(e => e.UserData!.FirstOrDefault(f => f.UserId == filter.User!.Id)!.PlaybackPositionTicks = |
| | 1960 | | } |
| | 1961 | | } |
| | 1962 | |
|
| 281 | 1963 | | if (filter.ArtistIds.Length > 0) |
| | 1964 | | { |
| 0 | 1965 | | baseQuery = baseQuery.WhereReferencedItem(context, ItemValueType.Artist, filter.ArtistIds); |
| | 1966 | | } |
| | 1967 | |
|
| 281 | 1968 | | if (filter.AlbumArtistIds.Length > 0) |
| | 1969 | | { |
| 0 | 1970 | | baseQuery = baseQuery.WhereReferencedItem(context, ItemValueType.AlbumArtist, filter.AlbumArtistIds); |
| | 1971 | | } |
| | 1972 | |
|
| 281 | 1973 | | if (filter.ContributingArtistIds.Length > 0) |
| | 1974 | | { |
| 0 | 1975 | | baseQuery = baseQuery.WhereReferencedItem(context, ItemValueType.Artist, filter.ContributingArtistIds); |
| | 1976 | | } |
| | 1977 | |
|
| 281 | 1978 | | if (filter.AlbumIds.Length > 0) |
| | 1979 | | { |
| 0 | 1980 | | var subQuery = context.BaseItems.WhereOneOrMany(filter.AlbumIds, f => f.Id); |
| 0 | 1981 | | baseQuery = baseQuery.Where(e => subQuery.Any(f => f.Name == e.Album)); |
| | 1982 | | } |
| | 1983 | |
|
| 281 | 1984 | | if (filter.ExcludeArtistIds.Length > 0) |
| | 1985 | | { |
| 0 | 1986 | | baseQuery = baseQuery.WhereReferencedItem(context, ItemValueType.Artist, filter.ExcludeArtistIds, true); |
| | 1987 | | } |
| | 1988 | |
|
| 281 | 1989 | | if (filter.GenreIds.Count > 0) |
| | 1990 | | { |
| 0 | 1991 | | baseQuery = baseQuery.WhereReferencedItem(context, ItemValueType.Genre, filter.GenreIds.ToArray()); |
| | 1992 | | } |
| | 1993 | |
|
| 281 | 1994 | | if (filter.Genres.Count > 0) |
| | 1995 | | { |
| 0 | 1996 | | var cleanGenres = filter.Genres.Select(e => GetCleanValue(e)).ToArray().OneOrManyExpressionBuilder<ItemValue |
| 0 | 1997 | | baseQuery = baseQuery |
| 0 | 1998 | | .Where(e => e.ItemValues!.AsQueryable().Where(f => f.ItemValue.Type == ItemValueType.Genre).Any(clea |
| | 1999 | | } |
| | 2000 | |
|
| 281 | 2001 | | if (tags.Count > 0) |
| | 2002 | | { |
| 0 | 2003 | | var cleanValues = tags.Select(e => GetCleanValue(e)).ToArray().OneOrManyExpressionBuilder<ItemValueMap, stri |
| 0 | 2004 | | baseQuery = baseQuery |
| 0 | 2005 | | .Where(e => e.ItemValues!.AsQueryable().Where(f => f.ItemValue.Type == ItemValueType.Tags).Any(clean |
| | 2006 | | } |
| | 2007 | |
|
| 281 | 2008 | | if (excludeTags.Count > 0) |
| | 2009 | | { |
| 0 | 2010 | | var cleanValues = excludeTags.Select(e => GetCleanValue(e)).ToArray().OneOrManyExpressionBuilder<ItemValueMa |
| 0 | 2011 | | baseQuery = baseQuery |
| 0 | 2012 | | .Where(e => !e.ItemValues!.AsQueryable().Where(f => f.ItemValue.Type == ItemValueType.Tags).Any(clea |
| | 2013 | | } |
| | 2014 | |
|
| 281 | 2015 | | if (filter.StudioIds.Length > 0) |
| | 2016 | | { |
| 0 | 2017 | | baseQuery = baseQuery.WhereReferencedItem(context, ItemValueType.Studios, filter.StudioIds.ToArray()); |
| | 2018 | | } |
| | 2019 | |
|
| 281 | 2020 | | if (filter.OfficialRatings.Length > 0) |
| | 2021 | | { |
| 0 | 2022 | | baseQuery = baseQuery |
| 0 | 2023 | | .Where(e => filter.OfficialRatings.Contains(e.OfficialRating)); |
| | 2024 | | } |
| | 2025 | |
|
| 281 | 2026 | | Expression<Func<BaseItemEntity, bool>>? minParentalRatingFilter = null; |
| 281 | 2027 | | if (filter.MinParentalRating != null) |
| | 2028 | | { |
| 0 | 2029 | | var min = filter.MinParentalRating; |
| 0 | 2030 | | minParentalRatingFilter = e => e.InheritedParentalRatingValue >= min.Score || e.InheritedParentalRatingValue |
| 0 | 2031 | | if (min.SubScore != null) |
| | 2032 | | { |
| 0 | 2033 | | minParentalRatingFilter = minParentalRatingFilter.And(e => e.InheritedParentalRatingValue >= min.SubScor |
| | 2034 | | } |
| | 2035 | | } |
| | 2036 | |
|
| 281 | 2037 | | Expression<Func<BaseItemEntity, bool>>? maxParentalRatingFilter = null; |
| 281 | 2038 | | if (filter.MaxParentalRating != null) |
| | 2039 | | { |
| 27 | 2040 | | var max = filter.MaxParentalRating; |
| 27 | 2041 | | maxParentalRatingFilter = e => e.InheritedParentalRatingValue <= max.Score || e.InheritedParentalRatingValue |
| 27 | 2042 | | if (max.SubScore != null) |
| | 2043 | | { |
| 0 | 2044 | | maxParentalRatingFilter = maxParentalRatingFilter.And(e => e.InheritedParentalRatingValue <= max.SubScor |
| | 2045 | | } |
| | 2046 | | } |
| | 2047 | |
|
| 281 | 2048 | | if (filter.HasParentalRating ?? false) |
| | 2049 | | { |
| 0 | 2050 | | if (minParentalRatingFilter != null) |
| | 2051 | | { |
| 0 | 2052 | | baseQuery = baseQuery.Where(minParentalRatingFilter); |
| | 2053 | | } |
| | 2054 | |
|
| 0 | 2055 | | if (maxParentalRatingFilter != null) |
| | 2056 | | { |
| 0 | 2057 | | baseQuery = baseQuery.Where(maxParentalRatingFilter); |
| | 2058 | | } |
| | 2059 | | } |
| 281 | 2060 | | else if (filter.BlockUnratedItems.Length > 0) |
| | 2061 | | { |
| 0 | 2062 | | var unratedItemTypes = filter.BlockUnratedItems.Select(f => f.ToString()).ToArray(); |
| 0 | 2063 | | Expression<Func<BaseItemEntity, bool>> unratedItemFilter = e => e.InheritedParentalRatingValue != null || !u |
| | 2064 | |
|
| 0 | 2065 | | if (minParentalRatingFilter != null && maxParentalRatingFilter != null) |
| | 2066 | | { |
| 0 | 2067 | | baseQuery = baseQuery.Where(unratedItemFilter.And(minParentalRatingFilter.And(maxParentalRatingFilter))) |
| | 2068 | | } |
| 0 | 2069 | | else if (minParentalRatingFilter != null) |
| | 2070 | | { |
| 0 | 2071 | | baseQuery = baseQuery.Where(unratedItemFilter.And(minParentalRatingFilter)); |
| | 2072 | | } |
| 0 | 2073 | | else if (maxParentalRatingFilter != null) |
| | 2074 | | { |
| 0 | 2075 | | baseQuery = baseQuery.Where(unratedItemFilter.And(maxParentalRatingFilter)); |
| | 2076 | | } |
| | 2077 | | else |
| | 2078 | | { |
| 0 | 2079 | | baseQuery = baseQuery.Where(unratedItemFilter); |
| | 2080 | | } |
| | 2081 | | } |
| 281 | 2082 | | else if (minParentalRatingFilter != null || maxParentalRatingFilter != null) |
| | 2083 | | { |
| 27 | 2084 | | if (minParentalRatingFilter != null) |
| | 2085 | | { |
| 0 | 2086 | | baseQuery = baseQuery.Where(minParentalRatingFilter); |
| | 2087 | | } |
| | 2088 | |
|
| 27 | 2089 | | if (maxParentalRatingFilter != null) |
| | 2090 | | { |
| 27 | 2091 | | baseQuery = baseQuery.Where(maxParentalRatingFilter); |
| | 2092 | | } |
| | 2093 | | } |
| 254 | 2094 | | else if (!filter.HasParentalRating ?? false) |
| | 2095 | | { |
| 0 | 2096 | | baseQuery = baseQuery |
| 0 | 2097 | | .Where(e => e.InheritedParentalRatingValue == null); |
| | 2098 | | } |
| | 2099 | |
|
| 281 | 2100 | | if (filter.HasOfficialRating.HasValue) |
| | 2101 | | { |
| 0 | 2102 | | if (filter.HasOfficialRating.Value) |
| | 2103 | | { |
| 0 | 2104 | | baseQuery = baseQuery |
| 0 | 2105 | | .Where(e => e.OfficialRating != null && e.OfficialRating != string.Empty); |
| | 2106 | | } |
| | 2107 | | else |
| | 2108 | | { |
| 0 | 2109 | | baseQuery = baseQuery |
| 0 | 2110 | | .Where(e => e.OfficialRating == null || e.OfficialRating == string.Empty); |
| | 2111 | | } |
| | 2112 | | } |
| | 2113 | |
|
| 281 | 2114 | | if (filter.HasOverview.HasValue) |
| | 2115 | | { |
| 0 | 2116 | | if (filter.HasOverview.Value) |
| | 2117 | | { |
| 0 | 2118 | | baseQuery = baseQuery |
| 0 | 2119 | | .Where(e => e.Overview != null && e.Overview != string.Empty); |
| | 2120 | | } |
| | 2121 | | else |
| | 2122 | | { |
| 0 | 2123 | | baseQuery = baseQuery |
| 0 | 2124 | | .Where(e => e.Overview == null || e.Overview == string.Empty); |
| | 2125 | | } |
| | 2126 | | } |
| | 2127 | |
|
| 281 | 2128 | | if (filter.HasOwnerId.HasValue) |
| | 2129 | | { |
| 0 | 2130 | | if (filter.HasOwnerId.Value) |
| | 2131 | | { |
| 0 | 2132 | | baseQuery = baseQuery |
| 0 | 2133 | | .Where(e => e.OwnerId != null); |
| | 2134 | | } |
| | 2135 | | else |
| | 2136 | | { |
| 0 | 2137 | | baseQuery = baseQuery |
| 0 | 2138 | | .Where(e => e.OwnerId == null); |
| | 2139 | | } |
| | 2140 | | } |
| | 2141 | |
|
| 281 | 2142 | | if (!string.IsNullOrWhiteSpace(filter.HasNoAudioTrackWithLanguage)) |
| | 2143 | | { |
| 0 | 2144 | | baseQuery = baseQuery |
| 0 | 2145 | | .Where(e => !e.MediaStreams!.Any(f => f.StreamType == MediaStreamTypeEntity.Audio && f.Language == filte |
| | 2146 | | } |
| | 2147 | |
|
| 281 | 2148 | | if (!string.IsNullOrWhiteSpace(filter.HasNoInternalSubtitleTrackWithLanguage)) |
| | 2149 | | { |
| 0 | 2150 | | baseQuery = baseQuery |
| 0 | 2151 | | .Where(e => !e.MediaStreams!.Any(f => f.StreamType == MediaStreamTypeEntity.Subtitle && !f.IsExternal && |
| | 2152 | | } |
| | 2153 | |
|
| 281 | 2154 | | if (!string.IsNullOrWhiteSpace(filter.HasNoExternalSubtitleTrackWithLanguage)) |
| | 2155 | | { |
| 0 | 2156 | | baseQuery = baseQuery |
| 0 | 2157 | | .Where(e => !e.MediaStreams!.Any(f => f.StreamType == MediaStreamTypeEntity.Subtitle && f.IsExternal && |
| | 2158 | | } |
| | 2159 | |
|
| 281 | 2160 | | if (!string.IsNullOrWhiteSpace(filter.HasNoSubtitleTrackWithLanguage)) |
| | 2161 | | { |
| 0 | 2162 | | baseQuery = baseQuery |
| 0 | 2163 | | .Where(e => !e.MediaStreams!.Any(f => f.StreamType == MediaStreamTypeEntity.Subtitle && f.Language == fi |
| | 2164 | | } |
| | 2165 | |
|
| 281 | 2166 | | if (filter.HasSubtitles.HasValue) |
| | 2167 | | { |
| 0 | 2168 | | baseQuery = baseQuery |
| 0 | 2169 | | .Where(e => e.MediaStreams!.Any(f => f.StreamType == MediaStreamTypeEntity.Subtitle) == filter.HasSubtit |
| | 2170 | | } |
| | 2171 | |
|
| 281 | 2172 | | if (filter.HasChapterImages.HasValue) |
| | 2173 | | { |
| 0 | 2174 | | baseQuery = baseQuery |
| 0 | 2175 | | .Where(e => e.Chapters!.Any(f => f.ImagePath != null) == filter.HasChapterImages.Value); |
| | 2176 | | } |
| | 2177 | |
|
| 281 | 2178 | | if (filter.HasDeadParentId.HasValue && filter.HasDeadParentId.Value) |
| | 2179 | | { |
| 9 | 2180 | | baseQuery = baseQuery |
| 9 | 2181 | | .Where(e => e.ParentId.HasValue && !context.BaseItems.Where(e => e.Id != EF.Constant(PlaceholderId)).Any |
| | 2182 | | } |
| | 2183 | |
|
| 281 | 2184 | | if (filter.IsDeadArtist.HasValue && filter.IsDeadArtist.Value) |
| | 2185 | | { |
| 9 | 2186 | | baseQuery = baseQuery |
| 9 | 2187 | | .Where(e => !context.ItemValues.Where(f => _getAllArtistsValueTypes.Contains(f.Type)).Any(f => f.Val |
| | 2188 | | } |
| | 2189 | |
|
| 281 | 2190 | | if (filter.IsDeadStudio.HasValue && filter.IsDeadStudio.Value) |
| | 2191 | | { |
| 9 | 2192 | | baseQuery = baseQuery |
| 9 | 2193 | | .Where(e => !context.ItemValues.Where(f => _getStudiosValueTypes.Contains(f.Type)).Any(f => f.Value |
| | 2194 | | } |
| | 2195 | |
|
| 281 | 2196 | | if (filter.IsDeadGenre.HasValue && filter.IsDeadGenre.Value) |
| | 2197 | | { |
| 9 | 2198 | | baseQuery = baseQuery |
| 9 | 2199 | | .Where(e => !context.ItemValues.Where(f => _getGenreValueTypes.Contains(f.Type)).Any(f => f.Value == |
| | 2200 | | } |
| | 2201 | |
|
| 281 | 2202 | | if (filter.IsDeadPerson.HasValue && filter.IsDeadPerson.Value) |
| | 2203 | | { |
| 0 | 2204 | | baseQuery = baseQuery |
| 0 | 2205 | | .Where(e => !context.Peoples.Any(f => f.Name == e.Name)); |
| | 2206 | | } |
| | 2207 | |
|
| 281 | 2208 | | if (filter.Years.Length > 0) |
| | 2209 | | { |
| 0 | 2210 | | baseQuery = baseQuery.WhereOneOrMany(filter.Years, e => e.ProductionYear!.Value); |
| | 2211 | | } |
| | 2212 | |
|
| 281 | 2213 | | var isVirtualItem = filter.IsVirtualItem ?? filter.IsMissing; |
| 281 | 2214 | | if (isVirtualItem.HasValue) |
| | 2215 | | { |
| 22 | 2216 | | baseQuery = baseQuery |
| 22 | 2217 | | .Where(e => e.IsVirtualItem == isVirtualItem.Value); |
| | 2218 | | } |
| | 2219 | |
|
| 281 | 2220 | | if (filter.IsSpecialSeason.HasValue) |
| | 2221 | | { |
| 0 | 2222 | | if (filter.IsSpecialSeason.Value) |
| | 2223 | | { |
| 0 | 2224 | | baseQuery = baseQuery |
| 0 | 2225 | | .Where(e => e.IndexNumber == 0); |
| | 2226 | | } |
| | 2227 | | else |
| | 2228 | | { |
| 0 | 2229 | | baseQuery = baseQuery |
| 0 | 2230 | | .Where(e => e.IndexNumber != 0); |
| | 2231 | | } |
| | 2232 | | } |
| | 2233 | |
|
| 281 | 2234 | | if (filter.IsUnaired.HasValue) |
| | 2235 | | { |
| 0 | 2236 | | if (filter.IsUnaired.Value) |
| | 2237 | | { |
| 0 | 2238 | | baseQuery = baseQuery |
| 0 | 2239 | | .Where(e => e.PremiereDate >= now); |
| | 2240 | | } |
| | 2241 | | else |
| | 2242 | | { |
| 0 | 2243 | | baseQuery = baseQuery |
| 0 | 2244 | | .Where(e => e.PremiereDate < now); |
| | 2245 | | } |
| | 2246 | | } |
| | 2247 | |
|
| 281 | 2248 | | if (filter.MediaTypes.Length > 0) |
| | 2249 | | { |
| 21 | 2250 | | var mediaTypes = filter.MediaTypes.Select(f => f.ToString()).ToArray(); |
| 21 | 2251 | | baseQuery = baseQuery.WhereOneOrMany(mediaTypes, e => e.MediaType); |
| | 2252 | | } |
| | 2253 | |
|
| 281 | 2254 | | if (filter.ItemIds.Length > 0) |
| | 2255 | | { |
| 0 | 2256 | | baseQuery = baseQuery.WhereOneOrMany(filter.ItemIds, e => e.Id); |
| | 2257 | | } |
| | 2258 | |
|
| 281 | 2259 | | if (filter.ExcludeItemIds.Length > 0) |
| | 2260 | | { |
| 0 | 2261 | | baseQuery = baseQuery |
| 0 | 2262 | | .Where(e => !filter.ExcludeItemIds.Contains(e.Id)); |
| | 2263 | | } |
| | 2264 | |
|
| 281 | 2265 | | if (filter.ExcludeProviderIds is not null && filter.ExcludeProviderIds.Count > 0) |
| | 2266 | | { |
| 0 | 2267 | | var exclude = filter.ExcludeProviderIds.Select(e => $"{e.Key}:{e.Value}").ToArray(); |
| 0 | 2268 | | baseQuery = baseQuery.Where(e => e.Provider!.Select(f => f.ProviderId + ":" + f.ProviderValue)!.All(f => !ex |
| | 2269 | | } |
| | 2270 | |
|
| 281 | 2271 | | if (filter.HasAnyProviderId is not null && filter.HasAnyProviderId.Count > 0) |
| | 2272 | | { |
| 0 | 2273 | | var include = filter.HasAnyProviderId.Select(e => $"{e.Key}:{e.Value}").ToArray(); |
| 0 | 2274 | | baseQuery = baseQuery.Where(e => e.Provider!.Select(f => f.ProviderId + ":" + f.ProviderValue)!.Any(f => inc |
| | 2275 | | } |
| | 2276 | |
|
| 281 | 2277 | | if (filter.HasImdbId.HasValue) |
| | 2278 | | { |
| 0 | 2279 | | baseQuery = baseQuery.Where(e => e.Provider!.Any(f => f.ProviderId == "imdb")); |
| | 2280 | | } |
| | 2281 | |
|
| 281 | 2282 | | if (filter.HasTmdbId.HasValue) |
| | 2283 | | { |
| 0 | 2284 | | baseQuery = baseQuery.Where(e => e.Provider!.Any(f => f.ProviderId == "tmdb")); |
| | 2285 | | } |
| | 2286 | |
|
| 281 | 2287 | | if (filter.HasTvdbId.HasValue) |
| | 2288 | | { |
| 0 | 2289 | | baseQuery = baseQuery.Where(e => e.Provider!.Any(f => f.ProviderId == "tvdb")); |
| | 2290 | | } |
| | 2291 | |
|
| 281 | 2292 | | var queryTopParentIds = filter.TopParentIds; |
| | 2293 | |
|
| 281 | 2294 | | if (queryTopParentIds.Length > 0) |
| | 2295 | | { |
| 17 | 2296 | | var includedItemByNameTypes = GetItemByNameTypesInQuery(filter); |
| 17 | 2297 | | var enableItemsByName = (filter.IncludeItemsByName ?? false) && includedItemByNameTypes.Count > 0; |
| 17 | 2298 | | if (enableItemsByName && includedItemByNameTypes.Count > 0) |
| | 2299 | | { |
| 0 | 2300 | | baseQuery = baseQuery.Where(e => includedItemByNameTypes.Contains(e.Type) || queryTopParentIds.Any(w => |
| | 2301 | | } |
| | 2302 | | else |
| | 2303 | | { |
| 17 | 2304 | | baseQuery = baseQuery.WhereOneOrMany(queryTopParentIds, e => e.TopParentId!.Value); |
| | 2305 | | } |
| | 2306 | | } |
| | 2307 | |
|
| 281 | 2308 | | if (filter.AncestorIds.Length > 0) |
| | 2309 | | { |
| 38 | 2310 | | baseQuery = baseQuery.Where(e => e.Parents!.Any(f => filter.AncestorIds.Contains(f.ParentItemId))); |
| | 2311 | | } |
| | 2312 | |
|
| 281 | 2313 | | if (!string.IsNullOrWhiteSpace(filter.AncestorWithPresentationUniqueKey)) |
| | 2314 | | { |
| 0 | 2315 | | baseQuery = baseQuery |
| 0 | 2316 | | .Where(e => context.BaseItems.Where(e => e.Id != EF.Constant(PlaceholderId)).Where(f => f.PresentationUn |
| | 2317 | | } |
| | 2318 | |
|
| 281 | 2319 | | if (!string.IsNullOrWhiteSpace(filter.SeriesPresentationUniqueKey)) |
| | 2320 | | { |
| 0 | 2321 | | baseQuery = baseQuery |
| 0 | 2322 | | .Where(e => e.SeriesPresentationUniqueKey == filter.SeriesPresentationUniqueKey); |
| | 2323 | | } |
| | 2324 | |
|
| 281 | 2325 | | if (filter.ExcludeInheritedTags.Length > 0) |
| | 2326 | | { |
| 0 | 2327 | | baseQuery = baseQuery |
| 0 | 2328 | | .Where(e => !e.ItemValues!.Where(w => w.ItemValue.Type == ItemValueType.InheritedTags || w.ItemValue.Typ |
| 0 | 2329 | | .Any(f => filter.ExcludeInheritedTags.Contains(f.ItemValue.CleanValue))); |
| | 2330 | | } |
| | 2331 | |
|
| 281 | 2332 | | if (filter.IncludeInheritedTags.Length > 0) |
| | 2333 | | { |
| | 2334 | | // Episodes do not store inherit tags from their parents in the database, and the tag may be still required |
| | 2335 | | // In addition to the tags for the episodes themselves, we need to manually query its parent (the season)'s |
| 0 | 2336 | | if (includeTypes.Length == 1 && includeTypes.FirstOrDefault() is BaseItemKind.Episode) |
| | 2337 | | { |
| 0 | 2338 | | baseQuery = baseQuery |
| 0 | 2339 | | .Where(e => e.ItemValues!.Where(f => f.ItemValue.Type == ItemValueType.InheritedTags || f.ItemValue. |
| 0 | 2340 | | .Any(f => filter.IncludeInheritedTags.Contains(f.ItemValue.CleanValue)) |
| 0 | 2341 | | || |
| 0 | 2342 | | (e.ParentId.HasValue && context.ItemValuesMap.Where(w => w.ItemId == e.ParentId.Value && (w.Item |
| 0 | 2343 | | .Any(f => filter.IncludeInheritedTags.Contains(f.ItemValue.CleanValue)))); |
| | 2344 | | } |
| | 2345 | |
|
| | 2346 | | // A playlist should be accessible to its owner regardless of allowed tags. |
| 0 | 2347 | | else if (includeTypes.Length == 1 && includeTypes.FirstOrDefault() is BaseItemKind.Playlist) |
| | 2348 | | { |
| 0 | 2349 | | baseQuery = baseQuery |
| 0 | 2350 | | .Where(e => e.ItemValues!.Where(f => f.ItemValue.Type == ItemValueType.InheritedTags || f.ItemValue. |
| 0 | 2351 | | .Any(f => filter.IncludeInheritedTags.Contains(f.ItemValue.CleanValue)) |
| 0 | 2352 | | || e.Data!.Contains($"OwnerUserId\":\"{filter.User!.Id:N}\"")); |
| | 2353 | | // d ^^ this is stupid it hate this. |
| | 2354 | | } |
| | 2355 | | else |
| | 2356 | | { |
| 0 | 2357 | | baseQuery = baseQuery |
| 0 | 2358 | | .Where(e => e.ItemValues!.Where(f => f.ItemValue.Type == ItemValueType.InheritedTags || f.ItemValue. |
| 0 | 2359 | | .Any(f => filter.IncludeInheritedTags.Contains(f.ItemValue.CleanValue))); |
| | 2360 | | } |
| | 2361 | | } |
| | 2362 | |
|
| 281 | 2363 | | if (filter.SeriesStatuses.Length > 0) |
| | 2364 | | { |
| 0 | 2365 | | var seriesStatus = filter.SeriesStatuses.Select(e => e.ToString()).ToArray(); |
| 0 | 2366 | | baseQuery = baseQuery |
| 0 | 2367 | | .Where(e => seriesStatus.Any(f => e.Data!.Contains(f))); |
| | 2368 | | } |
| | 2369 | |
|
| 281 | 2370 | | if (filter.BoxSetLibraryFolders.Length > 0) |
| | 2371 | | { |
| 0 | 2372 | | var boxsetFolders = filter.BoxSetLibraryFolders.Select(e => e.ToString("N", CultureInfo.InvariantCulture)).T |
| 0 | 2373 | | baseQuery = baseQuery |
| 0 | 2374 | | .Where(e => boxsetFolders.Any(f => e.Data!.Contains(f))); |
| | 2375 | | } |
| | 2376 | |
|
| 281 | 2377 | | if (filter.VideoTypes.Length > 0) |
| | 2378 | | { |
| 0 | 2379 | | var videoTypeBs = filter.VideoTypes.Select(e => $"\"VideoType\":\"{e}\""); |
| 0 | 2380 | | baseQuery = baseQuery |
| 0 | 2381 | | .Where(e => videoTypeBs.Any(f => e.Data!.Contains(f))); |
| | 2382 | | } |
| | 2383 | |
|
| 281 | 2384 | | if (filter.Is3D.HasValue) |
| | 2385 | | { |
| 0 | 2386 | | if (filter.Is3D.Value) |
| | 2387 | | { |
| 0 | 2388 | | baseQuery = baseQuery |
| 0 | 2389 | | .Where(e => e.Data!.Contains("Video3DFormat")); |
| | 2390 | | } |
| | 2391 | | else |
| | 2392 | | { |
| 0 | 2393 | | baseQuery = baseQuery |
| 0 | 2394 | | .Where(e => !e.Data!.Contains("Video3DFormat")); |
| | 2395 | | } |
| | 2396 | | } |
| | 2397 | |
|
| 281 | 2398 | | if (filter.IsPlaceHolder.HasValue) |
| | 2399 | | { |
| 0 | 2400 | | if (filter.IsPlaceHolder.Value) |
| | 2401 | | { |
| 0 | 2402 | | baseQuery = baseQuery |
| 0 | 2403 | | .Where(e => e.Data!.Contains("IsPlaceHolder\":true")); |
| | 2404 | | } |
| | 2405 | | else |
| | 2406 | | { |
| 0 | 2407 | | baseQuery = baseQuery |
| 0 | 2408 | | .Where(e => !e.Data!.Contains("IsPlaceHolder\":true")); |
| | 2409 | | } |
| | 2410 | | } |
| | 2411 | |
|
| 281 | 2412 | | if (filter.HasSpecialFeature.HasValue) |
| | 2413 | | { |
| 0 | 2414 | | if (filter.HasSpecialFeature.Value) |
| | 2415 | | { |
| 0 | 2416 | | baseQuery = baseQuery |
| 0 | 2417 | | .Where(e => e.ExtraIds != null); |
| | 2418 | | } |
| | 2419 | | else |
| | 2420 | | { |
| 0 | 2421 | | baseQuery = baseQuery |
| 0 | 2422 | | .Where(e => e.ExtraIds == null); |
| | 2423 | | } |
| | 2424 | | } |
| | 2425 | |
|
| 281 | 2426 | | if (filter.HasTrailer.HasValue || filter.HasThemeSong.HasValue || filter.HasThemeVideo.HasValue) |
| | 2427 | | { |
| 0 | 2428 | | if (filter.HasTrailer.GetValueOrDefault() || filter.HasThemeSong.GetValueOrDefault() || filter.HasThemeVideo |
| | 2429 | | { |
| 0 | 2430 | | baseQuery = baseQuery |
| 0 | 2431 | | .Where(e => e.ExtraIds != null); |
| | 2432 | | } |
| | 2433 | | else |
| | 2434 | | { |
| 0 | 2435 | | baseQuery = baseQuery |
| 0 | 2436 | | .Where(e => e.ExtraIds == null); |
| | 2437 | | } |
| | 2438 | | } |
| | 2439 | |
|
| 281 | 2440 | | return baseQuery; |
| | 2441 | | } |
| | 2442 | |
|
| | 2443 | | /// <inheritdoc/> |
| | 2444 | | public async Task<bool> ItemExistsAsync(Guid id) |
| | 2445 | | { |
| | 2446 | | var dbContext = await _dbProvider.CreateDbContextAsync().ConfigureAwait(false); |
| | 2447 | | await using (dbContext.ConfigureAwait(false)) |
| | 2448 | | { |
| | 2449 | | return await dbContext.BaseItems.AnyAsync(f => f.Id == id).ConfigureAwait(false); |
| | 2450 | | } |
| | 2451 | | } |
| | 2452 | | } |