mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 22:07:13 -04:00
OMDB improvements
- Improved parsing of production year (cases like '2001-2003') - Parse writer field as person - Parse director field as person - Parse actors fields as persons
This commit is contained in:
parent
c100f0818c
commit
c022b728f8
@ -226,7 +226,7 @@ namespace MediaBrowser.Providers.Omdb
|
|||||||
result.Item.SetProviderId(MetadataProviders.Imdb, imdbId);
|
result.Item.SetProviderId(MetadataProviders.Imdb, imdbId);
|
||||||
result.HasMetadata = true;
|
result.HasMetadata = true;
|
||||||
|
|
||||||
await new OmdbProvider(_jsonSerializer, _httpClient, _fileSystem, _configurationManager).Fetch(result.Item, imdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
|
await new OmdbProvider(_jsonSerializer, _httpClient, _fileSystem, _configurationManager).Fetch(result, imdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -265,7 +265,7 @@ namespace MediaBrowser.Providers.Omdb
|
|||||||
result.Item.SetProviderId(MetadataProviders.Imdb, imdbId);
|
result.Item.SetProviderId(MetadataProviders.Imdb, imdbId);
|
||||||
result.HasMetadata = true;
|
result.HasMetadata = true;
|
||||||
|
|
||||||
await new OmdbProvider(_jsonSerializer, _httpClient, _fileSystem, _configurationManager).Fetch(result.Item, imdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
|
await new OmdbProvider(_jsonSerializer, _httpClient, _fileSystem, _configurationManager).Fetch(result, imdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -3,6 +3,7 @@ using MediaBrowser.Common.Configuration;
|
|||||||
using MediaBrowser.Common.Net;
|
using MediaBrowser.Common.Net;
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
|
using MediaBrowser.Controller.Providers;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
using MediaBrowser.Model.Serialization;
|
using MediaBrowser.Model.Serialization;
|
||||||
using System;
|
using System;
|
||||||
@ -34,13 +35,16 @@ namespace MediaBrowser.Providers.Omdb
|
|||||||
_configurationManager = configurationManager;
|
_configurationManager = configurationManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Fetch(BaseItem item, string imdbId, string language, string country, CancellationToken cancellationToken)
|
public async Task Fetch<T>(MetadataResult<T> itemResult, string imdbId, string language, string country, CancellationToken cancellationToken)
|
||||||
|
where T :BaseItem
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(imdbId))
|
if (string.IsNullOrWhiteSpace(imdbId))
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("imdbId");
|
throw new ArgumentNullException("imdbId");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
T item = itemResult.Item;
|
||||||
|
|
||||||
var result = await GetRootObject(imdbId, cancellationToken);
|
var result = await GetRootObject(imdbId, cancellationToken);
|
||||||
|
|
||||||
// Only take the name and rating if the user's language is set to english, since Omdb has no localization
|
// Only take the name and rating if the user's language is set to english, since Omdb has no localization
|
||||||
@ -56,8 +60,8 @@ namespace MediaBrowser.Providers.Omdb
|
|||||||
|
|
||||||
int year;
|
int year;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(result.Year)
|
if (!string.IsNullOrEmpty(result.Year) && result.Year.Length >= 4
|
||||||
&& int.TryParse(result.Year, NumberStyles.Number, _usCulture, out year)
|
&& int.TryParse(result.Year.Substring(0, 4), NumberStyles.Number, _usCulture, out year)
|
||||||
&& year >= 0)
|
&& year >= 0)
|
||||||
{
|
{
|
||||||
item.ProductionYear = year;
|
item.ProductionYear = year;
|
||||||
@ -112,16 +116,19 @@ namespace MediaBrowser.Providers.Omdb
|
|||||||
item.SetProviderId(MetadataProviders.Imdb, result.imdbID);
|
item.SetProviderId(MetadataProviders.Imdb, result.imdbID);
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseAdditionalMetadata(item, result);
|
ParseAdditionalMetadata(itemResult, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<bool> FetchEpisodeData(BaseItem item, int episodeNumber, int seasonNumber, string imdbId, string language, string country, CancellationToken cancellationToken)
|
public async Task<bool> FetchEpisodeData<T>(MetadataResult<T> itemResult, int episodeNumber, int seasonNumber, string imdbId, string language, string country, CancellationToken cancellationToken)
|
||||||
|
where T : BaseItem
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(imdbId))
|
if (string.IsNullOrWhiteSpace(imdbId))
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("imdbId");
|
throw new ArgumentNullException("imdbId");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
T item = itemResult.Item;
|
||||||
|
|
||||||
var seasonResult = await GetSeasonRootObject(imdbId, seasonNumber, cancellationToken);
|
var seasonResult = await GetSeasonRootObject(imdbId, seasonNumber, cancellationToken);
|
||||||
|
|
||||||
RootObject result = null;
|
RootObject result = null;
|
||||||
@ -154,8 +161,8 @@ namespace MediaBrowser.Providers.Omdb
|
|||||||
|
|
||||||
int year;
|
int year;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(result.Year)
|
if (!string.IsNullOrEmpty(result.Year) && result.Year.Length >= 4
|
||||||
&& int.TryParse(result.Year, NumberStyles.Number, _usCulture, out year)
|
&& int.TryParse(result.Year.Substring(0, 4), NumberStyles.Number, _usCulture, out year)
|
||||||
&& year >= 0)
|
&& year >= 0)
|
||||||
{
|
{
|
||||||
item.ProductionYear = year;
|
item.ProductionYear = year;
|
||||||
@ -210,7 +217,7 @@ namespace MediaBrowser.Providers.Omdb
|
|||||||
item.SetProviderId(MetadataProviders.Imdb, result.imdbID);
|
item.SetProviderId(MetadataProviders.Imdb, result.imdbID);
|
||||||
}
|
}
|
||||||
|
|
||||||
ParseAdditionalMetadata(item, result);
|
ParseAdditionalMetadata(itemResult, result);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -376,8 +383,11 @@ namespace MediaBrowser.Providers.Omdb
|
|||||||
return Path.Combine(dataPath, filename);
|
return Path.Combine(dataPath, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ParseAdditionalMetadata(BaseItem item, RootObject result)
|
private void ParseAdditionalMetadata<T>(MetadataResult<T> itemResult, RootObject result)
|
||||||
|
where T : BaseItem
|
||||||
{
|
{
|
||||||
|
T item = itemResult.Item;
|
||||||
|
|
||||||
// Grab series genres because imdb data is better than tvdb. Leave movies alone
|
// Grab series genres because imdb data is better than tvdb. Leave movies alone
|
||||||
// But only do it if english is the preferred language because this data will not be localized
|
// But only do it if english is the preferred language because this data will not be localized
|
||||||
if (ShouldFetchGenres(item) &&
|
if (ShouldFetchGenres(item) &&
|
||||||
@ -417,6 +427,46 @@ namespace MediaBrowser.Providers.Omdb
|
|||||||
// Imdb plots are usually pretty short
|
// Imdb plots are usually pretty short
|
||||||
hasShortOverview.ShortOverview = result.Plot;
|
hasShortOverview.ShortOverview = result.Plot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(result.Director))
|
||||||
|
{
|
||||||
|
var person = new PersonInfo
|
||||||
|
{
|
||||||
|
Name = result.Director.Trim(),
|
||||||
|
Type = PersonType.Director
|
||||||
|
};
|
||||||
|
|
||||||
|
itemResult.AddPerson(person);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(result.Writer))
|
||||||
|
{
|
||||||
|
var person = new PersonInfo
|
||||||
|
{
|
||||||
|
Name = result.Director.Trim(),
|
||||||
|
Type = PersonType.Writer
|
||||||
|
};
|
||||||
|
|
||||||
|
itemResult.AddPerson(person);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(result.Actors))
|
||||||
|
{
|
||||||
|
var actorList = result.Actors.Split(',');
|
||||||
|
foreach (var actor in actorList)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrWhiteSpace(actor))
|
||||||
|
{
|
||||||
|
var person = new PersonInfo
|
||||||
|
{
|
||||||
|
Name = actor.Trim(),
|
||||||
|
Type = PersonType.Actor
|
||||||
|
};
|
||||||
|
|
||||||
|
itemResult.AddPerson(person);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool ShouldFetchGenres(BaseItem item)
|
private bool ShouldFetchGenres(BaseItem item)
|
||||||
|
@ -57,7 +57,7 @@ namespace MediaBrowser.Providers.TV
|
|||||||
{
|
{
|
||||||
var seriesImdbId = info.SeriesProviderIds[MetadataProviders.Imdb.ToString()];
|
var seriesImdbId = info.SeriesProviderIds[MetadataProviders.Imdb.ToString()];
|
||||||
|
|
||||||
result.HasMetadata = await new OmdbProvider(_jsonSerializer, _httpClient, _fileSystem, _configurationManager).FetchEpisodeData(result.Item, info.IndexNumber.Value, info.ParentIndexNumber.Value, seriesImdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
|
result.HasMetadata = await new OmdbProvider(_jsonSerializer, _httpClient, _fileSystem, _configurationManager).FetchEpisodeData(result, info.IndexNumber.Value, info.ParentIndexNumber.Value, seriesImdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
Reference in New Issue
Block a user