Implement basic metadata and image providers for episodes
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Jellyfin.Plugin.TubeArchivistMetadata.TubeArchivist;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Providers;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Jellyfin.Plugin.TubeArchivistMetadata.Providers
|
||||
{
|
||||
/// <summary>
|
||||
/// Metadata provider which interacts with TubeArchivist library.
|
||||
/// </summary>
|
||||
public class EpisodeMetadataProvider : IRemoteMetadataProvider<Episode, EpisodeInfo>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the provider name.
|
||||
/// </summary>
|
||||
public string Name => "TubeArchivist";
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<MetadataResult<Episode>> GetMetadata(EpisodeInfo info, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = new MetadataResult<Episode>();
|
||||
var taApi = TubeArchivistApi.GetInstance();
|
||||
var videoTAId = info.Path.Split("/").Last().Split(".").First();
|
||||
var video = await taApi.GetVideo(videoTAId).ConfigureAwait(true);
|
||||
Console.WriteLine("Metadata video received: ");
|
||||
Console.WriteLine(JsonConvert.SerializeObject(video));
|
||||
Console.WriteLine("Media YT id: " + videoTAId);
|
||||
|
||||
if (video != null)
|
||||
{
|
||||
var peopleInfo = new List<PersonInfo>();
|
||||
PeopleHelper.AddPerson(peopleInfo, new PersonInfo
|
||||
{
|
||||
Name = video.Channel.Name,
|
||||
ImageUrl = video.Channel.ThumbUrl,
|
||||
Type = PersonType.Actor,
|
||||
});
|
||||
result.HasMetadata = true;
|
||||
result.Item = video.ToEpisode();
|
||||
result.Provider = Name;
|
||||
result.People = peopleInfo;
|
||||
}
|
||||
|
||||
Console.WriteLine(result.Item.ProductionYear);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(EpisodeInfo searchInfo, CancellationToken cancellationToken)
|
||||
{
|
||||
var results = new List<RemoteSearchResult>();
|
||||
|
||||
var taApi = TubeArchivistApi.GetInstance();
|
||||
var videoTAId = searchInfo.Path.Split("/").Last().Split(".").First();
|
||||
var video = await taApi.GetVideo(videoTAId).ConfigureAwait(true);
|
||||
if (video != null)
|
||||
{
|
||||
results.Add(video.ToSearchResult());
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
|
||||
{
|
||||
if (Plugin.Instance == null)
|
||||
{
|
||||
throw new DataException("Uninitialized plugin!");
|
||||
}
|
||||
else
|
||||
{
|
||||
return await Plugin.Instance.HttpClient.GetAsync(url, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user