updated tvdb search

This commit is contained in:
Luke Pulverenti 2015-01-27 01:50:40 -05:00
parent f5919990c9
commit b3127f19b5
15 changed files with 175 additions and 55 deletions

View File

@ -455,7 +455,7 @@ namespace MediaBrowser.Api
var user = _userManager.GetUserById(id); 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.UpdateUser(user) :
_userManager.RenameUser(user, dtoUser.Name); _userManager.RenameUser(user, dtoUser.Name);

View File

@ -894,12 +894,14 @@ namespace MediaBrowser.Controller.Entities
/// <returns>System.String.</returns> /// <returns>System.String.</returns>
public string GetUserDataKey() 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() protected virtual string CreateUserDataKey()
@ -914,6 +916,12 @@ namespace MediaBrowser.Controller.Entities
return current.IsInMixedFolder == newItem.IsInMixedFolder; return current.IsInMixedFolder == newItem.IsInMixedFolder;
} }
public void AfterMetadataRefresh()
{
_sortName = null;
_userDataKey = null;
}
/// <summary> /// <summary>
/// Gets the preferred metadata language. /// Gets the preferred metadata language.
/// </summary> /// </summary>

View File

@ -121,12 +121,6 @@ namespace MediaBrowser.Controller.Entities
return args; return args;
} }
// Cache this since it will be used a lot
/// <summary>
/// The null task result
/// </summary>
private static readonly Task NullTaskResult = Task.FromResult<object>(null);
/// <summary> /// <summary>
/// Compare our current children (presumably just read from the repo) with the current state of the file system and adjust for any changes /// 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*** /// ***Currently does not contain logic to maintain items that are unavailable in the file system***
@ -138,7 +132,7 @@ namespace MediaBrowser.Controller.Entities
/// <param name="refreshOptions">The refresh options.</param> /// <param name="refreshOptions">The refresh options.</param>
/// <param name="directoryService">The directory service.</param> /// <param name="directoryService">The directory service.</param>
/// <returns>Task.</returns> /// <returns>Task.</returns>
protected override async Task ValidateChildrenInternal(IProgress<double> progress, CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService) protected override Task ValidateChildrenInternal(IProgress<double> progress, CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService)
{ {
var list = PhysicalLocationsList.ToList(); var list = PhysicalLocationsList.ToList();
@ -146,8 +140,10 @@ namespace MediaBrowser.Controller.Entities
if (!list.SequenceEqual(PhysicalLocationsList)) if (!list.SequenceEqual(PhysicalLocationsList))
{ {
await UpdateToRepository(ItemUpdateType.MetadataImport, cancellationToken).ConfigureAwait(false); return UpdateToRepository(ItemUpdateType.MetadataImport, cancellationToken);
} }
return Task.FromResult(true);
} }
/// <summary> /// <summary>

View File

@ -373,12 +373,7 @@ namespace MediaBrowser.Controller.Entities
/// <returns>Task.</returns> /// <returns>Task.</returns>
public Task ValidateChildren(IProgress<double> progress, CancellationToken cancellationToken, MetadataRefreshOptions metadataRefreshOptions, bool recursive = true) public Task ValidateChildren(IProgress<double> progress, CancellationToken cancellationToken, MetadataRefreshOptions metadataRefreshOptions, bool recursive = true)
{ {
return ValidateChildrenWithCancellationSupport(progress, cancellationToken, recursive, true, metadataRefreshOptions, metadataRefreshOptions.DirectoryService); return ValidateChildrenInternal(progress, cancellationToken, recursive, true, metadataRefreshOptions, metadataRefreshOptions.DirectoryService);
}
private Task ValidateChildrenWithCancellationSupport(IProgress<double> progress, CancellationToken cancellationToken, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService)
{
return ValidateChildrenInternal(progress, cancellationToken, recursive, refreshChildMetadata, refreshOptions, directoryService);
} }
private Dictionary<Guid, BaseItem> GetActualChildrenDictionary() private Dictionary<Guid, BaseItem> 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); .ConfigureAwait(false);
} }
} }

View File

@ -54,5 +54,10 @@ namespace MediaBrowser.Controller.Entities
/// Gets the item identities. /// Gets the item identities.
/// </summary> /// </summary>
List<IItemIdentity> Identities { get; set; } List<IItemIdentity> Identities { get; set; }
/// <summary>
/// Afters the metadata refresh.
/// </summary>
void AfterMetadataRefresh();
} }
} }

View File

