blob: 8274a2790442e0730370b96c4b7246997012a519 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Model.Dto;
using Microsoft.Extensions.Logging;
namespace Jellyfin.Plugin.JCoverXtremePro;
public class ImageProvider
: IRemoteImageProvider, IHasOrder
{
private ILogger _logger;
public ImageProvider(ILogger<ImageProvider> logger)
{
_logger = logger;
}
public bool Supports(BaseItem item)
{
return item is Movie;
}
public string Name => "Mediux";
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
{
return new List<ImageType>
{
ImageType.Primary,
ImageType.Backdrop,
};
}
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
{
var movieId = item.GetProviderId(MetadataProvider.Tmdb);
var movieJson =
await MediuxDownloader.instance.GetMediuxMetadata("https://mediux.pro/movies/" + movieId)
.ConfigureAwait(false);
var movieData = JsonSerializer.Deserialize<POJO.MovieData>(movieJson as JsonObject);
List<RemoteImageInfo> images = new();
foreach (var set in movieData.allSets)
{
foreach (var file in set.files)
{
var ft = file.JellyFinFileType();
if (ft == null)
{
continue;
}
if (!file.title.Contains(movieData.movie.title, StringComparison.InvariantCulture))
{
continue;
}
var imageInfo = new RemoteImageInfo
{
Url = file.downloadUrl,
ProviderName = set.user_created.username + "(from Mediux)",
ThumbnailUrl = file.downloadUrl,
Language = "en",
RatingType = RatingType.Likes,
Type = ft.Value
};
images.Add(imageInfo);
}
}
return images;
}
public int Order => 0;
public Task<HttpResponseMessage> GetImageResponse(string url, CancellationToken cancellationToken)
{
return MediuxDownloader.instance.DownloadFile(url);
}
}
|