support xbmc -trailer suffix

This commit is contained in:
Luke Pulverenti 2013-05-20 13:04:39 -04:00
parent 5355ac4021
commit 9430b09ae9
3 changed files with 34 additions and 14 deletions

View File

@ -48,6 +48,7 @@ namespace MediaBrowser.Controller.Entities
public const string TrailerFolderName = "trailers";
public const string ThemeSongsFolderName = "theme-music";
public const string ThemeVideosFolderName = "backdrops";
public const string XbmcTrailerFileSuffix = "-trailer";
private string _name;
/// <summary>
@ -707,27 +708,38 @@ namespace MediaBrowser.Controller.Entities
return new List<Trailer>();
}
var files = new List<FileSystemInfo>();
var folder = resolveArgs.GetFileSystemEntryByName(TrailerFolderName);
// Path doesn't exist. No biggie
if (folder == null)
if (folder != null)
{
return new List<Trailer>();
}
IEnumerable<FileSystemInfo> files;
try
{
files = new DirectoryInfo(folder.FullName).EnumerateFiles();
files.AddRange(new DirectoryInfo(folder.FullName).EnumerateFiles());
}
catch (IOException ex)
{
Logger.ErrorException("Error loading trailers for {0}", ex, Name);
return new List<Trailer>();
}
}
return LibraryManager.ResolvePaths<Trailer>(files, null).Select(video =>
// Support xbmc trailers (-trailer suffix on video file names)
files.AddRange(resolveArgs.FileSystemChildren.Where(i =>
{
if (!i.Attributes.HasFlag(FileAttributes.Directory))
{
if (System.IO.Path.GetFileNameWithoutExtension(i.Name).EndsWith(XbmcTrailerFileSuffix, StringComparison.OrdinalIgnoreCase) && !string.Equals(Path, i.FullName, StringComparison.OrdinalIgnoreCase))
{
return true;
}
}
return false;
}));
var trailers= LibraryManager.ResolvePaths<Trailer>(files, null).Select(video =>
{
// Try to retrieve it from the db. If we don't find it, use the resolved version
var dbItem = LibraryManager.RetrieveItem(video.Id) as Trailer;
@ -740,6 +752,8 @@ namespace MediaBrowser.Controller.Entities
return video;
}).ToList();
return trailers;
}
/// <summary>

View File

@ -31,6 +31,12 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers
{
return base.Resolve(args);
}
// Support xbmc local trailer convention, but only when looking for local trailers (hence the parent == null check)
if (args.Parent == null && Path.GetFileNameWithoutExtension(args.Path).EndsWith(BaseItem.XbmcTrailerFileSuffix, StringComparison.OrdinalIgnoreCase))
{
return base.Resolve(args);
}
}
return null;

View File

@ -158,7 +158,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Movies
}
// Don't misidentify xbmc trailers as a movie
if (child.Name.IndexOf("-trailer", StringComparison.OrdinalIgnoreCase) != -1)
if (child.Name.IndexOf(BaseItem.XbmcTrailerFileSuffix, StringComparison.OrdinalIgnoreCase) != -1)
{
continue;
}