summaryrefslogtreecommitdiff
path: root/ImageProvider.cs
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-08-11 22:10:30 +0200
committerLinnea Gräf <nea@nea.moe>2024-08-11 22:10:30 +0200
commit84cfa163f938089c72d9c1d089c136e05e052abe (patch)
tree506fe8ac7ee5db97d8423a0e55aed02f471bd1e9 /ImageProvider.cs
parentf60e3645e18a7f590dc913d0f555fcb82f072d07 (diff)
downloadJCoverXtremePro-84cfa163f938089c72d9c1d089c136e05e052abe.tar.gz
JCoverXtremePro-84cfa163f938089c72d9c1d089c136e05e052abe.tar.bz2
JCoverXtremePro-84cfa163f938089c72d9c1d089c136e05e052abe.zip
Add metadata cache
Diffstat (limited to 'ImageProvider.cs')
-rw-r--r--ImageProvider.cs51
1 files changed, 20 insertions, 31 deletions
diff --git a/ImageProvider.cs b/ImageProvider.cs
index df349eb..8274a27 100644
--- a/ImageProvider.cs
+++ b/ImageProvider.cs
@@ -1,3 +1,4 @@
+using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text.Json;
@@ -37,58 +38,46 @@ public class ImageProvider
return new List<ImageType>
{
ImageType.Primary,
- // ImageType.Backdrop,
+ ImageType.Backdrop,
};
}
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
{
- var movie = item as Movie;
var movieId = item.GetProviderId(MetadataProvider.Tmdb);
- var collectionId = item.GetProviderId(MetadataProvider.TmdbCollection);
- _logger.LogInformation(
- $"Help i am stuck in a movie labeling factory and have been taskted to label {movie.Name} " +
- $"({movieId} in collection {collectionId})"
- );
- var movieData =
+ var movieJson =
await MediuxDownloader.instance.GetMediuxMetadata("https://mediux.pro/movies/" + movieId)
.ConfigureAwait(false);
- var deserMovieData = JsonSerializer.Deserialize<POJO.MovieData>(movieData as JsonObject);
- _logger.LogInformation("Movie Data: {JsonData}", movieData.ToJsonString());
- _logger.LogInformation("Movie Data Decoded: {Data}", JsonSerializer.Serialize(deserMovieData));
+ var movieData = JsonSerializer.Deserialize<POJO.MovieData>(movieJson as JsonObject);
List<RemoteImageInfo> images = new();
- foreach (var set in deserMovieData.allSets)
+ foreach (var set in movieData.allSets)
{
- _logger.LogInformation("Set Data: {Name} {Data}", set.set_name, set.files.Count);
foreach (var file in set.files)
{
- _logger.LogInformation("Matching file {Name}", JsonSerializer.Serialize(file));
- if (file.fileType != "poster")
+ var ft = file.JellyFinFileType();
+ if (ft == null)
{
- _logger.LogInformation("Skipping non poster file");
continue;
}
- if (file.title.Contains(deserMovieData.movie.title))
+ if (!file.title.Contains(movieData.movie.title, StringComparison.InvariantCulture))
{
- _logger.LogInformation("Adding image");
- var imageInfo = new RemoteImageInfo
- {
- Url = file.downloadUrl,
- ProviderName = Name,
- ThumbnailUrl = file.downloadUrl,
- Language = "en",
- RatingType = RatingType.Likes,
- Type = ImageType.Primary,
- };
- _logger.LogInformation("Constructed image");
- images.Add(imageInfo);
- _logger.LogInformation("Appended image");
+ 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);
}
}
- _logger.LogInformation("Collected images {0}", images);
return images;
}