diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index 7918be8775..4f3c87508b 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -97,6 +97,8 @@ namespace MediaBrowser.Controller.Entities throw new InvalidOperationException("Unable to add " + item.Name); } + item.Parent = this; + var newChildren = Children.ToList(); await LibraryManager.CreateItem(item, cancellationToken).ConfigureAwait(false); @@ -120,6 +122,8 @@ namespace MediaBrowser.Controller.Entities throw new InvalidOperationException("Unable to remove " + item.Name); } + item.Parent = null; + var newChildren = Children.ToList(); LibraryManager.ReportItemRemoved(item); @@ -193,7 +197,6 @@ namespace MediaBrowser.Controller.Entities /// IEnumerable{BaseItem}. private IEnumerable GetIndexByPerson(User user, List personTypes, bool includeAudio, string indexName) { - // 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. using (new Profiler(indexName + " Index Build for " + Name, Logger)) diff --git a/MediaBrowser.Controller/Providers/Movies/MovieDbProvider.cs b/MediaBrowser.Controller/Providers/Movies/MovieDbProvider.cs index 835b365414..f5982cce91 100644 --- a/MediaBrowser.Controller/Providers/Movies/MovieDbProvider.cs +++ b/MediaBrowser.Controller/Providers/Movies/MovieDbProvider.cs @@ -40,7 +40,7 @@ namespace MediaBrowser.Controller.Providers.Movies /// /// The movie db /// - internal readonly SemaphoreSlim MovieDbResourcePool = new SemaphoreSlim(4, 4); + internal readonly SemaphoreSlim MovieDbResourcePool = new SemaphoreSlim(3, 3); internal static MovieDbProvider Current { get; private set; } @@ -101,6 +101,14 @@ namespace MediaBrowser.Controller.Providers.Movies /// true if XXXX, false otherwise 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; } @@ -228,7 +236,7 @@ namespace MediaBrowser.Controller.Providers.Movies { 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 //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 (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 item.SetProviderId(MetadataProviders.Tmdb, null); @@ -297,8 +307,6 @@ namespace MediaBrowser.Controller.Providers.Movies if (HasAltMeta(item)) 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); return true; } @@ -353,7 +361,7 @@ namespace MediaBrowser.Controller.Providers.Movies private bool HasLocalMeta(BaseItem item) { //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); } /// @@ -363,7 +371,7 @@ namespace MediaBrowser.Controller.Providers.Movies /// true if [has alt meta] [the specified item]; otherwise, false. 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); } /// @@ -422,12 +430,17 @@ namespace MediaBrowser.Controller.Providers.Movies /// Task{System.String}. public async Task FindId(BaseItem item, int? productionYear, CancellationToken cancellationToken) { - string justName = item.Path != null ? item.Path.Substring(item.Path.LastIndexOf(Path.DirectorySeparatorChar)) : string.Empty; - var id = justName.GetAttributeValue("tmdbid"); - if (id != null) + string id = null; + + if (item.LocationType == LocationType.FileSystem) { - Logger.Debug("Using tmdb id specified in path."); - return id; + string justName = item.Path != null ? item.Path.Substring(item.Path.LastIndexOf(Path.DirectorySeparatorChar)) : string.Empty; + id = justName.GetAttributeValue("tmdbid"); + if (id != null) + { + Logger.Debug("Using tmdb id specified in path."); + return id; + } } int? year; @@ -766,7 +779,7 @@ namespace MediaBrowser.Controller.Providers.Movies } //and save locally - if (ConfigurationManager.Configuration.SaveLocalMeta) + if (ConfigurationManager.Configuration.SaveLocalMeta && item.LocationType == LocationType.FileSystem) { var ms = new MemoryStream(); JsonSerializer.SerializeToStream(mainResult, ms); @@ -1086,8 +1099,10 @@ namespace MediaBrowser.Controller.Providers.Movies { cancellationToken.ThrowIfCancellationRequested(); + var hasLocalPoster = item.LocationType == LocationType.FileSystem ? item.HasLocalImage("folder") : item.HasImage(ImageType.Primary); + // 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); @@ -1116,7 +1131,7 @@ namespace MediaBrowser.Controller.Providers.Movies { 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) { @@ -1144,11 +1159,13 @@ namespace MediaBrowser.Controller.Providers.Movies { 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 { - 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) { diff --git a/MediaBrowser.Controller/Providers/Movies/MovieProviderFromJson.cs b/MediaBrowser.Controller/Providers/Movies/MovieProviderFromJson.cs index a86b7c848a..b3cf9334a8 100644 --- a/MediaBrowser.Controller/Providers/Movies/MovieProviderFromJson.cs +++ b/MediaBrowser.Controller/Providers/Movies/MovieProviderFromJson.cs @@ -1,6 +1,7 @@ using MediaBrowser.Common.Net; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Serialization; using System; @@ -20,6 +21,11 @@ namespace MediaBrowser.Controller.Providers.Movies { } + public override bool Supports(BaseItem item) + { + return item is Movie || item is BoxSet; + } + /// /// Gets the priority. /// diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 25c0c9842a..e0f2fee13f 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -494,8 +494,6 @@ namespace MediaBrowser.Server.Implementations.Library // Add in the plug-in folders foreach (var child in PluginFolderCreators) { - var folder = child.GetFolder(); - rootFolder.AddVirtualChild(child.GetFolder()); } @@ -1154,7 +1152,14 @@ namespace MediaBrowser.Server.Implementations.Library /// IEnumerable{BaseItem}. public IEnumerable RetrieveChildren(Folder parent) { - return ItemRepository.RetrieveChildren(parent); + var children = ItemRepository.RetrieveChildren(parent).ToList(); + + foreach (var child in children) + { + child.Parent = parent; + } + + return children; } } }