mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-11-16 18:42:52 -07:00
113 lines
3.6 KiB
C#
113 lines
3.6 KiB
C#
using MediaBrowser.Common.Extensions;
|
|
using MediaBrowser.Common.IO;
|
|
using MediaBrowser.Controller.Entities.Audio;
|
|
using MediaBrowser.Controller.Entities.TV;
|
|
using MediaBrowser.Controller.Library;
|
|
using MediaBrowser.Controller.Resolvers;
|
|
using MediaBrowser.Model.Entities;
|
|
using MediaBrowser.Model.Logging;
|
|
using System;
|
|
using System.IO;
|
|
|
|
namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
|
|
{
|
|
/// <summary>
|
|
/// Class SeriesResolver
|
|
/// </summary>
|
|
public class SeriesResolver : FolderResolver<Series>
|
|
{
|
|
private readonly IFileSystem _fileSystem;
|
|
private readonly ILogger _logger;
|
|
|
|
public SeriesResolver(IFileSystem fileSystem, ILogger logger)
|
|
{
|
|
_fileSystem = fileSystem;
|
|
_logger = logger;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the priority.
|
|
/// </summary>
|
|
/// <value>The priority.</value>
|
|
public override ResolverPriority Priority
|
|
{
|
|
get
|
|
{
|
|
return 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)
|
|
{
|
|
// Avoid expensive tests against VF's and all their children by not allowing this
|
|
if (args.Parent == null || args.Parent.IsRoot)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
// Optimization to avoid running these tests against Seasons
|
|
if (args.Parent is Series || args.Parent is Season || args.Parent is MusicArtist || args.Parent is MusicAlbum)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
var collectionType = args.GetCollectionType();
|
|
|
|
var isTvShowsFolder = string.Equals(collectionType, CollectionType.TvShows,
|
|
StringComparison.OrdinalIgnoreCase);
|
|
|
|
// If there's a collection type and it's not tv, it can't be a series
|
|
if (!string.IsNullOrEmpty(collectionType) &&
|
|
!isTvShowsFolder &&
|
|
!string.Equals(collectionType, CollectionType.BoxSets, StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
if (TVUtils.IsSeriesFolder(args.Path, isTvShowsFolder, args.FileSystemChildren, args.DirectoryService, _fileSystem, _logger))
|
|
{
|
|
return new Series();
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/// <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 void SetProviderIdFromPath(Series item, string path)
|
|
{
|
|
var justName = Path.GetFileName(path);
|
|
|
|
var id = justName.GetAttributeValue("tvdbid");
|
|
|
|
if (!string.IsNullOrEmpty(id))
|
|
{
|
|
item.SetProviderId(MetadataProviders.Tvdb, id);
|
|
}
|
|
}
|
|
}
|
|
}
|