updated movie db provider to support downloaded trailers

This commit is contained in:
Luke Pulverenti 2013-05-06 11:37:02 -04:00
parent 9dad74765f
commit f3bd103e91
4 changed files with 52 additions and 21 deletions

View File

@ -97,6 +97,8 @@ namespace MediaBrowser.Controller.Entities
throw new InvalidOperationException("Unable to add " + item.Name); throw new InvalidOperationException("Unable to add " + item.Name);
} }
item.Parent = this;
var newChildren = Children.ToList(); var newChildren = Children.ToList();
await LibraryManager.CreateItem(item, cancellationToken).ConfigureAwait(false); await LibraryManager.CreateItem(item, cancellationToken).ConfigureAwait(false);
@ -120,6 +122,8 @@ namespace MediaBrowser.Controller.Entities
throw new InvalidOperationException("Unable to remove " + item.Name); throw new InvalidOperationException("Unable to remove " + item.Name);
} }
item.Parent = null;
var newChildren = Children.ToList(); var newChildren = Children.ToList();
LibraryManager.ReportItemRemoved(item); LibraryManager.ReportItemRemoved(item);
@ -193,7 +197,6 @@ namespace MediaBrowser.Controller.Entities
/// <returns>IEnumerable{BaseItem}.</returns> /// <returns>IEnumerable{BaseItem}.</returns>
private IEnumerable<BaseItem> GetIndexByPerson(User user, List<string> personTypes, bool includeAudio, string indexName) private IEnumerable<BaseItem> GetIndexByPerson(User user, List<string> personTypes, bool includeAudio, string indexName)
{ {
// Even though this implementation means multiple iterations over the target list - it allows us to defer // Even though this implementation means multiple iterations over the target list - it allows us to defer
// the retrieval of the individual children for each index value until they are requested. // the retrieval of the individual children for each index value until they are requested.
using (new Profiler(indexName + " Index Build for " + Name, Logger)) using (new Profiler(indexName + " Index Build for " + Name, Logger))

View File

@ -40,7 +40,7 @@ namespace MediaBrowser.Controller.Providers.Movies
/// <summary> /// <summary>
/// The movie db /// The movie db
/// </summary> /// </summary>
internal readonly SemaphoreSlim MovieDbResourcePool = new SemaphoreSlim(4, 4); internal readonly SemaphoreSlim MovieDbResourcePool = new SemaphoreSlim(3, 3);
internal static MovieDbProvider Current { get; private set; } internal static MovieDbProvider Current { get; private set; }
@ -101,6 +101,14 @@ namespace MediaBrowser.Controller.Providers.Movies
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns> /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
public override bool Supports(BaseItem item) public override bool Supports(BaseItem item)
{ {
var trailer = item as Trailer;
if (trailer != null)
{
return !trailer.IsLocalTrailer;
}
// Don't support local trailers
return item is Movie || item is BoxSet; return item is Movie || item is BoxSet;
} }
@ -228,7 +236,7 @@ namespace MediaBrowser.Controller.Providers.Movies
{ {
base.SetLastRefreshed(item, value, providerVersion, status); base.SetLastRefreshed(item, value, providerVersion, status);
if (ConfigurationManager.Configuration.SaveLocalMeta) if (ConfigurationManager.Configuration.SaveLocalMeta && item.LocationType == LocationType.FileSystem)
{ {
//in addition to ours, we need to set the last refreshed time for the local data provider //in addition to ours, we need to set the last refreshed time for the local data provider
//so it won't see the new files we download and process them all over again //so it won't see the new files we download and process them all over again
@ -269,7 +277,9 @@ namespace MediaBrowser.Controller.Providers.Movies
{ {
if (item.DontFetchMeta) return false; if (item.DontFetchMeta) return false;
if (ConfigurationManager.Configuration.SaveLocalMeta && HasFileSystemStampChanged(item, providerInfo)) if (item.LocationType == LocationType.FileSystem &&
ConfigurationManager.Configuration.SaveLocalMeta &&
HasFileSystemStampChanged(item, providerInfo))
{ {
//If they deleted something from file system, chances are, this item was mis-identified the first time //If they deleted something from file system, chances are, this item was mis-identified the first time
item.SetProviderId(MetadataProviders.Tmdb, null); item.SetProviderId(MetadataProviders.Tmdb, null);
@ -297,8 +307,6 @@ namespace MediaBrowser.Controller.Providers.Movies
if (HasAltMeta(item)) if (HasAltMeta(item))
return false; //never refresh if has meta from other source return false; //never refresh if has meta from other source
Logger.Debug("MovieDbProvider - " + item.Name + " needs refresh. Download date: " + downloadDate + " item created date: " + item.DateCreated + " Check for Update age: " + ConfigurationManager.Configuration.MetadataRefreshDays); Logger.Debug("MovieDbProvider - " + item.Name + " needs refresh. Download date: " + downloadDate + " item created date: " + item.DateCreated + " Check for Update age: " + ConfigurationManager.Configuration.MetadataRefreshDays);
return true; return true;
} }
@ -353,7 +361,7 @@ namespace MediaBrowser.Controller.Providers.Movies
private bool HasLocalMeta(BaseItem item) private bool HasLocalMeta(BaseItem item)
{ {
//need at least the xml and folder.jpg/png or a movie.xml put in by someone else //need at least the xml and folder.jpg/png or a movie.xml put in by someone else
return item.ResolveArgs.ContainsMetaFileByName(LOCAL_META_FILE_NAME); return item.LocationType == LocationType.FileSystem && item.ResolveArgs.ContainsMetaFileByName(LOCAL_META_FILE_NAME);
} }
/// <summary> /// <summary>
@ -363,7 +371,7 @@ namespace MediaBrowser.Controller.Providers.Movies
/// <returns><c>true</c> if [has alt meta] [the specified item]; otherwise, <c>false</c>.</returns> /// <returns><c>true</c> if [has alt meta] [the specified item]; otherwise, <c>false</c>.</returns>
private bool HasAltMeta(BaseItem item) private bool HasAltMeta(BaseItem item)
{ {
return item.ResolveArgs.ContainsMetaFileByName(ALT_META_FILE_NAME); return item.LocationType == LocationType.FileSystem && item.ResolveArgs.ContainsMetaFileByName(ALT_META_FILE_NAME);
} }
/// <summary> /// <summary>
@ -421,14 +429,19 @@ namespace MediaBrowser.Controller.Providers.Movies
/// <param name="cancellationToken">The cancellation token</param> /// <param name="cancellationToken">The cancellation token</param>
/// <returns>Task{System.String}.</returns> /// <returns>Task{System.String}.</returns>
public async Task<string> FindId(BaseItem item, int? productionYear, CancellationToken cancellationToken) public async Task<string> FindId(BaseItem item, int? productionYear, CancellationToken cancellationToken)
{
string id = null;
if (item.LocationType == LocationType.FileSystem)
{ {
string justName = item.Path != null ? item.Path.Substring(item.Path.LastIndexOf(Path.DirectorySeparatorChar)) : string.Empty; string justName = item.Path != null ? item.Path.Substring(item.Path.LastIndexOf(Path.DirectorySeparatorChar)) : string.Empty;
var id = justName.GetAttributeValue("tmdbid"); id = justName.GetAttributeValue("tmdbid");
if (id != null) if (id != null)
{ {
Logger.Debug("Using tmdb id specified in path."); Logger.Debug("Using tmdb id specified in path.");
return id; return id;
} }
}
int? year; int? year;
string name = item.Name; string name = item.Name;
@ -766,7 +779,7 @@ namespace MediaBrowser.Controller.Providers.Movies
} }
//and save locally //and save locally
if (ConfigurationManager.Configuration.SaveLocalMeta) if (ConfigurationManager.Configuration.SaveLocalMeta && item.LocationType == LocationType.FileSystem)
{ {
var ms = new MemoryStream(); var ms = new MemoryStream();
JsonSerializer.SerializeToStream(mainResult, ms); JsonSerializer.SerializeToStream(mainResult, ms);
@ -1086,8 +1099,10 @@ namespace MediaBrowser.Controller.Providers.Movies
{ {
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
var hasLocalPoster = item.LocationType == LocationType.FileSystem ? item.HasLocalImage("folder") : item.HasImage(ImageType.Primary);
// poster // poster
if (images.posters != null && images.posters.Count > 0 && (ConfigurationManager.Configuration.RefreshItemImages || !item.HasLocalImage("folder"))) if (images.posters != null && images.posters.Count > 0 && (ConfigurationManager.Configuration.RefreshItemImages || !hasLocalPoster))
{ {
var tmdbSettings = await TmdbSettings.ConfigureAwait(false); var tmdbSettings = await TmdbSettings.ConfigureAwait(false);
@ -1116,7 +1131,7 @@ namespace MediaBrowser.Controller.Providers.Movies
{ {
try try
{ {
item.PrimaryImagePath = await ProviderManager.DownloadAndSaveImage(item, tmdbImageUrl + poster.file_path, "folder" + Path.GetExtension(poster.file_path), ConfigurationManager.Configuration.SaveLocalMeta, MovieDbResourcePool, cancellationToken).ConfigureAwait(false); item.PrimaryImagePath = await ProviderManager.DownloadAndSaveImage(item, tmdbImageUrl + poster.file_path, "folder" + Path.GetExtension(poster.file_path), ConfigurationManager.Configuration.SaveLocalMeta && item.LocationType == LocationType.FileSystem, MovieDbResourcePool, cancellationToken).ConfigureAwait(false);
} }
catch (HttpException) catch (HttpException)
{ {
@ -1144,11 +1159,13 @@ namespace MediaBrowser.Controller.Providers.Movies
{ {
var bdName = "backdrop" + (i == 0 ? "" : i.ToString(CultureInfo.InvariantCulture)); var bdName = "backdrop" + (i == 0 ? "" : i.ToString(CultureInfo.InvariantCulture));
if (ConfigurationManager.Configuration.RefreshItemImages || !item.HasLocalImage(bdName)) var hasLocalBackdrop = item.LocationType == LocationType.FileSystem ? item.HasLocalImage(bdName) : item.BackdropImagePaths.Count > i;
if (ConfigurationManager.Configuration.RefreshItemImages || !hasLocalBackdrop)
{ {
try try
{ {
item.BackdropImagePaths.Add(await ProviderManager.DownloadAndSaveImage(item, tmdbImageUrl + images.backdrops[i].file_path, bdName + Path.GetExtension(images.backdrops[i].file_path), ConfigurationManager.Configuration.SaveLocalMeta, MovieDbResourcePool, cancellationToken).ConfigureAwait(false)); item.BackdropImagePaths.Add(await ProviderManager.DownloadAndSaveImage(item, tmdbImageUrl + images.backdrops[i].file_path, bdName + Path.GetExtension(images.backdrops[i].file_path), ConfigurationManager.Configuration.SaveLocalMeta && item.LocationType == LocationType.FileSystem, MovieDbResourcePool, cancellationToken).ConfigureAwait(false));
} }
catch (HttpException) catch (HttpException)
{ {

View File

@ -1,6 +1,7 @@
using MediaBrowser.Common.Net; using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Model.Logging; using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Serialization; using MediaBrowser.Model.Serialization;
using System; using System;
@ -20,6 +21,11 @@ namespace MediaBrowser.Controller.Providers.Movies
{ {
} }
public override bool Supports(BaseItem item)
{
return item is Movie || item is BoxSet;
}
/// <summary> /// <summary>
/// Gets the priority. /// Gets the priority.
/// </summary> /// </summary>

View File

@ -494,8 +494,6 @@ namespace MediaBrowser.Server.Implementations.Library
// Add in the plug-in folders // Add in the plug-in folders
foreach (var child in PluginFolderCreators) foreach (var child in PluginFolderCreators)
{ {
var folder = child.GetFolder();
rootFolder.AddVirtualChild(child.GetFolder()); rootFolder.AddVirtualChild(child.GetFolder());
} }
@ -1154,7 +1152,14 @@ namespace MediaBrowser.Server.Implementations.Library
/// <returns>IEnumerable{BaseItem}.</returns> /// <returns>IEnumerable{BaseItem}.</returns>
public IEnumerable<BaseItem> RetrieveChildren(Folder parent) public IEnumerable<BaseItem> RetrieveChildren(Folder parent)
{ {
return ItemRepository.RetrieveChildren(parent); var children = ItemRepository.RetrieveChildren(parent).ToList();
foreach (var child in children)
{
child.Parent = parent;
}
return children;
} }
} }
} }