Merge pull request #1398 from softworkz/OmdbEpisodeProvider
Extended OmdbItemProvider to support series episodes
This commit is contained in:
commit
f6d74d9a0e
|
@ -565,7 +565,7 @@ namespace MediaBrowser.Model.Configuration
|
||||||
Type = ImageType.Thumb
|
Type = ImageType.Thumb
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
DisabledMetadataFetchers = new []{ "TheMovieDb" }
|
DisabledMetadataFetchers = new []{ "The Open Movie Database", "TheMovieDb" }
|
||||||
},
|
},
|
||||||
|
|
||||||
new MetadataOptions(0, 1280)
|
new MetadataOptions(0, 1280)
|
||||||
|
@ -586,6 +586,7 @@ namespace MediaBrowser.Model.Configuration
|
||||||
Type = ImageType.Primary
|
Type = ImageType.Primary
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
DisabledMetadataFetchers = new []{ "The Open Movie Database" },
|
||||||
DisabledImageFetchers = new []{ "TheMovieDb" }
|
DisabledImageFetchers = new []{ "TheMovieDb" }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -177,6 +177,7 @@
|
||||||
<Compile Include="TV\MovieDbSeasonProvider.cs" />
|
<Compile Include="TV\MovieDbSeasonProvider.cs" />
|
||||||
<Compile Include="TV\MovieDbSeriesImageProvider.cs" />
|
<Compile Include="TV\MovieDbSeriesImageProvider.cs" />
|
||||||
<Compile Include="TV\MovieDbSeriesProvider.cs" />
|
<Compile Include="TV\MovieDbSeriesProvider.cs" />
|
||||||
|
<Compile Include="TV\OmdbEpisodeProvider.cs" />
|
||||||
<Compile Include="TV\SeriesMetadataService.cs" />
|
<Compile Include="TV\SeriesMetadataService.cs" />
|
||||||
<Compile Include="TV\TvdbEpisodeImageProvider.cs" />
|
<Compile Include="TV\TvdbEpisodeImageProvider.cs" />
|
||||||
<Compile Include="People\TvdbPersonImageProvider.cs" />
|
<Compile Include="People\TvdbPersonImageProvider.cs" />
|
||||||
|
|
|
@ -60,12 +60,18 @@ namespace MediaBrowser.Providers.Omdb
|
||||||
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(ItemLookupInfo searchInfo, string type, CancellationToken cancellationToken)
|
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(ItemLookupInfo searchInfo, string type, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
bool isSearch = false;
|
bool isSearch = false;
|
||||||
|
var episodeSearchInfo = searchInfo as EpisodeInfo;
|
||||||
|
|
||||||
var list = new List<RemoteSearchResult>();
|
var list = new List<RemoteSearchResult>();
|
||||||
|
|
||||||
var imdbId = searchInfo.GetProviderId(MetadataProviders.Imdb);
|
var imdbId = searchInfo.GetProviderId(MetadataProviders.Imdb);
|
||||||
|
|
||||||
var url = "http://www.omdbapi.com/?plot=short&r=json";
|
var url = "http://www.omdbapi.com/?plot=full&r=json";
|
||||||
|
if (type == "episode" && episodeSearchInfo != null)
|
||||||
|
{
|
||||||
|
episodeSearchInfo.SeriesProviderIds.TryGetValue(MetadataProviders.Imdb.ToString(), out imdbId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var name = searchInfo.Name;
|
var name = searchInfo.Name;
|
||||||
var year = searchInfo.Year;
|
var year = searchInfo.Year;
|
||||||
|
@ -95,6 +101,18 @@ namespace MediaBrowser.Providers.Omdb
|
||||||
url += "&i=" + imdbId;
|
url += "&i=" + imdbId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (type == "episode")
|
||||||
|
{
|
||||||
|
if (searchInfo.IndexNumber.HasValue)
|
||||||
|
{
|
||||||
|
url += string.Format(CultureInfo.InvariantCulture, "&Episode={0}", searchInfo.IndexNumber);
|
||||||
|
}
|
||||||
|
if (searchInfo.ParentIndexNumber.HasValue)
|
||||||
|
{
|
||||||
|
url += string.Format(CultureInfo.InvariantCulture, "&Season={0}", searchInfo.ParentIndexNumber);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
using (var stream = await _httpClient.Get(new HttpRequestOptions
|
using (var stream = await _httpClient.Get(new HttpRequestOptions
|
||||||
{
|
{
|
||||||
Url = url,
|
Url = url,
|
||||||
|
@ -124,10 +142,20 @@ namespace MediaBrowser.Providers.Omdb
|
||||||
|
|
||||||
foreach (var result in resultList)
|
foreach (var result in resultList)
|
||||||
{
|
{
|
||||||
var item = new RemoteSearchResult();
|
var item = new RemoteSearchResult
|
||||||
|
{
|
||||||
|
IndexNumber = searchInfo.IndexNumber,
|
||||||
|
Name = result.Title,
|
||||||
|
ParentIndexNumber = searchInfo.ParentIndexNumber,
|
||||||
|
ProviderIds = searchInfo.ProviderIds,
|
||||||
|
SearchProviderName = Name
|
||||||
|
};
|
||||||
|
|
||||||
|
if (episodeSearchInfo != null && episodeSearchInfo.IndexNumberEnd.HasValue)
|
||||||
|
{
|
||||||
|
item.IndexNumberEnd = episodeSearchInfo.IndexNumberEnd.Value;
|
||||||
|
}
|
||||||
|
|
||||||
item.SearchProviderName = Name;
|
|
||||||
item.Name = result.Title;
|
|
||||||
item.SetProviderId(MetadataProviders.Imdb, result.imdbID);
|
item.SetProviderId(MetadataProviders.Imdb, result.imdbID);
|
||||||
|
|
||||||
int parsedYear;
|
int parsedYear;
|
||||||
|
@ -137,6 +165,13 @@ namespace MediaBrowser.Providers.Omdb
|
||||||
item.ProductionYear = parsedYear;
|
item.ProductionYear = parsedYear;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DateTime released;
|
||||||
|
if (!string.IsNullOrEmpty(result.Released)
|
||||||
|
&& DateTime.TryParse(result.Released, CultureInfo.InvariantCulture, DateTimeStyles.AllowWhiteSpaces, out released))
|
||||||
|
{
|
||||||
|
item.PremiereDate = released;
|
||||||
|
}
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(result.Poster) && !string.Equals(result.Poster, "N/A", StringComparison.OrdinalIgnoreCase))
|
if (!string.IsNullOrWhiteSpace(result.Poster) && !string.Equals(result.Poster, "N/A", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
item.ImageUrl = result.Poster;
|
item.ImageUrl = result.Poster;
|
||||||
|
@ -267,6 +302,8 @@ namespace MediaBrowser.Providers.Omdb
|
||||||
public string Year { get; set; }
|
public string Year { get; set; }
|
||||||
public string Rated { get; set; }
|
public string Rated { get; set; }
|
||||||
public string Released { get; set; }
|
public string Released { get; set; }
|
||||||
|
public string Season { get; set; }
|
||||||
|
public string Episode { get; set; }
|
||||||
public string Runtime { get; set; }
|
public string Runtime { get; set; }
|
||||||
public string Genre { get; set; }
|
public string Genre { get; set; }
|
||||||
public string Director { get; set; }
|
public string Director { get; set; }
|
||||||
|
@ -281,6 +318,7 @@ namespace MediaBrowser.Providers.Omdb
|
||||||
public string imdbRating { get; set; }
|
public string imdbRating { get; set; }
|
||||||
public string imdbVotes { get; set; }
|
public string imdbVotes { get; set; }
|
||||||
public string imdbID { get; set; }
|
public string imdbID { get; set; }
|
||||||
|
public string seriesID { get; set; }
|
||||||
public string Type { get; set; }
|
public string Type { get; set; }
|
||||||
public string Response { get; set; }
|
public string Response { get; set; }
|
||||||
}
|
}
|
||||||
|
|
89
MediaBrowser.Providers/TV/OmdbEpisodeProvider.cs
Normal file
89
MediaBrowser.Providers/TV/OmdbEpisodeProvider.cs
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
using MediaBrowser.Common.Net;
|
||||||
|
using MediaBrowser.Controller.Entities.TV;
|
||||||
|
using MediaBrowser.Controller.Library;
|
||||||
|
using MediaBrowser.Controller.Providers;
|
||||||
|
using MediaBrowser.Model.Entities;
|
||||||
|
using MediaBrowser.Model.Logging;
|
||||||
|
using MediaBrowser.Model.Providers;
|
||||||
|
using MediaBrowser.Model.Serialization;
|
||||||
|
using MediaBrowser.Providers.Omdb;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace MediaBrowser.Providers.TV
|
||||||
|
{
|
||||||
|
class OmdbEpisodeProvider :
|
||||||
|
IRemoteMetadataProvider<Episode, EpisodeInfo>,
|
||||||
|
IHasOrder
|
||||||
|
{
|
||||||
|
private readonly IJsonSerializer _jsonSerializer;
|
||||||
|
private readonly IHttpClient _httpClient;
|
||||||
|
private OmdbItemProvider _itemProvider;
|
||||||
|
|
||||||
|
public OmdbEpisodeProvider(IJsonSerializer jsonSerializer, IHttpClient httpClient, ILogger logger, ILibraryManager libraryManager)
|
||||||
|
{
|
||||||
|
_jsonSerializer = jsonSerializer;
|
||||||
|
_httpClient = httpClient;
|
||||||
|
_itemProvider = new OmdbItemProvider(jsonSerializer, httpClient, logger, libraryManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<IEnumerable<RemoteSearchResult>> GetSearchResults(EpisodeInfo searchInfo, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return _itemProvider.GetSearchResults(searchInfo, "episode", cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<MetadataResult<Episode>> GetMetadata(EpisodeInfo info, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var result = new MetadataResult<Episode>
|
||||||
|
{
|
||||||
|
Item = new Episode()
|
||||||
|
};
|
||||||
|
|
||||||
|
var imdbId = info.GetProviderId(MetadataProviders.Imdb);
|
||||||
|
if (string.IsNullOrWhiteSpace(imdbId))
|
||||||
|
{
|
||||||
|
imdbId = await GetEpisodeImdbId(info, cancellationToken).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(imdbId))
|
||||||
|
{
|
||||||
|
result.Item.SetProviderId(MetadataProviders.Imdb, imdbId);
|
||||||
|
result.HasMetadata = true;
|
||||||
|
|
||||||
|
await new OmdbProvider(_jsonSerializer, _httpClient).Fetch(result.Item, imdbId, info.MetadataLanguage, info.MetadataCountryCode, cancellationToken).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<string> GetEpisodeImdbId(EpisodeInfo info, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var results = await GetSearchResults(info, cancellationToken).ConfigureAwait(false);
|
||||||
|
var first = results.FirstOrDefault();
|
||||||
|
return first == null ? null : first.GetProviderId(MetadataProviders.Imdb);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Order
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// After TheTvDb
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string Name
|
||||||
|
{
|
||||||
|
get { return "The Open Movie Database"; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return _itemProvider.GetImageResponse(url, cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -428,10 +428,17 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||||
|
|
||||||
var episode = searchResults.FirstOrDefault();
|
var episode = searchResults.FirstOrDefault();
|
||||||
|
|
||||||
|
string episodeName = string.Empty;
|
||||||
|
|
||||||
if (episode == null)
|
if (episode == null)
|
||||||
{
|
{
|
||||||
_logger.Warn("No provider metadata found for {0} season {1} episode {2}", series.Name, seasonNumber, episodeNumber);
|
var msg = string.Format("No provider metadata found for {0} season {1} episode {2}", series.Name, seasonNumber, episodeNumber);
|
||||||
return null;
|
_logger.Warn(msg);
|
||||||
|
//throw new Exception(msg);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
episodeName = episode.Name;
|
||||||
}
|
}
|
||||||
|
|
||||||
var newPath = GetSeasonFolderPath(series, seasonNumber, options);
|
var newPath = GetSeasonFolderPath(series, seasonNumber, options);
|
||||||
|
@ -449,7 +456,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||||
// Remove additional 4 chars to prevent PathTooLongException for downloaded subtitles (eg. filename.ext.eng.srt)
|
// Remove additional 4 chars to prevent PathTooLongException for downloaded subtitles (eg. filename.ext.eng.srt)
|
||||||
maxFilenameLength -= 4;
|
maxFilenameLength -= 4;
|
||||||
|
|
||||||
var episodeFileName = GetEpisodeFileName(sourcePath, series.Name, seasonNumber, episodeNumber, endingEpisodeNumber, episode.Name, options, maxFilenameLength);
|
var episodeFileName = GetEpisodeFileName(sourcePath, series.Name, seasonNumber, episodeNumber, endingEpisodeNumber, episodeName, options, maxFilenameLength);
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(episodeFileName))
|
if (string.IsNullOrEmpty(episodeFileName))
|
||||||
{
|
{
|
||||||
|
@ -505,7 +512,7 @@ namespace MediaBrowser.Server.Implementations.FileOrganization
|
||||||
{
|
{
|
||||||
seriesName = _fileSystem.GetValidFilename(seriesName).Trim();
|
seriesName = _fileSystem.GetValidFilename(seriesName).Trim();
|
||||||
|
|
||||||
if (episodeTitle == null)
|
if (string.IsNullOrEmpty(episodeTitle))
|
||||||
{
|
{
|
||||||
episodeTitle = string.Empty;
|
episodeTitle = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
|
@ -370,6 +370,7 @@ namespace MediaBrowser.Server.Startup.Common
|
||||||
{
|
{
|
||||||
var migrations = new List<IVersionMigration>
|
var migrations = new List<IVersionMigration>
|
||||||
{
|
{
|
||||||
|
new OmdbEpisodeProviderMigration(ServerConfigurationManager),
|
||||||
new DbMigration(ServerConfigurationManager, TaskManager)
|
new DbMigration(ServerConfigurationManager, TaskManager)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -73,6 +73,7 @@
|
||||||
<Compile Include="MbLinkShortcutHandler.cs" />
|
<Compile Include="MbLinkShortcutHandler.cs" />
|
||||||
<Compile Include="Migrations\IVersionMigration.cs" />
|
<Compile Include="Migrations\IVersionMigration.cs" />
|
||||||
<Compile Include="Migrations\DbMigration.cs" />
|
<Compile Include="Migrations\DbMigration.cs" />
|
||||||
|
<Compile Include="Migrations\OmdbEpisodeProviderMigration.cs" />
|
||||||
<Compile Include="Migrations\RenameXmlOptions.cs" />
|
<Compile Include="Migrations\RenameXmlOptions.cs" />
|
||||||
<Compile Include="NativeEnvironment.cs" />
|
<Compile Include="NativeEnvironment.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
|
|
@ -0,0 +1,47 @@
|
||||||
|
using MediaBrowser.Controller.Configuration;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace MediaBrowser.Server.Startup.Common.Migrations
|
||||||
|
{
|
||||||
|
class OmdbEpisodeProviderMigration : IVersionMigration
|
||||||
|
{
|
||||||
|
private readonly IServerConfigurationManager _config;
|
||||||
|
private const string _providerName = "The Open Movie Database";
|
||||||
|
|
||||||
|
public OmdbEpisodeProviderMigration(IServerConfigurationManager config)
|
||||||
|
{
|
||||||
|
_config = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Run()
|
||||||
|
{
|
||||||
|
var migrationKey = this.GetType().FullName;
|
||||||
|
var migrationKeyList = _config.Configuration.Migrations.ToList();
|
||||||
|
|
||||||
|
if (!migrationKeyList.Contains(migrationKey))
|
||||||
|
{
|
||||||
|
foreach (var metaDataOption in _config.Configuration.MetadataOptions)
|
||||||
|
{
|
||||||
|
if (metaDataOption.ItemType == "Episode")
|
||||||
|
{
|
||||||
|
var disabledFetchers = metaDataOption.DisabledMetadataFetchers.ToList();
|
||||||
|
if (!disabledFetchers.Contains(_providerName))
|
||||||
|
{
|
||||||
|
disabledFetchers.Add(_providerName);
|
||||||
|
metaDataOption.DisabledMetadataFetchers = disabledFetchers.ToArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
migrationKeyList.Add(migrationKey);
|
||||||
|
_config.Configuration.Migrations = migrationKeyList.ToArray();
|
||||||
|
_config.SaveConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user