| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 | 
							- #nullable disable
 
- #pragma warning disable CS1591
 
- using System;
 
- using System.Collections.Generic;
 
- using System.IO;
 
- using Emby.Naming.Common;
 
- using Emby.Naming.TV;
 
- using Emby.Naming.Video;
 
- using MediaBrowser.Controller.Entities.TV;
 
- using MediaBrowser.Controller.Library;
 
- using MediaBrowser.Controller.Resolvers;
 
- using MediaBrowser.Model.Entities;
 
- using MediaBrowser.Model.IO;
 
- using Microsoft.Extensions.Logging;
 
- namespace Emby.Server.Implementations.Library.Resolvers.TV
 
- {
 
-     /// <summary>
 
-     /// Class SeriesResolver.
 
-     /// </summary>
 
-     public class SeriesResolver : GenericFolderResolver<Series>
 
-     {
 
-         private readonly ILogger<SeriesResolver> _logger;
 
-         private readonly NamingOptions _namingOptions;
 
-         /// <summary>
 
-         /// Initializes a new instance of the <see cref="SeriesResolver"/> class.
 
-         /// </summary>
 
-         /// <param name="logger">The logger.</param>
 
-         /// <param name="namingOptions">The naming options.</param>
 
-         public SeriesResolver(ILogger<SeriesResolver> logger,  NamingOptions namingOptions)
 
-         {
 
-             _logger = logger;
 
-             _namingOptions = namingOptions;
 
-         }
 
-         /// <summary>
 
-         /// Gets the priority.
 
-         /// </summary>
 
-         /// <value>The priority.</value>
 
-         public override ResolverPriority Priority => ResolverPriority.Second;
 
-         /// <summary>
 
-         /// Resolves the specified args.
 
-         /// </summary>
 
-         /// <param name="args">The args.</param>
 
-         /// <returns>Series.</returns>
 
-         protected override Series Resolve(ItemResolveArgs args)
 
-         {
 
-             if (args.IsDirectory)
 
-             {
 
-                 if (args.HasParent<Series>() || args.HasParent<Season>())
 
-                 {
 
-                     return null;
 
-                 }
 
-                 var seriesInfo = Naming.TV.SeriesResolver.Resolve(_namingOptions, args.Path);
 
-                 var collectionType = args.GetCollectionType();
 
-                 if (string.Equals(collectionType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase))
 
-                 {
 
-                     // TODO refactor into separate class or something, this is copied from LibraryManager.GetConfiguredContentType
 
-                     var configuredContentType = args.GetConfiguredContentType();
 
-                     if (!string.Equals(configuredContentType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase))
 
-                     {
 
-                         return new Series
 
-                         {
 
-                             Path = args.Path,
 
-                             Name = seriesInfo.Name
 
-                         };
 
-                     }
 
-                 }
 
-                 else if (string.IsNullOrEmpty(collectionType))
 
-                 {
 
-                     if (args.ContainsFileSystemEntryByName("tvshow.nfo"))
 
-                     {
 
-                         if (args.Parent is not null && args.Parent.IsRoot)
 
-                         {
 
-                             // For now, return null, but if we want to allow this in the future then add some additional checks to guard against a misplaced tvshow.nfo
 
-                             return null;
 
-                         }
 
-                         return new Series
 
-                         {
 
-                             Path = args.Path,
 
-                             Name = seriesInfo.Name
 
-                         };
 
-                     }
 
-                     if (args.Parent is not null && args.Parent.IsRoot)
 
-                     {
 
-                         return null;
 
-                     }
 
-                     if (IsSeriesFolder(args.Path, args.FileSystemChildren, false))
 
-                     {
 
-                         return new Series
 
-                         {
 
-                             Path = args.Path,
 
-                             Name = seriesInfo.Name
 
-                         };
 
-                     }
 
-                 }
 
-             }
 
-             return null;
 
-         }
 
-         private bool IsSeriesFolder(
 
-             string path,
 
-             IEnumerable<FileSystemMetadata> fileSystemChildren,
 
-             bool isTvContentType)
 
-         {
 
-             foreach (var child in fileSystemChildren)
 
-             {
 
-                 if (child.IsDirectory)
 
-                 {
 
-                     if (IsSeasonFolder(child.FullName, isTvContentType))
 
-                     {
 
-                         _logger.LogDebug("{Path} is a series because of season folder {Dir}.", path, child.FullName);
 
-                         return true;
 
-                     }
 
-                 }
 
-                 else
 
-                 {
 
-                     string fullName = child.FullName;
 
-                     if (VideoResolver.IsVideoFile(path, _namingOptions))
 
-                     {
 
-                         if (isTvContentType)
 
-                         {
 
-                             return true;
 
-                         }
 
-                         var namingOptions = _namingOptions;
 
-                         var episodeResolver = new Naming.TV.EpisodeResolver(namingOptions);
 
-                         var episodeInfo = episodeResolver.Resolve(fullName, false, true, false, fillExtendedInfo: false);
 
-                         if (episodeInfo is not null && episodeInfo.EpisodeNumber.HasValue)
 
-                         {
 
-                             return true;
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-             _logger.LogDebug("{Path} is not a series folder.", path);
 
-             return false;
 
-         }
 
-         /// <summary>
 
-         /// Determines whether [is season folder] [the specified path].
 
-         /// </summary>
 
-         /// <param name="path">The path.</param>
 
-         /// <param name="isTvContentType">if set to <c>true</c> [is tv content type].</param>
 
-         /// <returns><c>true</c> if [is season folder] [the specified path]; otherwise, <c>false</c>.</returns>
 
-         private static bool IsSeasonFolder(string path, bool isTvContentType)
 
-         {
 
-             var seasonNumber = SeasonPathParser.Parse(path, isTvContentType, isTvContentType).SeasonNumber;
 
-             return seasonNumber.HasValue;
 
-         }
 
-         /// <summary>
 
-         /// Sets the initial item values.
 
-         /// </summary>
 
-         /// <param name="item">The item.</param>
 
-         /// <param name="args">The args.</param>
 
-         protected override void SetInitialItemValues(Series item, ItemResolveArgs args)
 
-         {
 
-             base.SetInitialItemValues(item, args);
 
-             SetProviderIdFromPath(item, args.Path);
 
-         }
 
-         /// <summary>
 
-         /// Sets the provider id from path.
 
-         /// </summary>
 
-         /// <param name="item">The item.</param>
 
-         /// <param name="path">The path.</param>
 
-         private static void SetProviderIdFromPath(Series item, string path)
 
-         {
 
-             var justName = Path.GetFileName(path.AsSpan());
 
-             var imdbId = justName.GetAttributeValue("imdbid");
 
-             if (!string.IsNullOrEmpty(imdbId))
 
-             {
 
-                 item.SetProviderId(MetadataProvider.Imdb, imdbId);
 
-             }
 
-             var tvdbId = justName.GetAttributeValue("tvdbid");
 
-             if (!string.IsNullOrEmpty(tvdbId))
 
-             {
 
-                 item.SetProviderId(MetadataProvider.Tvdb, tvdbId);
 
-             }
 
-             var tvmazeId = justName.GetAttributeValue("tvmazeid");
 
-             if (!string.IsNullOrEmpty(tvmazeId))
 
-             {
 
-                 item.SetProviderId(MetadataProvider.TvMaze, tvmazeId);
 
-             }
 
-             var tmdbId = justName.GetAttributeValue("tmdbid");
 
-             if (!string.IsNullOrEmpty(tmdbId))
 
-             {
 
-                 item.SetProviderId(MetadataProvider.Tmdb, tmdbId);
 
-             }
 
-             var anidbId = justName.GetAttributeValue("anidbid");
 
-             if (!string.IsNullOrEmpty(anidbId))
 
-             {
 
-                 item.SetProviderId("AniDB", anidbId);
 
-             }
 
-             var aniListId = justName.GetAttributeValue("anilistid");
 
-             if (!string.IsNullOrEmpty(aniListId))
 
-             {
 
-                 item.SetProviderId("AniList", aniListId);
 
-             }
 
-             var aniSearchId = justName.GetAttributeValue("anisearchid");
 
-             if (!string.IsNullOrEmpty(aniSearchId))
 
-             {
 
-                 item.SetProviderId("AniSearch", aniSearchId);
 
-             }
 
-         }
 
-     }
 
- }
 
 
  |