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;
|
2016-05-22 18:37:50 -04:00
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
2013-02-20 20:33:05 -05:00
|
|
|
using MediaBrowser.Controller.Library;
|
2016-05-22 18:37:50 -04:00
|
|
|
using MediaBrowser.Model.Entities;
|
2013-02-20 20:33:05 -05:00
|
|
|
|
2016-11-03 02:37:52 -04:00
|
|
|
namespace Emby.Server.Implementations.Library.Resolvers.TV
|
2013-02-20 20:33:05 -05:00
|
|
|
{
|
2013-02-23 02:57:11 -05:00
|
|
|
/// <summary>
|
2019-11-01 18:38:54 +01:00
|
|
|
/// Class EpisodeResolver.
|
2013-02-23 02:57:11 -05:00
|
|
|
/// </summary>
|
2013-03-03 11:53:58 -05:00
|
|
|
public class EpisodeResolver : BaseVideoResolver<Episode>
|
2013-02-20 20:33:05 -05:00
|
|
|
{
|
2021-03-15 08:25:20 +01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Initializes a new instance of the <see cref="EpisodeResolver"/> class.
|
|
|
|
|
/// </summary>
|
2021-11-15 15:56:02 +01:00
|
|
|
/// <param name="namingOptions">The naming options.</param>
|
|
|
|
|
public EpisodeResolver(NamingOptions namingOptions)
|
|
|
|
|
: base(namingOptions)
|
2021-03-15 08:25:20 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-23 02:57:11 -05:00
|
|
|
/// <summary>
|
|
|
|
|
/// Resolves the specified args.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="args">The args.</param>
|
|
|
|
|
/// <returns>Episode.</returns>
|
2021-03-14 19:56:45 +01:00
|
|
|
public override Episode Resolve(ItemResolveArgs args)
|
2013-02-20 20:33:05 -05:00
|
|
|
{
|
2014-01-21 01:10:58 -05:00
|
|
|
var parent = args.Parent;
|
2014-01-22 12:05:06 -05:00
|
|
|
|
|
|
|
|
if (parent == null)
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-07 23:27:46 +00:00
|
|
|
// Just in case the user decided to nest episodes.
|
2016-07-09 13:39:04 -04:00
|
|
|
// Not officially supported but in some cases we can handle it.
|
2021-05-05 12:51:14 +01:00
|
|
|
|
|
|
|
|
var season = parent as Season ?? parent.GetParents().OfType<Season>().FirstOrDefault();
|
2016-07-09 13:39:04 -04: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-22 18:37:50 -04:00
|
|
|
// Also handle flat tv folders
|
2021-12-07 15:18:17 +01:00
|
|
|
if (season != null ||
|
|
|
|
|
string.Equals(args.GetCollectionType(), CollectionType.TvShows, StringComparison.OrdinalIgnoreCase) ||
|
|
|
|
|
args.HasParent<Series>())
|
2013-02-20 20:33:05 -05:00
|
|
|
{
|
2014-12-02 22:13:03 -05:00
|
|
|
var episode = ResolveVideo<Episode>(args, false);
|
2013-05-19 13:05:33 -04:00
|
|
|
|
2021-12-07 15:18:17 +01:00
|
|
|
// Ignore extras
|
|
|
|
|
if (episode == null || episode.ExtraType != null)
|
2016-07-05 01:40:18 -04:00
|
|
|
{
|
2021-12-07 15:18:17 +01:00
|
|
|
return null;
|
|
|
|
|
}
|
2016-07-05 02:01:31 -04:00
|
|
|
|
2021-12-07 15:18:17 +01:00
|
|
|
var series = parent as Series ?? parent.GetParents().OfType<Series>().FirstOrDefault();
|
2020-06-16 09:43:52 +12:00
|
|
|
|
2021-12-07 15:18:17 +01:00
|
|
|
if (series != null)
|
|
|
|
|
{
|
|
|
|
|
episode.SeriesId = series.Id;
|
|
|
|
|
episode.SeriesName = series.Name;
|
|
|
|
|
}
|
2017-02-01 15:56:28 -05:00
|
|
|
|
2021-12-07 15:18:17 +01:00
|
|
|
if (season != null)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
if (season == null && !episode.ParentIndexNumber.HasValue && (episode.IndexNumber.HasValue || episode.PremiereDate.HasValue))
|
|
|
|
|
{
|
|
|
|
|
episode.ParentIndexNumber = 1;
|
2016-07-05 01:40:18 -04:00
|
|
|
}
|
|
|
|
|
|
2013-05-20 23:16:43 -04:00
|
|
|
return episode;
|
2013-02-20 20:33:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|