Merge pull request #1731 from softworkz/MetadataMerging

Prioritize metadata merging by preferred language
pull/702/head
Luke 8 years ago committed by GitHub
commit 2c78e43aad

@ -13,13 +13,15 @@ namespace MediaBrowser.Controller.Providers
public MetadataResult()
{
Images = new List<LocalImageInfo>();
ResultLanguage = "en";
}
public List<PersonInfo> People { get; set; }
public bool HasMetadata { get; set; }
public T Item { get; set; }
public string ResultLanguage { get; set; }
public bool QueriedById { get; set; }
public void AddPerson(PersonInfo p)
{
if (People == null)

@ -651,6 +651,8 @@ namespace MediaBrowser.Providers.Manager
{
var refreshResult = new RefreshResult();
var results = new List<MetadataResult<TItemType>>();
foreach (var provider in providers)
{
var providerName = provider.GetType().Name;
@ -667,7 +669,7 @@ namespace MediaBrowser.Providers.Manager
if (result.HasMetadata)
{
MergeData(result, temp, new List<MetadataFields>(), false, false);
results.Add(result);
refreshResult.UpdateType = refreshResult.UpdateType | ItemUpdateType.MetadataDownload;
}
@ -688,6 +690,38 @@ namespace MediaBrowser.Providers.Manager
}
}
var orderedResults = new List<MetadataResult<TItemType>>();
if (string.IsNullOrEmpty(id.MetadataLanguage))
{
orderedResults.AddRange(results);
}
else
{
// prioritize results with matching ResultLanguage
foreach (var result in results)
{
if (!string.IsNullOrEmpty(result.ResultLanguage) && result.ResultLanguage == id.MetadataLanguage && result.QueriedById)
{
orderedResults.Add(result);
}
}
// add all other results
foreach (var result in results)
{
if (!orderedResults.Contains(result))
{
orderedResults.Add(result);
}
}
}
foreach (var result in results)
{
MergeData(result, temp, new List<MetadataFields>(), false, false);
}
return refreshResult;
}

@ -212,13 +212,15 @@ namespace MediaBrowser.Providers.Omdb
{
var result = new MetadataResult<Series>
{
Item = new Series()
Item = new Series(),
QueriedById = true
};
var imdbId = info.GetProviderId(MetadataProviders.Imdb);
if (string.IsNullOrWhiteSpace(imdbId))
{
imdbId = await GetSeriesImdbId(info, cancellationToken).ConfigureAwait(false);
result.QueriedById = false;
}
if (!string.IsNullOrEmpty(imdbId))
@ -251,13 +253,15 @@ namespace MediaBrowser.Providers.Omdb
{
var result = new MetadataResult<T>
{
Item = new T()
Item = new T(),
QueriedById = true
};
var imdbId = info.GetProviderId(MetadataProviders.Imdb);
if (string.IsNullOrWhiteSpace(imdbId))
{
imdbId = await GetMovieImdbId(info, cancellationToken).ConfigureAwait(false);
result.QueriedById = false;
}
if (!string.IsNullOrEmpty(imdbId))

@ -43,7 +43,8 @@ namespace MediaBrowser.Providers.TV
{
var result = new MetadataResult<Episode>()
{
Item = new Episode()
Item = new Episode(),
QueriedById = true
};
// Allowing this will dramatically increase scan times

@ -91,6 +91,13 @@ namespace MediaBrowser.Providers.TV
var response = await GetEpisodeInfo(seriesTmdbId, seasonNumber.Value, episodeNumber.Value, info.MetadataLanguage, cancellationToken).ConfigureAwait(false);
result.HasMetadata = true;
result.QueriedById = true;
if (!string.IsNullOrEmpty(response.overview))
{
// if overview is non-empty, we can assume that localized data was returned
result.ResultLanguage = info.MetadataLanguage;
}
var item = new Episode();
result.Item = item;

@ -119,6 +119,7 @@ namespace MediaBrowser.Providers.TV
public async Task<MetadataResult<Series>> GetMetadata(SeriesInfo info, CancellationToken cancellationToken)
{
var result = new MetadataResult<Series>();
result.QueriedById = true;
var tmdbId = info.GetProviderId(MetadataProviders.Tmdb);
@ -154,6 +155,7 @@ namespace MediaBrowser.Providers.TV
if (string.IsNullOrEmpty(tmdbId))
{
result.QueriedById = false;
var searchResults = await new MovieDbSearch(_logger, _jsonSerializer, _libraryManager).GetSearchResults(info, cancellationToken).ConfigureAwait(false);
var searchResult = searchResults.FirstOrDefault();
@ -168,7 +170,7 @@ namespace MediaBrowser.Providers.TV
{
cancellationToken.ThrowIfCancellationRequested();
result.Item = await FetchSeriesData(tmdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
result = await FetchMovieData(tmdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
result.HasMetadata = result.Item != null;
}
@ -176,7 +178,7 @@ namespace MediaBrowser.Providers.TV
return result;
}
private async Task<Series> FetchSeriesData(string tmdbId, string language, string preferredCountryCode, CancellationToken cancellationToken)
private async Task<MetadataResult<Series>> FetchMovieData(string tmdbId, string language, string preferredCountryCode, CancellationToken cancellationToken)
{
string dataFilePath = null;
RootObject seriesInfo = null;
@ -194,16 +196,18 @@ namespace MediaBrowser.Providers.TV
tmdbId = seriesInfo.id.ToString(_usCulture);
dataFilePath = GetDataFilePath(tmdbId, language);
_fileSystem.CreateDirectory(Path.GetDirectoryName(dataFilePath));
_fileSystem.CreateDirectory(Path.GetDirectoryName(dataFilePath));
_jsonSerializer.SerializeToFile(seriesInfo, dataFilePath);
await EnsureSeriesInfo(tmdbId, language, cancellationToken).ConfigureAwait(false);
var item = new Series();
var result = new MetadataResult<Series>();
result.Item = new Series();
result.ResultLanguage = seriesInfo.ResultLanguage;
ProcessMainInfo(item, seriesInfo, preferredCountryCode);
ProcessMainInfo(result.Item, seriesInfo, preferredCountryCode);
return item;
return result;
}
private void ProcessMainInfo(Series series, RootObject seriesInfo, string preferredCountryCode)
@ -324,7 +328,7 @@ namespace MediaBrowser.Providers.TV
var dataFilePath = GetDataFilePath(id, preferredMetadataLanguage);
_fileSystem.CreateDirectory(Path.GetDirectoryName(dataFilePath));
_fileSystem.CreateDirectory(Path.GetDirectoryName(dataFilePath));
_jsonSerializer.SerializeToFile(mainResult, dataFilePath);
}
@ -354,6 +358,11 @@ namespace MediaBrowser.Providers.TV
}).ConfigureAwait(false))
{
mainResult = _jsonSerializer.DeserializeFromStream<RootObject>(json);
if (!string.IsNullOrEmpty(language))
{
mainResult.ResultLanguage = language;
}
}
cancellationToken.ThrowIfCancellationRequested();
@ -385,6 +394,7 @@ namespace MediaBrowser.Providers.TV
var englishResult = _jsonSerializer.DeserializeFromStream<RootObject>(json);
mainResult.overview = englishResult.overview;
mainResult.ResultLanguage = "en";
}
}
@ -627,6 +637,7 @@ namespace MediaBrowser.Providers.TV
public ExternalIds external_ids { get; set; }
public Videos videos { get; set; }
public ContentRatings content_ratings { get; set; }
public string ResultLanguage { get; set; }
}
public int Order

