From b3127f19b546f3edce959dd70cafffb3d422a673 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 27 Jan 2015 01:50:40 -0500 Subject: [PATCH] updated tvdb search --- MediaBrowser.Api/UserService.cs | 2 +- MediaBrowser.Controller/Entities/BaseItem.cs | 14 ++- .../Entities/CollectionFolder.cs | 12 +- MediaBrowser.Controller/Entities/Folder.cs | 9 +- .../Entities/IHasMetadata.cs | 5 + .../Entities/Movies/BoxSet.cs | 1 + MediaBrowser.Controller/Entities/Trailer.cs | 2 +- MediaBrowser.Controller/Entities/User.cs | 10 +- .../Manager/MetadataService.cs | 4 +- .../Omdb/OmdbItemProvider.cs | 110 ++++++++++++++++-- .../TV/TvdbEpisodeProvider.cs | 13 ++- .../TV/TvdbSeriesProvider.cs | 39 +++++-- .../Dto/DtoService.cs | 3 +- .../Localization/Server/server.json | 1 + .../MediaBrowser.WebDashboard.csproj | 5 - 15 files changed, 175 insertions(+), 55 deletions(-) diff --git a/MediaBrowser.Api/UserService.cs b/MediaBrowser.Api/UserService.cs index 37553e4a4..4f49dd37d 100644 --- a/MediaBrowser.Api/UserService.cs +++ b/MediaBrowser.Api/UserService.cs @@ -455,7 +455,7 @@ namespace MediaBrowser.Api var user = _userManager.GetUserById(id); - var task = user.Name.Equals(dtoUser.Name, StringComparison.Ordinal) ? + var task = string.Equals(user.Name, dtoUser.Name, StringComparison.Ordinal) ? _userManager.UpdateUser(user) : _userManager.RenameUser(user, dtoUser.Name); diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index b819d14e5..67be6c2ce 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -894,12 +894,14 @@ namespace MediaBrowser.Controller.Entities /// System.String. public string GetUserDataKey() { - if (!string.IsNullOrWhiteSpace(_userDataKey)) + if (string.IsNullOrWhiteSpace(_userDataKey)) { - return _userDataKey; + var key = CreateUserDataKey(); + _userDataKey = key; + return key; } - return _userDataKey ?? (_userDataKey = CreateUserDataKey()); + return _userDataKey; } protected virtual string CreateUserDataKey() @@ -914,6 +916,12 @@ namespace MediaBrowser.Controller.Entities return current.IsInMixedFolder == newItem.IsInMixedFolder; } + public void AfterMetadataRefresh() + { + _sortName = null; + _userDataKey = null; + } + /// /// Gets the preferred metadata language. /// diff --git a/MediaBrowser.Controller/Entities/CollectionFolder.cs b/MediaBrowser.Controller/Entities/CollectionFolder.cs index f47a439a7..5452c63a4 100644 --- a/MediaBrowser.Controller/Entities/CollectionFolder.cs +++ b/MediaBrowser.Controller/Entities/CollectionFolder.cs @@ -121,12 +121,6 @@ namespace MediaBrowser.Controller.Entities return args; } - // Cache this since it will be used a lot - /// - /// The null task result - /// - private static readonly Task NullTaskResult = Task.FromResult(null); - /// /// Compare our current children (presumably just read from the repo) with the current state of the file system and adjust for any changes /// ***Currently does not contain logic to maintain items that are unavailable in the file system*** @@ -138,7 +132,7 @@ namespace MediaBrowser.Controller.Entities /// The refresh options. /// The directory service. /// Task. - protected override async Task ValidateChildrenInternal(IProgress progress, CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService) + protected override Task ValidateChildrenInternal(IProgress progress, CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService) { var list = PhysicalLocationsList.ToList(); @@ -146,8 +140,10 @@ namespace MediaBrowser.Controller.Entities if (!list.SequenceEqual(PhysicalLocationsList)) { - await UpdateToRepository(ItemUpdateType.MetadataImport, cancellationToken).ConfigureAwait(false); + return UpdateToRepository(ItemUpdateType.MetadataImport, cancellationToken); } + + return Task.FromResult(true); } /// diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index 8c13c7e66..7a902c0c5 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -373,12 +373,7 @@ namespace MediaBrowser.Controller.Entities /// Task. public Task ValidateChildren(IProgress progress, CancellationToken cancellationToken, MetadataRefreshOptions metadataRefreshOptions, bool recursive = true) { - return ValidateChildrenWithCancellationSupport(progress, cancellationToken, recursive, true, metadataRefreshOptions, metadataRefreshOptions.DirectoryService); - } - - private Task ValidateChildrenWithCancellationSupport(IProgress progress, CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService) - { - return ValidateChildrenInternal(progress, cancellationToken, recursive, refreshChildMetadata, refreshOptions, directoryService); + return ValidateChildrenInternal(progress, cancellationToken, recursive, true, metadataRefreshOptions, metadataRefreshOptions.DirectoryService); } private Dictionary GetActualChildrenDictionary() @@ -676,7 +671,7 @@ namespace MediaBrowser.Controller.Entities } }); - await child.ValidateChildrenWithCancellationSupport(innerProgress, cancellationToken, true, false, null, directoryService) + await child.ValidateChildrenInternal(innerProgress, cancellationToken, true, false, null, directoryService) .ConfigureAwait(false); } } diff --git a/MediaBrowser.Controller/Entities/IHasMetadata.cs b/MediaBrowser.Controller/Entities/IHasMetadata.cs index 10ddaa474..3643c58b3 100644 --- a/MediaBrowser.Controller/Entities/IHasMetadata.cs +++ b/MediaBrowser.Controller/Entities/IHasMetadata.cs @@ -54,5 +54,10 @@ namespace MediaBrowser.Controller.Entities /// Gets the item identities. /// List Identities { get; set; } + + /// + /// Afters the metadata refresh. + /// + void AfterMetadataRefresh(); } } diff --git a/MediaBrowser.Controller/Entities/Movies/BoxSet.cs b/MediaBrowser.Controller/Entities/Movies/BoxSet.cs index dea97aed4..b8f8dcbe1 100644 --- a/MediaBrowser.Controller/Entities/Movies/BoxSet.cs +++ b/MediaBrowser.Controller/Entities/Movies/BoxSet.cs @@ -138,6 +138,7 @@ namespace MediaBrowser.Controller.Entities.Movies public async Task RefreshAllMetadata(MetadataRefreshOptions refreshOptions, IProgress progress, CancellationToken cancellationToken) { + var b = this; // Refresh bottom up, children first, then the boxset // By then hopefully the movies within will have Tmdb collection values var items = GetRecursiveChildren().ToList(); diff --git a/MediaBrowser.Controller/Entities/Trailer.cs b/MediaBrowser.Controller/Entities/Trailer.cs index 72e3640f2..522e6edf6 100644 --- a/MediaBrowser.Controller/Entities/Trailer.cs +++ b/MediaBrowser.Controller/Entities/Trailer.cs @@ -1,12 +1,12 @@ using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Entities; +using MediaBrowser.Model.Users; using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Runtime.Serialization; -using MediaBrowser.Model.Users; namespace MediaBrowser.Controller.Entities { diff --git a/MediaBrowser.Controller/Entities/User.cs b/MediaBrowser.Controller/Entities/User.cs index ac1ab14de..3c89a9609 100644 --- a/MediaBrowser.Controller/Entities/User.cs +++ b/MediaBrowser.Controller/Entities/User.cs @@ -229,16 +229,16 @@ namespace MediaBrowser.Controller.Entities /// System.String. private string GetConfigurationDirectoryPath(string username) { - if (string.IsNullOrEmpty(username)) - { - throw new ArgumentNullException("username"); - } - var parentPath = ConfigurationManager.ApplicationPaths.UserConfigurationDirectoryPath; // Legacy if (!UsesIdForConfigurationPath) { + if (string.IsNullOrEmpty(username)) + { + throw new ArgumentNullException("username"); + } + var safeFolderName = FileSystem.GetValidFilename(username); return System.IO.Path.Combine(ConfigurationManager.ApplicationPaths.UserConfigurationDirectoryPath, safeFolderName); diff --git a/MediaBrowser.Providers/Manager/MetadataService.cs b/MediaBrowser.Providers/Manager/MetadataService.cs index fc329d64c..baccfa65b 100644 --- a/MediaBrowser.Providers/Manager/MetadataService.cs +++ b/MediaBrowser.Providers/Manager/MetadataService.cs @@ -114,7 +114,7 @@ namespace MediaBrowser.Providers.Manager catch (Exception ex) { localImagesFailed = true; - Logger.ErrorException("Error validating images for {0}", ex, item.Path ?? item.Name); + Logger.ErrorException("Error validating images for {0}", ex, item.Path ?? item.Name ?? "Unknown name"); refreshResult.AddStatus(ProviderRefreshStatus.Failure, ex.Message); } @@ -182,6 +182,8 @@ namespace MediaBrowser.Providers.Manager { await SaveProviderResult(itemOfType, refreshResult, refreshOptions.DirectoryService).ConfigureAwait(false); } + + itemOfType.AfterMetadataRefresh(); } private void MergeIdentities(TItemType item, TIdType id) diff --git a/MediaBrowser.Providers/Omdb/OmdbItemProvider.cs b/MediaBrowser.Providers/Omdb/OmdbItemProvider.cs index 1494eaee8..bc87c07c9 100644 --- a/MediaBrowser.Providers/Omdb/OmdbItemProvider.cs +++ b/MediaBrowser.Providers/Omdb/OmdbItemProvider.cs @@ -14,6 +14,8 @@ using MediaBrowser.Providers.Movies; using MediaBrowser.Providers.TV; using System; using System.Collections.Generic; +using System.Globalization; +using System.Net; using System.Threading; using System.Threading.Tasks; @@ -35,19 +37,75 @@ namespace MediaBrowser.Providers.Omdb _libraryManager = libraryManager; } - public async Task> GetSearchResults(SeriesInfo searchInfo, CancellationToken cancellationToken) + public Task> GetSearchResults(SeriesInfo searchInfo, CancellationToken cancellationToken) { - return new List(); + return GetSearchResults(searchInfo, "series", cancellationToken); } - public async Task> GetSearchResults(TrailerInfo searchInfo, CancellationToken cancellationToken) + public Task> GetSearchResults(MovieInfo searchInfo, CancellationToken cancellationToken) { - return new List(); + return GetSearchResults(searchInfo, "movie", cancellationToken); } - public async Task> GetSearchResults(MovieInfo searchInfo, CancellationToken cancellationToken) + public async Task> GetSearchResults(ItemLookupInfo searchInfo, string type, CancellationToken cancellationToken) { - return new List(); + var list = new List(); + + var imdbId = searchInfo.GetProviderId(MetadataProviders.Imdb); + if (!string.IsNullOrWhiteSpace(imdbId)) + { + return list; + } + + var url = "http://www.omdbapi.com/?plot=short&r=json"; + + var name = searchInfo.Name; + var year = searchInfo.Year; + + if (year.HasValue) + { + url += "&y=" + year.Value.ToString(CultureInfo.InvariantCulture); + } + + url += "&t=" + WebUtility.UrlEncode(name); + url += "&type=" + type; + + using (var stream = await _httpClient.Get(new HttpRequestOptions + { + Url = url, + ResourcePool = OmdbProvider.ResourcePool, + CancellationToken = cancellationToken, + CacheMode = CacheMode.Unconditional, + CacheLength = TimeSpan.FromDays(7) + + }).ConfigureAwait(false)) + { + var result = _jsonSerializer.DeserializeFromStream(stream); + + if (string.Equals(result.Response, "true", StringComparison.OrdinalIgnoreCase)) + { + var item = new RemoteSearchResult(); + + item.SearchProviderName = Name; + item.Name = result.Title; + item.SetProviderId(MetadataProviders.Imdb, result.imdbID); + + int parsedYear; + if (int.TryParse(result.Year, NumberStyles.Any, CultureInfo.InvariantCulture, out parsedYear)) + { + item.ProductionYear = parsedYear; + } + + if (!string.IsNullOrWhiteSpace(result.Poster) && !string.Equals(result.Poster, "N/A", StringComparison.OrdinalIgnoreCase)) + { + item.ImageUrl = result.Poster; + } + + list.Add(item); + } + } + + return list; } public Task> GetMetadata(ChannelItemLookupInfo info, CancellationToken cancellationToken) @@ -60,9 +118,14 @@ namespace MediaBrowser.Providers.Omdb return GetMovieResult(info, cancellationToken); } - public async Task> GetSearchResults(ChannelItemLookupInfo searchInfo, CancellationToken cancellationToken) + public Task> GetSearchResults(ChannelItemLookupInfo searchInfo, CancellationToken cancellationToken) { - return new List(); + if (searchInfo.ContentType != ChannelMediaContentType.MovieExtra || searchInfo.ExtraType != ExtraType.Trailer) + { + return Task.FromResult>(new List()); + } + + return GetSearchResults(searchInfo, "movie", cancellationToken); } public string Name @@ -185,7 +248,36 @@ namespace MediaBrowser.Providers.Omdb public Task GetImageResponse(string url, CancellationToken cancellationToken) { - throw new NotImplementedException(); + return _httpClient.GetResponse(new HttpRequestOptions + { + CancellationToken = cancellationToken, + Url = url, + ResourcePool = OmdbProvider.ResourcePool + }); + } + + class SearchResult + { + public string Title { get; set; } + public string Year { get; set; } + public string Rated { get; set; } + public string Released { get; set; } + public string Runtime { get; set; } + public string Genre { get; set; } + public string Director { get; set; } + public string Writer { get; set; } + public string Actors { get; set; } + public string Plot { get; set; } + public string Language { get; set; } + public string Country { get; set; } + public string Awards { get; set; } + public string Poster { get; set; } + public string Metascore { get; set; } + public string imdbRating { get; set; } + public string imdbVotes { get; set; } + public string imdbID { get; set; } + public string Type { get; set; } + public string Response { get; set; } } } } diff --git a/MediaBrowser.Providers/TV/TvdbEpisodeProvider.cs b/MediaBrowser.Providers/TV/TvdbEpisodeProvider.cs index 52c1ab7dd..cbd3f0af0 100644 --- a/MediaBrowser.Providers/TV/TvdbEpisodeProvider.cs +++ b/MediaBrowser.Providers/TV/TvdbEpisodeProvider.cs @@ -28,11 +28,13 @@ namespace MediaBrowser.Providers.TV internal static TvdbEpisodeProvider Current; private readonly IFileSystem _fileSystem; private readonly IServerConfigurationManager _config; + private readonly IHttpClient _httpClient; - public TvdbEpisodeProvider(IFileSystem fileSystem, IServerConfigurationManager config) + public TvdbEpisodeProvider(IFileSystem fileSystem, IServerConfigurationManager config, IHttpClient httpClient) { _fileSystem = fileSystem; _config = config; + _httpClient = httpClient; Current = this; } @@ -731,7 +733,12 @@ namespace MediaBrowser.Providers.TV public Task GetImageResponse(string url, CancellationToken cancellationToken) { - throw new NotImplementedException(); + return _httpClient.GetResponse(new HttpRequestOptions + { + CancellationToken = cancellationToken, + Url = url, + ResourcePool = TvdbSeriesProvider.Current.TvDbResourcePool + }); } public Task FindIdentity(EpisodeInfo info) @@ -743,7 +750,7 @@ namespace MediaBrowser.Providers.TV { return Task.FromResult(null); } - + var id = new EpisodeIdentity { Type = MetadataProviders.Tvdb.ToString(), diff --git a/MediaBrowser.Providers/TV/TvdbSeriesProvider.cs b/MediaBrowser.Providers/TV/TvdbSeriesProvider.cs index 2be319233..0f7a9f7d8 100644 --- a/MediaBrowser.Providers/TV/TvdbSeriesProvider.cs +++ b/MediaBrowser.Providers/TV/TvdbSeriesProvider.cs @@ -304,8 +304,6 @@ namespace MediaBrowser.Providers.TV private async Task> FindSeriesInternal(string name, CancellationToken cancellationToken) { - // TODO: Support returning more data, including image url's for the identify function - var url = string.Format(RootUrl + SeriesQuery, WebUtility.UrlEncode(name)); var doc = new XmlDocument(); @@ -330,6 +328,11 @@ namespace MediaBrowser.Providers.TV { foreach (XmlNode node in nodes) { + var searchResult = new RemoteSearchResult + { + SearchProviderName = Name + }; + var titles = new List(); var nameNode = node.SelectSingleNode("./SeriesName"); @@ -345,19 +348,35 @@ namespace MediaBrowser.Providers.TV titles.AddRange(alias); } + var imdbIdNode = node.SelectSingleNode("./IMDB_ID"); + if (imdbIdNode != null) + { + var val = imdbIdNode.InnerText; + if (!string.IsNullOrWhiteSpace(val)) + { + searchResult.SetProviderId(MetadataProviders.Imdb, val); + } + } + + var bannerNode = node.SelectSingleNode("./banner"); + if (bannerNode != null) + { + var val = bannerNode.InnerText; + if (!string.IsNullOrWhiteSpace(val)) + { + searchResult.ImageUrl = TVUtils.BannerUrl + val; + } + } + if (titles.Any(t => string.Equals(t, comparableName, StringComparison.OrdinalIgnoreCase))) { - var id = node.SelectSingleNode("./seriesid"); + var id = node.SelectSingleNode("./seriesid") ?? + node.SelectSingleNode("./id"); + if (id != null) { - var searchResult = new RemoteSearchResult - { - Name = titles.FirstOrDefault(), - SearchProviderName = Name - }; - + searchResult.Name = titles.FirstOrDefault(); searchResult.SetProviderId(MetadataProviders.Tvdb, id.InnerText); - searchResults.Add(searchResult); } } diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index 06b5138f1..0fa37435b 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -162,8 +162,7 @@ namespace MediaBrowser.Server.Implementations.Dto { SyncJobItemStatus.Converting, SyncJobItemStatus.Queued, - SyncJobItemStatus.Transferring, - SyncJobItemStatus.Synced + SyncJobItemStatus.Transferring } }); diff --git a/MediaBrowser.Server.Implementations/Localization/Server/server.json b/MediaBrowser.Server.Implementations/Localization/Server/server.json index d75a1bc3f..3e9c75220 100644 --- a/MediaBrowser.Server.Implementations/Localization/Server/server.json +++ b/MediaBrowser.Server.Implementations/Localization/Server/server.json @@ -56,6 +56,7 @@ "HeaderVideo": "Video", "HeaderPaths": "Paths", "CategorySync": "Sync", + "RegisterWithPayPal": "Register with PayPal", "HeaderSyncRequiresSupporterMembership": "Sync Requires a Supporter Membership", "HeaderEnjoyDayTrial": "Enjoy a 14 Day Free Trial", "LabelSyncTempPath": "Temporary file path:", diff --git a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj index 72f3a5757..0072ba257 100644 --- a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj +++ b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj @@ -2167,11 +2167,6 @@ PreserveNewest - - - PreserveNewest - - PreserveNewest