2021-05-20 21:28:18 +02:00
|
|
|
#nullable disable
|
|
|
|
|
2019-01-13 20:54:44 +01:00
|
|
|
using System;
|
2019-01-13 20:21:32 +01:00
|
|
|
using System.Linq;
|
2021-11-15 15:56:02 +01:00
|
|
|
using Emby.Naming.Common;
|
2023-11-09 22:00:29 +01:00
|
|
|
using Jellyfin.Data.Enums;
|
2016-05-23 00:37:50 +02:00
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
2013-02-21 02:33:05 +01:00
|
|
|
using MediaBrowser.Controller.Library;
|
2023-03-07 05:00:55 +01:00
|
|
|
using MediaBrowser.Controller.Providers;
|
2016-05-23 00:37:50 +02:00
|
|
|
using MediaBrowser.Model.Entities;
|
2022-01-04 22:52:52 +01:00
|
|
|
using Microsoft.Extensions.Logging;
|
2013-02-21 02:33:05 +01:00
|
|
|
|
2016-11-03 07:37:52 +01:00
|
|
|
namespace Emby.Server.Implementations.Library.Resolvers.TV
|
2013-02-21 02:33:05 +01:00
|
|
|
{
|
2013-02-23 08:57:11 +01:00
|
|
|
/// <summary>
|
2019-11-01 18:38:54 +01:00
|
|
|
/// Class EpisodeResolver.
|
2013-02-23 08:57:11 +01:00
|
|
|
/// </summary>
|
2013-03-03 17:53:58 +01:00
|
|
|
public class EpisodeResolver : BaseVideoResolver<Episode>
|
2013-02-21 02:33:05 +01:00
|
|
|
{
|
2021-03-15 08:25:20 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="EpisodeResolver"/> class.
|
|
|
|
/// </summary>
|
2022-01-04 22:52:52 +01:00
|
|
|
/// <param name="logger">The logger.</param>
|
2021-11-15 15:56:02 +01:00
|
|
|
/// <param name="namingOptions">The naming options.</param>
|
2023-03-07 05:00:55 +01:00
|
|
|
/// <param name="directoryService">The directory service.</param>
|
|
|
|
public EpisodeResolver(ILogger<EpisodeResolver> logger, NamingOptions namingOptions, IDirectoryService directoryService)
|
|
|
|
: base(logger, namingOptions, directoryService)
|
2021-03-15 08:25:20 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-02-23 08:57:11 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Resolves the specified args.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="args">The args.</param>
|
|
|
|
/// <returns>Episode.</returns>
|
2022-10-11 23:37:29 +02:00
|
|
|
protected override Episode Resolve(ItemResolveArgs args)
|
2013-02-21 02:33:05 +01:00
|
|
|
{
|
2014-01-21 07:10:58 +01:00
|
|
|
var parent = args.Parent;
|
2014-01-22 18:05:06 +01:00
|
|
|
|
2022-12-05 15:00:20 +01:00
|
|
|
if (parent is null)
|
2014-01-22 18:05:06 +01:00
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2019-01-08 00:27:46 +01:00
|
|
|
// Just in case the user decided to nest episodes.
|
2016-07-09 19:39:04 +02:00
|
|
|
// Not officially supported but in some cases we can handle it.
|
2021-05-05 13:51:14 +02:00
|
|
|
|
|
|
|
var season = parent as Season ?? parent.GetParents().OfType<Season>().FirstOrDefault();
|
2016-07-09 19:39:04 +02:00
|
|
|
|
2021-03-14 19:56:45 +01:00
|
|
|
// If the parent is a Season or Series and the parent is not an extras folder, then this is an Episode if the VideoResolver returns something
|
2016-05-23 00:37:50 +02:00
|
|
|
// Also handle flat tv folders
|
2023-11-09 22:00:29 +01:00
|
|
|
if (season is not null
|
|
|
|
|| args.GetCollectionType() == CollectionType.TvShows
|
|
|
|
|| args.HasParent<Series>())
|
2013-02-21 02:33:05 +01:00
|
|
|
{
|
2014-12-03 04:13:03 +01:00
|
|
|
var episode = ResolveVideo<Episode>(args, false);
|
2013-05-19 19:05:33 +02:00
|
|
|
|
2021-12-07 15:18:17 +01:00
|
|
|
// Ignore extras
|
2022-12-05 15:01:13 +01:00
|
|
|
if (episode is null || episode.ExtraType is not null)
|
2016-07-05 07:40:18 +02:00
|
|
|
{
|
2021-12-07 15:18:17 +01:00
|
|
|
return null;
|
|
|
|
}
|
2016-07-05 08:01:31 +02:00
|
|
|
|
2021-12-07 15:18:17 +01:00
|
|
|
var series = parent as Series ?? parent.GetParents().OfType<Series>().FirstOrDefault();
|
2020-06-15 23:43:52 +02:00
|
|
|
|
2022-12-05 15:01:13 +01:00
|
|
|
if (series is not null)
|
2021-12-07 15:18:17 +01:00
|
|
|
{
|
|
|
|
episode.SeriesId = series.Id;
|
|
|
|
episode.SeriesName = series.Name;
|
|
|
|
}
|
2017-02-01 21:56:28 +01:00
|
|
|
|
2022-12-05 15:01:13 +01:00
|
|
|
if (season is not null)
|
2021-12-07 15:18:17 +01:00
|
|
|
{
|
|
|
|
episode.SeasonId = season.Id;
|
|
|
|
episode.SeasonName = season.Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assume season 1 if there's no season folder and a season number could not be determined
|
2022-12-05 15:00:20 +01:00
|
|
|
if (season is null && !episode.ParentIndexNumber.HasValue && (episode.IndexNumber.HasValue || episode.PremiereDate.HasValue))
|
2021-12-07 15:18:17 +01:00
|
|
|
{
|
|
|
|
episode.ParentIndexNumber = 1;
|
2016-07-05 07:40:18 +02:00
|
|
|
}
|
|
|
|
|
2013-05-21 05:16:43 +02:00
|
|
|
return episode;
|
2013-02-21 02:33:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|