@ -108,6 +108,7 @@ namespace MediaBrowser.Providers.TV
public async Task<MetadataResult<Episode>> GetMetadata(EpisodeInfo searchInfo, CancellationToken cancellationToken)
{
var result = new MetadataResult<Episode>();
result.QueriedById = true;
if (TvdbSeriesProvider.IsValidSeries(searchInfo.SeriesProviderIds) &&
(searchInfo.IndexNumber.HasValue || searchInfo.PremiereDate.HasValue))
@ -713,6 +714,17 @@ namespace MediaBrowser.Providers.TV
}
}
break;
}
case "Language":
{
var val = reader.ReadElementContentAsString();
if (!string.IsNullOrWhiteSpace(val))
{
result.ResultLanguage = val;
}
break;
}

@ -93,9 +93,11 @@ namespace MediaBrowser.Providers.TV
public async Task<MetadataResult<Series>> GetMetadata(SeriesInfo itemId, CancellationToken cancellationToken)
{
var result = new MetadataResult<Series>();
result.QueriedById = true;
if (!IsValidSeries(itemId.ProviderIds))
{
result.QueriedById = false;
await Identify(itemId).ConfigureAwait(false);
}
@ -159,7 +161,7 @@ namespace MediaBrowser.Providers.TV
var seriesXmlPath = GetSeriesXmlPath(seriesProviderIds, metadataLanguage);
var actorsXmlPath = Path.Combine(seriesDataPath, "actors.xml");
FetchSeriesInfo(series, seriesXmlPath, cancellationToken);
FetchSeriesInfo(result, seriesXmlPath, cancellationToken);
cancellationToken.ThrowIfCancellationRequested();
@ -607,7 +609,7 @@ namespace MediaBrowser.Providers.TV
return name.Trim();
}
private void FetchSeriesInfo(Series item, string seriesXmlPath, CancellationToken cancellationToken)
private void FetchSeriesInfo(MetadataResult<Series> result, string seriesXmlPath, CancellationToken cancellationToken)
{
var settings = new XmlReaderSettings
{
@ -639,7 +641,7 @@ namespace MediaBrowser.Providers.TV
{
using (var subtree = reader.ReadSubtree())
{
FetchDataFromSeriesNode(item, subtree, cancellationToken);
FetchDataFromSeriesNode(result, subtree, cancellationToken);
}
break;
}
@ -667,9 +669,9 @@ namespace MediaBrowser.Providers.TV
}
}
if (item.Status.HasValue && item.Status.Value == SeriesStatus.Ended && episiodeAirDates.Count > 0)
if (result.Item.Status.HasValue && result.Item.Status.Value == SeriesStatus.Ended && episiodeAirDates.Count > 0)
{
item.EndDate = episiodeAirDates.Max();
result.Item.EndDate = episiodeAirDates.Max();
}
}
@ -861,8 +863,10 @@ namespace MediaBrowser.Providers.TV
}
}
private void FetchDataFromSeriesNode(Series item, XmlReader reader, CancellationToken cancellationToken)
private void FetchDataFromSeriesNode(MetadataResult<Series> result, XmlReader reader, CancellationToken cancellationToken)
{
Series item = result.Item;
reader.MoveToContent();
// Loop through each element
@ -886,6 +890,12 @@ namespace MediaBrowser.Providers.TV
break;
}
case "Language":
{
result.ResultLanguage = (reader.ReadElementContentAsString() ?? string.Empty).Trim();
break;
}
case "Airs_DayOfWeek":
{
var val = reader.ReadElementContentAsString();

Loading…
Cancel
Save