2013-02-20 18:33:05 -07:00
|
|
|
|
using MediaBrowser.Common.Extensions;
|
2013-09-17 19:43:34 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities.Audio;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
2013-03-03 09:53:58 -07:00
|
|
|
|
using MediaBrowser.Controller.Resolvers;
|
2013-02-20 18:33:05 -07:00
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
2013-03-02 23:58:04 -07:00
|
|
|
|
namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Class SeriesResolver
|
|
|
|
|
/// </summary>
|
2013-03-02 23:58:04 -07:00
|
|
|
|
public class SeriesResolver : FolderResolver<Series>
|
2013-02-20 18:33:05 -07: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
|
2013-12-05 09:50:21 -07:00
|
|
|
|
if (args.Parent is Series || args.Parent is Season || args.Parent is MusicArtist || args.Parent is MusicAlbum)
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-04 10:07:35 -07:00
|
|
|
|
var collectionType = args.GetCollectionType();
|
2013-07-27 11:24:48 -07:00
|
|
|
|
|
|
|
|
|
// If there's a collection type and it's not tv, it can't be a series
|
|
|
|
|
if (!string.IsNullOrEmpty(collectionType) &&
|
2013-10-26 15:01:21 -07:00
|
|
|
|
!string.Equals(collectionType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase) &&
|
|
|
|
|
!string.Equals(collectionType, CollectionType.BoxSets, StringComparison.OrdinalIgnoreCase))
|
2013-07-27 11:24:48 -07:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-20 18:33:05 -07:00
|
|
|
|
// It's a Series if any of the following conditions are met:
|
|
|
|
|
// series.xml exists
|
|
|
|
|
// [tvdbid= is present in the path
|
|
|
|
|
// TVUtils.IsSeriesFolder returns true
|
|
|
|
|
var filename = Path.GetFileName(args.Path);
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrEmpty(filename))
|
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-30 11:19:50 -07:00
|
|
|
|
// Without these movies that have the name season in them could cause the parent folder to be resolved as a series
|
2014-01-13 13:31:09 -07:00
|
|
|
|
if (filename.IndexOf("[tmdbid=", StringComparison.OrdinalIgnoreCase) != -1)
|
2013-05-30 11:19:50 -07:00
|
|
|
|
{
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-19 13:35:35 -07:00
|
|
|
|
if (args.ContainsMetaFileByName("series.xml") || filename.IndexOf("[tvdbid=", StringComparison.OrdinalIgnoreCase) != -1 || TVUtils.IsSeriesFolder(args.Path, collectionType == CollectionType.TvShows, args.FileSystemChildren, args.DirectoryService))
|
2013-02-20 18:33:05 -07: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);
|
|
|
|
|
|
2013-03-02 23:58:04 -07:00
|
|
|
|
SetProviderIdFromPath(item, args.Path);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Sets the provider id from path.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="item">The item.</param>
|
2013-04-10 09:04:13 -07:00
|
|
|
|
/// <param name="path">The path.</param>
|
2013-03-02 23:58:04 -07:00
|
|
|
|
private void SetProviderIdFromPath(Series item, string path)
|
2013-02-20 18:33:05 -07:00
|
|
|
|
{
|
2013-03-02 23:58:04 -07:00
|
|
|
|
var justName = Path.GetFileName(path);
|
2013-02-20 18:33:05 -07:00
|
|
|
|
|
|
|
|
|
var id = justName.GetAttributeValue("tvdbid");
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(id))
|
|
|
|
|
{
|
|
|
|
|
item.SetProviderId(MetadataProviders.Tvdb, id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|