From d451386f5d1b2aa08d69040938be2cf9ee89e0ef Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 18 Feb 2015 23:37:44 -0500 Subject: [PATCH] sync updates --- MediaBrowser.Api/ItemUpdateService.cs | 7 +++ .../Entities/Audio/MusicArtist.cs | 10 ++++ .../Entities/Audio/MusicGenre.cs | 5 ++ MediaBrowser.Controller/Entities/GameGenre.cs | 5 ++ MediaBrowser.Controller/Entities/Genre.cs | 5 ++ .../Entities/Movies/BoxSet.cs | 5 ++ MediaBrowser.Controller/Entities/Person.cs | 9 +++- MediaBrowser.Controller/Entities/Studio.cs | 6 ++- MediaBrowser.Controller/Entities/Year.cs | 5 ++ .../InternalMetadataFolderImageProvider.cs | 1 - MediaBrowser.Model/Dto/ImageOptions.cs | 6 +++ .../FileOrganization/EpisodeFileOrganizer.cs | 53 ++++++++++++++++--- .../HttpServer/HttpListenerHost.cs | 18 +++++++ 13 files changed, 124 insertions(+), 11 deletions(-) diff --git a/MediaBrowser.Api/ItemUpdateService.cs b/MediaBrowser.Api/ItemUpdateService.cs index ea90afc3ba..6517d738b9 100644 --- a/MediaBrowser.Api/ItemUpdateService.cs +++ b/MediaBrowser.Api/ItemUpdateService.cs @@ -83,6 +83,13 @@ namespace MediaBrowser.Api { info.ContentTypeOptions = GetContentTypeOptions(true); info.ContentType = configuredContentType; + + if (string.Equals(inheritedContentType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase)) + { + info.ContentTypeOptions = info.ContentTypeOptions + .Where(i => string.IsNullOrWhiteSpace(i.Value) || string.Equals(i.Value, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase)) + .ToList(); + } } } } diff --git a/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs b/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs index e65d3c0e78..2b81450414 100644 --- a/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs +++ b/MediaBrowser.Controller/Entities/Audio/MusicArtist.cs @@ -52,6 +52,16 @@ namespace MediaBrowser.Controller.Entities.Audio } } + public override bool IsSaveLocalMetadataEnabled() + { + if (IsAccessedByName) + { + return true; + } + + return base.IsSaveLocalMetadataEnabled(); + } + private readonly Task _cachedTask = Task.FromResult(true); protected override Task ValidateChildrenInternal(IProgress progress, CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService) { diff --git a/MediaBrowser.Controller/Entities/Audio/MusicGenre.cs b/MediaBrowser.Controller/Entities/Audio/MusicGenre.cs index ed09560732..971c092361 100644 --- a/MediaBrowser.Controller/Entities/Audio/MusicGenre.cs +++ b/MediaBrowser.Controller/Entities/Audio/MusicGenre.cs @@ -44,6 +44,11 @@ namespace MediaBrowser.Controller.Entities.Audio return false; } + public override bool IsSaveLocalMetadataEnabled() + { + return true; + } + /// /// Gets a value indicating whether this instance is owned item. /// diff --git a/MediaBrowser.Controller/Entities/GameGenre.cs b/MediaBrowser.Controller/Entities/GameGenre.cs index b246b9388f..c91acbe3f1 100644 --- a/MediaBrowser.Controller/Entities/GameGenre.cs +++ b/MediaBrowser.Controller/Entities/GameGenre.cs @@ -43,6 +43,11 @@ namespace MediaBrowser.Controller.Entities } } + public override bool IsSaveLocalMetadataEnabled() + { + return true; + } + public override bool CanDelete() { return false; diff --git a/MediaBrowser.Controller/Entities/Genre.cs b/MediaBrowser.Controller/Entities/Genre.cs index e17a5c1d8b..cb68e5dae9 100644 --- a/MediaBrowser.Controller/Entities/Genre.cs +++ b/MediaBrowser.Controller/Entities/Genre.cs @@ -34,6 +34,11 @@ namespace MediaBrowser.Controller.Entities } } + public override bool IsSaveLocalMetadataEnabled() + { + return true; + } + public override bool CanDelete() { return false; diff --git a/MediaBrowser.Controller/Entities/Movies/BoxSet.cs b/MediaBrowser.Controller/Entities/Movies/BoxSet.cs index d874046efd..0778643da5 100644 --- a/MediaBrowser.Controller/Entities/Movies/BoxSet.cs +++ b/MediaBrowser.Controller/Entities/Movies/BoxSet.cs @@ -79,6 +79,11 @@ namespace MediaBrowser.Controller.Entities.Movies return true; } + public override bool IsSaveLocalMetadataEnabled() + { + return true; + } + /// /// Gets the trailer ids. /// diff --git a/MediaBrowser.Controller/Entities/Person.cs b/MediaBrowser.Controller/Entities/Person.cs index d8cb69ca17..ef24d43470 100644 --- a/MediaBrowser.Controller/Entities/Person.cs +++ b/MediaBrowser.Controller/Entities/Person.cs @@ -1,8 +1,8 @@ -using System.Runtime.Serialization; -using MediaBrowser.Controller.Providers; +using MediaBrowser.Controller.Providers; using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; namespace MediaBrowser.Controller.Entities { @@ -50,6 +50,11 @@ namespace MediaBrowser.Controller.Entities return false; } + public override bool IsSaveLocalMetadataEnabled() + { + return true; + } + /// /// Gets a value indicating whether this instance is owned item. /// diff --git a/MediaBrowser.Controller/Entities/Studio.cs b/MediaBrowser.Controller/Entities/Studio.cs index 31bbaf422e..b8d359369b 100644 --- a/MediaBrowser.Controller/Entities/Studio.cs +++ b/MediaBrowser.Controller/Entities/Studio.cs @@ -45,6 +45,11 @@ namespace MediaBrowser.Controller.Entities return false; } + public override bool IsSaveLocalMetadataEnabled() + { + return true; + } + /// /// Gets a value indicating whether this instance is owned item. /// @@ -63,7 +68,6 @@ namespace MediaBrowser.Controller.Entities return inputItems.Where(GetItemFilter()); } - public Func GetItemFilter() { return i => i.Studios.Contains(Name, StringComparer.OrdinalIgnoreCase); diff --git a/MediaBrowser.Controller/Entities/Year.cs b/MediaBrowser.Controller/Entities/Year.cs index cf3ad3b6ab..a1a1523873 100644 --- a/MediaBrowser.Controller/Entities/Year.cs +++ b/MediaBrowser.Controller/Entities/Year.cs @@ -52,6 +52,11 @@ namespace MediaBrowser.Controller.Entities } } + public override bool IsSaveLocalMetadataEnabled() + { + return true; + } + public IEnumerable GetTaggedItems(IEnumerable inputItems) { int year; diff --git a/MediaBrowser.LocalMetadata/Images/InternalMetadataFolderImageProvider.cs b/MediaBrowser.LocalMetadata/Images/InternalMetadataFolderImageProvider.cs index 7473d48e9a..60533797ab 100644 --- a/MediaBrowser.LocalMetadata/Images/InternalMetadataFolderImageProvider.cs +++ b/MediaBrowser.LocalMetadata/Images/InternalMetadataFolderImageProvider.cs @@ -1,5 +1,4 @@ using MediaBrowser.Common.IO; -using MediaBrowser.Controller.Channels; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.Audio; diff --git a/MediaBrowser.Model/Dto/ImageOptions.cs b/MediaBrowser.Model/Dto/ImageOptions.cs index 8e35c1323f..98bd0279a7 100644 --- a/MediaBrowser.Model/Dto/ImageOptions.cs +++ b/MediaBrowser.Model/Dto/ImageOptions.cs @@ -87,6 +87,12 @@ namespace MediaBrowser.Model.Dto /// The percent played. public int? PercentPlayed { get; set; } + /// + /// Gets or sets the un played count. + /// + /// The un played count. + public int? UnPlayedCount { get; set; } + /// /// Gets or sets the color of the background. /// diff --git a/MediaBrowser.Server.Implementations/FileOrganization/EpisodeFileOrganizer.cs b/MediaBrowser.Server.Implementations/FileOrganization/EpisodeFileOrganizer.cs index 7415fe092f..4f0f42f3e6 100644 --- a/MediaBrowser.Server.Implementations/FileOrganization/EpisodeFileOrganizer.cs +++ b/MediaBrowser.Server.Implementations/FileOrganization/EpisodeFileOrganizer.cs @@ -5,10 +5,12 @@ using MediaBrowser.Controller.FileOrganization; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Entities; +using MediaBrowser.Model.Extensions; using MediaBrowser.Model.FileOrganization; using MediaBrowser.Model.Logging; -using MediaBrowser.Naming.Common; using MediaBrowser.Naming.IO; +using MediaBrowser.Server.Implementations.Library; +using MediaBrowser.Server.Implementations.Logging; using System; using System.Collections.Generic; using System.Globalization; @@ -16,8 +18,6 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; -using MediaBrowser.Server.Implementations.Library; -using MediaBrowser.Server.Implementations.Logging; namespace MediaBrowser.Server.Implementations.FileOrganization { @@ -202,15 +202,26 @@ namespace MediaBrowser.Server.Implementations.FileOrganization if (overwriteExisting) { + var hasRenamedFiles = false; + foreach (var path in otherDuplicatePaths) { _logger.Debug("Removing duplicate episode {0}", path); _libraryMonitor.ReportFileSystemChangeBeginning(path); + var renameRelatedFiles = false; + //var renameRelatedFiles = !hasRenamedFiles && + // string.Equals(Path.GetDirectoryName(path), Path.GetDirectoryName(result.TargetPath), StringComparison.OrdinalIgnoreCase); + + if (renameRelatedFiles) + { + hasRenamedFiles = true; + } + try { - DeleteLibraryFile(path); + DeleteLibraryFile(path, renameRelatedFiles, result.TargetPath); } catch (IOException ex) { @@ -224,13 +235,41 @@ namespace MediaBrowser.Server.Implementations.FileOrganization } } - private void DeleteLibraryFile(string path) + private void DeleteLibraryFile(string path, bool renameRelatedFiles, string targetPath) { - var filename = Path.GetFileNameWithoutExtension(path); - _fileSystem.DeleteFile(path); + if (!renameRelatedFiles) + { + return; + } + // Now find other files + var originalFilenameWithoutExtension = Path.GetFileNameWithoutExtension(path); + var directory = Path.GetDirectoryName(path); + + if (!string.IsNullOrWhiteSpace(originalFilenameWithoutExtension) && !string.IsNullOrWhiteSpace(directory)) + { + // Get all related files, e.g. metadata, images, etc + var files = Directory.EnumerateFiles(directory, "*", SearchOption.TopDirectoryOnly) + .Where(i => (Path.GetFileNameWithoutExtension(i) ?? string.Empty).StartsWith(originalFilenameWithoutExtension, StringComparison.OrdinalIgnoreCase)) + .ToList(); + + var targetFilenameWithoutExtension = Path.GetFileNameWithoutExtension(targetPath); + + foreach (var file in files) + { + directory = Path.GetDirectoryName(file); + var filename = Path.GetFileName(file); + + filename = filename.Replace(originalFilenameWithoutExtension, targetFilenameWithoutExtension, + StringComparison.OrdinalIgnoreCase); + + var destination = Path.Combine(directory, filename); + + File.Move(file, destination); + } + } } private List GetOtherDuplicatePaths(string targetPath, Series series, int seasonNumber, int episodeNumber, int? endingEpisodeNumber) diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs b/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs index 046941e3c1..6e8ba1c1d2 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -380,6 +380,14 @@ namespace MediaBrowser.Server.Implementations.HttpServer Priority = route.Priority, Summary = route.Summary }); + + // TODO: This is a hack for iOS. Remove it asap. + routes.Add(new RouteAttribute(DoubleNormalizeRoutePath(route.Path), route.Verbs) + { + Notes = route.Notes, + Priority = route.Priority, + Summary = route.Summary + }); } return routes.ToArray(); @@ -395,6 +403,16 @@ namespace MediaBrowser.Server.Implementations.HttpServer return "mediabrowser/" + path; } + private string DoubleNormalizeRoutePath(string path) + { + if (path.StartsWith("/", StringComparison.OrdinalIgnoreCase)) + { + return "/mediabrowser/mediabrowser" + path; + } + + return "mediabrowser//mediabrowser" + path; + } + /// /// Releases the specified instance. ///