@ -138,6 +138,7 @@ namespace MediaBrowser.Controller.Entities.Movies
public async Task RefreshAllMetadata(MetadataRefreshOptions refreshOptions, IProgress<double> progress, CancellationToken cancellationToken) public async Task RefreshAllMetadata(MetadataRefreshOptions refreshOptions, IProgress<double> progress, CancellationToken cancellationToken)
{ {
var b = this;
// Refresh bottom up, children first, then the boxset // Refresh bottom up, children first, then the boxset
// By then hopefully the movies within will have Tmdb collection values // By then hopefully the movies within will have Tmdb collection values
var items = GetRecursiveChildren().ToList(); var items = GetRecursiveChildren().ToList();

View File

@ -1,12 +1,12 @@
using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Configuration;
using MediaBrowser.Model.Entities; using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Users;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Runtime.Serialization; using System.Runtime.Serialization;
using MediaBrowser.Model.Users;
namespace MediaBrowser.Controller.Entities namespace MediaBrowser.Controller.Entities
{ {

View File

@ -229,16 +229,16 @@ namespace MediaBrowser.Controller.Entities
/// <returns>System.String.</returns> /// <returns>System.String.</returns>
private string GetConfigurationDirectoryPath(string username) private string GetConfigurationDirectoryPath(string username)
{ {
if (string.IsNullOrEmpty(username))
{
throw new ArgumentNullException("username");
}
var parentPath = ConfigurationManager.ApplicationPaths.UserConfigurationDirectoryPath; var parentPath = ConfigurationManager.ApplicationPaths.UserConfigurationDirectoryPath;
// Legacy // Legacy
if (!UsesIdForConfigurationPath) if (!UsesIdForConfigurationPath)
{ {
if (string.IsNullOrEmpty(username))
{
throw new ArgumentNullException("username");
}
var safeFolderName = FileSystem.GetValidFilename(username); var safeFolderName = FileSystem.GetValidFilename(username);
return System.IO.Path.Combine(ConfigurationManager.ApplicationPaths.UserConfigurationDirectoryPath, safeFolderName); return System.IO.Path.Combine(ConfigurationManager.ApplicationPaths.UserConfigurationDirectoryPath, safeFolderName);

View File

@ -114,7 +114,7 @@ namespace MediaBrowser.Providers.Manager
catch (Exception ex) catch (Exception ex)
{ {
localImagesFailed = true; 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); refreshResult.AddStatus(ProviderRefreshStatus.Failure, ex.Message);
} }
@ -182,6 +182,8 @@ namespace MediaBrowser.Providers.Manager
{ {
await SaveProviderResult(itemOfType, refreshResult, refreshOptions.DirectoryService).ConfigureAwait(false); await SaveProviderResult(itemOfType, refreshResult, refreshOptions.DirectoryService).ConfigureAwait(false);
} }
itemOfType.AfterMetadataRefresh();
} }
private void MergeIdentities(TItemType item, TIdType id) private void MergeIdentities(TItemType item, TIdType id)

View File

@ -14,6 +14,8 @@ using MediaBrowser.Providers.Movies;
using MediaBrowser.Providers.TV; using MediaBrowser.Providers.TV;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.Net;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -35,19 +37,75 @@ namespace MediaBrowser.Providers.Omdb
_libraryManager = libraryManager; _libraryManager = libraryManager;
} }
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(SeriesInfo searchInfo, CancellationToken cancellationToken) public Task<IEnumerable<RemoteSearchResult>> GetSearchResults(SeriesInfo searchInfo, CancellationToken cancellationToken)
{ {
return new List<RemoteSearchResult>(); return GetSearchResults(searchInfo, "series", cancellationToken);
} }
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(TrailerInfo searchInfo, CancellationToken cancellationToken) public Task<IEnumerable<RemoteSearchResult>> GetSearchResults(MovieInfo searchInfo, CancellationToken cancellationToken)
{ {
return new List<RemoteSearchResult>(); return GetSearchResults(searchInfo, "movie", cancellationToken);
} }
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(MovieInfo searchInfo, CancellationToken cancellationToken) public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(ItemLookupInfo searchInfo, string type, CancellationToken cancellationToken)
{ {
return new List<RemoteSearchResult>(); var list = new List<RemoteSearchResult>();
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<SearchResult>(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<MetadataResult<ChannelVideoItem>> GetMetadata(ChannelItemLookupInfo info, CancellationToken cancellationToken) public Task<MetadataResult<ChannelVideoItem>> GetMetadata(ChannelItemLookupInfo info, CancellationToken cancellationToken)
@ -60,9 +118,14 @@ namespace MediaBrowser.Providers.Omdb
return GetMovieResult<ChannelVideoItem>(info, cancellationToken); return GetMovieResult<ChannelVideoItem>(info, cancellationToken);
} }
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(ChannelItemLookupInfo searchInfo, CancellationToken cancellationToken) public Task<IEnumerable<RemoteSearchResult>> GetSearchResults(ChannelItemLookupInfo searchInfo, CancellationToken cancellationToken)
{ {
return new List<RemoteSearchResult>(); if (searchInfo.ContentType != ChannelMediaContentType.MovieExtra || searchInfo.ExtraType != ExtraType.Trailer)
{
return Task.FromResult<IEnumerable<RemoteSearchResult>>(new List<RemoteSearchResult>());
}
return GetSearchResults(searchInfo, "movie", cancellationToken);
} }
public string Name public string Name
@ -185,7 +248,36 @@ namespace MediaBrowser.Providers.Omdb
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken) public Task<HttpResponseInfo> 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; }
} }
} }
} }

