mirror of
https://github.com/C9Glax/tranga.git
synced 2025-06-30 16:04:16 +02:00
Metadata-Site Search (Interactive linking)
This commit is contained in:
@ -22,14 +22,13 @@ public abstract class MetadataFetcher
|
||||
{
|
||||
this.MetadataFetcherName = metadataFetcherName;
|
||||
}
|
||||
|
||||
public abstract MetadataEntry? FindLinkedMetadataEntry(Manga manga);
|
||||
|
||||
public bool TryGetMetadataEntry(Manga manga, [NotNullWhen(true)] out MetadataEntry? metadataEntry)
|
||||
{
|
||||
metadataEntry = FindLinkedMetadataEntry(manga);
|
||||
return metadataEntry != null;
|
||||
}
|
||||
internal MetadataEntry CreateMetadataEntry(Manga manga, string identifier) =>
|
||||
new (this, manga, identifier);
|
||||
|
||||
public abstract MetadataSearchResult[] SearchMetadataEntry(Manga manga);
|
||||
|
||||
public abstract MetadataSearchResult[] SearchMetadataEntry(string searchTerm);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the Manga linked in the MetadataEntry
|
||||
|
3
API/Schema/MetadataFetchers/MetadataSearchResult.cs
Normal file
3
API/Schema/MetadataFetchers/MetadataSearchResult.cs
Normal file
@ -0,0 +1,3 @@
|
||||
namespace API.Schema.MetadataFetchers;
|
||||
|
||||
public record MetadataSearchResult(string Identifier, string Name, string Url, string? Description = null, string? CoverUrl = null);
|
@ -10,7 +10,7 @@ public class MyAnimeList : MetadataFetcher
|
||||
private static readonly Jikan Jikan = new ();
|
||||
private static readonly Regex GetIdFromUrl = new(@"https?:\/\/myanimelist\.net\/manga\/([0-9]+)\/?.*");
|
||||
|
||||
public override MetadataEntry? FindLinkedMetadataEntry(Manga manga)
|
||||
public override MetadataSearchResult[] SearchMetadataEntry(Manga manga)
|
||||
{
|
||||
if (manga.Links.Any(link => link.LinkProvider.Equals("MyAnimeList", StringComparison.InvariantCultureIgnoreCase)))
|
||||
{
|
||||
@ -19,14 +19,23 @@ public class MyAnimeList : MetadataFetcher
|
||||
if (m.Success && m.Groups[1].Success)
|
||||
{
|
||||
long id = long.Parse(m.Groups[1].Value);
|
||||
return new MetadataEntry(this, manga, id.ToString()!);
|
||||
JikanDotNet.Manga data = Jikan.GetMangaAsync(id).Result.Data;
|
||||
return [new MetadataSearchResult(id.ToString(), data.Titles.First().Title, data.Url, data.Synopsis)];
|
||||
}
|
||||
}
|
||||
|
||||
ICollection<JikanDotNet.Manga> resultData = Jikan.SearchMangaAsync(manga.Name).Result.Data;
|
||||
return SearchMetadataEntry(manga.Name);
|
||||
}
|
||||
|
||||
public override MetadataSearchResult[] SearchMetadataEntry(string searchTerm)
|
||||
{
|
||||
|
||||
ICollection<JikanDotNet.Manga> resultData = Jikan.SearchMangaAsync(searchTerm).Result.Data;
|
||||
if (resultData.Count < 1)
|
||||
return null;
|
||||
return new MetadataEntry(this, manga, resultData.First().MalId.ToString());
|
||||
return [];
|
||||
return resultData.Select(data =>
|
||||
new MetadataSearchResult(data.MalId.ToString(), data.Titles.First().Title, data.Url, data.Synopsis))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Reference in New Issue
Block a user