jellyfin/MediaBrowser.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs

110 lines
3.6 KiB
C#
Raw Normal View History

2013-02-21 01:33:05 +00:00
using MediaBrowser.Common.Extensions;
2014-07-26 17:30:15 +00:00
using MediaBrowser.Common.IO;
2013-09-18 02:43:34 +00:00
using MediaBrowser.Controller.Entities.Audio;
2013-02-21 01:33:05 +00:00
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Resolvers;
2013-02-21 01:33:05 +00:00
using MediaBrowser.Model.Entities;
2014-07-30 03:31:35 +00:00
using MediaBrowser.Model.Logging;
2013-02-21 01:33:05 +00:00
using System;
using System.IO;
namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
2013-02-21 01:33:05 +00:00
{
/// <summary>
/// Class SeriesResolver
/// </summary>
public class SeriesResolver : FolderResolver<Series>
2013-02-21 01:33:05 +00:00
{
2014-07-26 17:30:15 +00:00
private readonly IFileSystem _fileSystem;
2014-07-30 03:31:35 +00:00
private readonly ILogger _logger;
2014-07-26 17:30:15 +00:00
2014-07-30 03:31:35 +00:00
public SeriesResolver(IFileSystem fileSystem, ILogger logger)
2014-07-26 17:30:15 +00:00
{
_fileSystem = fileSystem;
2014-07-30 03:31:35 +00:00
_logger = logger;
2014-07-26 17:30:15 +00:00
}
2013-02-21 01:33:05 +00:00
/// <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)
2013-02-21 01:33:05 +00:00
{
return null;
}
var collectionType = args.GetCollectionType();
// If there's a collection type and it's not tv, it can't be a series
if (!string.IsNullOrEmpty(collectionType) &&
2013-10-26 22:01:21 +00:00
!string.Equals(collectionType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase) &&
!string.Equals(collectionType, CollectionType.BoxSets, StringComparison.OrdinalIgnoreCase))
{
return null;
}
2014-07-26 17:30:15 +00:00
2014-07-30 03:31:35 +00:00
if (TVUtils.IsSeriesFolder(args.Path, string.Equals(collectionType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase), args.FileSystemChildren, args.DirectoryService, _fileSystem, _logger))
2013-02-21 01:33:05 +00:00
{
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);
2013-02-21 01:33:05 +00:00
}
/// <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)
2013-02-21 01:33:05 +00:00
{
var justName = Path.GetFileName(path);
2013-02-21 01:33:05 +00:00
var id = justName.GetAttributeValue("tvdbid");
if (!string.IsNullOrEmpty(id))
{
item.SetProviderId(MetadataProviders.Tvdb, id);
}
}
}
}