public async Task <IEnumerable <RemoteSearchResult> > GetSearchResults(PersonLookupInfo searchInfo, CancellationToken cancellationToken) { var tmdbId = searchInfo.GetProviderId(MetadataProvider.Tmdb); var tmdbSettings = await TmdbMovieProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false); var tmdbImageUrl = tmdbSettings.images.GetImageUrl("original"); if (!string.IsNullOrEmpty(tmdbId)) { await EnsurePersonInfo(tmdbId, cancellationToken).ConfigureAwait(false); var dataFilePath = GetPersonDataFilePath(_configurationManager.ApplicationPaths, tmdbId); var info = _jsonSerializer.DeserializeFromFile <PersonResult>(dataFilePath); var images = (info.Images ?? new PersonImages()).Profiles ?? new List <Profile>(); var result = new RemoteSearchResult { Name = info.Name, SearchProviderName = Name, ImageUrl = images.Count == 0 ? null : (tmdbImageUrl + images[0].File_Path) }; result.SetProviderId(MetadataProvider.Tmdb, info.Id.ToString(_usCulture)); result.SetProviderId(MetadataProvider.Imdb, info.Imdb_Id); return(new[] { result }); } if (searchInfo.IsAutomated) { // Don't hammer moviedb searching by name return(new List <RemoteSearchResult>()); } var url = string.Format( CultureInfo.InvariantCulture, TmdbUtils.BaseTmdbApiUrl + @"3/search/person?api_key={1}&query={0}", WebUtility.UrlEncode(searchInfo.Name), TmdbUtils.ApiKey); using var requestMessage = new HttpRequestMessage(HttpMethod.Get, url); foreach (var header in TmdbUtils.AcceptHeaders) { requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(header)); } var response = await TmdbMovieProvider.Current.GetMovieDbResponse(requestMessage).ConfigureAwait(false); await using var stream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false); var result2 = await _jsonSerializer.DeserializeFromStreamAsync <TmdbSearchResult <PersonSearchResult> >(stream).ConfigureAwait(false) ?? new TmdbSearchResult <PersonSearchResult>(); return(result2.Results.Select(i => GetSearchResult(i, tmdbImageUrl))); }
private async Task <List <RemoteSearchResult> > FindSeriesInternal(string name, string language, CancellationToken cancellationToken) { var comparableName = GetComparableName(name); var list = new List <Tuple <List <string>, RemoteSearchResult> >(); TvDbResponse <SeriesSearchResult[]> result; try { result = await _tvdbClientManager.GetSeriesByNameAsync(comparableName, language, cancellationToken) .ConfigureAwait(false); } catch (TvDbServerException e) { _logger.LogError(e, "No series results found for {Name}", comparableName); return(new List <RemoteSearchResult>()); } foreach (var seriesSearchResult in result.Data) { var tvdbTitles = new List <string> { GetComparableName(seriesSearchResult.SeriesName) }; tvdbTitles.AddRange(seriesSearchResult.Aliases.Select(GetComparableName)); DateTime.TryParse(seriesSearchResult.FirstAired, out var firstAired); var remoteSearchResult = new RemoteSearchResult { Name = tvdbTitles.FirstOrDefault(), ProductionYear = firstAired.Year, SearchProviderName = Name, ImageUrl = TvdbUtils.BannerUrl + seriesSearchResult.Banner }; try { var seriesSesult = await _tvdbClientManager.GetSeriesByIdAsync(seriesSearchResult.Id, language, cancellationToken) .ConfigureAwait(false); remoteSearchResult.SetProviderId(MetadataProvider.Imdb, seriesSesult.Data.ImdbId); remoteSearchResult.SetProviderId(MetadataProvider.Zap2It, seriesSesult.Data.Zap2itId); } catch (TvDbServerException e) { _logger.LogError(e, "Unable to retrieve series with id {TvdbId}", seriesSearchResult.Id); } remoteSearchResult.SetProviderId(MetadataProvider.Tvdb, seriesSearchResult.Id.ToString()); list.Add(new Tuple <List <string>, RemoteSearchResult>(tvdbTitles, remoteSearchResult)); } return(list .OrderBy(i => i.Item1.Contains(comparableName, StringComparer.OrdinalIgnoreCase) ? 0 : 1) .ThenBy(i => list.IndexOf(i)) .Select(i => i.Item2) .ToList()); }
public async Task <IEnumerable <RemoteSearchResult> > GetSearchResults(PersonLookupInfo searchInfo, CancellationToken cancellationToken) { var tmdbId = searchInfo.GetProviderId(MetadataProviders.Tmdb); var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false); var tmdbImageUrl = tmdbSettings.images.GetImageUrl("original"); if (!string.IsNullOrEmpty(tmdbId)) { await EnsurePersonInfo(tmdbId, cancellationToken).ConfigureAwait(false); var dataFilePath = GetPersonDataFilePath(_configurationManager.ApplicationPaths, tmdbId); var info = _jsonSerializer.DeserializeFromFile <PersonResult>(dataFilePath); var images = (info.images ?? new Images()).profiles ?? new List <Profile>(); var result = new RemoteSearchResult { Name = info.name, SearchProviderName = Name, ImageUrl = images.Count == 0 ? null : (tmdbImageUrl + images[0].file_path) }; result.SetProviderId(MetadataProviders.Tmdb, info.id.ToString(_usCulture)); result.SetProviderId(MetadataProviders.Imdb, info.imdb_id); return(new[] { result }); } if (searchInfo.IsAutomated) { // Don't hammer moviedb searching by name return(new List <RemoteSearchResult>()); } var url = string.Format(MovieDbProvider.BaseMovieDbUrl + @"3/search/person?api_key={1}&query={0}", WebUtility.UrlEncode(searchInfo.Name), MovieDbProvider.ApiKey); using (var response = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions { Url = url, CancellationToken = cancellationToken, AcceptHeader = MovieDbProvider.AcceptHeader }).ConfigureAwait(false)) { using (var json = response.Content) { var result = _jsonSerializer.DeserializeFromStream <PersonSearchResults>(json) ?? new PersonSearchResults(); return(result.Results.Select(i => GetSearchResult(i, tmdbImageUrl))); } } }
private async Task <IEnumerable <RemoteSearchResult> > FindSeriesInternal(string name, string language, CancellationToken cancellationToken) { var url = string.Format(SeriesSearchUrl, WebUtility.UrlEncode(name)); MazeSearchContainerShow[] mazeResultItems; using (var results = await _httpClient.Get(new HttpRequestOptions { Url = url, ResourcePool = TvMazeResourcePool, CancellationToken = cancellationToken }).ConfigureAwait(false)) { mazeResultItems = _jsonSerializer.DeserializeFromStream <MazeSearchContainerShow[]>(results); } var searchResults = new List <RemoteSearchResult>(); var comparableName = GetComparableName(name); foreach (var mazeResultItem in mazeResultItems) { var searchResult = new RemoteSearchResult { SearchProviderName = Name }; var mazeSeries = mazeResultItem.show; searchResult.Name = mazeSeries.name; searchResult.SetProviderId(MetadataProviders.TvMaze.ToString(), mazeSeries.id.ToString()); if (mazeSeries.externals != null && !string.IsNullOrWhiteSpace(mazeSeries.externals.imdb)) { searchResult.SetProviderId(MetadataProviders.Imdb.ToString(), mazeSeries.externals.imdb); } if (mazeSeries.image != null && mazeSeries.image.original != null) { searchResult.ImageUrl = mazeSeries.image.original.ToString(); } if (mazeSeries.premiered.HasValue) { searchResult.ProductionYear = mazeSeries.premiered.Value.Year; } searchResults.Add(searchResult); } if (searchResults.Count == 0) { _logger.Info("TV Maze Provider - Could not find " + name + ". Check name on tvmaze.com"); } return(searchResults); }
/// <inheritdoc /> public async Task <IEnumerable <RemoteSearchResult> > GetSearchResults(PersonLookupInfo searchInfo, CancellationToken cancellationToken) { var personTmdbId = Convert.ToInt32(searchInfo.GetProviderId(MetadataProvider.Tmdb), CultureInfo.InvariantCulture); if (personTmdbId <= 0) { var personResult = await _tmdbClientManager.GetPersonAsync(personTmdbId, cancellationToken).ConfigureAwait(false); if (personResult != null) { var result = new RemoteSearchResult { Name = personResult.Name, SearchProviderName = Name, Overview = personResult.Biography }; if (personResult.Images?.Profiles != null && personResult.Images.Profiles.Count > 0) { result.ImageUrl = _tmdbClientManager.GetProfileUrl(personResult.Images.Profiles[0].FilePath); } result.SetProviderId(MetadataProvider.Tmdb, personResult.Id.ToString(CultureInfo.InvariantCulture)); result.SetProviderId(MetadataProvider.Imdb, personResult.ExternalIds.ImdbId); return(new[] { result }); } } // TODO why? Because of the old rate limit? if (searchInfo.IsAutomated) { // Don't hammer moviedb searching by name return(Enumerable.Empty <RemoteSearchResult>()); } var personSearchResult = await _tmdbClientManager.SearchPersonAsync(searchInfo.Name, cancellationToken).ConfigureAwait(false); var remoteSearchResults = new List <RemoteSearchResult>(); for (var i = 0; i < personSearchResult.Count; i++) { var person = personSearchResult[i]; var remoteSearchResult = new RemoteSearchResult { SearchProviderName = Name, Name = person.Name, ImageUrl = _tmdbClientManager.GetProfileUrl(person.ProfilePath) }; remoteSearchResult.SetProviderId(MetadataProvider.Tmdb, person.Id.ToString(CultureInfo.InvariantCulture)); remoteSearchResults.Add(remoteSearchResult); } return(remoteSearchResults); }
private IEnumerable <RemoteSearchResult> GetResultsFromResponse(Stream stream) { using (var oReader = new StreamReader(stream, Encoding.UTF8)) { var settings = new XmlReaderSettings() { ValidationType = ValidationType.None, CheckCharacters = false, IgnoreProcessingInstructions = true, IgnoreComments = true }; using (var reader = XmlReader.Create(oReader, settings)) { var results = ReleaseResult.Parse(reader); return(results.Select(i => { var result = new RemoteSearchResult { Name = i.Title, ProductionYear = i.Year }; if (i.Artists.Count > 0) { result.AlbumArtist = new RemoteSearchResult { SearchProviderName = Name, Name = i.Artists[0].Item1 }; var artistId = i.Artists[0].Item2; if (artistId != null) { result.AlbumArtist.SetProviderId(MetadataProvider.MusicBrainzArtist, artistId); } } if (!string.IsNullOrWhiteSpace(i.ReleaseId)) { result.SetProviderId(MetadataProvider.MusicBrainzAlbum, i.ReleaseId); } if (!string.IsNullOrWhiteSpace(i.ReleaseGroupId)) { result.SetProviderId(MetadataProvider.MusicBrainzReleaseGroup, i.ReleaseGroupId); } return result; })); } } }
public async Task <IEnumerable <RemoteSearchResult> > GetMovieSearchResults(ItemLookupInfo searchInfo, CancellationToken cancellationToken) { var tmdbId = searchInfo.GetProviderId(MetadataProviders.Tmdb); if (!string.IsNullOrEmpty(tmdbId)) { cancellationToken.ThrowIfCancellationRequested(); var obj = await EnsureMovieInfo(tmdbId, searchInfo.MetadataLanguage, searchInfo.MetadataCountryCode, cancellationToken).ConfigureAwait(false); if (obj == null) { return(new List <RemoteSearchResult>()); } var tmdbSettings = await GetTmdbSettings(cancellationToken).ConfigureAwait(false); var tmdbImageUrl = tmdbSettings.images.GetImageUrl("original"); var remoteResult = new RemoteSearchResult { Name = obj.GetTitle(), SearchProviderName = Name, ImageUrl = string.IsNullOrWhiteSpace(obj.poster_path) ? null : tmdbImageUrl + obj.poster_path }; if (!string.IsNullOrWhiteSpace(obj.release_date)) { DateTimeOffset r; // These dates are always in this exact format if (DateTimeOffset.TryParse(obj.release_date, _usCulture, DateTimeStyles.None, out r)) { remoteResult.PremiereDate = r.ToUniversalTime(); remoteResult.ProductionYear = remoteResult.PremiereDate.Value.Year; } } remoteResult.SetProviderId(MetadataProviders.Tmdb, obj.id.ToString(_usCulture)); if (!string.IsNullOrWhiteSpace(obj.imdb_id)) { remoteResult.SetProviderId(MetadataProviders.Imdb, obj.imdb_id); } return(new[] { remoteResult }); } return(await new MovieDbSearch(_logger, _jsonSerializer, _libraryManager).GetMovieSearchResults(searchInfo, cancellationToken).ConfigureAwait(false)); }
public async Task <IEnumerable <RemoteSearchResult> > GetSearchResults(PersonLookupInfo searchInfo, CancellationToken cancellationToken) { if (searchInfo.TryGetProviderId(MetadataProvider.Tmdb, out var personTmdbId)) { var personResult = await _tmdbClientManager.GetPersonAsync(int.Parse(personTmdbId, CultureInfo.InvariantCulture), cancellationToken).ConfigureAwait(false); if (personResult != null) { var result = new RemoteSearchResult { Name = personResult.Name, SearchProviderName = Name, Overview = personResult.Biography }; if (personResult.Images?.Profiles != null && personResult.Images.Profiles.Count > 0) { result.ImageUrl = _tmdbClientManager.GetProfileUrl(personResult.Images.Profiles[0].FilePath); } result.SetProviderId(MetadataProvider.Tmdb, personResult.Id.ToString(CultureInfo.InvariantCulture)); if (!string.IsNullOrEmpty(personResult.ExternalIds.ImdbId)) { result.SetProviderId(MetadataProvider.Imdb, personResult.ExternalIds.ImdbId); } return(new[] { result }); } } var personSearchResult = await _tmdbClientManager.SearchPersonAsync(searchInfo.Name, cancellationToken).ConfigureAwait(false); var remoteSearchResults = new List <RemoteSearchResult>(); for (var i = 0; i < personSearchResult.Count; i++) { var person = personSearchResult[i]; var remoteSearchResult = new RemoteSearchResult { SearchProviderName = Name, Name = person.Name, ImageUrl = _tmdbClientManager.GetProfileUrl(person.ProfilePath) }; remoteSearchResult.SetProviderId(MetadataProvider.Tmdb, person.Id.ToString(CultureInfo.InvariantCulture)); remoteSearchResults.Add(remoteSearchResult); } return(remoteSearchResults); }
private List <RemoteSearchResult> GetResultsFromResponse(Stream stream, bool isSearch) { using (var oReader = new StreamReader(stream, Encoding.UTF8)) { var settings = _xmlSettings.Create(false); settings.CheckCharacters = false; settings.IgnoreProcessingInstructions = true; settings.IgnoreComments = true; using (var reader = XmlReader.Create(oReader, settings)) { var results = isSearch ? ReleaseResult.ParseSearch(reader) : ReleaseResult.ParseReleaseList(reader); return(results.Select(i => { var result = new RemoteSearchResult { Name = i.Title, ProductionYear = i.Year, Artists = i.Artists.ToArray() }; result.SetProviderId("IMVDb", i.ReleaseId); return result; }).ToList()); } } }
private IEnumerable <RemoteSearchResult> GetResultsFromResponse(XmlDocument doc) { var list = new List <RemoteSearchResult>(); var docElem = doc.DocumentElement; if (docElem == null) { return(list); } var artistList = docElem.FirstChild; if (artistList == null) { return(list); } var nodes = artistList.ChildNodes; if (nodes != null) { foreach (var node in nodes.Cast <XmlNode>()) { if (node.Attributes != null) { string name = null; string overview = null; string mbzId = node.Attributes["id"].Value; foreach (var child in node.ChildNodes.Cast <XmlNode>()) { if (string.Equals(child.Name, "name", StringComparison.OrdinalIgnoreCase)) { name = child.InnerText; } if (string.Equals(child.Name, "annotation", StringComparison.OrdinalIgnoreCase)) { overview = child.InnerText; } } if (!string.IsNullOrWhiteSpace(mbzId) && !string.IsNullOrWhiteSpace(name)) { var result = new RemoteSearchResult { Name = name, Overview = overview }; result.SetProviderId(MetadataProviders.MusicBrainzArtist, mbzId); list.Add(result); } } } } return(list); }
public async Task <IEnumerable <RemoteSearchResult> > GetSearchResults(SeriesInfo info, CancellationToken cancellationToken) { try { var results = new List <RemoteSearchResult>(); var searchResults = await ShokoAPI.SeriesSearch(info.Name).ContinueWith((e) => e.Result.ToList()); Logger.LogInformation($"Series search returned {searchResults.Count} results."); foreach (var series in searchResults) { var seriesId = series.IDs.ID.ToString(); var seriesInfo = ApiManager.GetSeriesInfoSync(seriesId); var imageUrl = seriesInfo.AniDB.Poster?.ToURLString(); var parsedSeries = new RemoteSearchResult { Name = Text.GetSeriesTitle(seriesInfo.AniDB.Titles, seriesInfo.Shoko.Name, info.MetadataLanguage), SearchProviderName = Name, ImageUrl = imageUrl, }; parsedSeries.SetProviderId("Shoko Series", seriesId); results.Add(parsedSeries); } return(results); } catch (Exception e) { Logger.LogError(e, $"Threw unexpectedly; {e.Message}"); return(new List <RemoteSearchResult>()); } }
/// <inheritdoc /> public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(MusicVideoInfo searchInfo, CancellationToken cancellationToken) { _logger.LogDebug("Get search result for {Name}", searchInfo.Name); var searchResults = await _imvdbClient.GetSearchResponseAsync(searchInfo, cancellationToken) .ConfigureAwait(false); if (searchResults == null) { return Enumerable.Empty<RemoteSearchResult>(); } return searchResults.Results.Select( r => { var result = new RemoteSearchResult { Name = r.SongTitle, ProductionYear = r.Year, Artists = r.Artists.Select(a => new RemoteSearchResult { Name = a.Name }).ToArray(), ImageUrl = r.Image?.Size1, }; result.SetProviderId(ImvdbPlugin.ProviderName, r.Id.ToString(CultureInfo.InvariantCulture)); return result; }); }
public async Task <IEnumerable <RemoteSearchResult> > GetSearchResults(BoxSetInfo searchInfo, CancellationToken cancellationToken) { _logger.LogInformation($"Shoko Scanner... Searching BoxSet ({searchInfo.Name})"); var searchResults = await ShokoAPI.SeriesSearch(searchInfo.Name); if (searchResults.Count() == 0) { searchResults = await ShokoAPI.SeriesStartsWith(searchInfo.Name); } var results = new List <RemoteSearchResult>(); foreach (var series in searchResults) { var imageUrl = Helper.GetImageUrl(series.Images.Posters.FirstOrDefault()); _logger.LogInformation(imageUrl); var parsedBoxSet = new RemoteSearchResult { Name = series.Name, SearchProviderName = Name, ImageUrl = imageUrl }; parsedBoxSet.SetProviderId("Shoko", series.IDs.ID.ToString()); results.Add(parsedBoxSet); } return(results); }
public static RemoteSearchResult ToRemoteSearchResult(this FilmSearchResponse_films src, ILogger logger) { try { if (src is null) { return(null); } var res = new RemoteSearchResult() { Name = src.GetLocalName(), ImageUrl = src.PosterUrl, PremiereDate = src.GetPremiereDate(), Overview = src.Description, SearchProviderName = Constants.ProviderName }; res.SetProviderId(Constants.ProviderId, Convert.ToString(src.FilmId)); return(res); } catch (Exception e) { logger.LogError(e, "Exception during parse"); return(null); } }
public async Task <IEnumerable <RemoteSearchResult> > GetSearchResults( PersonLookupInfo info, CancellationToken cancellationToken) { var name = info.GetProviderId(Name); if (string.IsNullOrWhiteSpace(name)) { name = info.Name; } #if __EMBY__ Logger.Info("[AVDC] SearchResults for actress: {0}", name); #else Logger.LogInformation("[AVDC] SearchResults for actress: {Name}", name); #endif var actress = await ApiClient.GetActress(name, cancellationToken); if (!actress.Valid()) { return(new List <RemoteSearchResult>()); } var result = new RemoteSearchResult { Name = actress.Name, SearchProviderName = Name, ImageUrl = ApiClient.GetActressImageUrl(actress.Name) }; result.SetProviderId(Name, actress.Name); return(new List <RemoteSearchResult> { result }); }
private RemoteSearchResult ResultToMetadataResult(SearchResult result, ItemLookupInfo searchInfo, int?indexNumberEnd) { var item = new RemoteSearchResult { IndexNumber = searchInfo.IndexNumber, Name = result.Title, ParentIndexNumber = searchInfo.ParentIndexNumber, SearchProviderName = Name, IndexNumberEnd = indexNumberEnd }; item.SetProviderId(MetadataProvider.Imdb, result.imdbID); if (OmdbProvider.TryParseYear(result.Year, out var parsedYear)) { item.ProductionYear = parsedYear; } if (!string.IsNullOrEmpty(result.Released) && DateTime.TryParse(result.Released, CultureInfo.InvariantCulture, DateTimeStyles.AllowWhiteSpaces, out var released)) { item.PremiereDate = released; } if (!string.IsNullOrWhiteSpace(result.Poster)) { item.ImageUrl = result.Poster; } return(item); }
/// <inheritdoc /> public async Task <IEnumerable <RemoteSearchResult> > GetSearchResults(ArtistInfo searchInfo, CancellationToken cancellationToken) { _logger.LogDebug("Get search result for {Name}", searchInfo.Name); var searchResults = await _imvdbClient.GetSearchResponseAsync(searchInfo, cancellationToken) .ConfigureAwait(false); if (searchResults == null) { return(Enumerable.Empty <RemoteSearchResult>()); } return(searchResults.Results.Select( r => { var result = new RemoteSearchResult { Name = r.Name }; result.SetProviderId(ImvdbPlugin.ProviderName, r.Id.ToString(CultureInfo.InvariantCulture)); return result; })); }
public async Task <IEnumerable <RemoteSearchResult> > GetSearchResults(BoxSetInfo searchInfo, CancellationToken cancellationToken) { var tmdbId = searchInfo.GetProviderId(MetadataProviders.Tmdb); if (!string.IsNullOrEmpty(tmdbId)) { await EnsureInfo(tmdbId, searchInfo.MetadataLanguage, cancellationToken).ConfigureAwait(false); var dataFilePath = GetDataFilePath(_config.ApplicationPaths, tmdbId, searchInfo.MetadataLanguage); var info = _json.DeserializeFromFile <RootObject>(dataFilePath); var images = (info.images ?? new Images()).posters ?? new List <Poster>(); var tmdbSettings = await MovieDbProvider.Current.GetTmdbSettings(cancellationToken).ConfigureAwait(false); var tmdbImageUrl = tmdbSettings.images.base_url + "original"; var result = new RemoteSearchResult { Name = info.name, SearchProviderName = Name, ImageUrl = images.Count == 0 ? null : (tmdbImageUrl + images[0].file_path) }; result.SetProviderId(MetadataProviders.Tmdb, info.id.ToString(_usCulture)); return(new[] { result }); } return(await new MovieDbSearch(_logger, _json, _libraryManager).GetSearchResults(searchInfo, cancellationToken).ConfigureAwait(false)); }
public async Task <IEnumerable <RemoteSearchResult> > GetSearchResults( SeriesInfo info, CancellationToken cancellationToken) { _logger.LogInformation($"[DOUBAN FRODO INFO] Searching \"{info.Name}\""); var results = new List <RemoteSearchResult>(); var searchResults = new List <Response.SearchTarget>(); string sid = info.GetProviderId(ProviderID); if (!string.IsNullOrEmpty(sid)) { searchResults.Add(FrodoUtils.MapSubjectToSearchTarget(await GetFrodoSubject(sid, "tv", cancellationToken))); } else { searchResults = await SearchFrodoByName(info.Name, "tv", cancellationToken). ConfigureAwait(false); } foreach (Response.SearchTarget searchTarget in searchResults) { var searchResult = new RemoteSearchResult() { Name = searchTarget?.Title, ImageUrl = searchTarget?.Cover_Url, ProductionYear = int.Parse(searchTarget?.Year) }; searchResult.SetProviderId(ProviderID, searchTarget.Id); results.Add(searchResult); } return(results); }
private List <RemoteSearchResult> GetResultsFromResponse(Stream stream) { using (var oReader = new StreamReader(stream, Encoding.UTF8)) { var settings = _xmlSettings.Create(false); settings.CheckCharacters = false; settings.IgnoreProcessingInstructions = true; settings.IgnoreComments = true; using (var reader = XmlReader.Create(oReader, settings)) { var results = ReleaseResult.Parse(reader); return(results.Select(i => { var result = new RemoteSearchResult { Name = i.Title, ProductionYear = i.Year }; if (i.Artists.Count > 0) { result.AlbumArtist = new RemoteSearchResult { SearchProviderName = Name, Name = i.Artists[0].Item1 }; result.AlbumArtist.SetProviderId(MetadataProviders.MusicBrainzArtist, i.Artists[0].Item2); } if (!string.IsNullOrWhiteSpace(i.ReleaseId)) { result.SetProviderId(MetadataProviders.MusicBrainzAlbum, i.ReleaseId); } if (!string.IsNullOrWhiteSpace(i.ReleaseGroupId)) { result.SetProviderId(MetadataProviders.MusicBrainzReleaseGroup, i.ReleaseGroupId); } return result; }).ToList()); } } }
public async Task<IEnumerable<RemoteSearchResult>> GetMovieSearchResults(ItemLookupInfo searchInfo, CancellationToken cancellationToken) { var tmdbId = searchInfo.GetProviderId(MetadataProvider.Tmdb); if (!string.IsNullOrEmpty(tmdbId)) { cancellationToken.ThrowIfCancellationRequested(); await EnsureMovieInfo(tmdbId, searchInfo.MetadataLanguage, cancellationToken).ConfigureAwait(false); var dataFilePath = GetDataFilePath(tmdbId, searchInfo.MetadataLanguage); var obj = _jsonSerializer.DeserializeFromFile<MovieResult>(dataFilePath); var tmdbSettings = await GetTmdbSettings(cancellationToken).ConfigureAwait(false); var tmdbImageUrl = tmdbSettings.images.GetImageUrl("original"); var remoteResult = new RemoteSearchResult { Name = obj.GetTitle(), SearchProviderName = Name, ImageUrl = string.IsNullOrWhiteSpace(obj.Poster_Path) ? null : tmdbImageUrl + obj.Poster_Path }; if (!string.IsNullOrWhiteSpace(obj.Release_Date)) { // These dates are always in this exact format if (DateTime.TryParse(obj.Release_Date, _usCulture, DateTimeStyles.None, out var r)) { remoteResult.PremiereDate = r.ToUniversalTime(); remoteResult.ProductionYear = remoteResult.PremiereDate.Value.Year; } } remoteResult.SetProviderId(MetadataProvider.Tmdb, obj.Id.ToString(_usCulture)); if (!string.IsNullOrWhiteSpace(obj.Imdb_Id)) { remoteResult.SetProviderId(MetadataProvider.Imdb, obj.Imdb_Id); } return new[] { remoteResult }; } return await new TmdbSearch(_logger, _jsonSerializer, _libraryManager).GetMovieSearchResults(searchInfo, cancellationToken).ConfigureAwait(false); }
private IEnumerable <RemoteSearchResult> GetResultsFromResponse(XmlDocument doc) { //var ns = new XmlNamespaceManager(doc.NameTable); //ns.AddNamespace("mb", "https://musicbrainz.org/ns/mmd-2.0#"); var list = new List <RemoteSearchResult>(); var docElem = doc.DocumentElement; if (docElem == null) { return(list); } var artistList = docElem.FirstChild; if (artistList == null) { return(list); } var nodes = artistList.ChildNodes; if (nodes != null) { foreach (var node in nodes.Cast <XmlNode>()) { if (node.Attributes != null) { string name = null; string mbzId = node.Attributes["id"].Value; foreach (var child in node.ChildNodes.Cast <XmlNode>()) { if (string.Equals(child.Name, "name", StringComparison.OrdinalIgnoreCase)) { name = node.InnerText; break; } } if (!string.IsNullOrWhiteSpace(mbzId) && !string.IsNullOrWhiteSpace(name)) { var result = new RemoteSearchResult { Name = name }; result.SetProviderId(MetadataProviders.MusicBrainzArtist, mbzId); list.Add(result); } } } } return(list); }
public async Task <IEnumerable <RemoteSearchResult> > GetSearchResults( SeriesInfo info, CancellationToken cancellationToken) { _logger.LogInformation("Douban: search name {0}", info.Name); var results = new List <RemoteSearchResult>(); // Only handle it when language is "zh" if (info.MetadataLanguage != "zh") { _logger.LogInformation("DoubanProvider: the required " + "language is not zh, so just bypass DoubanProvider"); return(results); } IEnumerable <string> sidList; string doubanId = info.GetProviderId(ProviderID); _logger.LogInformation("douban id is {0}", doubanId); if (!string.IsNullOrEmpty(doubanId)) { sidList = new List <string> { doubanId }; } else { sidList = await SearchSidByName(info.Name, cancellationToken). ConfigureAwait(false); } foreach (String sid in sidList) { var subject = await GetDoubanSubject(sid, cancellationToken). ConfigureAwait(false); if (subject.Subtype != "tv") { continue; } var searchResult = new RemoteSearchResult() { Name = subject.Title, ImageUrl = subject.Images.Large, Overview = subject.Summary, ProductionYear = int.Parse(subject.Year), }; searchResult.SetProviderId(ProviderID, sid); results.Add(searchResult); } return(results); }
private async Task <List <RemoteSearchResult> > GetSearchResultsTv(string name, int?year, string language, string baseImageUrl, CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("name"); } var url3 = string.Format(Search3, WebUtility.UrlEncode(name), ApiKey, language, "tv"); using (var json = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions { Url = url3, CancellationToken = cancellationToken, AcceptHeader = AcceptHeader }).ConfigureAwait(false)) { var searchResults = _json.DeserializeFromStream <TmdbTvSearchResults>(json); var results = searchResults.results ?? new List <TvResult>(); var index = 0; var resultTuples = results.Select(result => new Tuple <TvResult, int>(result, index++)).ToList(); return(resultTuples.OrderBy(i => GetSearchResultOrder(i.Item1, year)) .ThenBy(i => i.Item2) .Select(i => i.Item1) .Select(i => { var remoteResult = new RemoteSearchResult { SearchProviderName = MovieDbProvider.Current.Name, Name = i.name ?? i.original_name, ImageUrl = string.IsNullOrWhiteSpace(i.poster_path) ? null : baseImageUrl + i.poster_path }; if (!string.IsNullOrWhiteSpace(i.first_air_date)) { DateTime r; // These dates are always in this exact format if (DateTime.TryParseExact(i.first_air_date, "yyyy-MM-dd", EnUs, DateTimeStyles.None, out r)) { remoteResult.PremiereDate = r.ToUniversalTime(); remoteResult.ProductionYear = remoteResult.PremiereDate.Value.Year; } } remoteResult.SetProviderId(MetadataProviders.Tmdb, i.id.ToString(EnUs)); return remoteResult; }) .ToList()); } }
private IEnumerable <RemoteSearchResult> GetResultsFromResponse(XmlDocument doc) { return(ReleaseResult.Parse(doc).Select(i => { var result = new RemoteSearchResult { Name = i.Title }; if (!string.IsNullOrWhiteSpace(i.ReleaseId)) { result.SetProviderId(MetadataProviders.MusicBrainzAlbum, i.ReleaseId); } if (!string.IsNullOrWhiteSpace(i.ReleaseGroupId)) { result.SetProviderId(MetadataProviders.MusicBrainzAlbum, i.ReleaseGroupId); } return result; })); }
private async Task <List <RemoteSearchResult> > GetSearchResultsGeneric(string name, string type, int?year, string language, string baseImageUrl, CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("name"); } var url3 = string.Format(Search3, WebUtility.UrlEncode(name), ApiKey, language, type); using (var response = await MovieDbProvider.Current.GetMovieDbResponse(new HttpRequestOptions { Url = url3, CancellationToken = cancellationToken, AcceptHeader = AcceptHeader }).ConfigureAwait(false)) { using (var json = response.Content) { var searchResults = await _json.DeserializeFromStreamAsync <TmdbMovieSearchResults>(json).ConfigureAwait(false); var results = searchResults.results ?? new List <TmdbMovieSearchResult>(); return(results .Select(i => { var remoteResult = new RemoteSearchResult { SearchProviderName = MovieDbProvider.Current.Name, Name = i.title ?? i.name ?? i.original_title, ImageUrl = string.IsNullOrWhiteSpace(i.poster_path) ? null : baseImageUrl + i.poster_path }; if (!string.IsNullOrWhiteSpace(i.release_date)) { DateTimeOffset r; // These dates are always in this exact format if (DateTimeOffset.TryParseExact(i.release_date, "yyyy-MM-dd", EnUs, DateTimeStyles.None, out r)) { remoteResult.PremiereDate = r.ToUniversalTime(); remoteResult.ProductionYear = remoteResult.PremiereDate.Value.Year; } } remoteResult.SetProviderId(MetadataProviders.Tmdb, i.id.ToString(EnUs)); return remoteResult; }) .ToList()); } } }
private RemoteSearchResult ParseArtist(XmlReader reader, string artistId) { var result = new RemoteSearchResult(); reader.MoveToContent(); reader.Read(); // http://stackoverflow.com/questions/2299632/why-does-xmlreader-skip-every-other-element-if-there-is-no-whitespace-separator // Loop through each element while (!reader.EOF && reader.ReadState == ReadState.Interactive) { if (reader.NodeType == XmlNodeType.Element) { switch (reader.Name) { case "name": { result.Name = reader.ReadElementContentAsString(); break; } case "annotation": { result.Overview = reader.ReadElementContentAsString(); break; } default: { // there is sort-name if ever needed reader.Skip(); break; } } } else { reader.Read(); } } result.SetProviderId(MetadataProvider.MusicBrainzArtist, artistId); if (string.IsNullOrWhiteSpace(artistId) || string.IsNullOrWhiteSpace(result.Name)) { return(null); } return(result); }
private async Task <List <RemoteSearchResult> > GetSearchResultsTv(string name, int?year, string language, string baseImageUrl, CancellationToken cancellationToken) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("name"); } var url3 = string.Format(_searchURL, WebUtility.UrlEncode(name), TmdbUtils.ApiKey, language, "tv"); using (var response = await TmdbMovieProvider.Current.GetMovieDbResponse(new HttpRequestOptions { Url = url3, CancellationToken = cancellationToken, AcceptHeader = TmdbUtils.AcceptHeader }).ConfigureAwait(false)) { using (var json = response.Content) { var searchResults = await _json.DeserializeFromStreamAsync <TmdbSearchResult <TvResult> >(json).ConfigureAwait(false); var results = searchResults.Results ?? new List <TvResult>(); return(results .Select(i => { var remoteResult = new RemoteSearchResult { SearchProviderName = TmdbMovieProvider.Current.Name, Name = i.Name ?? i.Original_Name, ImageUrl = string.IsNullOrWhiteSpace(i.Poster_Path) ? null : baseImageUrl + i.Poster_Path }; if (!string.IsNullOrWhiteSpace(i.First_Air_Date)) { // These dates are always in this exact format if (DateTime.TryParseExact(i.First_Air_Date, "yyyy-MM-dd", _usCulture, DateTimeStyles.None, out var r)) { remoteResult.PremiereDate = r.ToUniversalTime(); remoteResult.ProductionYear = remoteResult.PremiereDate.Value.Year; } } remoteResult.SetProviderId(MetadataProviders.Tmdb, i.Id.ToString(_usCulture)); return remoteResult; }) .ToList()); } } }
private RemoteSearchResult GetSearchResult(XmlNode node) { var n = node.SelectSingleNode("./GameTitle"); if (n == null) { return(null); } var title = n.InnerText; int?year = null; var n2 = node.SelectSingleNode("./ReleaseDate"); if (n2 != null) { var ry = n2.InnerText; // TGDB will return both 1993 and 12/10/1993 so I need to account for both if (ry.Length > 4) { ry = ry.Substring(ry.LastIndexOf('/') + 1); } int tgdbReleaseYear; if (Int32.TryParse(ry, out tgdbReleaseYear)) { year = tgdbReleaseYear; } } // We have our match var idNode = node.SelectSingleNode("./id"); if (idNode != null) { var result = new RemoteSearchResult { Name = title, SearchProviderName = Name, ProductionYear = year }; result.SetProviderId(GamesDbExternalId.KeyName, idNode.InnerText); return(result); } return(null); }
private RemoteSearchResult MapSearchTvToRemoteSearchResult(SearchTv series) { var remoteResult = new RemoteSearchResult { Name = series.Name ?? series.OriginalName, SearchProviderName = Name, ImageUrl = _tmdbClientManager.GetPosterUrl(series.PosterPath), Overview = series.Overview }; remoteResult.SetProviderId(MetadataProvider.Tmdb, series.Id.ToString(CultureInfo.InvariantCulture)); remoteResult.PremiereDate = series.FirstAirDate?.ToUniversalTime(); return(remoteResult); }