From e1d36be2d7939be78fbcc00ad6218b12e1585a9e Mon Sep 17 00:00:00 2001 From: Daniel Haller Date: Wed, 24 Apr 2024 03:22:29 +0200 Subject: [PATCH] added more adn stuff --- components/ADN/ListAnimes.ts | 65 +++++++++++++++-- components/ADN/ListEpisodes.ts | 4 +- components/ADN/Types.ts | 3 +- components/Search/Types.ts | 70 +++++++++--------- pages/addanime.vue | 22 ++++-- src/api/routes/adn/adn.service.ts | 6 +- src/api/routes/service/service.service.ts | 36 ++++++++-- src/api/services/folder.ts | 21 +++++- src/api/services/subs.ts | 88 +++++++++++++++++++++-- 9 files changed, 248 insertions(+), 67 deletions(-) diff --git a/components/ADN/ListAnimes.ts b/components/ADN/ListAnimes.ts index 50fdae6..02f63ce 100644 --- a/components/ADN/ListAnimes.ts +++ b/components/ADN/ListAnimes.ts @@ -1,12 +1,12 @@ import type { ADNSearchFetch } from "./Types"; export async function searchADN(q: string) { - const { data, error } = await useFetch( + const { data: deData, error: deError } = await useFetch( `https://gw.api.animationdigitalnetwork.fr/show/catalog`, { method: "GET", headers: { - "x-target-distribution": "de", + "x-target-distribution": 'de', }, query: { "maxAgeCategory": "18", @@ -15,11 +15,64 @@ export async function searchADN(q: string) { } ); - if (error.value) { - throw new Error(error.value?.data.message as string) + if (deError.value) { + throw new Error(deError.value?.data.message as string) } - if (!data.value) return + if (!deData.value) return - return data.value.shows + const { data: frData, error: frError } = await useFetch( + `https://gw.api.animationdigitalnetwork.fr/show/catalog`, + { + method: "GET", + headers: { + "x-target-distribution": 'fr', + }, + query: { + "maxAgeCategory": "18", + "search": q + } + } + ); + + if (frError.value) { + throw new Error(frError.value?.data.message as string) + } + + if (!frData.value) return + + const deShows = deData.value.shows; + const frShows = frData.value.shows; + + const mergeLanguagesOfDuplicates = (shows: { + id: number + url: string + title: string + image2x: string + episodeCount: number, + languages: Array + }[]) => { + shows.forEach(show => { + const existingShow = shows.find(s => s.id === show.id); + if (existingShow) { + const existingShowIndex = shows.findIndex(s=> s === existingShow); + const rawLanguages = [...show.languages, ...existingShow.languages]; + const languages: Array = [] + + for (const l of rawLanguages) { + if (!languages.includes(l)) { + languages.push(l) + } + } + show.languages = languages + } + }); + return shows; + }; + + const allShows = mergeLanguagesOfDuplicates([...deShows, ...frShows]); + + const unique = [...new Map(allShows.map((s) => [s.id, s])).values()]; + + return unique } diff --git a/components/ADN/ListEpisodes.ts b/components/ADN/ListEpisodes.ts index feef9af..171cacb 100644 --- a/components/ADN/ListEpisodes.ts +++ b/components/ADN/ListEpisodes.ts @@ -1,10 +1,10 @@ import type { ADNEpisodes, ADNEpisodesFetch } from './Types' -export async function getEpisodesWithShowIdADN(id: number) { +export async function getEpisodesWithShowIdADN(id: number, lang: 'de' | 'fr') { const { data, error } = await useFetch(`https://gw.api.animationdigitalnetwork.fr/video/show/${id}?offset=0&limit=-1&order=asc`, { method: 'GET', headers: { - "x-target-distribution": "de", + "x-target-distribution": lang, }, }) diff --git a/components/ADN/Types.ts b/components/ADN/Types.ts index 3b4630f..53621b4 100644 --- a/components/ADN/Types.ts +++ b/components/ADN/Types.ts @@ -4,7 +4,8 @@ export interface ADNSearchFetch { url: string title: string image2x: string - episodeCount: number + episodeCount: number, + languages: Array }> } diff --git a/components/Search/Types.ts b/components/Search/Types.ts index c7e61ea..ab24023 100644 --- a/components/Search/Types.ts +++ b/components/Search/Types.ts @@ -1,43 +1,43 @@ export interface CrunchyrollSearchResult { - ID: string; - Url: string; - Title: string; - Description: string; - Dubs: Array; - Subs: Array; - Episodes: number; - Seasons: number; - PEGI: Array; - Year: number; - Images: { - poster_tall: Array< - Array<{ - height: number; - source: string; - type: string; - width: number; - }> - >; - poster_wide: Array< - Array<{ - height: number; - source: string; - type: string; - width: number; - }> - >; - }; + ID: string + Url: string + Title: string + Description: string + Dubs: Array + Subs: Array + Episodes: number + Seasons: number + PEGI: Array + Year: number + Images: { + poster_tall: Array< + Array<{ + height: number + source: string + type: string + width: number + }> + > + poster_wide: Array< + Array<{ + height: number + source: string + type: string + width: number + }> + > + } } -export interface CrunchyrollSearchResults - extends Array {} +export interface CrunchyrollSearchResults extends Array {} export interface ADNSearchResult { - id: number; - url: string; - title: string; - image2x: string; - episodeCount: number; + id: number + url: string + title: string + image2x: string + episodeCount: number + languages: Array } export interface ADNSearchResults extends Array {} diff --git a/pages/addanime.vue b/pages/addanime.vue index a006da1..c92e7ba 100644 --- a/pages/addanime.vue +++ b/pages/addanime.vue @@ -19,9 +19,6 @@ -
- ADN downloader is still in beta and can only download ADN Germany -
+
+
+ Dub: + {{ selectedDubs.map((t) => t.name).join(', ') }} +
+
Subs: @@ -206,6 +209,12 @@
+
+
+ Sub: + {{ selectedSubs.length !== 0 ? selectedSubs.map((t) => t.name).join(', ') : 'No Subs selected' }} +
+