| | | 1 | | #nullable disable |
| | | 2 | | |
| | | 3 | | #pragma warning disable CS1591 |
| | | 4 | | |
| | | 5 | | using System; |
| | | 6 | | using System.Collections.Generic; |
| | | 7 | | using System.Linq; |
| | | 8 | | using System.Text.Json.Serialization; |
| | | 9 | | using System.Threading; |
| | | 10 | | using System.Threading.Tasks; |
| | | 11 | | using Jellyfin.Data; |
| | | 12 | | using Jellyfin.Data.Enums; |
| | | 13 | | using Jellyfin.Database.Implementations.Entities; |
| | | 14 | | using Jellyfin.Database.Implementations.Enums; |
| | | 15 | | using MediaBrowser.Controller.Dto; |
| | | 16 | | using MediaBrowser.Controller.Providers; |
| | | 17 | | using MediaBrowser.Model.Entities; |
| | | 18 | | using MediaBrowser.Model.Querying; |
| | | 19 | | using MetadataProvider = MediaBrowser.Model.Entities.MetadataProvider; |
| | | 20 | | |
| | | 21 | | namespace MediaBrowser.Controller.Entities.TV |
| | | 22 | | { |
| | | 23 | | /// <summary> |
| | | 24 | | /// Class Series. |
| | | 25 | | /// </summary> |
| | | 26 | | public class Series : Folder, IHasTrailers, IHasDisplayOrder, IHasLookupInfo<SeriesInfo>, IMetadataContainer, ISuppo |
| | | 27 | | { |
| | 169 | 28 | | public Series() |
| | | 29 | | { |
| | 169 | 30 | | AirDays = Array.Empty<DayOfWeek>(); |
| | 169 | 31 | | } |
| | | 32 | | |
| | | 33 | | public DayOfWeek[] AirDays { get; set; } |
| | | 34 | | |
| | | 35 | | public string AirTime { get; set; } |
| | | 36 | | |
| | | 37 | | [JsonIgnore] |
| | 0 | 38 | | public override bool SupportsAddingToPlaylist => true; |
| | | 39 | | |
| | | 40 | | [JsonIgnore] |
| | 0 | 41 | | public override bool IsPreSorted => true; |
| | | 42 | | |
| | | 43 | | [JsonIgnore] |
| | 0 | 44 | | public override bool SupportsDateLastMediaAdded => true; |
| | | 45 | | |
| | | 46 | | [JsonIgnore] |
| | 3 | 47 | | public override bool SupportsInheritedParentImages => false; |
| | | 48 | | |
| | | 49 | | [JsonIgnore] |
| | 0 | 50 | | public override bool SupportsPeople => true; |
| | | 51 | | |
| | | 52 | | /// <inheritdoc /> |
| | | 53 | | [JsonIgnore] |
| | 0 | 54 | | public IReadOnlyList<BaseItem> LocalTrailers => GetExtras([Model.Entities.ExtraType.Trailer]).ToArray(); |
| | | 55 | | |
| | | 56 | | /// <summary> |
| | | 57 | | /// Gets or sets the display order. |
| | | 58 | | /// </summary> |
| | | 59 | | /// <remarks> |
| | | 60 | | /// Valid options are airdate, dvd or absolute. |
| | | 61 | | /// </remarks> |
| | | 62 | | public string DisplayOrder { get; set; } |
| | | 63 | | |
| | | 64 | | /// <summary> |
| | | 65 | | /// Gets or sets the status. |
| | | 66 | | /// </summary> |
| | | 67 | | /// <value>The status.</value> |
| | | 68 | | public SeriesStatus? Status { get; set; } |
| | | 69 | | |
| | | 70 | | public override double GetDefaultPrimaryImageAspectRatio() |
| | | 71 | | { |
| | 0 | 72 | | double value = 2; |
| | 0 | 73 | | value /= 3; |
| | | 74 | | |
| | 0 | 75 | | return value; |
| | | 76 | | } |
| | | 77 | | |
| | | 78 | | public override string CreatePresentationUniqueKey() |
| | | 79 | | { |
| | 0 | 80 | | if (LibraryManager.GetLibraryOptions(this).EnableAutomaticSeriesGrouping) |
| | | 81 | | { |
| | 0 | 82 | | var userdatakeys = GetUserDataKeys(); |
| | | 83 | | |
| | | 84 | | // The first user data key is a stable cross-folder identity. |
| | | 85 | | // When none exists, fall back to the (normalized) series name. |
| | 0 | 86 | | var groupingKey = userdatakeys.Count > 1 |
| | 0 | 87 | | ? userdatakeys[0] |
| | 0 | 88 | | : GetNameBasedGroupingKey(); |
| | | 89 | | |
| | 0 | 90 | | if (!string.IsNullOrEmpty(groupingKey)) |
| | | 91 | | { |
| | 0 | 92 | | return AppendPreferredLanguage(groupingKey); |
| | | 93 | | } |
| | | 94 | | } |
| | | 95 | | |
| | 0 | 96 | | return base.CreatePresentationUniqueKey(); |
| | | 97 | | } |
| | | 98 | | |
| | | 99 | | // The owning libraries are deliberately NOT part of the key. |
| | | 100 | | private string AppendPreferredLanguage(string key) |
| | | 101 | | { |
| | 0 | 102 | | var lang = GetPreferredMetadataLanguage(); |
| | 0 | 103 | | if (!string.IsNullOrEmpty(lang)) |
| | | 104 | | { |
| | 0 | 105 | | key += "-" + lang; |
| | | 106 | | } |
| | | 107 | | |
| | 0 | 108 | | return key; |
| | | 109 | | } |
| | | 110 | | |
| | | 111 | | private string GetNameBasedGroupingKey() |
| | | 112 | | { |
| | | 113 | | // Prefix with the type so a series can never collide with a same-named item of another kind. |
| | 0 | 114 | | return string.IsNullOrEmpty(Name) |
| | 0 | 115 | | ? null |
| | 0 | 116 | | : "series-" + Name.ToLowerInvariant(); |
| | | 117 | | } |
| | | 118 | | |
| | | 119 | | private static string GetUniqueSeriesKey(BaseItem series) |
| | | 120 | | { |
| | 0 | 121 | | return series.GetPresentationUniqueKey(); |
| | | 122 | | } |
| | | 123 | | |
| | | 124 | | public override int GetChildCount(User user) |
| | | 125 | | { |
| | 0 | 126 | | var seriesKey = GetUniqueSeriesKey(this); |
| | | 127 | | |
| | 0 | 128 | | var result = LibraryManager.GetCount(new InternalItemsQuery(user) |
| | 0 | 129 | | { |
| | 0 | 130 | | AncestorWithPresentationUniqueKey = null, |
| | 0 | 131 | | SeriesPresentationUniqueKey = seriesKey, |
| | 0 | 132 | | IncludeItemTypes = new[] { BaseItemKind.Season }, |
| | 0 | 133 | | IsVirtualItem = false, |
| | 0 | 134 | | Limit = 0, |
| | 0 | 135 | | DtoOptions = new DtoOptions(false) |
| | 0 | 136 | | { |
| | 0 | 137 | | EnableImages = false |
| | 0 | 138 | | } |
| | 0 | 139 | | }); |
| | | 140 | | |
| | 0 | 141 | | return result; |
| | | 142 | | } |
| | | 143 | | |
| | | 144 | | public override int GetRecursiveChildCount(User user) |
| | | 145 | | { |
| | 0 | 146 | | var seriesKey = GetUniqueSeriesKey(this); |
| | | 147 | | |
| | 0 | 148 | | var query = new InternalItemsQuery(user) |
| | 0 | 149 | | { |
| | 0 | 150 | | AncestorWithPresentationUniqueKey = null, |
| | 0 | 151 | | SeriesPresentationUniqueKey = seriesKey, |
| | 0 | 152 | | DtoOptions = new DtoOptions(false) |
| | 0 | 153 | | { |
| | 0 | 154 | | EnableImages = false |
| | 0 | 155 | | } |
| | 0 | 156 | | }; |
| | | 157 | | |
| | 0 | 158 | | if (query.IncludeItemTypes.Length == 0) |
| | | 159 | | { |
| | 0 | 160 | | query.IncludeItemTypes = new[] { BaseItemKind.Episode }; |
| | | 161 | | } |
| | | 162 | | |
| | 0 | 163 | | query.IsVirtualItem = false; |
| | 0 | 164 | | query.Limit = 0; |
| | 0 | 165 | | var totalRecordCount = LibraryManager.GetCount(query); |
| | | 166 | | |
| | 0 | 167 | | return totalRecordCount; |
| | | 168 | | } |
| | | 169 | | |
| | | 170 | | /// <summary> |
| | | 171 | | /// Gets the user data key. |
| | | 172 | | /// </summary> |
| | | 173 | | /// <returns>System.String.</returns> |
| | | 174 | | public override List<string> GetUserDataKeys() |
| | | 175 | | { |
| | 0 | 176 | | var list = base.GetUserDataKeys(); |
| | | 177 | | |
| | 0 | 178 | | if (this.TryGetProviderId(MetadataProvider.Imdb, out var key)) |
| | | 179 | | { |
| | 0 | 180 | | list.Insert(0, key); |
| | | 181 | | } |
| | | 182 | | |
| | 0 | 183 | | if (this.TryGetProviderId(MetadataProvider.Tvdb, out key)) |
| | | 184 | | { |
| | 0 | 185 | | list.Insert(0, key); |
| | | 186 | | } |
| | | 187 | | |
| | 0 | 188 | | if (this.TryGetProviderId(MetadataProvider.Custom, out key)) |
| | | 189 | | { |
| | 0 | 190 | | list.Insert(0, key); |
| | | 191 | | } |
| | | 192 | | |
| | 0 | 193 | | return list; |
| | | 194 | | } |
| | | 195 | | |
| | | 196 | | /// <inheritdoc /> |
| | | 197 | | protected override Guid[] GetExtraOwnerIds() |
| | | 198 | | { |
| | 0 | 199 | | if (!LibraryManager.GetLibraryOptions(this).EnableAutomaticSeriesGrouping) |
| | | 200 | | { |
| | 0 | 201 | | return base.GetExtraOwnerIds(); |
| | | 202 | | } |
| | | 203 | | |
| | | 204 | | // Setting PresentationUniqueKey on the query disables presentation-key grouping, so this |
| | | 205 | | // returns every folder-item of the merged series rather than the collapsed survivor. |
| | 0 | 206 | | var ids = LibraryManager.GetItemIds(new InternalItemsQuery |
| | 0 | 207 | | { |
| | 0 | 208 | | PresentationUniqueKey = GetPresentationUniqueKey(), |
| | 0 | 209 | | IncludeItemTypes = [BaseItemKind.Series] |
| | 0 | 210 | | }); |
| | | 211 | | |
| | 0 | 212 | | return ids.Count == 0 ? base.GetExtraOwnerIds() : ids.ToArray(); |
| | | 213 | | } |
| | | 214 | | |
| | | 215 | | public override IReadOnlyList<BaseItem> GetChildren(User user, bool includeLinkedChildren, InternalItemsQuery qu |
| | | 216 | | { |
| | 0 | 217 | | return GetSeasons(user, new DtoOptions(true)); |
| | | 218 | | } |
| | | 219 | | |
| | | 220 | | public IReadOnlyList<BaseItem> GetSeasons(User user, DtoOptions options) |
| | | 221 | | { |
| | 0 | 222 | | var query = new InternalItemsQuery(user) |
| | 0 | 223 | | { |
| | 0 | 224 | | DtoOptions = options |
| | 0 | 225 | | }; |
| | | 226 | | |
| | 0 | 227 | | SetSeasonQueryOptions(query, user); |
| | | 228 | | |
| | 0 | 229 | | return LibraryManager.GetItemList(query); |
| | | 230 | | } |
| | | 231 | | |
| | | 232 | | private void SetSeasonQueryOptions(InternalItemsQuery query, User user) |
| | | 233 | | { |
| | 0 | 234 | | var seriesKey = GetUniqueSeriesKey(this); |
| | | 235 | | |
| | 0 | 236 | | query.AncestorWithPresentationUniqueKey = null; |
| | 0 | 237 | | query.SeriesPresentationUniqueKey = seriesKey; |
| | 0 | 238 | | query.IncludeItemTypes = new[] { BaseItemKind.Season }; |
| | 0 | 239 | | query.OrderBy = new[] { (ItemSortBy.SortName, SortOrder.Ascending) }; |
| | | 240 | | |
| | 0 | 241 | | if (user is not null && !user.DisplayMissingEpisodes) |
| | | 242 | | { |
| | 0 | 243 | | query.IsMissing = false; |
| | | 244 | | } |
| | 0 | 245 | | } |
| | | 246 | | |
| | | 247 | | protected override QueryResult<BaseItem> GetItemsInternal(InternalItemsQuery query) |
| | | 248 | | { |
| | 0 | 249 | | var user = query.User; |
| | | 250 | | |
| | 0 | 251 | | if (SourceType == SourceType.Channel) |
| | | 252 | | { |
| | | 253 | | try |
| | | 254 | | { |
| | 0 | 255 | | query.Parent = this; |
| | 0 | 256 | | query.ChannelIds = [ChannelId]; |
| | 0 | 257 | | return ChannelManager.GetChannelItemsInternal(query, new Progress<double>(), CancellationToken.None) |
| | | 258 | | } |
| | 0 | 259 | | catch |
| | | 260 | | { |
| | | 261 | | // Already logged at lower levels |
| | 0 | 262 | | return new QueryResult<BaseItem>(); |
| | | 263 | | } |
| | | 264 | | } |
| | | 265 | | |
| | 0 | 266 | | if (query.Recursive) |
| | | 267 | | { |
| | 0 | 268 | | var seriesKey = GetUniqueSeriesKey(this); |
| | | 269 | | |
| | 0 | 270 | | query.AncestorWithPresentationUniqueKey = null; |
| | 0 | 271 | | query.SeriesPresentationUniqueKey = seriesKey; |
| | 0 | 272 | | if (query.OrderBy.Count == 0) |
| | | 273 | | { |
| | 0 | 274 | | query.OrderBy = new[] { (ItemSortBy.SortName, SortOrder.Ascending) }; |
| | | 275 | | } |
| | | 276 | | |
| | 0 | 277 | | if (query.IncludeItemTypes.Length == 0) |
| | | 278 | | { |
| | 0 | 279 | | query.IncludeItemTypes = new[] { BaseItemKind.Episode, BaseItemKind.Season }; |
| | | 280 | | } |
| | | 281 | | |
| | 0 | 282 | | query.IsVirtualItem = false; |
| | 0 | 283 | | return LibraryManager.GetItemsResult(query); |
| | | 284 | | } |
| | | 285 | | |
| | 0 | 286 | | SetSeasonQueryOptions(query, user); |
| | | 287 | | |
| | 0 | 288 | | return LibraryManager.GetItemsResult(query); |
| | 0 | 289 | | } |
| | | 290 | | |
| | | 291 | | public IEnumerable<BaseItem> GetEpisodes(User user, DtoOptions options, bool shouldIncludeMissingEpisodes) |
| | | 292 | | { |
| | 0 | 293 | | var seriesKey = GetUniqueSeriesKey(this); |
| | | 294 | | |
| | 0 | 295 | | var query = new InternalItemsQuery(user) |
| | 0 | 296 | | { |
| | 0 | 297 | | AncestorWithPresentationUniqueKey = null, |
| | 0 | 298 | | SeriesPresentationUniqueKey = seriesKey, |
| | 0 | 299 | | IncludeItemTypes = new[] { BaseItemKind.Episode, BaseItemKind.Season }, |
| | 0 | 300 | | OrderBy = new[] { (ItemSortBy.SortName, SortOrder.Ascending) }, |
| | 0 | 301 | | DtoOptions = options, |
| | 0 | 302 | | }; |
| | | 303 | | |
| | 0 | 304 | | if (!shouldIncludeMissingEpisodes) |
| | | 305 | | { |
| | 0 | 306 | | query.IsMissing = false; |
| | | 307 | | } |
| | | 308 | | |
| | 0 | 309 | | var allItems = LibraryManager.GetItemList(query); |
| | | 310 | | |
| | 0 | 311 | | var allSeriesEpisodes = allItems.OfType<Episode>().ToList(); |
| | | 312 | | |
| | 0 | 313 | | var allEpisodes = allItems.OfType<Season>() |
| | 0 | 314 | | .SelectMany(i => i.GetEpisodes(this, user, allSeriesEpisodes, options, shouldIncludeMissingEpisodes)) |
| | 0 | 315 | | .Reverse(); |
| | | 316 | | |
| | | 317 | | // Specials could appear twice based on above - once in season 0, once in the aired season |
| | | 318 | | // This depends on settings for that series |
| | | 319 | | // When this happens, remove the duplicate from season 0 |
| | | 320 | | |
| | 0 | 321 | | return allEpisodes.DistinctBy(i => i.Id).Reverse(); |
| | | 322 | | } |
| | | 323 | | |
| | | 324 | | public async Task RefreshAllMetadata(MetadataRefreshOptions refreshOptions, IProgress<double> progress, Cancella |
| | | 325 | | { |
| | 0 | 326 | | Children = null; // invalidate cached children. |
| | | 327 | | // Refresh bottom up, seasons and episodes first, then the series |
| | 0 | 328 | | var items = GetRecursiveChildren(); |
| | | 329 | | |
| | 0 | 330 | | var totalItems = items.Count; |
| | 0 | 331 | | var numComplete = 0; |
| | | 332 | | |
| | | 333 | | // Refresh seasons |
| | 0 | 334 | | foreach (var item in items) |
| | | 335 | | { |
| | 0 | 336 | | if (item is not Season) |
| | | 337 | | { |
| | | 338 | | continue; |
| | | 339 | | } |
| | | 340 | | |
| | 0 | 341 | | cancellationToken.ThrowIfCancellationRequested(); |
| | | 342 | | |
| | 0 | 343 | | if (refreshOptions.RefreshItem(item)) |
| | | 344 | | { |
| | 0 | 345 | | await item.RefreshMetadata(refreshOptions, cancellationToken).ConfigureAwait(false); |
| | | 346 | | } |
| | | 347 | | |
| | 0 | 348 | | numComplete++; |
| | 0 | 349 | | double percent = numComplete; |
| | 0 | 350 | | percent /= totalItems; |
| | 0 | 351 | | progress.Report(percent * 100); |
| | | 352 | | } |
| | | 353 | | |
| | | 354 | | // Refresh episodes and other children |
| | 0 | 355 | | foreach (var item in items) |
| | | 356 | | { |
| | 0 | 357 | | if (item is Season) |
| | | 358 | | { |
| | | 359 | | continue; |
| | | 360 | | } |
| | | 361 | | |
| | 0 | 362 | | cancellationToken.ThrowIfCancellationRequested(); |
| | | 363 | | |
| | 0 | 364 | | bool skipItem = item is Episode episode |
| | 0 | 365 | | && refreshOptions.MetadataRefreshMode != MetadataRefreshMode.FullRefresh |
| | 0 | 366 | | && !refreshOptions.ReplaceAllMetadata |
| | 0 | 367 | | && episode.IsMissingEpisode |
| | 0 | 368 | | && episode.LocationType == LocationType.Virtual |
| | 0 | 369 | | && episode.PremiereDate.HasValue |
| | 0 | 370 | | && (DateTime.UtcNow - episode.PremiereDate.Value).TotalDays > 30; |
| | | 371 | | |
| | 0 | 372 | | if (!skipItem) |
| | | 373 | | { |
| | 0 | 374 | | if (refreshOptions.RefreshItem(item)) |
| | | 375 | | { |
| | 0 | 376 | | await item.RefreshMetadata(refreshOptions, cancellationToken).ConfigureAwait(false); |
| | | 377 | | } |
| | | 378 | | } |
| | | 379 | | |
| | 0 | 380 | | numComplete++; |
| | 0 | 381 | | double percent = numComplete; |
| | 0 | 382 | | percent /= totalItems; |
| | 0 | 383 | | progress.Report(percent * 100); |
| | | 384 | | } |
| | | 385 | | |
| | 0 | 386 | | refreshOptions = new MetadataRefreshOptions(refreshOptions); |
| | 0 | 387 | | await ProviderManager.RefreshSingleItem(this, refreshOptions, cancellationToken).ConfigureAwait(false); |
| | 0 | 388 | | } |
| | | 389 | | |
| | | 390 | | public List<BaseItem> GetSeasonEpisodes(Season parentSeason, User user, DtoOptions options, bool shouldIncludeMi |
| | | 391 | | { |
| | 0 | 392 | | var queryFromSeries = ConfigurationManager.Configuration.DisplaySpecialsWithinSeasons; |
| | | 393 | | |
| | | 394 | | // add optimization when this setting is not enabled |
| | 0 | 395 | | var seriesKey = queryFromSeries ? |
| | 0 | 396 | | GetUniqueSeriesKey(this) : |
| | 0 | 397 | | GetUniqueSeriesKey(parentSeason); |
| | | 398 | | |
| | 0 | 399 | | var query = new InternalItemsQuery(user) |
| | 0 | 400 | | { |
| | 0 | 401 | | AncestorWithPresentationUniqueKey = queryFromSeries ? null : seriesKey, |
| | 0 | 402 | | SeriesPresentationUniqueKey = queryFromSeries ? seriesKey : null, |
| | 0 | 403 | | IncludeItemTypes = new[] { BaseItemKind.Episode }, |
| | 0 | 404 | | OrderBy = new[] { (ItemSortBy.SortName, SortOrder.Ascending) }, |
| | 0 | 405 | | DtoOptions = options |
| | 0 | 406 | | }; |
| | | 407 | | |
| | 0 | 408 | | if (!shouldIncludeMissingEpisodes) |
| | | 409 | | { |
| | 0 | 410 | | query.IsMissing = false; |
| | | 411 | | } |
| | | 412 | | |
| | | 413 | | IReadOnlyList<BaseItem> allItems; |
| | 0 | 414 | | if (SourceType == SourceType.Channel) |
| | | 415 | | { |
| | | 416 | | try |
| | | 417 | | { |
| | 0 | 418 | | query.Parent = parentSeason; |
| | 0 | 419 | | query.ChannelIds = [ChannelId]; |
| | 0 | 420 | | allItems = [.. ChannelManager.GetChannelItemsInternal(query, new Progress<double>(), CancellationTok |
| | 0 | 421 | | } |
| | 0 | 422 | | catch |
| | | 423 | | { |
| | | 424 | | // Already logged at lower levels |
| | 0 | 425 | | return []; |
| | | 426 | | } |
| | | 427 | | } |
| | | 428 | | else |
| | | 429 | | { |
| | 0 | 430 | | allItems = LibraryManager.GetItemList(query); |
| | | 431 | | } |
| | | 432 | | |
| | 0 | 433 | | return GetSeasonEpisodes(parentSeason, user, allItems, options, shouldIncludeMissingEpisodes); |
| | 0 | 434 | | } |
| | | 435 | | |
| | | 436 | | public List<BaseItem> GetSeasonEpisodes(Season parentSeason, User user, IEnumerable<BaseItem> allSeriesEpisodes, |
| | | 437 | | { |
| | 0 | 438 | | if (allSeriesEpisodes is null) |
| | | 439 | | { |
| | 0 | 440 | | return GetSeasonEpisodes(parentSeason, user, options, shouldIncludeMissingEpisodes); |
| | | 441 | | } |
| | | 442 | | |
| | 0 | 443 | | var episodes = FilterEpisodesBySeason(allSeriesEpisodes, parentSeason, ConfigurationManager.Configuration.Di |
| | | 444 | | |
| | 0 | 445 | | var sortBy = (parentSeason.IndexNumber ?? -1) == 0 ? ItemSortBy.SortName : ItemSortBy.AiredEpisodeOrder; |
| | | 446 | | |
| | 0 | 447 | | return LibraryManager.Sort(episodes, user, new[] { sortBy }, SortOrder.Ascending).ToList(); |
| | | 448 | | } |
| | | 449 | | |
| | | 450 | | /// <summary> |
| | | 451 | | /// Filters the episodes by season. |
| | | 452 | | /// </summary> |
| | | 453 | | /// <param name="episodes">The episodes.</param> |
| | | 454 | | /// <param name="parentSeason">The season.</param> |
| | | 455 | | /// <param name="includeSpecials"><c>true</c> to include special, <c>false</c> to not.</param> |
| | | 456 | | /// <returns>The set of episodes.</returns> |
| | | 457 | | public static IEnumerable<BaseItem> FilterEpisodesBySeason(IEnumerable<BaseItem> episodes, Season parentSeason, |
| | | 458 | | { |
| | 0 | 459 | | var seasonNumber = parentSeason.IndexNumber; |
| | 0 | 460 | | var seasonPresentationKey = GetUniqueSeriesKey(parentSeason); |
| | | 461 | | |
| | 0 | 462 | | var supportSpecialsInSeason = includeSpecials && seasonNumber.HasValue && seasonNumber.Value != 0; |
| | | 463 | | |
| | 0 | 464 | | return episodes.Where(episode => |
| | 0 | 465 | | { |
| | 0 | 466 | | var episodeItem = (Episode)episode; |
| | 0 | 467 | | |
| | 0 | 468 | | var currentSeasonNumber = supportSpecialsInSeason ? episodeItem.AiredSeasonNumber : episode.ParentIndexN |
| | 0 | 469 | | if (currentSeasonNumber.HasValue && seasonNumber.HasValue && currentSeasonNumber.Value == seasonNumber.V |
| | 0 | 470 | | { |
| | 0 | 471 | | return true; |
| | 0 | 472 | | } |
| | 0 | 473 | | |
| | 0 | 474 | | if (!currentSeasonNumber.HasValue && !seasonNumber.HasValue && parentSeason.LocationType == LocationType |
| | 0 | 475 | | { |
| | 0 | 476 | | return episodeItem.Season is null or { LocationType: LocationType.Virtual }; |
| | 0 | 477 | | } |
| | 0 | 478 | | |
| | 0 | 479 | | var season = episodeItem.Season; |
| | 0 | 480 | | return season is not null && string.Equals(GetUniqueSeriesKey(season), seasonPresentationKey, StringComp |
| | 0 | 481 | | }); |
| | | 482 | | } |
| | | 483 | | |
| | | 484 | | /// <summary> |
| | | 485 | | /// Filters the episodes by season. |
| | | 486 | | /// </summary> |
| | | 487 | | /// <param name="episodes">The episodes.</param> |
| | | 488 | | /// <param name="seasonNumber">The season.</param> |
| | | 489 | | /// <param name="includeSpecials"><c>true</c> to include special, <c>false</c> to not.</param> |
| | | 490 | | /// <returns>The set of episodes.</returns> |
| | | 491 | | public static IEnumerable<Episode> FilterEpisodesBySeason(IEnumerable<Episode> episodes, int seasonNumber, bool |
| | | 492 | | { |
| | 0 | 493 | | if (!includeSpecials || seasonNumber < 1) |
| | | 494 | | { |
| | 0 | 495 | | return episodes.Where(i => (i.ParentIndexNumber ?? -1) == seasonNumber); |
| | | 496 | | } |
| | | 497 | | |
| | 0 | 498 | | return episodes.Where(i => |
| | 0 | 499 | | { |
| | 0 | 500 | | var episode = i; |
| | 0 | 501 | | |
| | 0 | 502 | | if (episode is not null) |
| | 0 | 503 | | { |
| | 0 | 504 | | var currentSeasonNumber = episode.AiredSeasonNumber; |
| | 0 | 505 | | |
| | 0 | 506 | | return currentSeasonNumber.HasValue && currentSeasonNumber.Value == seasonNumber; |
| | 0 | 507 | | } |
| | 0 | 508 | | |
| | 0 | 509 | | return false; |
| | 0 | 510 | | }); |
| | | 511 | | } |
| | | 512 | | |
| | | 513 | | protected override bool GetBlockUnratedValue(User user) |
| | | 514 | | { |
| | 0 | 515 | | return user.GetPreferenceValues<UnratedItem>(PreferenceKind.BlockUnratedItems).Contains(UnratedItem.Series); |
| | | 516 | | } |
| | | 517 | | |
| | | 518 | | public override UnratedItem GetBlockUnratedType() |
| | | 519 | | { |
| | 10 | 520 | | return UnratedItem.Series; |
| | | 521 | | } |
| | | 522 | | |
| | | 523 | | public SeriesInfo GetLookupInfo() |
| | | 524 | | { |
| | 0 | 525 | | var info = GetItemLookupInfo<SeriesInfo>(); |
| | | 526 | | |
| | 0 | 527 | | return info; |
| | | 528 | | } |
| | | 529 | | |
| | | 530 | | public override bool BeforeMetadataRefresh(bool replaceAllMetadata) |
| | | 531 | | { |
| | 0 | 532 | | var hasChanges = base.BeforeMetadataRefresh(replaceAllMetadata); |
| | | 533 | | |
| | 0 | 534 | | if (ProductionYear is null) |
| | | 535 | | { |
| | 0 | 536 | | var info = LibraryManager.ParseName(Name); |
| | | 537 | | |
| | 0 | 538 | | var yearInName = info.Year; |
| | | 539 | | |
| | 0 | 540 | | if (yearInName.HasValue) |
| | | 541 | | { |
| | 0 | 542 | | ProductionYear = yearInName; |
| | 0 | 543 | | hasChanges = true; |
| | | 544 | | } |
| | | 545 | | } |
| | | 546 | | |
| | 0 | 547 | | return hasChanges; |
| | | 548 | | } |
| | | 549 | | } |
| | | 550 | | } |