Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow AniDB as an agent for movies #53

Merged
merged 5 commits into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Jellyfin.Plugin.Anime/Jellyfin.Plugin.Anime.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>Jellyfin.Plugin.Anime</RootNamespace>
<AssemblyVersion>4.0.0</AssemblyVersion>
<FileVersion>4.0.0</FileVersion>
<AssemblyVersion>5.0.0</AssemblyVersion>
<FileVersion>5.0.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion Jellyfin.Plugin.Anime/Providers/AniDB/AniDbExternalId.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;

Expand All @@ -7,7 +8,7 @@ namespace Jellyfin.Plugin.Anime.Providers.AniDB
public class AniDbExternalId : IExternalId
{
public bool Supports(IHasProviderIds item)
=> item is Series;
=> item is Series || item is Movie;

public string Name
=> "AniDB";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;

namespace Jellyfin.Plugin.Anime.Providers.AniDB.Metadata
{
/// <summary>
/// Copies the series image into a Movie, if the Movie does not otherwise have any primary image.
/// </summary>
public class AniDbMovieImageProvider : IRemoteImageProvider
{
private readonly IApplicationPaths _appPaths;
private readonly IHttpClient _httpClient;

public AniDbMovieImageProvider(IApplicationPaths appPaths, IHttpClient httpClient)
{
_appPaths = appPaths;
_httpClient = httpClient;
}

public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
{
return new AniDbSeriesImagesProvider(_httpClient, _appPaths).GetImageResponse(url, cancellationToken);
}

public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
{
var movie = (Movie)item;
var seriesId = movie.ProviderIds.GetOrDefault(ProviderNames.AniDb);
if (string.IsNullOrEmpty(seriesId))
return Enumerable.Empty<RemoteImageInfo>();

return await new AniDbSeriesImagesProvider(_httpClient, _appPaths).GetImages(seriesId, cancellationToken);
}

public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
{
return new[] { ImageType.Primary };
}

public string Name => "AniDB";

public bool Supports(BaseItem item)
{
return item is Movie;
}
}
}
112 changes: 112 additions & 0 deletions Jellyfin.Plugin.Anime/Providers/AniDB/Metadata/AniDbMovieProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Providers;
using Microsoft.Extensions.Logging;

namespace Jellyfin.Plugin.Anime.Providers.AniDB.Metadata
{
public class AniDbMovieProvider : IRemoteMetadataProvider<Movie, MovieInfo>
{
private readonly AniDbSeriesProvider _seriesProvider;
// private readonly AniDbEpisodeProvider _episodeProvider;
private readonly ILogger _log;

public string Name => "AniDB";

public AniDbMovieProvider(IApplicationPaths appPaths, IHttpClient httpClient, ILoggerFactory loggerFactory)
{
_seriesProvider = new AniDbSeriesProvider(appPaths, httpClient);
// _episodeProvider = new AniDbEpisodeProvider(config, httpClient);
_log = loggerFactory.CreateLogger("AniDB");
}

public async Task<MetadataResult<Movie>> GetMetadata(MovieInfo info, CancellationToken cancellationToken)
{
// Empty result
var result = new MetadataResult<Movie>
{
HasMetadata = false,
Item = new Movie
{
Name = info.Name
}
};

var seriesId = info.ProviderIds.GetOrDefault(ProviderNames.AniDb);
if (seriesId == null)
{
return result;
}

var seriesInfo = new SeriesInfo();
seriesInfo.ProviderIds.Add(ProviderNames.AniDb, seriesId);

var seriesResult = await _seriesProvider.GetMetadata(seriesInfo, cancellationToken);
if (seriesResult.HasMetadata)
{
// Leaving this commented out in case there's information
// that's only contained on the 'Complete Movie' episode information
// var episodeInfo = new EpisodeInfo();
// episodeInfo.ProviderIds.Add(ProviderNames.AniDb, seriesId + ":1");

// var episodeResult = await _episodeProvider.GetMetadata(episodeInfo, cancellationToken);
// if (episodeResult.HasMetadata)
// {
result = new MetadataResult<Movie>
{
HasMetadata = true,
Item = new Movie
{
Name = seriesResult.Item.Name,
Overview = seriesResult.Item.Overview,
PremiereDate = seriesResult.Item.PremiereDate,
ProductionYear = seriesResult.Item.ProductionYear,
EndDate = seriesResult.Item.EndDate,
CommunityRating = seriesResult.Item.CommunityRating,
Studios = seriesResult.Item.Studios,
Genres = seriesResult.Item.Genres,
ProviderIds = seriesResult.Item.ProviderIds,
},
People = seriesResult.People,
Images = seriesResult.Images
};
// }
}

return result;
}

public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(MovieInfo searchInfo, CancellationToken cancellationToken)
{
var metadata = await GetMetadata(searchInfo, cancellationToken).ConfigureAwait(false);

var list = new List<RemoteSearchResult>();

if (metadata.HasMetadata)
{
var res = new RemoteSearchResult
{
Name = metadata.Item.Name,
PremiereDate = metadata.Item.PremiereDate,
ProductionYear = metadata.Item.ProductionYear,
ProviderIds = metadata.Item.ProviderIds,
SearchProviderName = Name
};

list.Add(res);
}

return list;
}

public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
{
return _seriesProvider.GetImageResponse(url, cancellationToken);
}
}
}
2 changes: 1 addition & 1 deletion build.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
name: "jellyfin-plugin-anime"
guid: "a4df60c5-6ab4-412a-8f79-2cab93fb2bc5"
version: "4"
version: "5"
jellyfin_version: "10.3.0"
owner: "jellyfin"
nicename: "Anime"
Expand Down