Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1d89a8f61e | ||
|
|
db5454393f | ||
|
|
e18c6a1c54 | ||
|
|
49d60aeabd | ||
|
|
c78537c9d8 | ||
|
|
def689a1ca | ||
|
|
8bddc61d41 | ||
|
|
b6587acaf4 | ||
|
|
dd1ead4568 | ||
|
|
d83c060ab9 | ||
|
|
f214f36cb2 | ||
|
|
6e654844aa | ||
|
|
38282fd854 | ||
|
|
754a7296f6 | ||
|
|
784e2d80a2 | ||
|
|
4ed8dc3a54 | ||
|
|
27027642eb |
No files matched your search
@@ -1,5 +1,34 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## [1.0.4](https://github.com/Masutayunikon/FanKarr/compare/v1.0.3...v1.0.4) (2026-03-10)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* add log for debug ([6876c5e](https://github.com/Masutayunikon/FanKarr/commit/6876c5ee6c7734e664a6da4e4bc721cc7c5abdf7))
|
||||||
|
* add log for debug ([d8cdeae](https://github.com/Masutayunikon/FanKarr/commit/d8cdeae675bc73b5842d18d01eff9d5bb0e0a7e8))
|
||||||
|
|
||||||
|
## [1.0.3](https://github.com/Masutayunikon/FanKarr/compare/v1.0.2...v1.0.3) (2026-03-10)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* organize file ([d6550e9](https://github.com/Masutayunikon/FanKarr/commit/d6550e9961789073be1583e03d599afb6d295004))
|
||||||
|
|
||||||
|
## [1.0.2](https://github.com/Masutayunikon/FanKarr/compare/v1.0.1...v1.0.2) (2026-03-10)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* organize use torrent hash and not name ([61901f9](https://github.com/Masutayunikon/FanKarr/commit/61901f9014a759e2950311cd96266ea8201fa902))
|
||||||
|
|
||||||
|
## [1.0.1](https://github.com/Masutayunikon/FanKarr/compare/v1.0.0...v1.0.1) (2026-03-10)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* docker errors ([2702764](https://github.com/Masutayunikon/FanKarr/commit/27027642eb55b75adb04446a88e5007e88f75948))
|
||||||
|
|
||||||
## 1.0.0 (2026-03-10)
|
## 1.0.0 (2026-03-10)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -8,7 +8,7 @@ import {
|
|||||||
registerDriver, getDriver, getAvailableClients,
|
registerDriver, getDriver, getAvailableClients,
|
||||||
listClients, addClient, removeClient, getClient,
|
listClients, addClient, removeClient, getClient,
|
||||||
sanitizeClient, dispatchDownload, dispatchList
|
sanitizeClient, dispatchDownload, dispatchList
|
||||||
} from './torrent-clients'
|
} from './torrent-clients/index.js'
|
||||||
import qbittorrentDriver from './torrent-clients/qbittorrent.js'
|
import qbittorrentDriver from './torrent-clients/qbittorrent.js'
|
||||||
import { organizeTorrent, autoOrganizeAll } from './organize.js'
|
import { organizeTorrent, autoOrganizeAll } from './organize.js'
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ const PORT = 3001
|
|||||||
const FANKAI_API = 'https://metadata.fankai.fr'
|
const FANKAI_API = 'https://metadata.fankai.fr'
|
||||||
const TORRENTS_PATH = path.join(process.cwd(), 'data', 'torrent_final.json')
|
const TORRENTS_PATH = path.join(process.cwd(), 'data', 'torrent_final.json')
|
||||||
const GITHUB_RAW_URL = process.env.GITHUB_RAW_URL
|
const GITHUB_RAW_URL = process.env.GITHUB_RAW_URL
|
||||||
?? 'https://raw.githubusercontent.com/CHANGE_ME/fankarr-scraper/main/data/torrent_final.json'
|
?? 'https://raw.githubusercontent.com/masutayunikon/fankarr-scraper/main/data/torrent_final.json'
|
||||||
|
|
||||||
app.use(express.json())
|
app.use(express.json())
|
||||||
app.use(cookieParser())
|
app.use(cookieParser())
|
||||||
@@ -50,7 +50,7 @@ app.get('/api/torrent-clients/available', requireAuth, (_req, res) => {
|
|||||||
res.json(getAvailableClients())
|
res.json(getAvailableClients())
|
||||||
})
|
})
|
||||||
app.get('/api/torrent-clients', requireAuth, (_req, res) => {
|
app.get('/api/torrent-clients', requireAuth, (_req, res) => {
|
||||||
res.json(listClients().map(c => sanitizeClient(c)))
|
res.json(listClients().map((c: any) => sanitizeClient(c)))
|
||||||
})
|
})
|
||||||
app.post('/api/torrent-clients', requireAuth, (req, res) => {
|
app.post('/api/torrent-clients', requireAuth, (req, res) => {
|
||||||
const { name, type, config } = req.body
|
const { name, type, config } = req.body
|
||||||
@@ -222,7 +222,7 @@ app.post('/api/download', requireAuth, async (req, res) => {
|
|||||||
const url = req.body.torrent_url ?? req.body.magnet
|
const url = req.body.torrent_url ?? req.body.magnet
|
||||||
if (!url) { res.status(400).json({ error: 'torrent_url ou magnet requis' }); return }
|
if (!url) { res.status(400).json({ error: 'torrent_url ou magnet requis' }); return }
|
||||||
const results = await dispatchDownload(url)
|
const results = await dispatchDownload(url)
|
||||||
res.status(results.every(r => r.ok) ? 200 : 207).json({ results })
|
res.status(results.every((r: any) => r.ok) ? 200 : 207).json({ results })
|
||||||
})
|
})
|
||||||
|
|
||||||
// ── Downloads — liste torrents Fankai ──────────────────────────
|
// ── Downloads — liste torrents Fankai ──────────────────────────
|
||||||
|
|||||||
+84
-61
@@ -49,9 +49,9 @@ function readTorrents(): any[] {
|
|||||||
} catch { return [] }
|
} catch { return [] }
|
||||||
}
|
}
|
||||||
|
|
||||||
function findTorrentByName(name: string): any | null {
|
function findTorrentByHash(hash: string): any | null {
|
||||||
const torrents = readTorrents()
|
const torrents = readTorrents()
|
||||||
return torrents.find(t => t.raw === name) ?? null
|
return torrents.find(t => t.infohash?.toLowerCase() === hash.toLowerCase()) ?? null
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── Filesystem ops ───────────────────────────────────────────
|
// ─── Filesystem ops ───────────────────────────────────────────
|
||||||
@@ -68,7 +68,8 @@ function tryHardlink(src: string, dest: string): boolean {
|
|||||||
try {
|
try {
|
||||||
fs.linkSync(src, dest)
|
fs.linkSync(src, dest)
|
||||||
return true
|
return true
|
||||||
} catch {
|
} catch (err) {
|
||||||
|
console.warn(`[organize] hardlink échoué (${err instanceof Error ? err.message : err})`)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,35 +91,40 @@ export interface OrganizeResult {
|
|||||||
|
|
||||||
export async function organizeTorrent(
|
export async function organizeTorrent(
|
||||||
hash : string,
|
hash : string,
|
||||||
name : string, // nom du dossier torrent dans completePath
|
name : string, // nom du dossier torrent (retourné par qB)
|
||||||
savePath: string // save_path retourné par qBittorrent
|
savePath: string // save_path retourné par qBittorrent
|
||||||
): Promise<OrganizeResult> {
|
): Promise<OrganizeResult> {
|
||||||
const settings = readSettings()
|
const settings = readSettings()
|
||||||
const { mediaPath, completePath, organizeMode } = settings
|
const { mediaPath, completePath, organizeMode } = settings
|
||||||
|
|
||||||
|
console.log(`[organize] ── Début organisation ──────────────────────`)
|
||||||
|
console.log(`[organize] hash : ${hash}`)
|
||||||
|
console.log(`[organize] name : ${name}`)
|
||||||
|
console.log(`[organize] save_path : ${savePath}`)
|
||||||
|
console.log(`[organize] mediaPath : ${mediaPath}`)
|
||||||
|
console.log(`[organize] completePath: ${completePath}`)
|
||||||
|
console.log(`[organize] mode : ${organizeMode}`)
|
||||||
|
|
||||||
const result: OrganizeResult = { total: 0, skipped: 0, done: 0, errors: [] }
|
const result: OrganizeResult = { total: 0, skipped: 0, done: 0, errors: [] }
|
||||||
|
|
||||||
// Trouver le torrent dans torrent_final.json
|
// Trouver le torrent dans torrent_final.json via infohash
|
||||||
const torrent = findTorrentByName(name)
|
const torrent = findTorrentByHash(hash)
|
||||||
if (!torrent) {
|
if (!torrent) {
|
||||||
throw new Error(`Torrent introuvable dans torrent_final.json : "${name}"`)
|
console.error(`[organize] ✗ Aucun torrent avec infohash="${hash}" dans torrent_final.json`)
|
||||||
|
throw new Error(`Torrent introuvable pour le hash : "${hash}"`)
|
||||||
}
|
}
|
||||||
|
console.log(`[organize] ✓ Torrent trouvé : ${torrent.raw}`)
|
||||||
|
|
||||||
const serieTitle = torrent.serie_title || torrent.show_title || name
|
const serieTitle = torrent.serie_title || torrent.show_title || name
|
||||||
const torrentFiles: any[] = torrent.torrent_files ?? []
|
const torrentFiles: any[] = torrent.torrent_files ?? []
|
||||||
|
console.log(`[organize] serie_title : ${serieTitle}`)
|
||||||
|
console.log(`[organize] fichiers : ${torrentFiles.length}`)
|
||||||
|
|
||||||
if (torrentFiles.length === 0) {
|
if (torrentFiles.length === 0) {
|
||||||
throw new Error(`Aucun fichier trouvé dans le torrent "${name}"`)
|
throw new Error(`Aucun fichier trouvé dans le torrent "${name}"`)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Résoudre season_number par episode_id
|
// Map filename → season_number depuis resolved_episodes
|
||||||
const epSeasonMap = new Map<number, number>()
|
|
||||||
for (const ep of torrent.resolved_episodes ?? []) {
|
|
||||||
if (ep.filename) {
|
|
||||||
epSeasonMap.set(ep.episode_number, ep.season_number)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Map filename → season_number
|
|
||||||
const filenameSeasonMap = new Map<string, number>()
|
const filenameSeasonMap = new Map<string, number>()
|
||||||
for (const ep of torrent.resolved_episodes ?? []) {
|
for (const ep of torrent.resolved_episodes ?? []) {
|
||||||
if (ep.filename && ep.season_number !== undefined) {
|
if (ep.filename && ep.season_number !== undefined) {
|
||||||
@@ -130,51 +136,59 @@ export async function organizeTorrent(
|
|||||||
|
|
||||||
for (const tf of torrentFiles) {
|
for (const tf of torrentFiles) {
|
||||||
const filename = tf.filename
|
const filename = tf.filename
|
||||||
const filePath: string[] = tf.path // ex: ["Saga 1 - ...", "file.mkv"]
|
const filePath: string[] = tf.path
|
||||||
|
|
||||||
|
console.log(`[organize] ── Fichier : ${filename}`)
|
||||||
|
console.log(`[organize] path[] : ${JSON.stringify(filePath)}`)
|
||||||
|
|
||||||
// Skip si déjà organisé
|
// Skip si déjà organisé
|
||||||
if (isOrganized(hash, filename)) {
|
if (isOrganized(hash, filename)) {
|
||||||
|
console.log(`[organize] → déjà organisé, skip`)
|
||||||
result.skipped++
|
result.skipped++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construire le chemin source
|
// Essayer plusieurs chemins sources possibles
|
||||||
// save_path peut déjà contenir le nom du dossier ou pas selon le client
|
const candidates = [
|
||||||
const torrentDir = path.join(savePath, name)
|
path.join(savePath, name, ...filePath.slice(0, -1), filename),
|
||||||
const torrentDirAlt = savePath // au cas où save_path inclut déjà le nom
|
path.join(savePath, ...filePath.slice(0, -1), filename),
|
||||||
|
path.join(savePath, name, filename),
|
||||||
|
path.join(savePath, filename),
|
||||||
|
path.join(completePath, name, ...filePath.slice(0, -1), filename),
|
||||||
|
path.join(completePath, name, filename),
|
||||||
|
path.join(completePath, filename),
|
||||||
|
]
|
||||||
|
|
||||||
// Chemin source = dossier torrent + sous-dossiers + fichier
|
let src: string | null = null
|
||||||
const subPath = filePath.length > 1
|
for (const candidate of candidates) {
|
||||||
? path.join(...filePath.slice(0, -1), filename)
|
console.log(`[organize] candidate: ${candidate} → ${fs.existsSync(candidate) ? '✓ EXISTS' : '✗ absent'}`)
|
||||||
: filename
|
if (fs.existsSync(candidate)) {
|
||||||
|
src = candidate
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let src = path.join(torrentDir, subPath)
|
if (!src) {
|
||||||
if (!fs.existsSync(src)) {
|
const err = `Source introuvable (essayé ${candidates.length} chemins)`
|
||||||
// Fallback: save_path sans le nom du torrent
|
console.error(`[organize] ✗ ${err}`)
|
||||||
src = path.join(torrentDirAlt, subPath)
|
result.errors.push({ file: filename, error: err })
|
||||||
}
|
|
||||||
if (!fs.existsSync(src)) {
|
|
||||||
// Fallback: fichier directement dans save_path/name
|
|
||||||
src = path.join(torrentDir, filename)
|
|
||||||
}
|
|
||||||
if (!fs.existsSync(src)) {
|
|
||||||
result.errors.push({ file: filename, error: `Source introuvable : ${src}` })
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Déterminer la saison
|
console.log(`[organize] ✓ source : ${src}`)
|
||||||
let seasonNum = filenameSeasonMap.get(filename)
|
|
||||||
if (seasonNum === undefined) {
|
|
||||||
// Fallback : season_number = 1
|
|
||||||
seasonNum = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
// Construire le chemin destination
|
// Déterminer la saison
|
||||||
|
const seasonNum = filenameSeasonMap.get(filename) ?? 1
|
||||||
|
console.log(`[organize] saison : ${seasonNum}`)
|
||||||
|
|
||||||
|
// Chemin destination
|
||||||
const destDir = path.join(mediaPath, serieTitle, seasonFolder(seasonNum))
|
const destDir = path.join(mediaPath, serieTitle, seasonFolder(seasonNum))
|
||||||
const dest = path.join(destDir, filename)
|
const dest = path.join(destDir, filename)
|
||||||
|
console.log(`[organize] dest : ${dest}`)
|
||||||
|
|
||||||
// Skip si dest existe déjà
|
// Skip si dest existe déjà
|
||||||
if (fs.existsSync(dest)) {
|
if (fs.existsSync(dest)) {
|
||||||
|
console.log(`[organize] → dest existe déjà, skip`)
|
||||||
markOrganized(hash, filename)
|
markOrganized(hash, filename)
|
||||||
result.skipped++
|
result.skipped++
|
||||||
continue
|
continue
|
||||||
@@ -186,33 +200,29 @@ export async function organizeTorrent(
|
|||||||
if (organizeMode === 'hardlink') {
|
if (organizeMode === 'hardlink') {
|
||||||
const ok = tryHardlink(src, dest)
|
const ok = tryHardlink(src, dest)
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
// Hardlink impossible (filesystems différents) → copy
|
console.warn(`[organize] hardlink impossible → fallback copy`)
|
||||||
console.warn(`[organize] hardlink échoué pour ${filename}, fallback copy`)
|
|
||||||
copyFile(src, dest)
|
copyFile(src, dest)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// move = copy + delete source
|
|
||||||
copyFile(src, dest)
|
copyFile(src, dest)
|
||||||
fs.unlinkSync(src)
|
fs.unlinkSync(src)
|
||||||
}
|
}
|
||||||
|
|
||||||
markOrganized(hash, filename)
|
markOrganized(hash, filename)
|
||||||
result.done++
|
result.done++
|
||||||
console.log(`[organize] ${organizeMode} ${filename} → ${dest}`)
|
console.log(`[organize] ✓ ${organizeMode} OK`)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
result.errors.push({
|
const msg = err instanceof Error ? err.message : 'Erreur inconnue'
|
||||||
file : filename,
|
console.error(`[organize] ✗ ${msg}`)
|
||||||
error: err instanceof Error ? err.message : 'Erreur inconnue'
|
result.errors.push({ file: filename, error: msg })
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(`[organize] ── Résultat : ${result.done} OK, ${result.skipped} skippés, ${result.errors.length} erreurs`)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── Auto-organise polling ────────────────────────────────────
|
// ─── Auto-organise polling ────────────────────────────────────
|
||||||
// Appelé depuis index.ts au démarrage, toutes les 30s
|
|
||||||
// Détecte les torrents "seeding" non encore organisés
|
|
||||||
|
|
||||||
export async function autoOrganizeAll(
|
export async function autoOrganizeAll(
|
||||||
listFn: () => Promise<any[]>
|
listFn: () => Promise<any[]>
|
||||||
@@ -220,22 +230,35 @@ export async function autoOrganizeAll(
|
|||||||
let torrents: any[]
|
let torrents: any[]
|
||||||
try {
|
try {
|
||||||
torrents = await listFn()
|
torrents = await listFn()
|
||||||
} catch { return }
|
} catch (err) {
|
||||||
|
console.error('[organize] autoOrganizeAll: impossible de récupérer la liste des torrents:', err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`[organize] autoOrganizeAll: ${torrents.length} torrents récupérés`)
|
||||||
|
|
||||||
const organized = loadOrganized()
|
const organized = loadOrganized()
|
||||||
|
|
||||||
for (const t of torrents) {
|
for (const t of torrents) {
|
||||||
if (t.state !== 'seeding') continue
|
if (t.state !== 'seeding') {
|
||||||
|
console.log(`[organize] skip ${t.name} (state=${t.state})`)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// Vérifier si tous les fichiers sont déjà organisés
|
const torrent = findTorrentByHash(t.hash)
|
||||||
const torrent = findTorrentByName(t.name)
|
if (!torrent) {
|
||||||
if (!torrent) continue
|
console.warn(`[organize] hash ${t.hash} (${t.name}) non trouvé dans torrent_final.json`)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
const files: any[] = torrent.torrent_files ?? []
|
const files: any[] = torrent.torrent_files ?? []
|
||||||
if (files.length === 0) continue
|
if (files.length === 0) continue
|
||||||
|
|
||||||
const allDone = files.every(f => organized[t.hash]?.[f.filename])
|
const allDone = files.every((f: any) => organized[t.hash]?.[f.filename])
|
||||||
if (allDone) continue
|
if (allDone) {
|
||||||
|
console.log(`[organize] ${t.name} → déjà entièrement organisé`)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
console.log(`[organize] Auto-organisation : ${t.name}`)
|
console.log(`[organize] Auto-organisation : ${t.name}`)
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in new issue
Block a user