View File

@ -28,11 +28,13 @@ namespace MediaBrowser.Providers.TV
internal static TvdbEpisodeProvider Current; internal static TvdbEpisodeProvider Current;
private readonly IFileSystem _fileSystem; private readonly IFileSystem _fileSystem;
private readonly IServerConfigurationManager _config; private readonly IServerConfigurationManager _config;
private readonly IHttpClient _httpClient;
public TvdbEpisodeProvider(IFileSystem fileSystem, IServerConfigurationManager config) public TvdbEpisodeProvider(IFileSystem fileSystem, IServerConfigurationManager config, IHttpClient httpClient)
{ {
_fileSystem = fileSystem; _fileSystem = fileSystem;
_config = config; _config = config;
_httpClient = httpClient;
Current = this; Current = this;
} }
@ -731,7 +733,12 @@ namespace MediaBrowser.Providers.TV
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken) public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
{ {
throw new NotImplementedException(); return _httpClient.GetResponse(new HttpRequestOptions
{
CancellationToken = cancellationToken,
Url = url,
ResourcePool = TvdbSeriesProvider.Current.TvDbResourcePool
});
} }
public Task<EpisodeIdentity> FindIdentity(EpisodeInfo info) public Task<EpisodeIdentity> FindIdentity(EpisodeInfo info)
@ -743,7 +750,7 @@ namespace MediaBrowser.Providers.TV
{ {
return Task.FromResult<EpisodeIdentity>(null); return Task.FromResult<EpisodeIdentity>(null);
} }
var id = new EpisodeIdentity var id = new EpisodeIdentity
{ {
Type = MetadataProviders.Tvdb.ToString(), Type = MetadataProviders.Tvdb.ToString(),

View File

@ -304,8 +304,6 @@ namespace MediaBrowser.Providers.TV
private async Task<IEnumerable<RemoteSearchResult>> FindSeriesInternal(string name, CancellationToken cancellationToken) private async Task<IEnumerable<RemoteSearchResult>> 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 url = string.Format(RootUrl + SeriesQuery, WebUtility.UrlEncode(name));
var doc = new XmlDocument(); var doc = new XmlDocument();
@ -330,6 +328,11 @@ namespace MediaBrowser.Providers.TV
{ {
foreach (XmlNode node in nodes) foreach (XmlNode node in nodes)
{ {
var searchResult = new RemoteSearchResult
{
SearchProviderName = Name
};
var titles = new List<string>(); var titles = new List<string>();
var nameNode = node.SelectSingleNode("./SeriesName"); var nameNode = node.SelectSingleNode("./SeriesName");
@ -345,19 +348,35 @@ namespace MediaBrowser.Providers.TV
titles.AddRange(alias); 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))) 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) if (id != null)
{ {
var searchResult = new RemoteSearchResult searchResult.Name = titles.FirstOrDefault();
{
Name = titles.FirstOrDefault(),
SearchProviderName = Name
};
searchResult.SetProviderId(MetadataProviders.Tvdb, id.InnerText); searchResult.SetProviderId(MetadataProviders.Tvdb, id.InnerText);
searchResults.Add(searchResult); searchResults.Add(searchResult);
} }
} }

View File

@ -162,8 +162,7 @@ namespace MediaBrowser.Server.Implementations.Dto
{ {
SyncJobItemStatus.Converting, SyncJobItemStatus.Converting,
SyncJobItemStatus.Queued, SyncJobItemStatus.Queued,
SyncJobItemStatus.Transferring, SyncJobItemStatus.Transferring
SyncJobItemStatus.Synced
} }
}); });

View File

@ -56,6 +56,7 @@
"HeaderVideo": "Video", "HeaderVideo": "Video",
"HeaderPaths": "Paths", "HeaderPaths": "Paths",
"CategorySync": "Sync", "CategorySync": "Sync",
"RegisterWithPayPal": "Register with PayPal",
"HeaderSyncRequiresSupporterMembership": "Sync Requires a Supporter Membership", "HeaderSyncRequiresSupporterMembership": "Sync Requires a Supporter Membership",
"HeaderEnjoyDayTrial": "Enjoy a 14 Day Free Trial", "HeaderEnjoyDayTrial": "Enjoy a 14 Day Free Trial",
"LabelSyncTempPath": "Temporary file path:", "LabelSyncTempPath": "Temporary file path:",

View File

@ -2167,11 +2167,6 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Content Include="dashboard-ui\css\images\supporter\registerpaypal.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="dashboard-ui\css\images\notifications\done.png"> <Content Include="dashboard-ui\css\images\notifications\done.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>