fix: telechargement depuis les demandes de saison et integral
This commit is contained in:
1 parent
62c5b2e622
commit
7f4121d9e4
1 file changed
+38
-15
+38
-15
@@ -84,6 +84,12 @@ async function autoDownloadRequest(req: SerieRequest): Promise<void> {
|
|||||||
const toDownload: TorrentEntry[] = []
|
const toDownload: TorrentEntry[] = []
|
||||||
const seenHashes = new Set<string>()
|
const seenHashes = new Set<string>()
|
||||||
|
|
||||||
|
// Tous les torrents pack (série + saisons) pour résoudre les ep.paths
|
||||||
|
const allPackTorrents: any[] = [
|
||||||
|
...(serieData.torrents ?? []),
|
||||||
|
...(serieData.seasons ?? []).flatMap((s: any) => s.torrents ?? []),
|
||||||
|
]
|
||||||
|
|
||||||
function addTorrent(t: any, file_index?: number | null, file_path?: string | null) {
|
function addTorrent(t: any, file_index?: number | null, file_path?: string | null) {
|
||||||
const key = `${t.infohash ?? t.magnet ?? t.torrent_url}:${file_index ?? ''}`
|
const key = `${t.infohash ?? t.magnet ?? t.torrent_url}:${file_index ?? ''}`
|
||||||
if (seenHashes.has(key)) return
|
if (seenHashes.has(key)) return
|
||||||
@@ -91,29 +97,40 @@ async function autoDownloadRequest(req: SerieRequest): Promise<void> {
|
|||||||
toDownload.push({ url: t.torrent_url, magnet: t.magnet ?? null, infohash: t.infohash ?? null, file_index: file_index ?? null, file_path: file_path ?? null })
|
toDownload.push({ url: t.torrent_url, magnet: t.magnet ?? null, infohash: t.infohash ?? null, file_index: file_index ?? null, file_path: file_path ?? null })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ajoute tous les épisodes d'une liste via leurs torrents individuels ou via file_index dans un pack.
|
||||||
|
* Utilisé en fallback quand il n'y a pas de torrent de saison/série globale.
|
||||||
|
*/
|
||||||
|
function addEpisodesByIndex(epList: any[]) {
|
||||||
|
for (const ep of epList) {
|
||||||
|
if (ep.torrents?.length > 0) {
|
||||||
|
for (const t of ep.torrents) addTorrent(t)
|
||||||
|
} else if (ep.paths?.length > 0) {
|
||||||
|
for (const p of ep.paths) {
|
||||||
|
const pack = allPackTorrents.find((t: any) => t.infohash?.toLowerCase() === p.infohash?.toLowerCase())
|
||||||
|
if (pack) addTorrent(pack, p.file_index ?? null, p.path ?? null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (episodes.length > 0) {
|
if (episodes.length > 0) {
|
||||||
// ── Épisodes ciblés ───────────────────────────────────────
|
// ── Épisodes ciblés ───────────────────────────────────────
|
||||||
for (const season of serieData.seasons ?? []) {
|
for (const season of serieData.seasons ?? []) {
|
||||||
for (const ep of season.episodes ?? []) {
|
const targets = (season.episodes ?? []).filter((ep: any) => episodes.includes(ep.id))
|
||||||
if (!episodes.includes(ep.id)) continue
|
addEpisodesByIndex(targets)
|
||||||
if (ep.torrents?.length > 0) {
|
|
||||||
// Torrent individuel
|
|
||||||
for (const t of ep.torrents) addTorrent(t)
|
|
||||||
} else if (ep.paths?.length > 0) {
|
|
||||||
// Épisode contenu dans un pack — télécharger le fichier spécifique
|
|
||||||
for (const p of ep.paths) {
|
|
||||||
const pack = [...(serieData.torrents ?? []), ...(serieData.seasons ?? []).flatMap((s: any) => s.torrents ?? [])]
|
|
||||||
.find((t: any) => t.infohash?.toLowerCase() === p.infohash?.toLowerCase())
|
|
||||||
if (pack) addTorrent(pack, p.file_index ?? null, p.path ?? null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (seasons.length > 0) {
|
} else if (seasons.length > 0) {
|
||||||
// ── Saisons ciblées ───────────────────────────────────────
|
// ── Saisons ciblées ───────────────────────────────────────
|
||||||
for (const season of serieData.seasons ?? []) {
|
for (const season of serieData.seasons ?? []) {
|
||||||
if (!seasons.includes(season.season_number)) continue
|
if (!seasons.includes(season.season_number)) continue
|
||||||
for (const t of season.torrents ?? []) addTorrent(t)
|
if ((season.torrents ?? []).length > 0) {
|
||||||
|
// Pack saison disponible → télécharger en bloc
|
||||||
|
for (const t of season.torrents) addTorrent(t)
|
||||||
|
} else {
|
||||||
|
// Pas de pack → épisode par épisode avec file_index
|
||||||
|
addEpisodesByIndex(season.episodes ?? [])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// ── Toutes les saisons : intégrale en priorité ────────────
|
// ── Toutes les saisons : intégrale en priorité ────────────
|
||||||
@@ -124,6 +141,12 @@ async function autoDownloadRequest(req: SerieRequest): Promise<void> {
|
|||||||
for (const t of season.torrents ?? []) addTorrent(t)
|
for (const t of season.torrents ?? []) addTorrent(t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Sinon épisode par épisode avec file_index
|
||||||
|
if (toDownload.length === 0) {
|
||||||
|
for (const season of serieData.seasons ?? []) {
|
||||||
|
addEpisodesByIndex(season.episodes ?? [])
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (toDownload.length === 0) {
|
if (toDownload.length === 0) {
|
||||||
|
|||||||
Reference in new issue
Block a user