This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
namespace Aberwyn.Data
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Aberwyn.Data
|
||||
{
|
||||
public class MovieMetadataService
|
||||
{
|
||||
@@ -42,6 +45,55 @@
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<Node?> SearchMovieAsync(string title, string country = "SE")
|
||||
{
|
||||
var query = new
|
||||
{
|
||||
query = @"
|
||||
query SearchTitle($query: String!, $country: Country!) {
|
||||
searchTitles(
|
||||
country: $country,
|
||||
filter: { searchQuery: $query },
|
||||
first: 1
|
||||
) {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
title
|
||||
releaseYear
|
||||
content {
|
||||
imdbId
|
||||
}
|
||||
offers {
|
||||
provider {
|
||||
id
|
||||
clearName
|
||||
}
|
||||
monetizationType
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}",
|
||||
variables = new
|
||||
{
|
||||
query = title,
|
||||
country = country
|
||||
}
|
||||
};
|
||||
|
||||
var requestBody = new StringContent(JsonSerializer.Serialize(query), Encoding.UTF8, "application/json");
|
||||
_http.DefaultRequestHeaders.Add("Accept", "application/json");
|
||||
_http.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0");
|
||||
var response = await _http.PostAsync("https://apis.justwatch.com/graphql", requestBody);
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
return null;
|
||||
|
||||
var result = await response.Content.ReadFromJsonAsync<JustWatchResponse>();
|
||||
|
||||
return result?.data?.searchTitles?.edges?.FirstOrDefault()?.node;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -84,6 +84,15 @@ namespace Aberwyn.Data
|
||||
if (metadata != null)
|
||||
{
|
||||
torrentItem.Metadata = metadata;
|
||||
var movie = await _movieMetadataService.SearchMovieAsync(torrentItem.MovieName);
|
||||
if (movie?.offers != null)
|
||||
{
|
||||
metadata.Providers = movie.offers
|
||||
.Where(o => o.monetizationType == "FLATRATE") // typ Netflix, Prime
|
||||
.Select(o => o.provider.clearName)
|
||||
.Distinct()
|
||||
.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
_context.TorrentItems.Add(torrentItem);
|
||||
|
||||
1240
Aberwyn/Migrations/20250820133435_AddProvidersToMovieMetadata.Designer.cs
generated
Normal file
1240
Aberwyn/Migrations/20250820133435_AddProvidersToMovieMetadata.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,26 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Aberwyn.Migrations
|
||||
{
|
||||
public partial class AddProvidersToMovieMetadata : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "Metadata_Providers",
|
||||
table: "TorrentItems",
|
||||
type: "longtext",
|
||||
nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "Metadata_Providers",
|
||||
table: "TorrentItems");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1171,6 +1171,9 @@ namespace Aberwyn.Migrations
|
||||
b1.Property<string>("Poster")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b1.Property<string>("Providers")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b1.Property<string>("Runtime")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
|
||||
@@ -83,6 +83,52 @@ public class MovieMetadata
|
||||
public string? Actors { get; set; }
|
||||
public string? Runtime { get; set; }
|
||||
public string? ImdbID { get; set; }
|
||||
public string? Providers { get; set; }
|
||||
}
|
||||
public class JustWatchResponse
|
||||
{
|
||||
public Data data { get; set; }
|
||||
}
|
||||
|
||||
public class Data
|
||||
{
|
||||
public SearchTitles searchTitles { get; set; }
|
||||
}
|
||||
|
||||
public class SearchTitles
|
||||
{
|
||||
public List<Edge> edges { get; set; }
|
||||
}
|
||||
|
||||
public class Edge
|
||||
{
|
||||
public Node node { get; set; }
|
||||
}
|
||||
|
||||
public class Node
|
||||
{
|
||||
public string id { get; set; }
|
||||
public string title { get; set; }
|
||||
public int? releaseYear { get; set; }
|
||||
public Content content { get; set; }
|
||||
public List<Offer> offers { get; set; }
|
||||
}
|
||||
|
||||
public class Content
|
||||
{
|
||||
public string imdbId { get; set; }
|
||||
}
|
||||
|
||||
public class Offer
|
||||
{
|
||||
public Provider provider { get; set; }
|
||||
public string monetizationType { get; set; } // FLATRATE, RENT, BUY
|
||||
}
|
||||
|
||||
public class Provider
|
||||
{
|
||||
public int id { get; set; }
|
||||
public string clearName { get; set; }
|
||||
}
|
||||
|
||||
public enum TorrentStatus
|
||||
|
||||
@@ -178,6 +178,18 @@ builder.Logging.ClearProviders();
|
||||
builder.Logging.AddConsole();
|
||||
builder.Logging.AddDebug();
|
||||
|
||||
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("AllowAll", policy =>
|
||||
{
|
||||
policy.AllowAnyOrigin() // Tillåt alla domäner
|
||||
.AllowAnyHeader() // Tillåt alla headers
|
||||
.AllowAnyMethod(); // Tillåt GET, POST, etc.
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// Eller om du vill ha mer detaljerad loggning:
|
||||
builder.Logging.SetMinimumLevel(LogLevel.Information);
|
||||
var app = builder.Build();
|
||||
@@ -210,7 +222,7 @@ app.UseRouting();
|
||||
app.UseSession();
|
||||
app.UseAuthentication();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.UseCors("AllowAll");
|
||||
// Routing
|
||||
app.MapControllers();
|
||||
app.MapControllerRoute(
|
||||
|
||||
@@ -16,7 +16,14 @@
|
||||
<div class="col-title">
|
||||
<img src="@t.Metadata?.Poster" alt="@t.Title" class="poster" onclick="showLightbox(this.src)" />
|
||||
<div class="title-info">
|
||||
<strong>@t.Title (@t.Metadata?.Year)</strong>
|
||||
@if (!string.IsNullOrEmpty(t.Metadata?.Title))
|
||||
{
|
||||
<strong>@t.MovieName (@t.Metadata?.Year)</strong>
|
||||
} else
|
||||
{
|
||||
<strong>@t.Title</strong>
|
||||
}
|
||||
|
||||
<div class="meta">
|
||||
@if (!string.IsNullOrEmpty(t.Metadata?.Genre))
|
||||
{
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
display: grid;
|
||||
grid-template-columns: 4fr 1fr 1fr 2fr 1fr;
|
||||
align-items: center;
|
||||
padding: 8px 0;
|
||||
padding: 4px 0;
|
||||
}
|
||||
.torrent-header {
|
||||
font-weight: 600;
|
||||
|
||||
Reference in New Issue
Block a user