Compare commits

...
114 Commits
Author SHA1 Message Date
MasutaYunikon 2d49125e09 Merge pull request #54 from Masutayunikon/release-please--branches--main
chore(main): release 2.2.0
2026-03-23 15:38:51 +01:00
MasutaYunikon 721047c95f chore(main): release 2.2.0 2026-03-23 15:38:03 +01:00
MasutaYunikon 74662de2b6 Merge remote-tracking branch 'origin/main' 2026-03-23 15:37:23 +01:00
MasutaYunikon 84ef0333f3 feat: add organize all button
fix: organizer reuse the wrong name for gitlab path
2026-03-23 15:37:07 +01:00
MasutaYunikon c6624843b9 Merge pull request #53 from Masutayunikon/release-please--branches--main
chore(main): release 2.1.3
2026-03-23 06:09:59 +01:00
MasutaYunikon 8bd30913cd chore(main): release 2.1.3 2026-03-23 06:09:36 +01:00
MasutaYunikon d7eb932ed3 Merge remote-tracking branch 'origin/main' 2026-03-23 06:09:04 +01:00
MasutaYunikon 4594dc5189 fix: use magnet before torrent 2026-03-23 06:08:48 +01:00
MasutaYunikon 894a621e85 Merge pull request #52 from Masutayunikon/release-please--branches--main
chore(main): release 2.1.2
2026-03-23 05:38:16 +01:00
MasutaYunikon 23dbf86e70 chore(main): release 2.1.2 2026-03-23 05:38:02 +01:00
MasutaYunikon d86138ef1c Merge remote-tracking branch 'origin/main' 2026-03-23 05:37:32 +01:00
MasutaYunikon 4aa6f99676 fix: path now work on every device 2026-03-23 05:37:23 +01:00
MasutaYunikon 10432e0f99 Merge pull request #51 from Masutayunikon/release-please--branches--main
chore(main): release 2.1.1
2026-03-23 05:32:19 +01:00
MasutaYunikon 4f69f8bf92 chore(main): release 2.1.1 2026-03-23 05:32:01 +01:00
MasutaYunikon 1511dd3ca3 Merge remote-tracking branch 'origin/main' 2026-03-23 05:31:29 +01:00
MasutaYunikon 23967a81d6 fix: torrent path to hash 2026-03-23 05:31:20 +01:00
MasutaYunikon 21ff025376 Merge pull request #50 from Masutayunikon/release-please--branches--main
chore(main): release 2.1.0
2026-03-23 05:00:49 +01:00
MasutaYunikon 9ba19f9539 chore(main): release 2.1.0 2026-03-23 05:00:34 +01:00
MasutaYunikon 215d802b12 fix: remove logo
Release-As: 2.1.0
2026-03-23 05:00:05 +01:00
MasutaYunikon 21dccbe5d9 Merge remote-tracking branch 'origin/main'
Release-As: 2.1.0
2026-03-23 04:56:45 +01:00
MasutaYunikon 329150f1c4 fix(organize): migration vers paths { infohash, path } pour le matching fichiers
BREAKING CHANGE: le format paths[] dans series/{id}.json passe de string[]
à { infohash: string, path: string }[] — nécessite une mise à jour du scraper.

fix(organize): buildFileMap matche par infohash au lieu d'index ou titre

L'ancien système utilisait soit un index positionnel fragile, soit le titre
du torrent comme clé de matching — les deux cassaient si l'utilisateur
renommait le torrent dans qBittorrent ou si un pack intégrale ne couvrait
pas tous les épisodes. Désormais chaque path est lié à un infohash précis.

fix(organize): source fichier via save_path qBittorrent + fullPath relatif

path.join(savePath, fullPath) utilise le save_path retourné par qBittorrent
au lieu de deviner le nom du dossier depuis le titre du torrent. Résiste
aux renommages de dossier côté client.

fix(organize): scanMediaPath adapté au nouveau format paths[]

L'index filename → infohash est maintenant construit directement depuis
ep.paths[].infohash sans passer par la hiérarchie torrents série/saison/épisode.
2026-03-23 04:52:33 +01:00
MasutaYunikon 17f7234b49 Merge pull request #48 from Masutayunikon/release-please--branches--main
chore(main): release 2.0.0
2026-03-23 04:05:16 +01:00
MasutaYunikon 8e529d3845 chore(main): release 2.0.0 2026-03-23 04:04:52 +01:00
MasutaYunikon a3f3539a27 Merge remote-tracking branch 'origin/main' 2026-03-23 04:04:23 +01:00
MasutaYunikon d5c37e8f2c feat!: migration vers nouvelle architecture API et scraper par série
BREAKING CHANGE: suppression de torrent_final.json au profit d'un système
de fichiers par série (series/{id}.json) avec cache mémoire GitHub 6h.
Version majeure — nécessite un nouveau scraper et une mise à jour complète.

feat(api): cache mémoire GitHub TTL 6h avec invalidation via /api/update

Plus de fichiers locaux dans /config pour les torrents. Les données sont
fetchées depuis GitHub (available.json + series/{id}.json) et mises en
cache 6h. /api/update vide le cache pour forcer le rechargement.

feat(api): adaptation complète à la nouvelle structure API Fankai

- normalizeSerie/Season/Episode pour aplatir images.poster → poster_image
- Proxy wsrv.nl pour redimensionner les images (poster 300px, fanart 1280px,
  thumbnail 400px) et réduire le temps de chargement
- duration en secondes → affichage en minutes dans SerieView

feat(organize): refonte complète sans torrent_final.json

- organize-worker.ts reçoit seriesData via message au lieu de lire un fichier
- buildFileMap construit filename→{season_number,original_filename} depuis paths[]
- enrichSeriesDataWithOriginalFilenames fetche /seasons/{id}/episodes avant
  de passer les données au worker pour le renommage correct des fichiers
- Suppression de SERIE_TITLE_GITLAB_MAP (Kaï→Kai résolu côté API)
- scanMediaPath adapté : plus de torrentsPath, prend seriesData en paramètre

feat(api): matching torrents par hiérarchie série/saison/épisode

- Torrents niveau série → pack_integrale
- Torrents niveau saison → pack_saison (indexé par season_number)
- Torrents niveau épisode → episode
- Matching via paths[torrentIdx] pour résoudre episode↔fichier

feat(series-view): badge "Hors Fankai" sur épisodes de torrents manuels
feat(series-view): tooltip raw name sur boutons intégrale via :title
feat(scraper): extraction nom bencode dans raw pour torrents locaux
fix(series): boutons saison Yu-Gi-Oh via fallback season_number
fix(catalogue): état download basé sur épisodes organisés vs torrents bruts

Release-As: 2.0.0
2026-03-23 04:04:12 +01:00
MasutaYunikon a5f5dfb0da Merge pull request #47 from Masutayunikon/release-please--branches--main
chore(main): release 1.14.0
2026-03-21 08:01:19 +01:00
MasutaYunikon 08531c80f3 chore(main): release 1.14.0 2026-03-21 07:59:16 +01:00
MasutaYunikon 96ce207027 Merge remote-tracking branch 'origin/main' 2026-03-21 07:58:54 +01:00
MasutaYunikon 13f9a27af8 fix(series): résolution boutons de téléchargement saisons Yu-Gi-Oh et séries similaires
Les boutons "Saison entière" n'apparaissaient pas pour les séries dont les
season_id du scraper ne correspondent pas aux season_id de l'API Fankai.

- Ajouter seasonTorrentMapBySn indexé par season_number en fallback
- Utiliser season_number comme clé de secours dans enrichedSeasons

fix(catalogue): état "partiel" incorrect quand l'intégrale est organisée

Le badge partial s'affichait même quand tous les épisodes étaient organisés
via un pack_integrale, car les torrents d'épisodes séparés faisaient baisser
le ratio. La logique est maintenant basée sur les episode_id uniques.

feat(series-view): badge "Hors Fankai" sur les épisodes de torrents manuels

Les épisodes issus de MANUAL_TORRENTS (ex: MHA Film 4) sont maintenant
marqués d'un badge violet "Hors Fankai" avec tooltip explicatif.

- Propager manual: true du torrent dans le TorrentRef de l'épisode
- Afficher le badge dans SerieView.vue si ep.torrent?.manual

feat(series-view): tooltip avec le nom du torrent sur les boutons intégrale

Quand plusieurs intégrales existent pour une série, survoler le bouton
affiche le raw name du torrent via :title="t.raw".

feat(scraper): extraction du nom bencode pour les torrents locaux

Le champ raw des LOCAL_TORRENTS est maintenant renseigné depuis info.name
extrait directement du fichier .torrent via bencode, au lieu d'utiliser
la clé du dictionnaire LOCAL_TORRENTS.

- fetch_torrent_files_from_local retourne maintenant (files, infohash, name)
- torrent["raw"] est mis à jour avec le vrai nom bencode
2026-03-21 07:58:45 +01:00
MasutaYunikon d0d40c02b5 Merge pull request #46 from Masutayunikon/release-please--branches--main
chore(main): release 1.13.0
2026-03-21 04:21:36 +01:00
MasutaYunikon 0e541a19ba chore(main): release 1.13.0 2026-03-21 04:21:09 +01:00
MasutaYunikon 1d71c40a2b Merge pull request #45 from Masutayunikon/release-please--branches--main
chore(main): release 1.12.2
2026-03-21 04:20:11 +01:00
MasutaYunikon adc3e91122 chore(main): release 1.12.2 2026-03-21 04:18:31 +01:00
MasutaYunikon b260208701 Merge remote-tracking branch 'origin/main' 2026-03-21 04:18:09 +01:00
MasutaYunikon 3dd517c37f fix: use season number from resolved episodes in priority 2026-03-21 04:17:59 +01:00
MasutaYunikon 93397bee77 Merge pull request #44 from Masutayunikon/release-please--branches--main
chore(main): release 1.12.1
2026-03-21 04:00:35 +01:00
MasutaYunikon 3f72c01911 chore(main): release 1.12.1 2026-03-21 03:59:32 +01:00
MasutaYunikon 77e6a2e38c Merge remote-tracking branch 'origin/main' 2026-03-21 03:59:09 +01:00
MasutaYunikon bef99183aa fix: path 2026-03-21 03:58:55 +01:00
MasutaYunikon 7b84229510 Merge pull request #43 from Masutayunikon/release-please--branches--main
chore(main): release 1.12.0
2026-03-21 03:45:31 +01:00
MasutaYunikon 23c46a621e chore(main): release 1.12.0 2026-03-21 03:45:10 +01:00
MasutaYunikon 4dc7255bb0 Merge remote-tracking branch 'origin/main' 2026-03-21 03:44:46 +01:00
MasutaYunikon 180513c98a feat: now rename episodes with original_filename from api 2026-03-21 03:44:37 +01:00
MasutaYunikon 00894bc069 Merge pull request #42 from Masutayunikon/release-please--branches--main
chore(main): release 1.11.10
2026-03-21 03:18:52 +01:00
MasutaYunikon a1b128640d chore(main): release 1.11.10 2026-03-21 03:18:32 +01:00
MasutaYunikon 8bec4c62fa fix: improve torrent organization and cleanup logic 2026-03-21 03:18:09 +01:00
MasutaYunikon a7ba6a54a3 Merge remote-tracking branch 'origin/main' 2026-03-21 02:14:03 +01:00
MasutaYunikon 33d0b9a52d fix: season 0 not clonficting anymore 2026-03-21 02:13:52 +01:00
MasutaYunikon 46546d0178 Merge pull request #41 from Masutayunikon/release-please--branches--main
chore(main): release 1.11.9
2026-03-21 00:09:13 +01:00
MasutaYunikon 756ced0001 chore(main): release 1.11.9 2026-03-20 22:03:02 +01:00
MasutaYunikon 2addb39ba3 Merge remote-tracking branch 'origin/main' 2026-03-20 22:02:40 +01:00
MasutaYunikon 232ede4292 fix: season 0 resolved is no longer skipped in the worker 2026-03-20 22:02:17 +01:00
MasutaYunikon f161e84a1d Merge pull request #40 from Masutayunikon/release-please--branches--main
chore(main): release 1.11.8
2026-03-20 20:31:54 +01:00
MasutaYunikon 4d4a8029f6 chore(main): release 1.11.8 2026-03-20 20:31:00 +01:00
MasutaYunikon 2a1dcddd90 Merge remote-tracking branch 'origin/main' 2026-03-20 20:30:33 +01:00
MasutaYunikon 4d319f97bc fix: config path /config/config to /config 2026-03-20 20:30:23 +01:00
MasutaYunikon 3372d4cb40 Merge pull request #39 from Masutayunikon/release-please--branches--main
chore(main): release 1.11.7
2026-03-20 20:18:44 +01:00
MasutaYunikon eb22bb669f chore(main): release 1.11.7 2026-03-20 20:18:19 +01:00
MasutaYunikon 0d64a66977 Merge remote-tracking branch 'origin/main' 2026-03-20 20:17:54 +01:00
MasutaYunikon b0e81166e1 fix: worker path 2026-03-20 20:17:46 +01:00
MasutaYunikon 79d7aa7485 Merge pull request #38 from Masutayunikon/release-please--branches--main
chore(main): release 1.11.6
2026-03-20 17:30:18 +01:00
MasutaYunikon af995a84cb chore(main): release 1.11.6 2026-03-20 17:29:09 +01:00
MasutaYunikon 5a71bdca3c Merge remote-tracking branch 'origin/main' 2026-03-20 17:28:46 +01:00
MasutaYunikon 77d918fbe0 fix: path 2026-03-20 17:28:09 +01:00
MasutaYunikon a0b255338d Merge pull request #37 from Masutayunikon/release-please--branches--main
chore(main): release 1.11.5
2026-03-20 17:01:44 +01:00
MasutaYunikon e0b09c144f chore(main): release 1.11.5 2026-03-20 17:00:37 +01:00
MasutaYunikon 418d09b07f Merge remote-tracking branch 'origin/main' 2026-03-20 17:00:07 +01:00
MasutaYunikon 4c7936b019 fix: export _isBunBinary 2026-03-20 16:59:58 +01:00
MasutaYunikon 77f42b5b3e Merge pull request #36 from Masutayunikon/release-please--branches--main
chore(main): release 1.11.4
2026-03-20 16:57:17 +01:00
MasutaYunikon bd69f7a730 chore(main): release 1.11.4 2026-03-20 16:55:47 +01:00
MasutaYunikon 3ce6523248 Merge remote-tracking branch 'origin/main' 2026-03-20 16:55:16 +01:00
MasutaYunikon 2efed9dcfc fix: add config.ts with config variable (BASE_DIR...) 2026-03-20 16:55:03 +01:00
MasutaYunikon 88e2a0bc38 Merge pull request #35 from Masutayunikon/release-please--branches--main
chore(main): release 1.11.3
2026-03-20 16:08:46 +01:00
MasutaYunikon 338e3f8547 chore(main): release 1.11.3 2026-03-20 15:41:14 +01:00
MasutaYunikon d1ccc902da Merge remote-tracking branch 'origin/main' 2026-03-20 15:40:40 +01:00
MasutaYunikon 5e54e24b60 fix: entrypoint.sh config directory 2026-03-20 15:40:28 +01:00
MasutaYunikon aae2f592b5 Merge pull request #34 from Masutayunikon/release-please--branches--main
chore(main): release 1.11.2
2026-03-20 02:11:37 +01:00
MasutaYunikon bd94e6a460 chore(main): release 1.11.2 2026-03-20 02:11:01 +01:00
MasutaYunikon cbe3e1a786 Merge remote-tracking branch 'origin/main' 2026-03-20 02:10:38 +01:00
MasutaYunikon 7a0917e053 fix: port 9898, /config volume, Kaï→Kai matching, NFO pagination GitLab, saison 0 specials, JoJo/Hokuto strict season resolve
- Port par défaut 3001 → 9898
- Volume /app/data → /config (entrypoint, docker-compose, README)
- Normalisation titres Kaï/Kai dans index.ts (catalogue + déduplication + serie detail)
- Fix pagination GitLab NFO (per_page=100 → loop multi-pages)
- Fix _is_bonus_filename avec word boundaries (\b) — évite faux positifs "national"→"ona"
- Fix dossier Bonus/Specials exclus : récupère flottants (7,5/19,5) et S00Exx → saison 0
- _EP_FLOAT_PATTERN supporte virgules (7,5) en plus des points (7.5)
- Ajout strict_season dans find_episode/resolve_ep — évite collision ep1 S1 vs ep1 S2 (JoJo Parties)
- Ajout SEASON_EP_OFFSET pour Hokuto No Ken (saison 02 torrent → +16 offset API)
- Fallback non-strict si strict_season échoue (Hokuto ep 5-16 S1)
- Fix collect_covered_episodes : fallback torrent.serie_id si absent dans resolved_episodes
- Fix s6_verify : get_all_specials + compteur S00 séparé, déduplication Kaï/Kai, format OK/TOTAL
- Ajout MANUAL_TORRENTS dans s4 (MHA Film 4 You're Next URL Nyaa)
- Injection torrents locaux manquants dans pipeline (Reborn! Kaï via fichier local)
- Fix s5 : résolution directe torrents manuels season_number=0
- Fix s2 : pack_saga_slash et pack_partie_slash → pack_integrale, lookahead (?<!/) sur episode_num_tiret_apres
- Fix s5 skip condition : re-résoudre si resolved_count < files_count (Fairy Tail)
- README : note hardlinks volumes multiples, port, chemins config
2026-03-20 02:10:27 +01:00
MasutaYunikon 8ac4f7a65b Merge pull request #33 from Masutayunikon/release-please--branches--main
chore(main): release 1.11.1
2026-03-14 00:59:14 +01:00
MasutaYunikon 453cd47e85 chore(main): release 1.11.1 2026-03-14 00:58:57 +01:00
MasutaYunikon d5679ec529 Merge remote-tracking branch 'origin/main' 2026-03-14 00:58:37 +01:00
MasutaYunikon 2f0be502c3 fix: worker now work on multiple github files pages 2026-03-14 00:58:29 +01:00
MasutaYunikon ec971915b5 Merge pull request #32 from Masutayunikon/release-please--branches--main
chore(main): release 1.11.0
2026-03-13 19:03:34 +01:00
MasutaYunikon bb71b241d1 chore(main): release 1.11.0 2026-03-13 19:03:16 +01:00
MasutaYunikon 7aa01755ec Merge remote-tracking branch 'origin/main' 2026-03-13 19:02:46 +01:00
MasutaYunikon 8ce0ca1f24 feat: fix worker for multiple series in integral (one piece fix ?) 2026-03-13 19:02:38 +01:00
MasutaYunikon 620aac6b38 Merge pull request #31 from Masutayunikon/release-please--branches--main
chore(main): release 1.10.3
2026-03-13 04:35:00 +01:00
MasutaYunikon e99e413e4e chore(main): release 1.10.3 2026-03-13 04:34:21 +01:00
MasutaYunikon fb578cf9f9 Merge remote-tracking branch 'origin/main' 2026-03-13 04:34:00 +01:00
MasutaYunikon 78e3055344 fix: worker path 2026-03-13 04:33:51 +01:00
MasutaYunikon 15f5847c97 Merge pull request #30 from Masutayunikon/release-please--branches--main
chore(main): release 1.10.2
2026-03-13 04:25:54 +01:00
MasutaYunikon 8736b58d8c chore(main): release 1.10.2 2026-03-13 04:25:39 +01:00
MasutaYunikon 12e8e2f93a Merge remote-tracking branch 'origin/main' 2026-03-13 04:25:17 +01:00
MasutaYunikon ed2306bb70 fix: add target node 2026-03-13 04:25:09 +01:00
MasutaYunikon b3fd57c2c8 Merge pull request #29 from Masutayunikon/release-please--branches--main
chore(main): release 1.10.1
2026-03-13 04:22:24 +01:00
MasutaYunikon c2da12409a chore(main): release 1.10.1 2026-03-13 04:22:06 +01:00
MasutaYunikon 178a57c444 Merge remote-tracking branch 'origin/main' 2026-03-13 04:21:42 +01:00
MasutaYunikon 1afe13c555 fix: add target node 2026-03-13 04:21:34 +01:00
MasutaYunikon c8963cc4cf Merge pull request #28 from Masutayunikon/release-please--branches--main
chore(main): release 1.10.0
2026-03-13 04:19:01 +01:00
MasutaYunikon 391b793e39 chore(main): release 1.10.0 2026-03-13 04:18:23 +01:00
MasutaYunikon 9a1519e6cd Merge pull request #27 from Masutayunikon/release-please--branches--main
chore(main): release 1.9.5
2026-03-13 04:17:27 +01:00
MasutaYunikon a12237af68 chore(main): release 1.9.5 2026-03-13 04:16:50 +01:00
MasutaYunikon d304aa6a26 Merge remote-tracking branch 'origin/main' 2026-03-13 04:16:29 +01:00
MasutaYunikon 27092b3968 fix: worker outside the exe 2026-03-13 04:16:07 +01:00
MasutaYunikon c1c36018b1 Merge pull request #26 from Masutayunikon/release-please--branches--main
chore(main): release 1.9.4
2026-03-13 04:12:38 +01:00
MasutaYunikon b462ec717b chore(main): release 1.9.4 2026-03-13 04:11:56 +01:00
MasutaYunikon 65518861ac Merge remote-tracking branch 'origin/main' 2026-03-13 04:11:36 +01:00
MasutaYunikon ed75280e70 fix: worker outside the exe 2026-03-13 04:11:27 +01:00
MasutaYunikon 9f53a9fef5 Merge pull request #25 from Masutayunikon/release-please--branches--main
chore(main): release 1.9.3
2026-03-13 04:02:39 +01:00
MasutaYunikon 3e5dc8d1d4 chore(main): release 1.9.3 2026-03-13 04:02:06 +01:00
MasutaYunikon bcb7f656a1 Merge remote-tracking branch 'origin/main' 2026-03-13 04:01:43 +01:00
MasutaYunikon 372359d040 fix: use bcryptjs for compilation 2026-03-13 04:01:34 +01:00
21 changed files with 1217 additions and 570 deletions

No files matched your search

+1 -1
View File
@@ -2,7 +2,7 @@ node_modules
.git .git
.gitignore .gitignore
*.md *.md
data config
.env .env
.env.* .env.*
!.env.example !.env.example
+5 -2
View File
@@ -97,16 +97,19 @@ jobs:
bun build server/index.ts --compile --target ${{ matrix.bun-target }} --outfile ${{ matrix.binary }} bun build server/index.ts --compile --target ${{ matrix.bun-target }} --outfile ${{ matrix.binary }}
shell: pwsh shell: pwsh
- name: Build worker
run: bun build server/organize-worker.ts --target node --outfile organize-worker.js
- name: Package archive (Windows) - name: Package archive (Windows)
if: matrix.target == 'windows-x64' if: matrix.target == 'windows-x64'
run: Compress-Archive -Path ${{ matrix.binary }}, public -DestinationPath ${{ matrix.archive }} run: Compress-Archive -Path ${{ matrix.binary }}, organize-worker.js, public -DestinationPath ${{ matrix.archive }}
shell: pwsh shell: pwsh
- name: Package archive (Unix) - name: Package archive (Unix)
if: matrix.target != 'windows-x64' if: matrix.target != 'windows-x64'
run: | run: |
chmod +x ${{ matrix.binary }} chmod +x ${{ matrix.binary }}
zip -r ${{ matrix.archive }} ${{ matrix.binary }} public/ zip -r ${{ matrix.archive }} ${{ matrix.binary }} organize-worker.js public/
- name: Upload archive to Release - name: Upload archive to Release
uses: softprops/action-gh-release@v2 uses: softprops/action-gh-release@v2
+336
View File
@@ -1,5 +1,341 @@
# Changelog # Changelog
## [2.2.0](https://github.com/Masutayunikon/FanKarr/compare/v2.1.3...v2.2.0) (2026-03-23)
### Features
* add organize all button ([bbaccfd](https://github.com/Masutayunikon/FanKarr/commit/bbaccfd97b51724932f2ebf22cad81be1cde61c0))
### Bug Fixes
* organizer reuse the wrong name for gitlab path ([bbaccfd](https://github.com/Masutayunikon/FanKarr/commit/bbaccfd97b51724932f2ebf22cad81be1cde61c0))
## [2.1.3](https://github.com/Masutayunikon/FanKarr/compare/v2.1.2...v2.1.3) (2026-03-23)
### Bug Fixes
* use magnet before torrent ([ed4665a](https://github.com/Masutayunikon/FanKarr/commit/ed4665a378d15c0b45a2be32d612e41082a43df1))
## [2.1.2](https://github.com/Masutayunikon/FanKarr/compare/v2.1.1...v2.1.2) (2026-03-23)
### Bug Fixes
* path now work on every device ([cfc3440](https://github.com/Masutayunikon/FanKarr/commit/cfc3440a95cb73802778e01d5f256f473e0cc952))
## [2.1.1](https://github.com/Masutayunikon/FanKarr/compare/v2.1.0...v2.1.1) (2026-03-23)
### Bug Fixes
* torrent path to hash ([d9e453b](https://github.com/Masutayunikon/FanKarr/commit/d9e453b486b9fd85b69ee134bee2bd6a1a6d3702))
## [2.1.0](https://github.com/Masutayunikon/FanKarr/compare/v2.0.0...v2.1.0) (2026-03-23)
### ⚠ BREAKING CHANGES
* **organize:** le format paths[] dans series/{id}.json passe de string[] à { infohash: string, path: string }[] — nécessite une mise à jour du scraper.
### Bug Fixes
* **organize:** buildFileMap matche par infohash au lieu d'index ou titre ([43ac2ed](https://github.com/Masutayunikon/FanKarr/commit/43ac2ed2e85d9e769735547817f19100d3d7f980))
* **organize:** migration vers paths { infohash, path } pour le matching fichiers ([43ac2ed](https://github.com/Masutayunikon/FanKarr/commit/43ac2ed2e85d9e769735547817f19100d3d7f980))
* **organize:** scanMediaPath adapté au nouveau format paths[] ([43ac2ed](https://github.com/Masutayunikon/FanKarr/commit/43ac2ed2e85d9e769735547817f19100d3d7f980))
* **organize:** source fichier via save_path qBittorrent + fullPath relatif ([43ac2ed](https://github.com/Masutayunikon/FanKarr/commit/43ac2ed2e85d9e769735547817f19100d3d7f980))
* remove logo ([48416c4](https://github.com/Masutayunikon/FanKarr/commit/48416c4fef3a964b05aa135ffd9e80d5dec9a81a))
## [2.0.0](https://github.com/Masutayunikon/FanKarr/compare/v1.14.0...v2.0.0) (2026-03-23)
### ⚠ BREAKING CHANGES
* suppression de torrent_final.json au profit d'un système de fichiers par série (series/{id}.json) avec cache mémoire GitHub 6h. Version majeure — nécessite un nouveau scraper et une mise à jour complète.
### Features
* **api:** adaptation complète à la nouvelle structure API Fankai ([b3fd7dd](https://github.com/Masutayunikon/FanKarr/commit/b3fd7dded40bf067acc8552cbf5f34a57d27000c))
* **api:** cache mémoire GitHub TTL 6h avec invalidation via /api/update ([b3fd7dd](https://github.com/Masutayunikon/FanKarr/commit/b3fd7dded40bf067acc8552cbf5f34a57d27000c))
* **api:** matching torrents par hiérarchie série/saison/épisode ([b3fd7dd](https://github.com/Masutayunikon/FanKarr/commit/b3fd7dded40bf067acc8552cbf5f34a57d27000c))
* migration vers nouvelle architecture API et scraper par série ([b3fd7dd](https://github.com/Masutayunikon/FanKarr/commit/b3fd7dded40bf067acc8552cbf5f34a57d27000c))
* **organize:** refonte complète sans torrent_final.json ([b3fd7dd](https://github.com/Masutayunikon/FanKarr/commit/b3fd7dded40bf067acc8552cbf5f34a57d27000c))
* **scraper:** extraction nom bencode dans raw pour torrents locaux ([b3fd7dd](https://github.com/Masutayunikon/FanKarr/commit/b3fd7dded40bf067acc8552cbf5f34a57d27000c))
* **series-view:** badge "Hors Fankai" sur épisodes de torrents manuels ([b3fd7dd](https://github.com/Masutayunikon/FanKarr/commit/b3fd7dded40bf067acc8552cbf5f34a57d27000c))
* **series-view:** tooltip raw name sur boutons intégrale via :title ([b3fd7dd](https://github.com/Masutayunikon/FanKarr/commit/b3fd7dded40bf067acc8552cbf5f34a57d27000c))
### Bug Fixes
* **catalogue:** état download basé sur épisodes organisés vs torrents bruts ([b3fd7dd](https://github.com/Masutayunikon/FanKarr/commit/b3fd7dded40bf067acc8552cbf5f34a57d27000c))
* **series:** boutons saison Yu-Gi-Oh via fallback season_number ([b3fd7dd](https://github.com/Masutayunikon/FanKarr/commit/b3fd7dded40bf067acc8552cbf5f34a57d27000c))
## [1.14.0](https://github.com/Masutayunikon/FanKarr/compare/v1.13.0...v1.14.0) (2026-03-21)
### Features
* **scraper:** extraction du nom bencode pour les torrents locaux ([67237e9](https://github.com/Masutayunikon/FanKarr/commit/67237e977e34edda4d92a9375de4c4e470725eb1))
* **series-view:** badge "Hors Fankai" sur les épisodes de torrents manuels ([67237e9](https://github.com/Masutayunikon/FanKarr/commit/67237e977e34edda4d92a9375de4c4e470725eb1))
* **series-view:** tooltip avec le nom du torrent sur les boutons intégrale ([67237e9](https://github.com/Masutayunikon/FanKarr/commit/67237e977e34edda4d92a9375de4c4e470725eb1))
### Bug Fixes
* **catalogue:** état "partiel" incorrect quand l'intégrale est organisée ([67237e9](https://github.com/Masutayunikon/FanKarr/commit/67237e977e34edda4d92a9375de4c4e470725eb1))
* **series:** résolution boutons de téléchargement saisons Yu-Gi-Oh et séries similaires ([67237e9](https://github.com/Masutayunikon/FanKarr/commit/67237e977e34edda4d92a9375de4c4e470725eb1))
## [1.13.0](https://github.com/Masutayunikon/FanKarr/compare/v1.12.2...v1.13.0) (2026-03-21)
### Features
* add favicon ([dc4a2d4](https://github.com/Masutayunikon/FanKarr/commit/dc4a2d48f5c0cddd8e431ce33a69fc9146143fb6))
* add README.md ([4eb487a](https://github.com/Masutayunikon/FanKarr/commit/4eb487a96beed8c82cb19d9a9b63c3b69d841386))
* add windows / linux / macos binaries on build ([f17a73b](https://github.com/Masutayunikon/FanKarr/commit/f17a73b9591fb49a75bd5fcdadf1970585877dab))
* **auth:** génération automatique du JWT secret au démarrage ([eaa52e9](https://github.com/Masutayunikon/FanKarr/commit/eaa52e90900ff0e198beae190d7ad0298a702482))
* cache images ([da460de](https://github.com/Masutayunikon/FanKarr/commit/da460de60c4eec6851ea58ce0ae646a1208f6018))
* fix worker for multiple series in integral (one piece fix ?) ([2c773f8](https://github.com/Masutayunikon/FanKarr/commit/2c773f83ffd76d82c77a50a9c5729f20ea22b450))
* initial project ([eaf01cf](https://github.com/Masutayunikon/FanKarr/commit/eaf01cfc591dd72f9b093b533ced6c12a6c490a1))
* make the organizer threaded to not consumme api main thread ([14c0e56](https://github.com/Masutayunikon/FanKarr/commit/14c0e567525e179da82c6b58d9886cc3d544a98d))
* now rename episodes with original_filename from api ([9bdb21a](https://github.com/Masutayunikon/FanKarr/commit/9bdb21a673ebb9871548aea6691bafbd049554ce))
* **organize:** scan initial mediaPath + logs fichier centralisés ([807f786](https://github.com/Masutayunikon/FanKarr/commit/807f786b038579ca9d7cd136998f759cecae2255))
* **organize:** worker thread + badges statut + notifications ([b7242bc](https://github.com/Masutayunikon/FanKarr/commit/b7242bc95f59d259ab1a636aa304bf149f895041))
* **serie:** badges état organisation sur épisodes et saisons ([4d3a6bd](https://github.com/Masutayunikon/FanKarr/commit/4d3a6bd276907f793452429d62693fafc1d804db))
* **ui:** états catalogue + logs + badges erreurs downloads ([5326828](https://github.com/Masutayunikon/FanKarr/commit/5326828d89aa10a53bbe1ac4016a5eee4d5dbc97))
* UX improvements, folder picker, download state & NFO support ([20771fc](https://github.com/Masutayunikon/FanKarr/commit/20771fc31c187fd1fea8aa9b07093b15621a5b85))
### Bug Fixes
* add config.ts with config variable (BASE_DIR...) ([a3eb67c](https://github.com/Masutayunikon/FanKarr/commit/a3eb67c9a0944500142a6636d57cae0acfd7543d))
* add log for debug ([6876c5e](https://github.com/Masutayunikon/FanKarr/commit/6876c5ee6c7734e664a6da4e4bc721cc7c5abdf7))
* add log for debug ([d8cdeae](https://github.com/Masutayunikon/FanKarr/commit/d8cdeae675bc73b5842d18d01eff9d5bb0e0a7e8))
* add target node ([58b09f2](https://github.com/Masutayunikon/FanKarr/commit/58b09f2267345c60ed589c160f7e47698e9be9a4))
* add target node ([6c629e0](https://github.com/Masutayunikon/FanKarr/commit/6c629e0f6b4d38453cfb22fd315e02d9e8750c45))
* add user permissions when the scripts is launched ([501bbfc](https://github.com/Masutayunikon/FanKarr/commit/501bbfcf18c236f7ac382c50d90482b1f51244c1))
* CatalogView.vue badge deleted ([d897192](https://github.com/Masutayunikon/FanKarr/commit/d8971920462efd8d1d99eb867016c96713dfef58))
* config path /config/config to /config ([7518191](https://github.com/Masutayunikon/FanKarr/commit/75181910244621a8eca989067fd4777922914d8e))
* docker errors ([2702764](https://github.com/Masutayunikon/FanKarr/commit/27027642eb55b75adb04446a88e5007e88f75948))
* docker is able to change directory ([af08f7d](https://github.com/Masutayunikon/FanKarr/commit/af08f7d9d4fb2e23c5feac6d33b2ef495f9d91b2))
* empty docker-compose.yml ([303dfd8](https://github.com/Masutayunikon/FanKarr/commit/303dfd85b5d033e2b247fd064ae1ae612fdb49e1))
* entrypoint.sh config directory ([7e4b2fa](https://github.com/Masutayunikon/FanKarr/commit/7e4b2fa60a5946d3220618f13420a07fa57e8e1b))
* export _isBunBinary ([3d43de3](https://github.com/Masutayunikon/FanKarr/commit/3d43de3eb223ec0338e0b9aebffff35e116e00a0))
* improve torrent organization and cleanup logic ([1908cb3](https://github.com/Masutayunikon/FanKarr/commit/1908cb3e8c5b99e91e26735f7cfa3dcd23709df7))
* logger third args ([5abac1e](https://github.com/Masutayunikon/FanKarr/commit/5abac1e11236ed1e8f7f0de7f0cff881d1b60f10))
* nfo settings and add json file when not existing ([0b6bfa6](https://github.com/Masutayunikon/FanKarr/commit/0b6bfa6a81d99353be877ed6d99687ad3d55adbc))
* organize file ([d6550e9](https://github.com/Masutayunikon/FanKarr/commit/d6550e9961789073be1583e03d599afb6d295004))
* organize use torrent hash and not name ([61901f9](https://github.com/Masutayunikon/FanKarr/commit/61901f9014a759e2950311cd96266ea8201fa902))
* path ([7ddd9ca](https://github.com/Masutayunikon/FanKarr/commit/7ddd9cad9271d79a258f45245bf405f13b9d764f))
* path ([0329ee2](https://github.com/Masutayunikon/FanKarr/commit/0329ee27a34038456eb297f07b808de3157d88f4))
* path ([314f817](https://github.com/Masutayunikon/FanKarr/commit/314f817280f39d10eb21c4784f2aea41b9a6d32c))
* port 9898, /config volume, Kaï→Kai matching, NFO pagination GitLab, saison 0 specials, JoJo/Hokuto strict season resolve ([3a278ba](https://github.com/Masutayunikon/FanKarr/commit/3a278ba33388d6ff6f33413d7696d58d0172c953))
* remove user creation in entrypoint.sh ([92d9fa6](https://github.com/Masutayunikon/FanKarr/commit/92d9fa6b01f1e2de1ceb13528afd309b21f9d4cb))
* rename if the torrent name is not the same as the api ([b8fcf71](https://github.com/Masutayunikon/FanKarr/commit/b8fcf71f54ab14e5572a7553d8554b617b4981b7))
* season 0 not clonficting anymore ([635082d](https://github.com/Masutayunikon/FanKarr/commit/635082de00bb42bdeaf20b1654f742ad1c4addbe))
* season 0 resolved is no longer skipped in the worker ([c48ec76](https://github.com/Masutayunikon/FanKarr/commit/c48ec769ba7725327e657366e882498846d0c63f))
* season fallback ([e9b5091](https://github.com/Masutayunikon/FanKarr/commit/e9b5091242d73be77bf6fb525ce2865554e336cc))
* skip excluded folders ([edf806d](https://github.com/Masutayunikon/FanKarr/commit/edf806d9bc48d4de1c3609a4b0405442305d546e))
* title readme align ([8ba3b37](https://github.com/Masutayunikon/FanKarr/commit/8ba3b370d1e2cd1565f9c2453be8706e3c198243))
* use bcryptjs for compilation ([6a6981e](https://github.com/Masutayunikon/FanKarr/commit/6a6981e10a3a9019f49982d7680e562872ee95a5))
* use season number from resolved episodes in priority ([dc48634](https://github.com/Masutayunikon/FanKarr/commit/dc486347193a8066a32d8f0106518abc2b04b7e2))
* worker now work on multiple github files pages ([71784cd](https://github.com/Masutayunikon/FanKarr/commit/71784cd8bd8f3ea5dc7423687b080c1588d70854))
* worker outside the exe ([c2ab58e](https://github.com/Masutayunikon/FanKarr/commit/c2ab58e7b2c34aae09b50dbdfde3277da4c276ff))
* worker outside the exe ([a47c3a4](https://github.com/Masutayunikon/FanKarr/commit/a47c3a43fb5dbbedd87c9ac2d584c3290fcc6097))
* worker path ([3df8def](https://github.com/Masutayunikon/FanKarr/commit/3df8defa5e46b09722a345c7c3a94e91aa16e4d8))
* worker path ([360572b](https://github.com/Masutayunikon/FanKarr/commit/360572b8be64dafbb452dfcb849a40305bf1b8cf))
* workflow directory ([baebd8f](https://github.com/Masutayunikon/FanKarr/commit/baebd8fae146db70ee1cce0c876d2d3bc0f9bf4e))
* workflow directory ([d8405c1](https://github.com/Masutayunikon/FanKarr/commit/d8405c1589f277cd8fdd3e1fd15cc02d98834aa6))
* workflow permmisions ([3620bfb](https://github.com/Masutayunikon/FanKarr/commit/3620bfb71d8c2774b23c097e5e01326099c2f180))
## [1.12.2](https://github.com/Masutayunikon/FanKarr/compare/v1.12.1...v1.12.2) (2026-03-21)
### Bug Fixes
* use season number from resolved episodes in priority ([dc48634](https://github.com/Masutayunikon/FanKarr/commit/dc486347193a8066a32d8f0106518abc2b04b7e2))
## [1.12.1](https://github.com/Masutayunikon/FanKarr/compare/v1.12.0...v1.12.1) (2026-03-21)
### Bug Fixes
* path ([7ddd9ca](https://github.com/Masutayunikon/FanKarr/commit/7ddd9cad9271d79a258f45245bf405f13b9d764f))
## [1.12.0](https://github.com/Masutayunikon/FanKarr/compare/v1.11.10...v1.12.0) (2026-03-21)
### Features
* now rename episodes with original_filename from api ([9bdb21a](https://github.com/Masutayunikon/FanKarr/commit/9bdb21a673ebb9871548aea6691bafbd049554ce))
## [1.11.10](https://github.com/Masutayunikon/FanKarr/compare/v1.11.9...v1.11.10) (2026-03-21)
### Bug Fixes
* improve torrent organization and cleanup logic ([1908cb3](https://github.com/Masutayunikon/FanKarr/commit/1908cb3e8c5b99e91e26735f7cfa3dcd23709df7))
* season 0 not clonficting anymore ([635082d](https://github.com/Masutayunikon/FanKarr/commit/635082de00bb42bdeaf20b1654f742ad1c4addbe))
## [1.11.9](https://github.com/Masutayunikon/FanKarr/compare/v1.11.8...v1.11.9) (2026-03-20)
### Bug Fixes
* season 0 resolved is no longer skipped in the worker ([c48ec76](https://github.com/Masutayunikon/FanKarr/commit/c48ec769ba7725327e657366e882498846d0c63f))
## [1.11.8](https://github.com/Masutayunikon/FanKarr/compare/v1.11.7...v1.11.8) (2026-03-20)
### Bug Fixes
* config path /config/config to /config ([7518191](https://github.com/Masutayunikon/FanKarr/commit/75181910244621a8eca989067fd4777922914d8e))
## [1.11.7](https://github.com/Masutayunikon/FanKarr/compare/v1.11.6...v1.11.7) (2026-03-20)
### Bug Fixes
* worker path ([3df8def](https://github.com/Masutayunikon/FanKarr/commit/3df8defa5e46b09722a345c7c3a94e91aa16e4d8))
## [1.11.6](https://github.com/Masutayunikon/FanKarr/compare/v1.11.5...v1.11.6) (2026-03-20)
### Bug Fixes
* path ([0329ee2](https://github.com/Masutayunikon/FanKarr/commit/0329ee27a34038456eb297f07b808de3157d88f4))
## [1.11.5](https://github.com/Masutayunikon/FanKarr/compare/v1.11.4...v1.11.5) (2026-03-20)
### Bug Fixes
* export _isBunBinary ([3d43de3](https://github.com/Masutayunikon/FanKarr/commit/3d43de3eb223ec0338e0b9aebffff35e116e00a0))
## [1.11.4](https://github.com/Masutayunikon/FanKarr/compare/v1.11.3...v1.11.4) (2026-03-20)
### Bug Fixes
* add config.ts with config variable (BASE_DIR...) ([a3eb67c](https://github.com/Masutayunikon/FanKarr/commit/a3eb67c9a0944500142a6636d57cae0acfd7543d))
## [1.11.3](https://github.com/Masutayunikon/FanKarr/compare/v1.11.2...v1.11.3) (2026-03-20)
### Bug Fixes
* entrypoint.sh config directory ([7e4b2fa](https://github.com/Masutayunikon/FanKarr/commit/7e4b2fa60a5946d3220618f13420a07fa57e8e1b))
## [1.11.2](https://github.com/Masutayunikon/FanKarr/compare/v1.11.1...v1.11.2) (2026-03-20)
### Bug Fixes
* port 9898, /config volume, Kaï→Kai matching, NFO pagination GitLab, saison 0 specials, JoJo/Hokuto strict season resolve ([3a278ba](https://github.com/Masutayunikon/FanKarr/commit/3a278ba33388d6ff6f33413d7696d58d0172c953))
## [1.11.1](https://github.com/Masutayunikon/FanKarr/compare/v1.11.0...v1.11.1) (2026-03-13)
### Bug Fixes
* worker now work on multiple github files pages ([71784cd](https://github.com/Masutayunikon/FanKarr/commit/71784cd8bd8f3ea5dc7423687b080c1588d70854))
## [1.11.0](https://github.com/Masutayunikon/FanKarr/compare/v1.10.3...v1.11.0) (2026-03-13)
### Features
* fix worker for multiple series in integral (one piece fix ?) ([2c773f8](https://github.com/Masutayunikon/FanKarr/commit/2c773f83ffd76d82c77a50a9c5729f20ea22b450))
## [1.10.3](https://github.com/Masutayunikon/FanKarr/compare/v1.10.2...v1.10.3) (2026-03-13)
### Bug Fixes
* worker path ([360572b](https://github.com/Masutayunikon/FanKarr/commit/360572b8be64dafbb452dfcb849a40305bf1b8cf))
## [1.10.2](https://github.com/Masutayunikon/FanKarr/compare/v1.10.1...v1.10.2) (2026-03-13)
### Bug Fixes
* add target node ([58b09f2](https://github.com/Masutayunikon/FanKarr/commit/58b09f2267345c60ed589c160f7e47698e9be9a4))
## [1.10.1](https://github.com/Masutayunikon/FanKarr/compare/v1.10.0...v1.10.1) (2026-03-13)
### Bug Fixes
* add target node ([6c629e0](https://github.com/Masutayunikon/FanKarr/commit/6c629e0f6b4d38453cfb22fd315e02d9e8750c45))
## [1.10.0](https://github.com/Masutayunikon/FanKarr/compare/v1.9.5...v1.10.0) (2026-03-13)
### Features
* add favicon ([dc4a2d4](https://github.com/Masutayunikon/FanKarr/commit/dc4a2d48f5c0cddd8e431ce33a69fc9146143fb6))
* add README.md ([4eb487a](https://github.com/Masutayunikon/FanKarr/commit/4eb487a96beed8c82cb19d9a9b63c3b69d841386))
* add windows / linux / macos binaries on build ([f17a73b](https://github.com/Masutayunikon/FanKarr/commit/f17a73b9591fb49a75bd5fcdadf1970585877dab))
* **auth:** génération automatique du JWT secret au démarrage ([eaa52e9](https://github.com/Masutayunikon/FanKarr/commit/eaa52e90900ff0e198beae190d7ad0298a702482))
* cache images ([da460de](https://github.com/Masutayunikon/FanKarr/commit/da460de60c4eec6851ea58ce0ae646a1208f6018))
* initial project ([eaf01cf](https://github.com/Masutayunikon/FanKarr/commit/eaf01cfc591dd72f9b093b533ced6c12a6c490a1))
* make the organizer threaded to not consumme api main thread ([14c0e56](https://github.com/Masutayunikon/FanKarr/commit/14c0e567525e179da82c6b58d9886cc3d544a98d))
* **organize:** scan initial mediaPath + logs fichier centralisés ([807f786](https://github.com/Masutayunikon/FanKarr/commit/807f786b038579ca9d7cd136998f759cecae2255))
* **organize:** worker thread + badges statut + notifications ([b7242bc](https://github.com/Masutayunikon/FanKarr/commit/b7242bc95f59d259ab1a636aa304bf149f895041))
* **serie:** badges état organisation sur épisodes et saisons ([4d3a6bd](https://github.com/Masutayunikon/FanKarr/commit/4d3a6bd276907f793452429d62693fafc1d804db))
* **ui:** états catalogue + logs + badges erreurs downloads ([5326828](https://github.com/Masutayunikon/FanKarr/commit/5326828d89aa10a53bbe1ac4016a5eee4d5dbc97))
* UX improvements, folder picker, download state & NFO support ([20771fc](https://github.com/Masutayunikon/FanKarr/commit/20771fc31c187fd1fea8aa9b07093b15621a5b85))
### 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))
* add user permissions when the scripts is launched ([501bbfc](https://github.com/Masutayunikon/FanKarr/commit/501bbfcf18c236f7ac382c50d90482b1f51244c1))
* CatalogView.vue badge deleted ([d897192](https://github.com/Masutayunikon/FanKarr/commit/d8971920462efd8d1d99eb867016c96713dfef58))
* docker errors ([2702764](https://github.com/Masutayunikon/FanKarr/commit/27027642eb55b75adb04446a88e5007e88f75948))
* docker is able to change directory ([af08f7d](https://github.com/Masutayunikon/FanKarr/commit/af08f7d9d4fb2e23c5feac6d33b2ef495f9d91b2))
* empty docker-compose.yml ([303dfd8](https://github.com/Masutayunikon/FanKarr/commit/303dfd85b5d033e2b247fd064ae1ae612fdb49e1))
* logger third args ([5abac1e](https://github.com/Masutayunikon/FanKarr/commit/5abac1e11236ed1e8f7f0de7f0cff881d1b60f10))
* nfo settings and add json file when not existing ([0b6bfa6](https://github.com/Masutayunikon/FanKarr/commit/0b6bfa6a81d99353be877ed6d99687ad3d55adbc))
* organize file ([d6550e9](https://github.com/Masutayunikon/FanKarr/commit/d6550e9961789073be1583e03d599afb6d295004))
* organize use torrent hash and not name ([61901f9](https://github.com/Masutayunikon/FanKarr/commit/61901f9014a759e2950311cd96266ea8201fa902))
* path ([314f817](https://github.com/Masutayunikon/FanKarr/commit/314f817280f39d10eb21c4784f2aea41b9a6d32c))
* remove user creation in entrypoint.sh ([92d9fa6](https://github.com/Masutayunikon/FanKarr/commit/92d9fa6b01f1e2de1ceb13528afd309b21f9d4cb))
* rename if the torrent name is not the same as the api ([b8fcf71](https://github.com/Masutayunikon/FanKarr/commit/b8fcf71f54ab14e5572a7553d8554b617b4981b7))
* season fallback ([e9b5091](https://github.com/Masutayunikon/FanKarr/commit/e9b5091242d73be77bf6fb525ce2865554e336cc))
* skip excluded folders ([edf806d](https://github.com/Masutayunikon/FanKarr/commit/edf806d9bc48d4de1c3609a4b0405442305d546e))
* title readme align ([8ba3b37](https://github.com/Masutayunikon/FanKarr/commit/8ba3b370d1e2cd1565f9c2453be8706e3c198243))
* use bcryptjs for compilation ([6a6981e](https://github.com/Masutayunikon/FanKarr/commit/6a6981e10a3a9019f49982d7680e562872ee95a5))
* worker outside the exe ([c2ab58e](https://github.com/Masutayunikon/FanKarr/commit/c2ab58e7b2c34aae09b50dbdfde3277da4c276ff))
* worker outside the exe ([a47c3a4](https://github.com/Masutayunikon/FanKarr/commit/a47c3a43fb5dbbedd87c9ac2d584c3290fcc6097))
* workflow directory ([baebd8f](https://github.com/Masutayunikon/FanKarr/commit/baebd8fae146db70ee1cce0c876d2d3bc0f9bf4e))
* workflow directory ([d8405c1](https://github.com/Masutayunikon/FanKarr/commit/d8405c1589f277cd8fdd3e1fd15cc02d98834aa6))
* workflow permmisions ([3620bfb](https://github.com/Masutayunikon/FanKarr/commit/3620bfb71d8c2774b23c097e5e01326099c2f180))
## [1.9.5](https://github.com/Masutayunikon/FanKarr/compare/v1.9.4...v1.9.5) (2026-03-13)
### Bug Fixes
* worker outside the exe ([c2ab58e](https://github.com/Masutayunikon/FanKarr/commit/c2ab58e7b2c34aae09b50dbdfde3277da4c276ff))
## [1.9.4](https://github.com/Masutayunikon/FanKarr/compare/v1.9.3...v1.9.4) (2026-03-13)
### Bug Fixes
* worker outside the exe ([a47c3a4](https://github.com/Masutayunikon/FanKarr/commit/a47c3a43fb5dbbedd87c9ac2d584c3290fcc6097))
## [1.9.3](https://github.com/Masutayunikon/FanKarr/compare/v1.9.2...v1.9.3) (2026-03-13)
### Bug Fixes
* use bcryptjs for compilation ([6a6981e](https://github.com/Masutayunikon/FanKarr/commit/6a6981e10a3a9019f49982d7680e562872ee95a5))
## [1.9.2](https://github.com/Masutayunikon/FanKarr/compare/v1.9.1...v1.9.2) (2026-03-13) ## [1.9.2](https://github.com/Masutayunikon/FanKarr/compare/v1.9.1...v1.9.2) (2026-03-13)
+1 -1
View File
@@ -24,7 +24,7 @@ COPY --from=build /app/dist/server /app/dist/server
COPY --from=build /app/dist/client /app/public COPY --from=build /app/dist/client /app/public
COPY entrypoint.sh /entrypoint.sh COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh RUN chmod +x /entrypoint.sh
RUN mkdir -p /app/data RUN mkdir -p /config
EXPOSE 3001 EXPOSE 3001
ENV NODE_ENV=production ENV NODE_ENV=production
+29 -27
View File
@@ -2,7 +2,6 @@
# Fankarr # Fankarr
![Version](https://img.shields.io/github/v/release/masutayunikon/fankarr?style=flat-square&color=e8513a&label=version) ![Version](https://img.shields.io/github/v/release/masutayunikon/fankarr?style=flat-square&color=e8513a&label=version)
![Docker Image Size](https://img.shields.io/docker/image-size/masutayunikon/fankarr/latest?style=flat-square&color=1e2d3d&label=image) ![Docker Image Size](https://img.shields.io/docker/image-size/masutayunikon/fankarr/latest?style=flat-square&color=1e2d3d&label=image)
![Docker Pulls](https://img.shields.io/docker/pulls/masutayunikon/fankarr?style=flat-square&color=1e2d3d) ![Docker Pulls](https://img.shields.io/docker/pulls/masutayunikon/fankarr?style=flat-square&color=1e2d3d)
@@ -11,7 +10,7 @@
![Node](https://img.shields.io/badge/node-20-5a7a94?style=flat-square) ![Node](https://img.shields.io/badge/node-20-5a7a94?style=flat-square)
![Vue](https://img.shields.io/badge/vue-3-42b883?style=flat-square) ![Vue](https://img.shields.io/badge/vue-3-42b883?style=flat-square)
**Gestionnaire de téléchargements pour le catalogue [Fankai](https://fankai.fr)** **Gestionnaire de téléchargements pour le catalogue [Fankai](https://fankai.fr)**
Inspiré de Radarr/Sonarr — interface dédiée aux éditions Kai & Yabai Inspiré de Radarr/Sonarr — interface dédiée aux éditions Kai & Yabai
</div> </div>
@@ -83,11 +82,10 @@ services:
- PGID=1000 # GID de votre utilisateur (id -g) - PGID=1000 # GID de votre utilisateur (id -g)
- TZ=Europe/Paris # Votre timezone - TZ=Europe/Paris # Votre timezone
volumes: volumes:
- ./data:/app/data # Config, logs, base de données - ./config:/config # Config, logs, base de données
- /votre/chemin/media:/media/Kai # Destination Jellyfin - /votre/chemin:/media # Racine de votre médiathèque (voir note hardlinks)
- /votre/chemin/complete:/downloads/complete # Dossier complétés qBittorrent
ports: ports:
- 3001:3001 - 9898:9898
restart: unless-stopped restart: unless-stopped
``` ```
@@ -95,15 +93,19 @@ services:
docker compose up -d docker compose up -d
``` ```
> **⚠️ Note sur les hardlinks** : Pour que le mode `hardlink` fonctionne, vos dossiers de téléchargement complets et votre médiathèque doivent être sur le **même filesystem**. La solution recommandée est de monter un seul volume racine (ex: `/votre/chemin:/media`) et de configurer vos chemins à l'intérieur — comme le font Radarr et Sonarr.
>
> Vous pouvez tout à fait monter plusieurs volumes si vous le souhaitez, mais dans ce cas les hardlinks ne seront pas possibles entre deux volumes différents et Fankarr basculera automatiquement en copie.
### Binaire autonome (Windows / Linux / macOS) ### Binaire autonome (Windows / Linux / macOS)
Téléchargez l'archive correspondant à votre système depuis les [Releases GitHub](https://github.com/masutayunikon/fankarr/releases/latest) : Téléchargez l'archive correspondant à votre système depuis les [Releases GitHub](https://github.com/masutayunikon/fankarr/releases/latest) :
| Système | Archive | | Système | Archive |
|---|---| | --------------------- | ------------------------- |
| Windows x64 | `fankarr-windows-x64.zip` | | Windows x64 | `fankarr-windows-x64.zip` |
| Linux x64 | `fankarr-linux-x64.zip` | | Linux x64 | `fankarr-linux-x64.zip` |
| macOS (Apple Silicon) | `fankarr-macos.zip` | | macOS (Apple Silicon) | `fankarr-macos.zip` |
Extrayez l'archive — elle contient le binaire **et** le dossier `public/` qui doivent rester ensemble : Extrayez l'archive — elle contient le binaire **et** le dossier `public/` qui doivent rester ensemble :
@@ -120,22 +122,22 @@ chmod +x fankarr
./fankarr ./fankarr
``` ```
Fankarr sera accessible sur `http://localhost:3001`. Les données (config, logs, base de données) sont sauvegardées dans un dossier `data/` créé automatiquement à côté du binaire. Fankarr sera accessible sur `http://localhost:9898`. Les données (config, logs, base de données) sont sauvegardées dans un dossier `data/` créé automatiquement à côté du binaire.
### Variables d'environnement ### Variables d'environnement
| Variable | Défaut | Description | | Variable | Défaut | Description |
|---|---|---| | ---------------- | ------------ | ----------------------------------------------------------------------- |
| `PUID` | `1000` | UID utilisateur pour les permissions fichiers (Docker) | | `PUID` | `1000` | UID utilisateur pour les permissions fichiers (Docker) |
| `PGID` | `1000` | GID utilisateur pour les permissions fichiers (Docker) | | `PGID` | `1000` | GID utilisateur pour les permissions fichiers (Docker) |
| `TZ` | — | Timezone (ex: `Europe/Paris`) | | `TZ` | — | Timezone (ex: `Europe/Paris`) |
| `PORT` | `3001` | Port d'écoute du serveur | | `PORT` | `9898` | Port d'écoute du serveur |
| `JWT_SECRET` | auto-généré | Secret JWT — généré automatiquement dans `data/secret.key` si absent | | `JWT_SECRET` | auto-généré | Secret JWT — généré automatiquement dans `/config/secret.key` si absent |
| `GITHUB_RAW_URL` | repo scraper | URL du `torrent_final.json` à utiliser | | `GITHUB_RAW_URL` | repo scraper | URL du `torrent_final.json` à utiliser |
### Premier démarrage ### Premier démarrage
1. Ouvrir `http://localhost:3001` 1. Ouvrir `http://localhost:9898`
2. Créer un mot de passe à la première connexion 2. Créer un mot de passe à la première connexion
3. Aller dans **Paramètres** → ajouter votre client qBittorrent 3. Aller dans **Paramètres** → ajouter votre client qBittorrent
4. Vérifier les chemins `completePath` et `mediaPath` 4. Vérifier les chemins `completePath` et `mediaPath`
@@ -173,12 +175,12 @@ Fankarr est disponible dans l'appstore personnalisé. Pour l'installer :
## Stack technique ## Stack technique
| Couche | Technologie | | Couche | Technologie |
|---|---| | ----------------- | ---------------------------------------- |
| Frontend | Vue 3 + Vite + Tailwind CSS | | Frontend | Vue 3 + Vite + Tailwind CSS |
| Backend | Express 5 + TypeScript | | Backend | Express 5 + TypeScript |
| Auth | JWT + bcrypt | | Auth | JWT + bcrypt |
| Packaging Docker | `node:20-slim` + pnpm + gosu (PUID/PGID) | | Packaging Docker | `node:20-slim` + pnpm + gosu (PUID/PGID) |
| Packaging binaire | Bun (self-contained, pas de Node requis) | | Packaging binaire | Bun (self-contained, pas de Node requis) |
--- ---
+14 -15
View File
@@ -1,15 +1,14 @@
services: fankarr:
fankarr: image: masutayunikon/fankarr:latest
image: masutayunikon/fankarr:latest container_name: fankarr
container_name: fankarr environment:
environment: - PUID=1000 # UID de votre utilisateur (id -u)
- PUID=1000 # UID de votre utilisateur (id -u) - PGID=1000 # GID de votre utilisateur (id -g)
- PGID=1000 # GID de votre utilisateur (id -g) - TZ=Europe/Paris # Votre timezone
- TZ=Europe/Paris # Votre timezone volumes:
volumes: - ./config:/config # Config, logs, base de données
- ./data:/app/data # Config, logs, base de données - /votre/chemin:/media # Racine de votre mediatheque (hardlinks compatibles)
- /votre/chemin/media:/media/Kai # Destination Jellyfin ports:
- /votre/chemin/complete:/downloads/complete # Dossier complétés qBittorrent - 9898:9898
ports: restart: unless-stopped
- 3001:3001
restart: unless-stopped
+1 -1
View File
@@ -7,6 +7,6 @@ PGID=${PGID:-1000}
echo "[fankarr] Running as UID=${PUID} GID=${PGID}" echo "[fankarr] Running as UID=${PUID} GID=${PGID}"
# Corriger les permissions du dossier data # Corriger les permissions du dossier data
chown -R "$PUID:$PGID" /app/data chown -R "$PUID:$PGID" /config
exec gosu "$PUID:$PGID" node dist/server/index.js exec gosu "$PUID:$PGID" node dist/server/index.js
+7 -7
View File
@@ -8,16 +8,15 @@
"dev:server": "tsx watch server/index.ts", "dev:server": "tsx watch server/index.ts",
"dev:client": "vite", "dev:client": "vite",
"build": "vite build && tsc -p tsconfig.server.json", "build": "vite build && tsc -p tsconfig.server.json",
"build:bun:linux": "bun build server/index.ts --compile --target bun-linux-x64 --outfile binaries/fankarr-linux-x64", "build:bun:linux": "bun build server/index.ts --compile --target bun-linux-x64 --outfile binaries/fankarr-linux-x64 && bun build server/organize-worker.ts --target node --outfile binaries/organize-worker.js",
"build:bun:windows": "bun build server/index.ts --compile --target bun-windows-x64 --outfile binaries/fankarr-windows-x64.exe", "build:bun:windows": "bun build server/index.ts --compile --target bun-windows-x64 --outfile binaries/fankarr-windows-x64.exe && bun build server/organize-worker.ts --target node --outfile binaries/organize-worker.js",
"build:bun:macos": "bun build server/index.ts --compile --target bun-darwin-arm64 --outfile binaries/fankarr-macos", "build:bun:macos": "bun build server/index.ts --compile --target bun-darwin-arm64 --outfile binaries/fankarr-macos && bun build server/organize-worker.ts --target node --outfile binaries/organize-worker.js",
"build:bun:all": "pnpm build:bun:linux && pnpm build:bun:windows && pnpm build:bun:macos", "build:bun:all": "pnpm build:bun:linux && pnpm build:bun:windows && pnpm build:bun:macos",
"start": "node dist/server/index.js", "start": "node dist/server/index.js",
"preview": "vite preview" "preview": "vite preview"
}, },
"dependencies": { "dependencies": {
"@tailwindcss/vite": "^4.2.1", "@tailwindcss/vite": "^4.2.1",
"bcrypt": "^6.0.0",
"cookie-parser": "^1.4.7", "cookie-parser": "^1.4.7",
"express": "^5.2.1", "express": "^5.2.1",
"jsonwebtoken": "^9.0.3", "jsonwebtoken": "^9.0.3",
@@ -25,10 +24,10 @@
"pinia": "^3.0.4", "pinia": "^3.0.4",
"tailwindcss": "^4.2.1", "tailwindcss": "^4.2.1",
"vue": "^3.5.25", "vue": "^3.5.25",
"vue-router": "^5.0.3" "vue-router": "^5.0.3",
"bcryptjs": "^3.0.3"
}, },
"devDependencies": { "devDependencies": {
"@types/bcrypt": "^5.0.2",
"@types/cookie-parser": "^1.4.8", "@types/cookie-parser": "^1.4.8",
"@types/express": "^5.0.6", "@types/express": "^5.0.6",
"@types/jsonwebtoken": "^9.0.9", "@types/jsonwebtoken": "^9.0.9",
@@ -39,6 +38,7 @@
"tsx": "^4.21.0", "tsx": "^4.21.0",
"typescript": "~5.9.3", "typescript": "~5.9.3",
"vite": "^7.3.1", "vite": "^7.3.1",
"vue-tsc": "^3.1.5" "vue-tsc": "^3.1.5",
"@types/bcrypt": "^5.0.2"
} }
} }
+7 -22
View File
@@ -11,9 +11,9 @@ importers:
'@tailwindcss/vite': '@tailwindcss/vite':
specifier: ^4.2.1 specifier: ^4.2.1
version: 4.2.1(vite@7.3.1(@types/node@24.12.0)(jiti@2.6.1)(lightningcss@1.31.1)(tsx@4.21.0)(yaml@2.8.2)) version: 4.2.1(vite@7.3.1(@types/node@24.12.0)(jiti@2.6.1)(lightningcss@1.31.1)(tsx@4.21.0)(yaml@2.8.2))
bcrypt: bcryptjs:
specifier: ^6.0.0 specifier: ^3.0.3
version: 6.0.0 version: 3.0.3
cookie-parser: cookie-parser:
specifier: ^1.4.7 specifier: ^1.4.7
version: 1.4.7 version: 1.4.7
@@ -650,9 +650,9 @@ packages:
resolution: {integrity: sha512-cbdCP0PGOBq0ASG+sjnKIoYkWMKhhz+F/h9pRexUdX2Hd38+WOlBkRKlqkGOSm0YQpcFMQBJeK4WspUAkwsEdg==} resolution: {integrity: sha512-cbdCP0PGOBq0ASG+sjnKIoYkWMKhhz+F/h9pRexUdX2Hd38+WOlBkRKlqkGOSm0YQpcFMQBJeK4WspUAkwsEdg==}
engines: {node: '>=20.19.0'} engines: {node: '>=20.19.0'}
bcrypt@6.0.0: bcryptjs@3.0.3:
resolution: {integrity: sha512-cU8v/EGSrnH+HnxV2z0J7/blxH8gq7Xh2JFT6Aroax7UohdmiJJlxApMxtKfuI7z68NvvVcmR78k2LbT6efhRg==} resolution: {integrity: sha512-GlF5wPWnSa/X5LKM1o0wz0suXIINz1iHRLvTS+sLyi7XPbe5ycmYI3DlZqVGZZtDgl4DmasFg7gOB3JYbphV5g==}
engines: {node: '>= 18'} hasBin: true
birpc@2.9.0: birpc@2.9.0:
resolution: {integrity: sha512-KrayHS5pBi69Xi9JmvoqrIgYGDkD6mcSe/i6YKi3w5kekCLzrX4+nawcXqrj2tIp50Kw/mT/s3p+GVK0A0sKxw==} resolution: {integrity: sha512-KrayHS5pBi69Xi9JmvoqrIgYGDkD6mcSe/i6YKi3w5kekCLzrX4+nawcXqrj2tIp50Kw/mT/s3p+GVK0A0sKxw==}
@@ -1087,10 +1087,6 @@ packages:
resolution: {integrity: sha512-8Ofs/AUQh8MaEcrlq5xOX0CQ9ypTF5dl78mjlMNfOK08fzpgTHQRQPBxcPlEtIw0yRpws+Zo/3r+5WRby7u3Gg==} resolution: {integrity: sha512-8Ofs/AUQh8MaEcrlq5xOX0CQ9ypTF5dl78mjlMNfOK08fzpgTHQRQPBxcPlEtIw0yRpws+Zo/3r+5WRby7u3Gg==}
engines: {node: '>= 0.6'} engines: {node: '>= 0.6'}
node-addon-api@8.6.0:
resolution: {integrity: sha512-gBVjCaqDlRUk0EwoPNKzIr9KkS9041G/q31IBShPs1Xz6UTA+EXdZADbzqAJQrpDRq71CIMnOP5VMut3SL0z5Q==}
engines: {node: ^18 || ^20 || >= 21}
node-domexception@1.0.0: node-domexception@1.0.0:
resolution: {integrity: sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==} resolution: {integrity: sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==}
engines: {node: '>=10.5.0'} engines: {node: '>=10.5.0'}
@@ -1100,10 +1096,6 @@ packages:
resolution: {integrity: sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==} resolution: {integrity: sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==}
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
node-gyp-build@4.8.4:
resolution: {integrity: sha512-LA4ZjwlnUblHVgq0oBF3Jl/6h/Nvs5fzBLwdEF4nuxnFdsfajde4WfxtJr3CaiH+F6ewcIB/q4jQ4UzPyid+CQ==}
hasBin: true
object-inspect@1.13.4: object-inspect@1.13.4:
resolution: {integrity: sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==} resolution: {integrity: sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==}
engines: {node: '>= 0.4'} engines: {node: '>= 0.4'}
@@ -1919,10 +1911,7 @@ snapshots:
'@babel/parser': 7.29.0 '@babel/parser': 7.29.0
ast-kit: 2.2.0 ast-kit: 2.2.0
bcrypt@6.0.0: bcryptjs@3.0.3: {}
dependencies:
node-addon-api: 8.6.0
node-gyp-build: 4.8.4
birpc@2.9.0: {} birpc@2.9.0: {}
@@ -2351,8 +2340,6 @@ snapshots:
negotiator@1.0.0: {} negotiator@1.0.0: {}
node-addon-api@8.6.0: {}
node-domexception@1.0.0: {} node-domexception@1.0.0: {}
node-fetch@3.3.2: node-fetch@3.3.2:
@@ -2361,8 +2348,6 @@ snapshots:
fetch-blob: 3.2.0 fetch-blob: 3.2.0
formdata-polyfill: 4.0.10 formdata-polyfill: 4.0.10
node-gyp-build@4.8.4: {}
object-inspect@1.13.4: {} object-inspect@1.13.4: {}
on-finished@2.4.1: on-finished@2.4.1:
+3 -2
View File
@@ -1,11 +1,12 @@
import fs from 'fs' import fs from 'fs'
import path from 'path' import path from 'path'
import bcrypt from 'bcrypt' import bcrypt from 'bcryptjs'
import jwt from 'jsonwebtoken' import jwt from 'jsonwebtoken'
import type { Request, Response, NextFunction } from 'express' import type { Request, Response, NextFunction } from 'express'
import { JWT_SECRET } from './secret.js' import { JWT_SECRET } from './secret.js'
import { DATA_DIR } from './config.js'
const DATA_PATH = path.join(process.cwd(), 'data', 'auth.json') const DATA_PATH = path.join(DATA_DIR, 'auth.json')
const SALT_ROUNDS = 10 const SALT_ROUNDS = 10
interface AuthData { interface AuthData {
+13
View File
@@ -0,0 +1,13 @@
import fs from 'fs'
import path from 'path'
export const _isBunBinary = typeof (globalThis as any).Bun !== 'undefined'
&& path.dirname((process as any).execPath) !== process.cwd()
export const BASE_DIR = _isBunBinary
? path.dirname((process as any).execPath)
: process.cwd()
export const DATA_DIR = fs.existsSync('/.dockerenv')
? '/config'
: path.join(BASE_DIR, 'config')
+433 -226
View File
@@ -12,24 +12,15 @@ import {
import qbittorrentDriver from './torrent-clients/qbittorrent.js' import qbittorrentDriver from './torrent-clients/qbittorrent.js'
import { organizeTorrent, autoOrganizeAll, scanMediaPath } from './organize.js' import { organizeTorrent, autoOrganizeAll, scanMediaPath } from './organize.js'
import { logger, readLogs, clearLogs, logsFileSize } from './logger.js' import { logger, readLogs, clearLogs, logsFileSize } from './logger.js'
import { DATA_DIR, BASE_DIR } from './config.js'
registerDriver(qbittorrentDriver) registerDriver(qbittorrentDriver)
// ── Base directory ─────────────────────────────────────────────
// Binaire Bun compilé : data/ et public/ sont à côté de l'exécutable
// Docker / dev : relatif au cwd (comportement inchangé)
const _isBunBinary = typeof (globalThis as any).Bun !== 'undefined'
&& path.dirname((process as any).execPath) !== process.cwd()
export const BASE_DIR = _isBunBinary
? path.dirname((process as any).execPath)
: process.cwd()
const app = express() const app = express()
const PORT = Number(process.env.PORT) || 3001 const PORT = Number(process.env.PORT) || 9898
const FANKAI_API = 'https://metadata.fankai.fr' const FANKAI_API = 'https://metadata.fankai.fr'
const TORRENTS_PATH = path.join(BASE_DIR, 'data', 'torrent_final.json') const GITHUB_BASE = process.env.GITHUB_BASE
const GITHUB_RAW_URL = process.env.GITHUB_RAW_URL ?? 'https://raw.githubusercontent.com/masutayunikon/fankarr-scraper/main'
?? '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())
@@ -95,71 +86,289 @@ app.get('/api/torrent-clients/:uuid/healthcheck', requireAuth, async (req, res)
res.json(await driver.healthcheck(client.config)) res.json(await driver.healthcheck(client.config))
}) })
// ── Helpers ──────────────────────────────────────────────────── // ── Cache GitHub ───────────────────────────────────────────────
function readTorrents(): any[] {
const CACHE_TTL_MS = 6 * 60 * 60 * 1000 // 6 heures
interface CacheEntry<T> { data: T; expiresAt: number }
const _cache = new Map<string, CacheEntry<any>>()
function cacheGet<T>(key: string): T | null {
const entry = _cache.get(key)
if (!entry) return null
if (Date.now() > entry.expiresAt) { _cache.delete(key); return null }
return entry.data as T
}
function cacheSet<T>(key: string, data: T): void {
_cache.set(key, { data, expiresAt: Date.now() + CACHE_TTL_MS })
}
function cacheClear(): void { _cache.clear() }
async function githubGet(urlPath: string): Promise<any> {
const key = urlPath
const cached = cacheGet(key)
if (cached) return cached
const res = await fetch(`${GITHUB_BASE}/${urlPath}`)
if (!res.ok) throw new Error(`GitHub ${res.status}: ${urlPath}`)
const data = await res.json()
cacheSet(key, data)
return data
}
async function readAvailable(): Promise<number[]> {
try { try {
if (!fs.existsSync(TORRENTS_PATH)) return [] return await githubGet('available.json') as number[]
return JSON.parse(fs.readFileSync(TORRENTS_PATH, 'utf-8'))
} catch { return [] } } catch { return [] }
} }
async function readSerieData(serieId: number): Promise<any | null> {
try {
return await githubGet(`series/${serieId}.json`)
} catch { return null }
}
// Extrait tous les torrents d'un series/{id}.json avec leur type et niveau hiérarchique
// Retourne une liste plate compatible avec l'ancienne interface { infohash, torrent_url, magnet, raw, type, ... }
function extractTorrentsFromSerieData(sd: any): any[] {
const result: any[] = []
if (!sd) return result
// Torrents au niveau série → pack_integrale (ou pack_saison si une seule saison)
for (const t of sd.torrents ?? []) {
result.push({
...t,
raw : t.title,
type : 'pack_integrale',
serie_id : sd.id,
serie_title: sd.title,
// episodes couverts : tous les épisodes de toutes les saisons qui ont paths[i]
_serieLevel: true,
_serieData : sd,
_torrentIdx: (sd.torrents ?? []).indexOf(t),
})
}
// Torrents au niveau saison → pack_saison
for (const season of sd.seasons ?? []) {
for (const t of season.torrents ?? []) {
result.push({
...t,
raw : t.title,
type : 'pack_saison',
serie_id : sd.id,
serie_title : sd.title,
season_id : season.id,
season_number: season.season_number,
_seasonLevel : true,
_season : season,
_torrentIdx : (season.torrents ?? []).indexOf(t),
})
}
// Torrents au niveau épisode → episode
for (const ep of season.episodes ?? []) {
for (const t of ep.torrents ?? []) {
result.push({
...t,
raw : t.title,
type : 'episode',
serie_id : sd.id,
serie_title : sd.title,
season_id : season.id,
season_number: season.season_number,
episode_id : ep.id,
episode_number: ep.episode_number,
_episodeLevel: true,
_episode : ep,
_torrentIdx : (ep.torrents ?? []).indexOf(t),
})
}
}
}
return result
}
// Construit resolved_episodes pour un torrent à partir des paths[torrentIdx]
// Construit les épisodes résolus pour un torrent donné par son infohash
function buildResolvedEpisodes(sd: any, hash: string, seasonFilter?: number): any[] {
const resolved: any[] = []
const h = hash.toLowerCase()
for (const season of sd.seasons ?? []) {
if (seasonFilter !== undefined && season.season_number !== seasonFilter) continue
for (const ep of season.episodes ?? []) {
const paths: any[] = ep.paths ?? []
// Nouveau format { infohash, path } ou legacy string
let filePath: string | null = null
for (const p of paths) {
if (typeof p === 'string') {
if (!filePath) filePath = p.replace(/\\/g, '/') // legacy fallback
} else if (p?.infohash?.toLowerCase() === h) {
filePath = p.path.replace(/\\/g, '/')
break
}
}
if (!filePath) continue
const filename = filePath.split('/').pop() ?? filePath
resolved.push({
episode_id : ep.id,
episode_number : ep.episode_number,
season_number : season.season_number,
season_id : season.id,
filename,
original_filename: filename,
})
}
}
return resolved
}
async function fankaiGet(endpoint: string): Promise<any> { async function fankaiGet(endpoint: string): Promise<any> {
const res = await fetch(`${FANKAI_API}${endpoint}`) const res = await fetch(`${FANKAI_API}${endpoint}`)
if (!res.ok) throw new Error(`Fankai API ${res.status}: ${endpoint}`) if (!res.ok) throw new Error(`Fankai API ${res.status}: ${endpoint}`)
return res.json() return res.json()
} }
function indexBySerie(torrents: any[]): Map<number, any[]> {
const map = new Map<number, any[]>() function normalizeTitle(s: string): string {
for (const t of torrents) { return s.toLowerCase()
if (!t.serie_id) continue .normalize('NFD')
if (!map.has(t.serie_id)) map.set(t.serie_id, []) .replace(/[\u0300-\u036f]/g, '')
map.get(t.serie_id)!.push(t) .replace(/[^a-z0-9]/g, ' ')
} .replace(/\s+/g, ' ')
return map .trim()
} }
// ── Series ───────────────────────────────────────────────────── function imgProxy(url: string | null | undefined, w: number, q = 70): string | null {
if (!url) return null
const stripped = url.replace(/^https?:\/\//, '')
return `https://wsrv.nl/?url=${stripped}&w=${w}&q=${q}`
}
function normalizeSerie(serie: any): any {
const poster = serie.poster_image ?? serie.images?.poster ?? null
const fanart = serie.fanart_image ?? serie.images?.fanart ?? null
return {
...serie,
poster_image: imgProxy(poster, 300),
fanart_image: imgProxy(fanart, 1280, 60),
}
}
function normalizeSeason(season: any): any {
const poster = season.poster_image ?? season.images?.poster ?? null
return {
...season,
poster_image: imgProxy(poster, 300),
}
}
function normalizeEpisode(ep: any): any {
const thumb = ep.thumb_image ?? ep.thumbnail ?? null
return {
...ep,
thumb_image: imgProxy(thumb, 400),
}
}
// ── Enrichissement seriesData avec original_filename depuis l'API ──────────────
// Fetche /seasons/{id}/episodes pour chaque saison et injecte original_filename
// dans chaque épisode du serieData, indexé par episode_id
async function enrichSeriesDataWithOriginalFilenames(seriesData: any[]): Promise<any[]> {
return Promise.all(seriesData.map(async (sd) => {
if (!sd) return sd
const enrichedSeasons = await Promise.all((sd.seasons ?? []).map(async (season: any) => {
let epsData: any[] = []
try {
const res = await fankaiGet(`/seasons/${season.id}/episodes`)
epsData = Array.isArray(res) ? res : (res.episodes ?? [])
} catch { return season }
// Index episode_id → original_filename
const origMap = new Map<number, string>()
for (const ep of epsData) {
if (ep.id && ep.original_filename) origMap.set(ep.id, ep.original_filename)
}
// Injecter dans les épisodes du serieData
const enrichedEpisodes = (season.episodes ?? []).map((ep: any) => ({
...ep,
original_filename: origMap.get(ep.id) ?? null,
}))
return { ...season, episodes: enrichedEpisodes }
}))
return { ...sd, seasons: enrichedSeasons }
}))
}
// Helper réutilisable : charge + enrichit toutes les seriesData du cache
async function loadEnrichedSeriesData(): Promise<any[]> {
const ids = await readAvailable()
const allSd = await Promise.all(ids.map(id => readSerieData(id)))
const valid = allSd.filter(Boolean)
return enrichSeriesDataWithOriginalFilenames(valid)
}
function computeSerieDownloadState( function computeSerieDownloadState(
serieTorrents : any[], serieData : any | null,
organized : Record<string, Record<string, string>>, organized : Record<string, Record<string, string>>,
activeTorrents: Set<string> // hashes actuellement dans qB en downloading activeTorrents: Set<string>
): 'none' | 'downloading' | 'partial' | 'complete' { ): 'none' | 'downloading' | 'partial' | 'complete' {
if (serieTorrents.length === 0) return 'none' if (!serieData) return 'none'
// Un torrent de la série est en cours de téléchargement ? const allTorrents = extractTorrentsFromSerieData(serieData)
const hasActive = serieTorrents.some(t => activeTorrents.has(t.infohash?.toLowerCase())) if (allTorrents.length === 0) return 'none'
const hasActive = allTorrents.some(t => t.infohash && activeTorrents.has(t.infohash.toLowerCase()))
if (hasActive) return 'downloading' if (hasActive) return 'downloading'
// Compter les fichiers attendus vs organisés // Collecter tous les episode_id de la série et ceux organisés
let totalFiles = 0 const allEpisodeIds = new Set<number>()
let doneFiles = 0 const organizedEpisodeIds = new Set<number>()
for (const t of serieTorrents) {
const files: any[] = t.torrent_files ?? [] for (const season of serieData.seasons ?? []) {
if (files.length === 0) { for (const ep of season.episodes ?? []) {
// Fichier unique if ((ep.torrents ?? []).length > 0 || (ep.paths ?? []).length > 0) {
totalFiles++ allEpisodeIds.add(ep.id)
if (organized[t.infohash?.toLowerCase()]?.[t.raw]) doneFiles++ }
} else {
totalFiles += files.length
doneFiles += files.filter((f: any) => organized[t.infohash?.toLowerCase()]?.[f.filename]).length
} }
} }
if (totalFiles === 0) return 'none' // Vérifier via organized.json : si le filename du path est organisé
if (doneFiles === 0) return 'none' for (const t of allTorrents) {
if (doneFiles >= totalFiles) return 'complete' const hash = t.infohash?.toLowerCase()
if (!hash) continue
const orgFiles = organized[hash] ?? {}
if (Object.keys(orgFiles).length === 0) continue
const resolved = buildResolvedEpisodes(serieData, hash, t.season_number)
for (const ep of resolved) {
if (orgFiles[ep.filename]) organizedEpisodeIds.add(ep.episode_id)
}
}
if (allEpisodeIds.size === 0) return 'none'
if (organizedEpisodeIds.size === 0) return 'none'
if (organizedEpisodeIds.size >= allEpisodeIds.size) return 'complete'
return 'partial' return 'partial'
} }
app.get('/api/series', requireAuth, async (_req, res) => { app.get('/api/series', requireAuth, async (_req, res) => {
try { try {
const [apiData, torrents] = await Promise.all([fankaiGet('/series'), Promise.resolve(readTorrents())]) const [apiData, availableIds] = await Promise.all([
const byId = indexBySerie(torrents) fankaiGet('/series'),
readAvailable(),
])
const availableSet = new Set<number>(availableIds)
// Charger organized.json // Charger organized.json
let organized: Record<string, Record<string, string>> = {} let organized: Record<string, Record<string, string>> = {}
try { try {
const orgPath = path.join(process.cwd(), 'data', 'organized.json') const orgPath = path.join(DATA_DIR, 'organized.json')
if (fs.existsSync(orgPath)) if (fs.existsSync(orgPath))
organized = JSON.parse(fs.readFileSync(orgPath, 'utf-8')) organized = JSON.parse(fs.readFileSync(orgPath, 'utf-8'))
} catch {} } catch {}
@@ -170,19 +379,31 @@ app.get('/api/series', requireAuth, async (_req, res) => {
const { category } = readSettings() const { category } = readSettings()
const active = await dispatchList(category ?? 'fankai') const active = await dispatchList(category ?? 'fankai')
for (const t of active) { for (const t of active) {
if (t.state === 'downloading' && t.hash) if (t.hash) activeTorrents.add(t.hash.toLowerCase())
activeTorrents.add(t.hash.toLowerCase())
} }
} catch {} } catch {}
const seriesList = Array.isArray(apiData) ? apiData : (apiData.series ?? []) const seriesRaw = (Array.isArray(apiData) ? apiData : (apiData.series ?? [])).map(normalizeSerie)
res.json({ series: seriesList.map((serie: any) => {
const serieTorrents = byId.get(serie.id) ?? [] // Charger les series data en parallèle uniquement pour celles qui ont des torrents
const serieDataMap = new Map<number, any>()
await Promise.all(
seriesRaw
.filter((s: any) => availableSet.has(s.id))
.map(async (s: any) => {
const sd = await readSerieData(s.id)
if (sd) serieDataMap.set(s.id, sd)
})
)
res.json({ series: seriesRaw.map((serie: any) => {
const hasTorrents = availableSet.has(serie.id)
const serieData = serieDataMap.get(serie.id) ?? null
return { return {
...serie, ...serie,
torrent_count : serieTorrents.length, torrent_count : serieData ? extractTorrentsFromSerieData(serieData).length : 0,
has_torrents : serieTorrents.length > 0, has_torrents : hasTorrents,
download_state: computeSerieDownloadState(serieTorrents, organized, activeTorrents), download_state: computeSerieDownloadState(serieData, organized, activeTorrents),
} }
})}) })})
} catch (err) { } catch (err) {
@@ -193,129 +414,127 @@ app.get('/api/series', requireAuth, async (_req, res) => {
app.get('/api/series/:id', requireAuth, async (req, res) => { app.get('/api/series/:id', requireAuth, async (req, res) => {
const id = Number(req.params.id) const id = Number(req.params.id)
try { try {
const [serie, seasonsData] = await Promise.all([fankaiGet(`/series/${id}`), fankaiGet(`/series/${id}/seasons`)]) const [serieRaw, seasonsData, serieData] = await Promise.all([
fankaiGet(`/series/${id}`),
fankaiGet(`/series/${id}/seasons`),
readSerieData(id),
])
const serie = normalizeSerie(serieRaw)
const seasons = Array.isArray(seasonsData) ? seasonsData : (seasonsData.seasons ?? []) const seasons = Array.isArray(seasonsData) ? seasonsData : (seasonsData.seasons ?? [])
// Fetch épisodes depuis l'API Fankai (avec original_filename, thumb_image, etc.)
const seasonsWithEpisodes = await Promise.all(seasons.map(async (season: any) => { const seasonsWithEpisodes = await Promise.all(seasons.map(async (season: any) => {
const epsData = await fankaiGet(`/seasons/${season.id}/episodes`) const epsData = await fankaiGet(`/seasons/${season.id}/episodes`)
return { ...season, episodes: Array.isArray(epsData) ? epsData : (epsData.episodes ?? []) } const episodes = (Array.isArray(epsData) ? epsData : (epsData.episodes ?? [])).map(normalizeEpisode)
return { ...normalizeSeason(season), episodes }
})) }))
const torrents = readTorrents().filter(t => t.serie_id === id) // Charger organized.json
const allSeasonIds = new Set<number>(seasonsWithEpisodes.filter((s: any) => s.season_number !== 0).map((s: any) => s.id))
const availableEpisodeIds = new Set<number>()
const episodeTorrentMap: Record<number, any> = {}
const seasonTorrentMap : Record<number, any> = {}
const integraleTorrents: any[] = []
const packEpisodesTorrents: any[] = []
for (const t of torrents) {
const ref = { torrent_url: t.torrent_url, magnet: t.magnet, type: t.type, raw: t.raw }
for (const ep of t.resolved_episodes ?? []) {
availableEpisodeIds.add(ep.episode_id)
if (t.type === 'episode') episodeTorrentMap[ep.episode_id] = ref
}
if (t.type === 'pack_saison') {
const rs: any[] = t.resolved_seasons ?? []
if (rs.length > 1) {
packEpisodesTorrents.push(t)
} else {
const sids = rs.length > 0 ? rs.map((r: any) => r.season_id) : [t.season_id]
for (const sid of sids) { if (sid) seasonTorrentMap[sid] = ref }
}
} else if (t.type === 'pack_integrale') {
integraleTorrents.push(t)
} else if (t.type === 'pack_episodes') {
packEpisodesTorrents.push(t)
}
}
let promotedIntegrale: any = null
if (integraleTorrents.length === 0 && allSeasonIds.size > 0) {
for (const t of torrents.filter(t => t.type === 'pack_saison')) {
const rs: any[] = t.resolved_seasons ?? []
const tIds = new Set<number>(rs.length > 0 ? rs.map((r: any) => r.season_id) : t.season_id ? [t.season_id] : [])
if ([...allSeasonIds].every(sid => tIds.has(sid))) { promotedIntegrale = t; break }
}
}
if (integraleTorrents.length > 0 || promotedIntegrale) {
for (const key of Object.keys(seasonTorrentMap)) delete seasonTorrentMap[Number(key)]
if (promotedIntegrale) {
const idx = packEpisodesTorrents.indexOf(promotedIntegrale)
if (idx !== -1) packEpisodesTorrents.splice(idx, 1)
}
}
function packEpisodesLabel(t: any): string {
const eps: any[] = t.resolved_episodes ?? []
if (!eps.length) return t.raw
const bySeason = new Map<number, number[]>()
for (const ep of eps) {
const sn = ep.season_number ?? 0
if (!bySeason.has(sn)) bySeason.set(sn, [])
bySeason.get(sn)!.push(ep.episode_number)
}
return [...bySeason.entries()].sort(([a], [b]) => a - b).map(([sn, nums]) => {
const s = nums.sort((a, b) => a - b)
const label = sn === 0 ? 'S0' : `S${sn}`
return s[0] === s[s.length-1] ? `${label} Ep ${s[0]}` : `${label} Eps ${s[0]}-${s[s.length-1]}`
}).join(' · ')
}
// Charger organized.json pour les badges d'état
let organized: Record<string, Record<string, string>> = {} let organized: Record<string, Record<string, string>> = {}
try { try {
const orgPath = path.join(process.cwd(), 'data', 'organized.json') const orgPath = path.join(DATA_DIR, 'organized.json')
if (fs.existsSync(orgPath)) if (fs.existsSync(orgPath))
organized = JSON.parse(fs.readFileSync(orgPath, 'utf-8')) organized = JSON.parse(fs.readFileSync(orgPath, 'utf-8'))
} catch {} } catch {}
// Construire un set des episode_id organisés // ── Construire les maps torrent depuis series/{id}.json ───────────
// On croise resolved_episodes de chaque torrent avec organized.json const availableEpisodeIds = new Set<number>()
const organizedEpisodeIds = new Set<number>() const episodeTorrentMap : Record<number, any> = {} // episode_id → ref
for (const t of torrents) { const seasonTorrentMapBySn : Record<number, any> = {} // season_number → ref
const hash = t.infohash?.toLowerCase() const integraleTorrents : any[] = []
const files = t.torrent_files ?? [] const packEpisodesTorrents : any[] = []
const orgFiles = organized[hash] ?? {} const organizedEpisodeIds = new Set<number>()
if (Object.keys(orgFiles).length === 0) continue
// Au moins un fichier organisé pour ce torrent → on marque les épisodes résolus if (serieData) {
for (const ep of t.resolved_episodes ?? []) { // ── Torrents niveau série (pack_integrale) ──────────────────
// Vérifier si le fichier de cet épisode est organisé for (const t of (serieData.torrents ?? [])) {
const epFile = files.find((f: any) => const ref = { torrent_url: t.torrent_url, magnet: t.magnet, type: 'pack_integrale', raw: t.title, manual: t.manual ?? false }
f.episode_ids?.includes(ep.episode_id) || f.episode_number === ep.episode_number integraleTorrents.push({ ...t, raw: t.title })
)
if (epFile ? orgFiles[epFile.filename] : Object.keys(orgFiles).length > 0) { const resolved = buildResolvedEpisodes(serieData, t.infohash)
organizedEpisodeIds.add(ep.episode_id) for (const ep of resolved) availableEpisodeIds.add(ep.episode_id)
const orgFiles = organized[t.infohash?.toLowerCase()] ?? {}
for (const ep of resolved) {
if (orgFiles[ep.filename]) organizedEpisodeIds.add(ep.episode_id)
} }
} }
// ── Torrents niveau saison (pack_saison) ────────────────────
for (const season of serieData.seasons ?? []) {
for (const t of (season.torrents ?? [])) {
const ref = { torrent_url: t.torrent_url, magnet: t.magnet, type: 'pack_saison', raw: t.title, manual: t.manual ?? false }
seasonTorrentMapBySn[season.season_number] = ref
const resolved = buildResolvedEpisodes(serieData, t.infohash, season.season_number)
for (const ep of resolved) availableEpisodeIds.add(ep.episode_id)
const orgFiles = organized[t.infohash?.toLowerCase()] ?? {}
for (const ep of resolved) {
if (orgFiles[ep.filename]) organizedEpisodeIds.add(ep.episode_id)
}
}
// ── Torrents niveau épisode ─────────────────────────────
for (const ep of season.episodes ?? []) {
for (const t of (ep.torrents ?? [])) {
const ref = { torrent_url: t.torrent_url, magnet: t.magnet, type: 'episode', raw: t.title, manual: t.manual ?? false }
episodeTorrentMap[ep.id] = ref
availableEpisodeIds.add(ep.id)
const orgFiles = organized[t.infohash?.toLowerCase()] ?? {}
const paths: any[] = ep.paths ?? []
const match = paths.find((p: any) => typeof p === 'object' && p.infohash?.toLowerCase() === t.infohash?.toLowerCase())
const filename = match ? match.path.split('/').pop() : null
if (filename && orgFiles[filename]) organizedEpisodeIds.add(ep.id)
}
}
}
// Pack_saison multi-saisons → packEpisodesTorrents si couvre plusieurs saisons
// (cas où un seul torrent couvre plusieurs saisons mais pas toutes → affiché en hero)
// Pour l'instant on le traite comme pack_integrale si au niveau série
} }
// ── Promotion intégrale ───────────────────────────────────────────
// Si pas de pack_integrale explicite mais un pack_saison couvre toutes les saisons
// → déjà géré car on met les torrents série en integraleTorrents directement
// ── Enrichissement des saisons API ───────────────────────────────
const enrichedSeasons = seasonsWithEpisodes.map((season: any) => { const enrichedSeasons = seasonsWithEpisodes.map((season: any) => {
const eps = season.episodes.map((ep: any) => ({ const eps = season.episodes.map((ep: any) => {
...ep, // Chercher le torrent : niveau épisode d'abord, sinon le torrent de saison/intégrale sert juste de disponibilité
available : availableEpisodeIds.has(ep.id), const epTorrent = episodeTorrentMap[ep.id] ?? null
torrent : episodeTorrentMap[ep.id] ?? null, // original_filename vient de l'API Fankai directement
organized : organizedEpisodeIds.has(ep.id), return {
})) ...ep,
// State saison : none / partial / complete available : availableEpisodeIds.has(ep.id),
torrent : epTorrent,
organized : organizedEpisodeIds.has(ep.id),
}
})
const total = eps.filter((e: any) => e.available).length const total = eps.filter((e: any) => e.available).length
const orgCount = eps.filter((e: any) => e.organized).length const orgCount = eps.filter((e: any) => e.organized).length
const seasonOrganizedState = const seasonOrganizedState =
orgCount === 0 ? 'none' : orgCount === 0 ? 'none' :
orgCount >= total && total > 0 ? 'complete' : 'partial' orgCount >= total && total > 0 ? 'complete' : 'partial'
return { return {
...season, ...season,
torrent : seasonTorrentMap[season.id] ?? null, torrent : seasonTorrentMapBySn[season.season_number] ?? null,
organized_state : seasonOrganizedState, organized_state : seasonOrganizedState,
organized_count : orgCount, organized_count : orgCount,
episodes : eps, episodes : eps,
} }
}) })
// ── Hero bundles ──────────────────────────────────────────────────
function packEpisodesLabel(t: any): string {
return t.raw ?? t.title ?? 'Pack'
}
const heroBundles: any[] = [ const heroBundles: any[] = [
...integraleTorrents.map(t => ({ label: 'Intégrale', torrent_url: t.torrent_url, magnet: t.magnet, raw: t.raw })), ...integraleTorrents.map(t => ({ label: 'Intégrale', torrent_url: t.torrent_url, magnet: t.magnet, raw: t.title ?? t.raw })),
...(promotedIntegrale ? [{ label: 'Intégrale', torrent_url: promotedIntegrale.torrent_url, magnet: promotedIntegrale.magnet, raw: promotedIntegrale.raw }] : []), ...packEpisodesTorrents.map(t => ({ label: packEpisodesLabel(t), torrent_url: t.torrent_url, magnet: t.magnet, raw: t.title ?? t.raw }))
...packEpisodesTorrents.map(t => ({ label: packEpisodesLabel(t), torrent_url: t.torrent_url, magnet: t.magnet, raw: t.raw }))
] ]
res.json({ serie, seasons: enrichedSeasons, torrents_integrale: heroBundles }) res.json({ serie, seasons: enrichedSeasons, torrents_integrale: heroBundles })
@@ -326,7 +545,7 @@ app.get('/api/series/:id', requireAuth, async (req, res) => {
// ── Download ─────────────────────────────────────────────────── // ── Download ───────────────────────────────────────────────────
app.post('/api/download', requireAuth, async (req, res) => { app.post('/api/download', requireAuth, async (req, res) => {
const url = req.body.torrent_url ?? req.body.magnet const url = req.body.magnet ?? req.body.torrent_url
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: any) => r.ok) ? 200 : 207).json({ results }) res.status(results.every((r: any) => r.ok) ? 200 : 207).json({ results })
@@ -338,38 +557,41 @@ app.get('/api/downloads', requireAuth, async (_req, res) => {
const { category } = readSettings() const { category } = readSettings()
const torrents = await dispatchList(category ?? 'fankai') const torrents = await dispatchList(category ?? 'fankai')
// Enrichir avec l'état d'organisation
let organized: Record<string, Record<string, string>> = {} let organized: Record<string, Record<string, string>> = {}
try { try {
const orgPath = path.join(process.cwd(), 'data', 'organized.json') const orgPath = path.join(DATA_DIR, 'organized.json')
if (fs.existsSync(orgPath)) if (fs.existsSync(orgPath))
organized = JSON.parse(fs.readFileSync(orgPath, 'utf-8')) organized = JSON.parse(fs.readFileSync(orgPath, 'utf-8'))
} catch {} } catch {}
let torrentFinal: any[] = [] const enriched = await Promise.all(torrents.map(async (t: any) => {
try {
const tfPath = path.join(process.cwd(), 'data', 'torrent_final.json')
if (fs.existsSync(tfPath))
torrentFinal = JSON.parse(fs.readFileSync(tfPath, 'utf-8'))
} catch {}
const enriched = torrents.map((t: any) => {
const orgFiles = organized[t.hash] ?? {} const orgFiles = organized[t.hash] ?? {}
const meta = torrentFinal.find((m: any) => // Chercher les métadonnées via le cache GitHub
m.infohash?.toLowerCase() === t.hash?.toLowerCase() let totalFiles = 1
) try {
const totalFiles = (meta?.torrent_files?.length ?? 0) || 1 const availableIds = await readAvailable()
for (const id of availableIds) {
const sd = await readSerieData(id)
if (!sd) continue
const allT = extractTorrentsFromSerieData(sd)
const match = allT.find((st: any) => st.infohash?.toLowerCase() === t.hash?.toLowerCase())
if (match) {
const resolved = buildResolvedEpisodes(sd, match.infohash, match.season_number)
totalFiles = resolved.length || 1
break
}
}
} catch {}
const doneFiles = Object.keys(orgFiles).length const doneFiles = Object.keys(orgFiles).length
let organizeState: 'none' | 'partial' | 'done' = 'none' let organizeState: 'none' | 'partial' | 'done' = 'none'
if (doneFiles >= totalFiles) organizeState = 'done' if (doneFiles >= totalFiles) organizeState = 'done'
else if (doneFiles > 0) organizeState = 'partial' else if (doneFiles > 0) organizeState = 'partial'
// Récupérer les erreurs depuis recentOrganized
const notif = recentOrganized.find(n => n.hash === t.hash) const notif = recentOrganized.find(n => n.hash === t.hash)
const errorFiles = notif?.errorFiles ?? [] const errorFiles = notif?.errorFiles ?? []
return { ...t, organizeState, organizeProgress: { done: doneFiles, total: totalFiles }, errorFiles } return { ...t, organizeState, organizeProgress: { done: doneFiles, total: totalFiles }, errorFiles }
}) }))
res.json(enriched) res.json(enriched)
} catch (err) { } catch (err) {
@@ -377,7 +599,7 @@ app.get('/api/downloads', requireAuth, async (_req, res) => {
} }
}) })
// ── Résultats d'organisation récents (pour notifications frontend) ── // ── Résultats d'organisation récents ──────────────────────────
interface OrganizeNotif { interface OrganizeNotif {
hash : string hash : string
name : string name : string
@@ -399,13 +621,11 @@ app.get('/api/organize/recent', requireAuth, (_req, res) => {
res.json(recentOrganized) res.json(recentOrganized)
}) })
// Vider les notifs lues
app.post('/api/organize/recent/clear', requireAuth, (_req, res) => { app.post('/api/organize/recent/clear', requireAuth, (_req, res) => {
recentOrganized.length = 0 recentOrganized.length = 0
res.json({ ok: true }) res.json({ ok: true })
}) })
app.post('/api/organize', requireAuth, async (req, res) => { app.post('/api/organize', requireAuth, async (req, res) => {
const { hash, name, save_path } = req.body const { hash, name, save_path } = req.body
if (!hash || !name || !save_path) { if (!hash || !name || !save_path) {
@@ -413,14 +633,14 @@ app.post('/api/organize', requireAuth, async (req, res) => {
return return
} }
try { try {
const result = await organizeTorrent(hash, name, save_path) const seriesData = await loadEnrichedSeriesData()
const result = await organizeTorrent(hash, name, save_path, seriesData)
res.json(result) res.json(result)
} catch (err) { } catch (err) {
res.status(500).json({ error: err instanceof Error ? err.message : 'Erreur inconnue' }) res.status(500).json({ error: err instanceof Error ? err.message : 'Erreur inconnue' })
} }
}) })
// ── Torrents status ────────────────────────────────────────────
// ── Logs ────────────────────────────────────────────────────── // ── Logs ──────────────────────────────────────────────────────
app.get('/api/logs', requireAuth, (req, res) => { app.get('/api/logs', requireAuth, (req, res) => {
const limit = Number(req.query.limit) || 100 const limit = Number(req.query.limit) || 100
@@ -458,27 +678,21 @@ app.get('/api/browse', requireAuth, (req, res) => {
} }
}) })
app.get('/api/torrents/status', requireAuth, (_req, res) => { app.get('/api/torrents/status', requireAuth, async (_req, res) => {
try { try {
if (!fs.existsSync(TORRENTS_PATH)) { res.json({ exists: false, count: 0, empty: true }); return } const available = await readAvailable()
const raw = fs.readFileSync(TORRENTS_PATH, 'utf-8').trim() res.json({ exists: available.length > 0, count: available.length, empty: available.length === 0 })
if (!raw || raw === '[]') { res.json({ exists: true, count: 0, empty: true }); return }
const data = JSON.parse(raw)
const count = Array.isArray(data) ? data.length : 0
res.json({ exists: true, count, empty: count === 0 })
} catch { res.json({ exists: false, count: 0, empty: true }) } } catch { res.json({ exists: false, count: 0, empty: true }) }
}) })
// ── Update torrent_final.json ────────────────────────────────── // ── Update : vide le cache pour forcer le rechargement depuis GitHub ──────────
app.post('/api/update', requireAuth, async (_req, res) => { app.post('/api/update', requireAuth, async (_req, res) => {
try { try {
const response = await fetch(GITHUB_RAW_URL) cacheClear()
if (!response.ok) throw new Error(`GitHub a répondu ${response.status}`) // Pré-charger available.json pour vérifier que GitHub répond
const data = await response.json() as unknown[] const availableIds = await readAvailable()
if (!Array.isArray(data)) throw new Error('Format invalide') if (!Array.isArray(availableIds)) throw new Error('available.json invalide')
fs.mkdirSync(path.dirname(TORRENTS_PATH), { recursive: true }) res.json({ ok: true, count: availableIds.length })
fs.writeFileSync(TORRENTS_PATH, JSON.stringify(data, null, 2), 'utf-8')
res.json({ ok: true, count: data.length })
} catch (err) { } catch (err) {
res.status(500).json({ error: err instanceof Error ? err.message : 'Erreur inconnue' }) res.status(500).json({ error: err instanceof Error ? err.message : 'Erreur inconnue' })
} }
@@ -487,8 +701,9 @@ app.post('/api/update', requireAuth, async (_req, res) => {
app.post('/api/scan', requireAuth, async (_req, res) => { app.post('/api/scan', requireAuth, async (_req, res) => {
try { try {
const { mediaPath } = readSettings() const { mediaPath } = readSettings()
const ORGANIZED_PATH = path.join(process.cwd(), 'data', 'organized.json') const ORGANIZED_PATH = path.join(DATA_DIR, 'organized.json')
const result = await scanMediaPath(mediaPath, TORRENTS_PATH, ORGANIZED_PATH) const seriesData = await loadEnrichedSeriesData()
const result = await scanMediaPath(mediaPath, ORGANIZED_PATH, seriesData)
logger.info('api', `Scan manuel: ${result.found} fichiers scannés, ${result.added} ajoutés`) logger.info('api', `Scan manuel: ${result.found} fichiers scannés, ${result.added} ajoutés`)
res.json({ ok: true, ...result }) res.json({ ok: true, ...result })
} catch (err) { } catch (err) {
@@ -496,7 +711,7 @@ app.post('/api/scan', requireAuth, async (_req, res) => {
} }
}) })
// ── SPA fallback (prod) — doit être après toutes les routes API ─ // ── SPA fallback (prod) ────────────────────────────────────────
if (fs.existsSync(PUBLIC_PATH)) { if (fs.existsSync(PUBLIC_PATH)) {
app.get('*path', (_req, res) => { app.get('*path', (_req, res) => {
res.sendFile(path.join(PUBLIC_PATH, 'index.html')) res.sendFile(path.join(PUBLIC_PATH, 'index.html'))
@@ -505,43 +720,35 @@ if (fs.existsSync(PUBLIC_PATH)) {
// ── Start ────────────────────────────────────────────────────── // ── Start ──────────────────────────────────────────────────────
app.listen(PORT, async () => { app.listen(PORT, async () => {
// Télécharger torrent_final.json si absent console.log(`[fankarr] Serveur sur http://localhost:${PORT}`)
if (!fs.existsSync(TORRENTS_PATH)) { console.log(`[fankarr] Cache GitHub TTL: 6h — premier fetch au démarrage...`)
try {
console.log('[fankarr] torrent_final.json absent → téléchargement...') // Pré-chauffer le cache available.json au démarrage
const response = await fetch(GITHUB_RAW_URL) try {
if (!response.ok) throw new Error(`GitHub a répondu ${response.status}`) const available = await readAvailable()
const data = await response.json() as unknown[] console.log(`[fankarr] ${available.length} séries disponibles (via GitHub)`)
if (!Array.isArray(data)) throw new Error('Format invalide') } catch (err) {
fs.mkdirSync(path.dirname(TORRENTS_PATH), { recursive: true }) console.warn(`[fankarr] ⚠ Impossible de charger available.json: ${err instanceof Error ? err.message : err}`)
fs.writeFileSync(TORRENTS_PATH, JSON.stringify(data, null, 2), 'utf-8')
console.log(`[fankarr] ${data.length} torrents téléchargés`)
} catch (err) {
console.warn(`[fankarr] ⚠ Téléchargement échoué: ${err instanceof Error ? err.message : err}`)
}
} }
try { // Scan initial du mediaPath
const data = JSON.parse(fs.readFileSync(TORRENTS_PATH, 'utf-8')) const ORGANIZED_PATH = path.join(DATA_DIR, 'organized.json')
const count = Array.isArray(data) ? data.length : 0
if (count === 0) console.warn('[fankarr] ⚠ torrent_final.json est vide')
else console.log(`[fankarr] ${count} torrents chargés`)
} catch { console.warn('[fankarr] ⚠ torrent_final.json introuvable ou illisible') }
console.log(`[fankarr] Serveur sur http://localhost:${PORT}`)
// Scan initial du mediaPath pour reconnaître les fichiers déjà présents
const ORGANIZED_PATH = path.join(process.cwd(), 'data', 'organized.json')
const { mediaPath } = readSettings() const { mediaPath } = readSettings()
scanMediaPath(mediaPath, TORRENTS_PATH, ORGANIZED_PATH).catch(err => loadEnrichedSeriesData().then(seriesData =>
scanMediaPath(mediaPath, ORGANIZED_PATH, seriesData)
).catch(err =>
logger.error('organize', `scanMediaPath échoué: ${err}`) logger.error('organize', `scanMediaPath échoué: ${err}`)
) )
// Auto-organise toutes les 30s // Auto-organise — polling différentiel toutes les 5 minutes
// Le worker ne se lance que si un torrent vient de passer en seeding
const autoOrganize = async () => { const autoOrganize = async () => {
try { try {
const { category } = readSettings() const { category } = readSettings()
const seriesData = await loadEnrichedSeriesData()
await autoOrganizeAll( await autoOrganizeAll(
() => dispatchList(category ?? 'fankai'), () => dispatchList(category ?? 'fankai'),
seriesData,
(result) => { (result) => {
if (result.done > 0 || result.errors > 0) { if (result.done > 0 || result.errors > 0) {
pushNotif({ ...result, at: new Date().toISOString() }) pushNotif({ ...result, at: new Date().toISOString() })
@@ -552,9 +759,9 @@ app.listen(PORT, async () => {
console.error('[organize] Erreur auto-organise:', err) console.error('[organize] Erreur auto-organise:', err)
} }
} }
// Premier run 30s après démarrage, puis toutes les 30s // Premier run 10s après démarrage, puis toutes les 5 minutes
setTimeout(() => { setTimeout(() => {
autoOrganize() autoOrganize()
setInterval(autoOrganize, 30_000) setInterval(autoOrganize, 5 * 60_000)
}, 30_000) }, 10_000)
}) })
+2 -1
View File
@@ -8,6 +8,7 @@
import fs from 'fs' import fs from 'fs'
import path from 'path' import path from 'path'
import { DATA_DIR } from './config.js'
export type LogLevel = 'debug' | 'info' | 'warn' | 'error' export type LogLevel = 'debug' | 'info' | 'warn' | 'error'
@@ -19,7 +20,7 @@ export interface LogEntry {
meta? : Record<string, any> meta? : Record<string, any>
} }
const LOGS_PATH = path.join(process.cwd(), 'data', 'logs.jsonl') const LOGS_PATH = path.join(DATA_DIR, 'logs.jsonl')
const MAX_LINES = 2000 // rotation auto au-delà const MAX_LINES = 2000 // rotation auto au-delà
const IS_PROD = process.env.NODE_ENV === 'production' const IS_PROD = process.env.NODE_ENV === 'production'
+175 -156
View File
@@ -4,8 +4,8 @@
* Worker thread dédié à l'organisation des fichiers. * Worker thread dédié à l'organisation des fichiers.
* Tourne dans un thread séparé pour ne pas bloquer le event loop Express. * Tourne dans un thread séparé pour ne pas bloquer le event loop Express.
* *
* Messages reçus (parentPort.on) : { type: 'run', torrents: TorrentInfo[] } * Messages reçus : { type: 'run', torrents: TorrentInfo[], seriesData: SerieData[] }
* Messages envoyés (parentPort.postMessage) : * Messages envoyés :
* { type: 'log', level: 'info'|'warn'|'error', msg: string } * { type: 'log', level: 'info'|'warn'|'error', msg: string }
* { type: 'result', hash: string, name: string, done, skipped, errors } * { type: 'result', hash: string, name: string, done, skipped, errors }
* { type: 'done' } * { type: 'done' }
@@ -15,38 +15,26 @@ import fs from 'fs'
import fsp from 'fs/promises' import fsp from 'fs/promises'
import path from 'path' import path from 'path'
import { parentPort } from 'worker_threads' import { parentPort } from 'worker_threads'
import { DATA_DIR } from './config.js'
// Base directory : binaire Bun ou cwd (Docker/dev) const ORGANIZED_PATH = path.join(DATA_DIR, 'organized.json')
const _isBunBinary = typeof (globalThis as any).Bun !== 'undefined'
&& path.dirname((process as any).execPath) !== process.cwd()
const BASE_DIR = _isBunBinary
? path.dirname((process as any).execPath)
: process.cwd()
const TORRENTS_PATH = path.join(BASE_DIR, 'data', 'torrent_final.json')
const ORGANIZED_PATH = path.join(BASE_DIR, 'data', 'organized.json')
// ─── Utils log ──────────────────────────────────────────────── // ─── Utils log ────────────────────────────────────────────────
// Le worker tourne dans un thread séparé — il passe les logs au thread principal
// qui les écrit dans le fichier via logger.ts
function log(msg: string) { parentPort?.postMessage({ type: 'log', level: 'info', msg }) } function log(msg: string) { parentPort?.postMessage({ type: 'log', level: 'info', msg }) }
function warn(msg: string) { parentPort?.postMessage({ type: 'log', level: 'warn', msg }) } function warn(msg: string) { parentPort?.postMessage({ type: 'log', level: 'warn', msg }) }
function error(msg: string) { parentPort?.postMessage({ type: 'log', level: 'error', msg }) } function error(msg: string) { parentPort?.postMessage({ type: 'log', level: 'error', msg }) }
function debug(msg: string) { parentPort?.postMessage({ type: 'log', level: 'debug', msg }) } function debug(msg: string) { parentPort?.postMessage({ type: 'log', level: 'debug', msg }) }
// ─── Settings (lu directement, pas d'import circulaire) ────── // ─── Settings ─────────────────────────────────────────────────
function readSettings(): { mediaPath: string; completePath: string; organizeMode: string; nfoSupport: boolean } { function readSettings(): { mediaPath: string; completePath: string; organizeMode: string; nfoSupport: boolean } {
try { try {
const p = path.join(process.cwd(), 'data', 'settings.json') const p = path.join(DATA_DIR, 'settings.json')
if (!fs.existsSync(p)) return { mediaPath: '', completePath: '', organizeMode: 'hardlink', nfoSupport: false } if (!fs.existsSync(p)) return { mediaPath: '', completePath: '', organizeMode: 'hardlink', nfoSupport: false }
return JSON.parse(fs.readFileSync(p, 'utf-8')) return JSON.parse(fs.readFileSync(p, 'utf-8'))
} catch { return { mediaPath: '', completePath: '', organizeMode: 'hardlink', nfoSupport: false } } } catch { return { mediaPath: '', completePath: '', organizeMode: 'hardlink', nfoSupport: false } }
} }
// ─── Organized log ──────────────────────────────────────────── // ─── Organized log ────────────────────────────────────────────
function loadOrganized(): Record<string, Record<string, string>> { function loadOrganized(): Record<string, Record<string, string>> {
try { try {
if (!fs.existsSync(ORGANIZED_PATH)) return {} if (!fs.existsSync(ORGANIZED_PATH)) return {}
@@ -65,18 +53,79 @@ function isOrganized(hash: string, filename: string): boolean {
return !!loadOrganized()[hash]?.[filename] return !!loadOrganized()[hash]?.[filename]
} }
// ─── Torrent lookup ─────────────────────────────────────────── // ─── Lookup torrent dans les seriesData passées via message ───
function findTorrentByHash(hash: string, seriesData: any[]): { torrent: any; serieData: any } | null {
for (const sd of seriesData) {
// Niveau série
for (const t of sd.torrents ?? []) {
if (t.infohash?.toLowerCase() === hash.toLowerCase())
return { torrent: t, serieData: sd }
}
// Niveau saison
for (const season of sd.seasons ?? []) {
for (const t of season.torrents ?? []) {
if (t.infohash?.toLowerCase() === hash.toLowerCase())
return { torrent: { ...t, _season: season }, serieData: sd }
}
// Niveau épisode — compter combien d'épisodes partagent ce torrent
const matchingEpisodes = season.episodes?.filter((ep: any) =>
ep.torrents?.some((t: any) => t.infohash?.toLowerCase() === hash.toLowerCase())
) ?? []
function findTorrentByHash(hash: string): any | null { if (matchingEpisodes.length === 1) {
try { // Torrent propre à un seul épisode → cas épisode unique
if (!fs.existsSync(TORRENTS_PATH)) return null const ep = matchingEpisodes[0]
const torrents = JSON.parse(fs.readFileSync(TORRENTS_PATH, 'utf-8')) const t = ep.torrents.find((t: any) => t.infohash?.toLowerCase() === hash.toLowerCase())
return torrents.find((t: any) => t.infohash?.toLowerCase() === hash.toLowerCase()) ?? null return { torrent: { ...t, _episode: ep, _season: season }, serieData: sd }
} catch { return null } } else if (matchingEpisodes.length > 1) {
// Même torrent partagé entre plusieurs épisodes → traiter comme pack_saison
const t = matchingEpisodes[0].torrents.find((t: any) => t.infohash?.toLowerCase() === hash.toLowerCase())
return { torrent: { ...t, _season: season }, serieData: sd }
}
}
}
return null
} }
// ─── Dossiers exclus (bonus, musique, images) ──────────────── // Construit la map filename → { season_number, original_filename, fullPath }
// Supporte les deux formats : { infohash, path } et string (legacy)
function buildFileMap(
serieData : any,
hash : string,
seasonFilter?: number
): Map<string, { season_number: number; original_filename: string; fullPath: string }> {
const map = new Map<string, { season_number: number; original_filename: string; fullPath: string }>()
const h = hash.toLowerCase()
for (const season of serieData.seasons ?? []) {
if (seasonFilter !== undefined && season.season_number !== seasonFilter) continue
for (const ep of season.episodes ?? []) {
const paths: any[] = ep.paths ?? []
let matchedPath: string | null = null
for (const p of paths) {
if (typeof p === 'string') {
if (!matchedPath) matchedPath = p.replace(/\\/g, '/')
} else if (p?.infohash?.toLowerCase() === h) {
matchedPath = p.path.replace(/\\/g, '/')
break
}
}
if (!matchedPath) continue
const filename = matchedPath.split('/').pop() ?? matchedPath
const original = ep.original_filename ?? filename
map.set(filename, {
season_number : season.season_number,
original_filename: original,
fullPath : matchedPath,
})
}
}
return map
}
// ─── Dossiers exclus ─────────────────────────────────────────
const EXCLUDED_FOLDERS = new Set([ const EXCLUDED_FOLDERS = new Set([
'endings', 'ending', 'openings', 'opening', 'ost', 'artworks', 'artwork', 'endings', 'ending', 'openings', 'opening', 'ost', 'artworks', 'artwork',
'bonus', 'extras', 'extra', 'specials', 'special', 'ncop', 'nced', 'bonus', 'extras', 'extra', 'specials', 'special', 'ncop', 'nced',
@@ -95,27 +144,23 @@ function isInExcludedFolder(filePath: string[]): boolean {
} }
// ─── Map correction titres API → titres GitLab ─────────────── // ─── Map correction titres API → titres GitLab ───────────────
const SERIE_TITLE_GITLAB_MAP: Record<string, string> = { const SERIE_TITLE_GITLAB_MAP: Record<string, string> = {
'Enfer Et Paradis Henshū' : 'Enfer et Paradis Henshū', 'Enfer Et Paradis Henshū' : 'Enfer et Paradis Henshū',
'Hajime No Ippo Henshū' : 'Hajime no Ippo Henshū', 'Hajime No Ippo Henshū' : 'Hajime no Ippo Henshū',
'Hikaru No Go Henshū' : 'Hikaru no Go Henshū', 'Hikaru No Go Henshū' : 'Hikaru no Go Henshū',
'Hokuto No Ken Kaï' : 'Hokuto no Ken Kaï', 'Hokuto No Ken Kaï' : 'Hokuto no Ken Kaï',
'Kaguya-sama : Love is War Henshū' : 'Kaguya-sama - Love is War Henshū', 'Kaguya-sama : Love is War Henshū' : 'Kaguya-sama - Love is War Henshū',
'Kenshin le Vagabond Henshū' : 'Kenshin le vagabond Henshū', 'Kenshin le Vagabond Henshū' : 'Kenshin le vagabond Henshū',
'Kuroko No Basket Henshū' : 'Kuroko no Basket Henshū', 'Kuroko No Basket Henshū' : 'Kuroko no Basket Henshū',
'Shingeki No Kyojin Henshū' : 'Shingeki no Kyojin Henshū', 'Shingeki No Kyojin Henshū' : 'Shingeki no Kyojin Henshū',
'Tower Of God Henshū' : 'Tower of God Henshū', 'Tower Of God Henshū' : 'Tower of God Henshū',
} }
function getGitlabSerieTitle(serieTitle: string): string { function getGitlabSerieTitle(serieTitle: string): string {
return SERIE_TITLE_GITLAB_MAP[serieTitle] ?? serieTitle return SERIE_TITLE_GITLAB_MAP[serieTitle] ?? serieTitle
} }
// ─── GitLab NFO downloader ──────────────────────────────────── // ─── GitLab NFO downloader ────────────────────────────────────
const GITLAB_API = 'https://gitlab.com/api/v4/projects/ElPouki%2Ffankai_pack/repository' const GITLAB_API = 'https://gitlab.com/api/v4/projects/ElPouki%2Ffankai_pack/repository'
const GITLAB_RAW_BASE = 'https://gitlab.com/ElPouki/fankai_pack/-/raw/main/pack' const GITLAB_RAW_BASE = 'https://gitlab.com/ElPouki/fankai_pack/-/raw/main/pack'
@@ -136,40 +181,36 @@ async function fetchBinary(url: string): Promise<Buffer> {
async function downloadGitlabFolder(serieTitle: string, destRoot: string): Promise<void> { async function downloadGitlabFolder(serieTitle: string, destRoot: string): Promise<void> {
const gitlabTitle = getGitlabSerieTitle(serieTitle) const gitlabTitle = getGitlabSerieTitle(serieTitle)
const folderPath = `pack/${gitlabTitle}` const folderPath = `pack/${gitlabTitle}`
log(`[nfo] Récupération dossier GitLab: ${gitlabTitle}`) log(`[nfo] Récupération dossier GitLab: ${gitlabTitle}`)
// Lister récursivement tous les fichiers du dossier let files: any[] = []
let files: any[]
try { try {
files = await fetchJson( let page = 1
`${GITLAB_API}/tree?path=${encodeURIComponent(folderPath)}&recursive=true&per_page=100&ref=main` while (true) {
) const batch = await fetchJson(
`${GITLAB_API}/tree?path=${encodeURIComponent(folderPath)}&recursive=true&per_page=100&page=${page}&ref=main`
)
if (!Array.isArray(batch) || batch.length === 0) break
files.push(...batch)
if (batch.length < 100) break
page++
}
} catch (err) { } catch (err) {
warn(`[nfo] Dossier GitLab introuvable pour "${gitlabTitle}": ${err instanceof Error ? err.message : err}`) warn(`[nfo] Dossier GitLab introuvable pour "${serieTitle}": ${err instanceof Error ? err.message : err}`)
return return
} }
if (!Array.isArray(files) || files.length === 0) { if (files.length === 0) { warn(`[nfo] Aucun fichier trouvé pour "${serieTitle}"`); return }
warn(`[nfo] Aucun fichier trouvé sur GitLab pour "${gitlabTitle}"`)
return
}
const fileEntries = files.filter((f: any) => f.type === 'blob') const fileEntries = files.filter((f: any) => f.type === 'blob')
log(`[nfo] ${fileEntries.length} fichiers à télécharger`) log(`[nfo] ${fileEntries.length} fichiers à télécharger`)
for (const entry of fileEntries) { for (const entry of fileEntries) {
// entry.path = "pack/Black Lagoon Henshū/Saison 1/fichier.nfo"
// On retire le préfixe "pack/{gitlabTitle}/" pour obtenir le chemin relatif
const relativePath = entry.path.replace(`pack/${gitlabTitle}/`, '') const relativePath = entry.path.replace(`pack/${gitlabTitle}/`, '')
const destPath = path.join(destRoot, relativePath) const destPath = path.join(destRoot, relativePath)
const destDir = path.dirname(destPath)
// Skip si déjà présent
if (fs.existsSync(destPath)) continue if (fs.existsSync(destPath)) continue
try { try {
fs.mkdirSync(destDir, { recursive: true }) fs.mkdirSync(path.dirname(destPath), { recursive: true })
const rawUrl = `${GITLAB_RAW_BASE}/${encodeURIComponent(gitlabTitle)}/${relativePath.split('/').map(encodeURIComponent).join('/')}` const rawUrl = `${GITLAB_RAW_BASE}/${encodeURIComponent(gitlabTitle)}/${relativePath.split('/').map(encodeURIComponent).join('/')}`
const data = await fetchBinary(rawUrl) const data = await fetchBinary(rawUrl)
fs.writeFileSync(destPath, data) fs.writeFileSync(destPath, data)
@@ -178,15 +219,11 @@ async function downloadGitlabFolder(serieTitle: string, destRoot: string): Promi
warn(`[nfo] ✗ ${relativePath}: ${err instanceof Error ? err.message : err}`) warn(`[nfo] ✗ ${relativePath}: ${err instanceof Error ? err.message : err}`)
} }
} }
log(`[nfo] GitLab synchronisé pour "${gitlabTitle}"`)
log(`[nfo] Dossier GitLab synchronisé pour "${serieTitle}"`)
} }
// ─── Filesystem ops ─────────────────────────────────────────── // ─── Filesystem ops ───────────────────────────────────────────
function seasonFolder(n: number): string { return `Saison ${n}` }
function seasonFolder(n: number): string {
return `Saison ${n}`
}
function tryHardlink(src: string, dest: string): boolean { function tryHardlink(src: string, dest: string): boolean {
try { fs.linkSync(src, dest); return true } try { fs.linkSync(src, dest); return true }
@@ -197,47 +234,63 @@ function tryHardlink(src: string, dest: string): boolean {
} }
// ─── Organise un torrent ────────────────────────────────────── // ─── Organise un torrent ──────────────────────────────────────
async function organizeTorrent(hash: string, name: string, savePath: string, seriesData: any[]) {
async function organizeTorrent(hash: string, name: string, savePath: string) {
const { mediaPath, completePath, organizeMode, nfoSupport } = readSettings() const { mediaPath, completePath, organizeMode, nfoSupport } = readSettings()
const result = { total: 0, skipped: 0, done: 0, errors: [] as { file: string; error: string }[] } const result = { total: 0, skipped: 0, done: 0, errors: [] as { file: string; error: string }[] }
log(`[organize] ── ${name} ──`) log(`[organize] ── ${name} ──`)
log(`[organize] hash=${hash} save_path=${savePath} mode=${organizeMode}`) log(`[organize] hash=${hash} save_path=${savePath} mode=${organizeMode}`)
const torrent = findTorrentByHash(hash) const found = findTorrentByHash(hash, seriesData)
if (!torrent) { if (!found) {
error(`[organize] ✗ Hash ${hash} introuvable dans torrent_final.json`) error(`[organize] ✗ Hash ${hash} introuvable dans les données série`)
throw new Error(`Torrent introuvable : ${hash}`) throw new Error(`Torrent introuvable : ${hash}`)
} }
log(`[organize] ✓ Trouvé : ${torrent.raw}`)
const serieTitle = torrent.serie_title || torrent.show_title || name const { torrent, serieData } = found
const torrentFiles: any[] = torrent.torrent_files ?? [] const serieTitle = serieData.title ?? serieData.show_title ?? name
log(`[organize] serie=${serieTitle} fichiers=${torrentFiles.length}`) const torrentTitle = torrent.title ?? name
log(`[organize] ✓ Trouvé : ${torrentTitle} — série: ${serieTitle}`)
// ── Téléchargement NFO/images depuis GitLab ─────────────── // ── NFO/images depuis GitLab ──────────────────────────────
if (nfoSupport) { if (nfoSupport) {
const serieDestRoot = path.join(mediaPath, serieTitle) await downloadGitlabFolder(serieTitle, path.join(mediaPath, serieTitle))
await downloadGitlabFolder(serieTitle, serieDestRoot)
} }
// ── Cas fichier unique ──────────────────────────────────── // ── Cas torrent épisode unique ────────────────────────────
if (torrentFiles.length === 0) { if (torrent._episode) {
log(`[organize] torrent_files vide → tentative fichier unique`) const ep = torrent._episode
const candidates = [path.join(savePath, name), path.join(completePath, name)] const season = torrent._season
let src: string | null = null const paths: any[] = ep.paths ?? []
for (const c of candidates) { let filePath: string | null = null
if (fs.existsSync(c)) log(`[organize] ✓ source trouvée: ${c}`) for (const p of paths) {
else debug(`[organize] candidate absent: ${c}`) if (typeof p === 'string') { if (!filePath) filePath = p.replace(/\\/g, '/') }
if (fs.existsSync(c)) { src = c; break } else if (p?.infohash?.toLowerCase() === hash.toLowerCase()) { filePath = p.path.replace(/\\/g, '/'); break }
} }
if (!src) throw new Error(`Source introuvable pour "${name}"`) const filename = filePath?.split('/').pop() ?? name
const original = ep.original_filename ?? filename
const destDir = path.join(mediaPath, serieTitle, seasonFolder(season.season_number ?? 1))
const dest = path.join(destDir, original)
const seasonNum = torrent.resolved_episodes?.[0]?.season_number ?? 1 if (isOrganized(hash, filename)) return { ...result, total: 1, skipped: 1 }
const destDir = path.join(mediaPath, serieTitle, seasonFolder(seasonNum))
const dest = path.join(destDir, name) const candidates = filePath ? [
log(`[organize] dest: ${dest}`) path.join(savePath, filePath),
path.join(completePath, filePath),
path.join(savePath, filename),
path.join(completePath, filename),
] : [
path.join(savePath, filename),
path.join(completePath, filename),
]
let src: string | null = null
for (const c of candidates) { if (fs.existsSync(c)) { src = c; break } }
if (!src) {
error(`[organize] ✗ ${filename} introuvable`)
return { ...result, total: 1, errors: [{ file: filename, error: 'Source introuvable' }] }
}
if (!fs.existsSync(dest)) { if (!fs.existsSync(dest)) {
fs.mkdirSync(destDir, { recursive: true }) fs.mkdirSync(destDir, { recursive: true })
@@ -247,83 +300,47 @@ async function organizeTorrent(hash: string, name: string, savePath: string) {
await fsp.copyFile(src, dest) await fsp.copyFile(src, dest)
await fsp.unlink(src) await fsp.unlink(src)
} }
log(`[organize] ✓ ${organizeMode} OK`)
} else {
log(`[organize] → dest existe déjà, skip`)
} }
markOrganized(hash, name) markOrganized(hash, filename)
log(`[organize] ✓ ${original} → Saison ${season.season_number}`)
return { ...result, total: 1, done: 1 } return { ...result, total: 1, done: 1 }
} }
// ── Map filename → season ───────────────────────────────── // ── Pack saison / intégrale ───────────────────────────────
// Priorité : season_number dans torrent_files (packs multi-saisons) const seasonFilter = torrent._season?.season_number
// Fallback : resolved_episodes matchés par episode_number (torrents individuels) const fileMap = buildFileMap(serieData, hash, seasonFilter)
const filenameSeasonMap = new Map<string, number>()
// Index resolved_episodes par episode_number pour lookup rapide if (fileMap.size === 0) {
const epByNum = new Map<number, number>() // ep_number → season_number warn(`[organize] Aucun fichier mappé pour ${name}`)
for (const ep of torrent.resolved_episodes ?? []) { return result
if (ep.episode_number !== undefined && ep.season_number !== undefined)
epByNum.set(ep.episode_number, ep.season_number)
} }
for (const tf of torrentFiles) { result.total = fileMap.size
const sn: number | null = tf.season_number ?? null
if (sn !== null) {
filenameSeasonMap.set(tf.filename, sn)
} else if (tf.num !== undefined && epByNum.has(tf.num)) {
filenameSeasonMap.set(tf.filename, epByNum.get(tf.num)!)
} else if (torrent.season_number !== undefined) {
filenameSeasonMap.set(tf.filename, torrent.season_number)
}
}
result.total = torrentFiles.length
for (const tf of torrentFiles) {
const filename = tf.filename
const filePath: string[] = tf.path
// Skip les fichiers dans des dossiers bonus/musique/images
if (isInExcludedFolder(filePath)) {
log(`[organize] skip bonus: ${filename}`)
result.skipped++
continue
}
for (const [filename, { season_number, original_filename, fullPath }] of fileMap) {
if (isOrganized(hash, filename)) { result.skipped++; continue } if (isOrganized(hash, filename)) { result.skipped++; continue }
// Source : on utilise save_path + fullPath (chemin relatif exact dans le torrent)
// save_path vient de qBittorrent → résiste aux renommages de dossier
const candidates = [ const candidates = [
path.join(savePath, name, ...filePath.slice(0, -1), filename), path.join(savePath, fullPath),
path.join(savePath, ...filePath.slice(0, -1), filename), path.join(completePath, fullPath),
path.join(savePath, name, filename),
path.join(savePath, filename), path.join(savePath, filename),
path.join(completePath, name, ...filePath.slice(0, -1), filename),
path.join(completePath, name, filename),
path.join(completePath, filename), path.join(completePath, filename),
] ]
let src: string | null = null let src: string | null = null
for (const c of candidates) { for (const c of candidates) { if (fs.existsSync(c)) { src = c; break } }
if (fs.existsSync(c)) { src = c; break }
}
if (!src) { if (!src) {
const tried = candidates.map(c => ` • ${c}`).join('\n') error(`[organize] ✗ ${filename} introuvable`)
error(`[organize] ✗ ${filename} introuvable:\n${tried}`)
result.errors.push({ file: filename, error: 'Source introuvable' }) result.errors.push({ file: filename, error: 'Source introuvable' })
continue continue
} }
const seasonNum = filenameSeasonMap.get(filename) ?? 1 const destDir = path.join(mediaPath, serieTitle, seasonFolder(season_number))
const destDir = path.join(mediaPath, serieTitle, seasonFolder(seasonNum)) const dest = path.join(destDir, original_filename)
const dest = path.join(destDir, filename)
if (fs.existsSync(dest)) { if (fs.existsSync(dest)) { markOrganized(hash, filename); result.skipped++; continue }
markOrganized(hash, filename)
result.skipped++
continue
}
try { try {
fs.mkdirSync(destDir, { recursive: true }) fs.mkdirSync(destDir, { recursive: true })
@@ -335,7 +352,7 @@ async function organizeTorrent(hash: string, name: string, savePath: string) {
} }
markOrganized(hash, filename) markOrganized(hash, filename)
result.done++ result.done++
log(`[organize] ✓ ${filename} → Saison ${String(seasonNum).padStart(3,'0')}`) log(`[organize] ✓ ${original_filename} → Saison ${season_number}`)
} catch (err) { } catch (err) {
const msg = err instanceof Error ? err.message : 'Erreur inconnue' const msg = err instanceof Error ? err.message : 'Erreur inconnue'
error(`[organize] ✗ ${filename}: ${msg}`) error(`[organize] ✗ ${filename}: ${msg}`)
@@ -343,37 +360,39 @@ async function organizeTorrent(hash: string, name: string, savePath: string) {
} }
} }
log(`[organize] ── Résultat ${name}: ${result.done} OK, ${result.skipped} skippés, ${result.errors.length} erreurs`) log(`[organize] ── ${name}: ${result.done} OK, ${result.skipped} skippés, ${result.errors.length} erreurs`)
return result return result
} }
// ─── Boucle principale du worker ───────────────────────────── // ─── Boucle principale du worker ─────────────────────────────
parentPort?.on('message', async (msg: any) => { parentPort?.on('message', async (msg: any) => {
if (msg.type !== 'run') return if (msg.type !== 'run') return
const torrents: any[] = msg.torrents const torrents: any[] = msg.torrents
const seriesData: any[] = msg.seriesData ?? []
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') continue
const torrent = findTorrentByHash(t.hash) const found = findTorrentByHash(t.hash, seriesData)
if (!torrent) { if (!found) {
warn(`[organize] hash ${t.hash} (${t.name}) non trouvé`) warn(`[organize] hash ${t.hash} (${t.name}) non trouvé dans les données série`)
continue continue
} }
const files: any[] = torrent.torrent_files ?? [] // Vérifier si déjà tout organisé
// Pour fichier unique : vérifier via le name directement const { torrent, serieData } = found
const allDone = files.length > 0 const seasonFilter = torrent._season?.season_number
? files.every((f: any) => organized[t.hash]?.[f.filename]) const fileMap = buildFileMap(serieData, t.hash, seasonFilter)
const allDone = fileMap.size > 0
? [...fileMap.keys()].every(f => organized[t.hash]?.[f])
: !!organized[t.hash]?.[t.name] : !!organized[t.hash]?.[t.name]
if (allDone) continue if (allDone) continue
try { try {
const result = await organizeTorrent(t.hash, t.name, t.save_path) const result = await organizeTorrent(t.hash, t.name, t.save_path, seriesData)
parentPort?.postMessage({ type: 'result', hash: t.hash, name: t.name, ...result }) parentPort?.postMessage({ type: 'result', hash: t.hash, name: t.name, ...result })
} catch (err) { } catch (err) {
error(`[organize] Erreur ${t.name}: ${err instanceof Error ? err.message : err}`) error(`[organize] Erreur ${t.name}: ${err instanceof Error ? err.message : err}`)
+108 -73
View File
@@ -2,17 +2,29 @@
* organize.ts * organize.ts
* =========== * ===========
* Lance l'organizer dans un Worker Thread dédié pour ne pas bloquer Express. * Lance l'organizer dans un Worker Thread dédié pour ne pas bloquer Express.
* Le worker gère tout le filesystem (copy, hardlink, move).
*/ */
import fs from 'fs' import fs from 'fs'
import path from 'path' import path from 'path'
import { Worker } from 'worker_threads' import { Worker } from 'worker_threads'
import { logger } from './logger.js' import { logger } from './logger.js'
import { DATA_DIR } from './config.js'
const ORGANIZED_PATH = path.join(DATA_DIR, 'organized.json')
// Un seul worker à la fois // Un seul worker à la fois
let workerRunning = false let workerRunning = false
// État précédent des torrents pour détecter les passages downloading → seeding
const _prevStates = new Map<string, string>()
function resolveWorkerPath(): string {
if (typeof (globalThis as any).Bun !== 'undefined') {
return path.join(path.dirname((process as any).execPath), 'organize-worker.js')
}
return path.join(path.dirname(new URL(import.meta.url).pathname), 'organize-worker.js')
}
export interface OrganizeResult { export interface OrganizeResult {
total : number total : number
skipped : number skipped : number
@@ -22,13 +34,12 @@ export interface OrganizeResult {
/** /**
* Scan initial du mediaPath au démarrage. * Scan initial du mediaPath au démarrage.
* Parcourt récursivement le dossier Jellyfin et marque dans organized.json * Construit l'index filename → infohash depuis les seriesData passées en paramètre.
* tous les fichiers déjà présents qui correspondent à un torrent connu.
*/ */
export async function scanMediaPath( export async function scanMediaPath(
mediaPath : string, mediaPath : string,
torrentsPath: string, organizedPath: string,
organizedPath: string seriesData : any[] = []
): Promise<{ found: number; added: number }> { ): Promise<{ found: number; added: number }> {
const result = { found: 0, added: 0 } const result = { found: 0, added: 0 }
@@ -37,27 +48,22 @@ export async function scanMediaPath(
return result return result
} }
// Charger torrent_final.json // Construire index filename → infohash depuis les seriesData
let torrents: any[] = []
try {
if (!fs.existsSync(torrentsPath)) return result
torrents = JSON.parse(fs.readFileSync(torrentsPath, 'utf-8'))
} catch {
logger.error('organize', 'scanMediaPath: impossible de lire torrent_final.json')
return result
}
// Construire un index filename → { hash, infohash }
const filenameIndex = new Map<string, string>() // filename → infohash const filenameIndex = new Map<string, string>() // filename → infohash
for (const t of torrents) { for (const sd of seriesData) {
const hash = t.infohash?.toLowerCase() for (const season of sd.seasons ?? []) {
if (!hash) continue for (const ep of season.episodes ?? []) {
for (const f of t.torrent_files ?? []) { for (const p of ep.paths ?? []) {
if (f.filename) filenameIndex.set(f.filename, hash) if (typeof p === 'string') {
} // Legacy : pas d'infohash disponible, on skip pour le scan
// Fichier unique (torrent_files vide) → on indexe par raw name continue
if ((t.torrent_files ?? []).length === 0 && t.raw) { }
filenameIndex.set(t.raw, hash) const hash = p.infohash?.toLowerCase()
if (!hash || !p.path) continue
const filename = p.path.replace(/\\/g, '/').split('/').pop()
if (filename) filenameIndex.set(filename, hash)
}
}
} }
} }
@@ -68,7 +74,8 @@ export async function scanMediaPath(
organized = JSON.parse(fs.readFileSync(organizedPath, 'utf-8')) organized = JSON.parse(fs.readFileSync(organizedPath, 'utf-8'))
} catch {} } catch {}
// Parcourir récursivement mediaPath const presentFiles = new Set<string>()
function walk(dir: string) { function walk(dir: string) {
let entries: fs.Dirent[] let entries: fs.Dirent[]
try { entries = fs.readdirSync(dir, { withFileTypes: true }) } try { entries = fs.readdirSync(dir, { withFileTypes: true }) }
@@ -81,8 +88,8 @@ export async function scanMediaPath(
result.found++ result.found++
const hash = filenameIndex.get(entry.name) const hash = filenameIndex.get(entry.name)
if (!hash) continue if (!hash) continue
if (organized[hash]?.[entry.name]) continue // déjà connu presentFiles.add(`${hash}:${entry.name}`)
// Marquer comme organisé if (organized[hash]?.[entry.name]) continue
if (!organized[hash]) organized[hash] = {} if (!organized[hash]) organized[hash] = {}
organized[hash][entry.name] = new Date().toISOString() organized[hash][entry.name] = new Date().toISOString()
result.added++ result.added++
@@ -92,9 +99,21 @@ export async function scanMediaPath(
walk(mediaPath) walk(mediaPath)
if (result.added > 0) { // Nettoyer les entrées orphelines
let removed = 0
for (const [hash, files] of Object.entries(organized)) {
for (const filename of Object.keys(files)) {
if (!presentFiles.has(`${hash}:${filename}`) && filenameIndex.get(filename) === hash) {
delete organized[hash][filename]
removed++
}
}
if (Object.keys(organized[hash]).length === 0) delete organized[hash]
}
if (result.added > 0 || removed > 0) {
fs.writeFileSync(organizedPath, JSON.stringify(organized, null, 2), 'utf-8') fs.writeFileSync(organizedPath, JSON.stringify(organized, null, 2), 'utf-8')
logger.info('organize', `scanMediaPath: ${result.found} fichiers scannés, ${result.added} ajoutés à organized.json`) logger.info('organize', `scanMediaPath: ${result.found} fichiers, ${result.added} ajoutés, ${removed} orphelins supprimés`)
} else { } else {
logger.info('organize', `scanMediaPath: ${result.found} fichiers scannés, rien de nouveau`) logger.info('organize', `scanMediaPath: ${result.found} fichiers scannés, rien de nouveau`)
} }
@@ -103,16 +122,15 @@ export async function scanMediaPath(
} }
/** /**
* Lance l'auto-organisation dans un worker thread. * Auto-organisation — appelée depuis index.ts avec les seriesData du cache GitHub.
* listFn est appelée dans le thread principal (accès qBittorrent),
* puis les données sont passées au worker.
*/ */
export async function autoOrganizeAll( export async function autoOrganizeAll(
listFn : () => Promise<any[]>, listFn : () => Promise<any[]>,
onResult?: (r: { hash: string; name: string; done: number; skipped: number; errors: number; errorFiles: { file: string; error: string }[] }) => void seriesData : any[],
onResult ?: (r: { hash: string; name: string; done: number; skipped: number; errors: number; errorFiles: { file: string; error: string }[] }) => void
): Promise<void> { ): Promise<void> {
if (workerRunning) { if (workerRunning) {
logger.debug('organize', 'Worker déjà en cours, skip') console.log('[organize] Worker déjà en cours, skip')
return return
} }
@@ -120,76 +138,93 @@ export async function autoOrganizeAll(
try { try {
torrents = await listFn() torrents = await listFn()
} catch (err) { } catch (err) {
logger.error('organize', "Impossible de récupérer la liste des torrents: " + (err instanceof Error ? err.message : String(err))) console.error('[organize] Impossible de récupérer la liste des torrents:', err)
return return
} }
if (torrents.length === 0) return if (torrents.length === 0) return
const isFirstRun = _prevStates.size === 0
const seedingCount = torrents.filter(t => t.state === 'seeding').length const seedingCount = torrents.filter(t => t.state === 'seeding').length
const newlySeeding = torrents.filter(t => {
const prev = _prevStates.get(t.hash)
return t.state === 'seeding' && (prev === undefined || prev !== 'seeding')
})
for (const t of torrents) _prevStates.set(t.hash, t.state)
// Charger organized.json pour vérifier s'il reste des torrents non organisés
let organized: Record<string, Record<string, string>> = {}
try {
const orgPath = path.join(DATA_DIR, 'organized.json')
if (fs.existsSync(orgPath))
organized = JSON.parse(fs.readFileSync(orgPath, 'utf-8'))
} catch {}
const hasUnorganized = torrents.some(t =>
t.state === 'seeding' && !organized[t.hash?.toLowerCase()]
)
if (!isFirstRun && newlySeeding.length === 0 && !hasUnorganized) return
if (seedingCount === 0) return if (seedingCount === 0) return
logger.info('organize', `Lancement worker (${seedingCount} torrents en seeding)`) if (newlySeeding.length > 0 && !isFirstRun) {
console.log(`[organize] ${newlySeeding.length} nouveau(x) torrent(s) terminé(s) → lancement worker`)
} else {
console.log(`[organize] Lancement worker (${seedingCount} torrents en seeding)`)
}
workerRunning = true workerRunning = true
const workerPath = path.join(path.dirname(new URL(import.meta.url).pathname), 'organize-worker.js') const worker = new Worker(resolveWorkerPath())
const worker = new Worker(workerPath)
worker.on('message', (msg: any) => { worker.on('message', (msg: any) => {
if (msg.type === 'log') { if (msg.type === 'log') {
logger[msg.level as 'debug'|'info'|'warn'|'error']('organize', msg.msg) if (msg.level === 'error') console.error(msg.msg)
else if (msg.level === 'warn') console.warn(msg.msg)
else console.log(msg.msg)
} else if (msg.type === 'result') { } else if (msg.type === 'result') {
logger.info('organize', `${msg.name} → ${msg.done} OK, ${msg.skipped} skippés, ${msg.errors.length} erreurs`) console.log(`[organize] ${msg.name} → ${msg.done} OK, ${msg.skipped} skippés, ${msg.errors.length} erreurs`)
onResult?.({ onResult?.({
hash : msg.hash, hash : msg.hash,
name : msg.name, name : msg.name,
done : msg.done, done : msg.done,
skipped : msg.skipped, skipped : msg.skipped,
errors : msg.errors.length, errors : msg.errors.length,
errorFiles : msg.errors, errorFiles: msg.errors,
}) })
} else if (msg.type === 'done') { } else if (msg.type === 'done') {
logger.debug('organize', 'Worker terminé') console.log('[organize] Worker terminé')
workerRunning = false workerRunning = false
worker.terminate() worker.terminate()
} }
}) })
worker.on('error', (err) => { worker.on('error', (err) => { console.error('[organize] Worker erreur:', err); workerRunning = false })
logger.error('organize', `Worker erreur: ${err instanceof Error ? err.message : err}`) worker.on('exit', (code) => { if (code !== 0) console.error(`[organize] Worker exit ${code}`); workerRunning = false })
workerRunning = false
})
worker.on('exit', (code) => { worker.postMessage({ type: 'run', torrents, seriesData })
if (code !== 0) logger.error('organize', `Worker exit code ${code}`)
workerRunning = false
})
// Envoyer les torrents au worker
worker.postMessage({ type: 'run', torrents })
} }
/** /**
* Organisation manuelle d'un torrent (appelée depuis l'API /organize). * Organisation manuelle d'un torrent.
* Lance aussi dans un worker thread.
*/ */
export async function organizeTorrent( export async function organizeTorrent(
hash : string, hash : string,
name : string, name : string,
savePath: string savePath : string,
seriesData: any[]
): Promise<OrganizeResult> { ): Promise<OrganizeResult> {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const workerPath = path.join(path.dirname(new URL(import.meta.url).pathname), 'organize-worker.js') const worker = new Worker(resolveWorkerPath())
const worker = new Worker(workerPath)
// On envoie un seul torrent "fictif seeding"
const fakeTorrent = { hash, name, save_path: savePath, state: 'seeding' } const fakeTorrent = { hash, name, save_path: savePath, state: 'seeding' }
const result: OrganizeResult = { total: 0, skipped: 0, done: 0, errors: [] } const result: OrganizeResult = { total: 0, skipped: 0, done: 0, errors: [] }
worker.on('message', (msg: any) => { worker.on('message', (msg: any) => {
if (msg.type === 'log') { if (msg.type === 'log') {
logger[msg.level as 'debug'|'info'|'warn'|'error']('organize', msg.msg) if (msg.level === 'error') console.error(msg.msg)
else if (msg.level === 'warn') console.warn(msg.msg)
else console.log(msg.msg)
} else if (msg.type === 'result') { } else if (msg.type === 'result') {
result.total = msg.total result.total = msg.total
result.skipped = msg.skipped result.skipped = msg.skipped
@@ -204,6 +239,6 @@ export async function organizeTorrent(
worker.on('error', (err) => { worker.terminate(); reject(err) }) worker.on('error', (err) => { worker.terminate(); reject(err) })
worker.on('exit', (code) => { if (code !== 0) reject(new Error(`Worker exit ${code}`)) }) worker.on('exit', (code) => { if (code !== 0) reject(new Error(`Worker exit ${code}`)) })
worker.postMessage({ type: 'run', torrents: [fakeTorrent] }) worker.postMessage({ type: 'run', torrents: [fakeTorrent], seriesData })
}) })
} }
+2 -1
View File
@@ -9,8 +9,9 @@
import fs from 'fs' import fs from 'fs'
import path from 'path' import path from 'path'
import crypto from 'crypto' import crypto from 'crypto'
import { DATA_DIR } from './config.js'
const SECRET_PATH = path.join(process.cwd(), 'data', 'secret.key') const SECRET_PATH = path.join(DATA_DIR, 'secret.key')
function generateSecret(): string { function generateSecret(): string {
return crypto.randomBytes(48).toString('hex') return crypto.randomBytes(48).toString('hex')
+2 -6
View File
@@ -1,12 +1,8 @@
import fs from 'fs' import fs from 'fs'
import path from 'path' import path from 'path'
import { DATA_DIR } from './config.js'
const _isBunBinary = typeof (globalThis as any).Bun !== 'undefined' const DATA_PATH = path.join(DATA_DIR, 'settings.json')
&& path.dirname((process as any).execPath) !== process.cwd()
const BASE_DIR = _isBunBinary
? path.dirname((process as any).execPath)
: process.cwd()
const DATA_PATH = path.join(BASE_DIR, 'data', 'settings.json')
export interface Settings { export interface Settings {
mediaPath : string mediaPath : string
+2 -1
View File
@@ -9,6 +9,7 @@
import { randomUUID } from 'crypto' import { randomUUID } from 'crypto'
import fs from 'fs' import fs from 'fs'
import path from 'path' import path from 'path'
import { DATA_DIR } from '../config.js'
// ─── Types ──────────────────────────────────────────────────────────────────── // ─── Types ────────────────────────────────────────────────────────────────────
@@ -77,7 +78,7 @@ export function getAvailableClients(): TorrentClientDefinition[] {
// ─── Persistence (clients enregistrés) ──────────────────────────────────────── // ─── Persistence (clients enregistrés) ────────────────────────────────────────
const CLIENTS_PATH = path.join(process.cwd(), 'data', 'torrent_clients.json') const CLIENTS_PATH = path.join(DATA_DIR, 'torrent_clients.json')
function loadClients(): SavedClient[] { function loadClients(): SavedClient[] {
try { try {
+43 -1
View File
@@ -10,6 +10,12 @@
<h1 class="text-xl font-black text-white font-sans">Téléchargements</h1> <h1 class="text-xl font-black text-white font-sans">Téléchargements</h1>
</div> </div>
<div class="flex items-center gap-3"> <div class="flex items-center gap-3">
<button
@click="organizeAll"
:disabled="organizingAll"
class="border border-[#1e2d3d] text-[#5a7a94] px-4 py-1.5 text-xs tracking-widest hover:border-green-500 hover:text-green-500 transition-colors cursor-pointer disabled:opacity-50">
{{ organizingAll ? '...' : 'ORGANISER TOUT' }}
</button>
<div class="flex items-center gap-2 text-[10px] text-[#5a7a94] tracking-widest"> <div class="flex items-center gap-2 text-[10px] text-[#5a7a94] tracking-widest">
<div class="w-1.5 h-1.5 rounded-full" :class="polling ? 'bg-green-500 animate-pulse' : 'bg-[#1e2d3d]'"/> <div class="w-1.5 h-1.5 rounded-full" :class="polling ? 'bg-green-500 animate-pulse' : 'bg-[#1e2d3d]'"/>
{{ polling ? 'EN DIRECT' : 'PAUSE' }} {{ polling ? 'EN DIRECT' : 'PAUSE' }}
@@ -190,6 +196,7 @@ const loading = ref(true)
const polling = ref(true) const polling = ref(true)
const noClients = ref(false) const noClients = ref(false)
const organizing = ref<Record<string, boolean>>({}) const organizing = ref<Record<string, boolean>>({})
const organizingAll = ref(false)
const activeTab = ref<'active' | 'done'>('active') const activeTab = ref<'active' | 'done'>('active')
const hideOrganized = ref(false) const hideOrganized = ref(false)
@@ -251,7 +258,7 @@ function togglePolling() {
onMounted(startPolling) onMounted(startPolling)
onUnmounted(stopPolling) onUnmounted(stopPolling)
// ── Organiser ────────────────────────────────────────────────── // ── Organiser un torrent ───────────────────────────────────────
async function organize(torrent: any) { async function organize(torrent: any) {
organizing.value[torrent.hash] = true organizing.value[torrent.hash] = true
try { try {
@@ -263,6 +270,7 @@ async function organize(torrent: any) {
}) })
if (res.ok) { if (res.ok) {
toast(`${torrent.name} organisé ✓`, 'success') toast(`${torrent.name} organisé ✓`, 'success')
await fetchTorrents()
} else { } else {
const { error } = await res.json() const { error } = await res.json()
toast(error ?? 'Erreur lors de l\'organisation', 'error') toast(error ?? 'Erreur lors de l\'organisation', 'error')
@@ -274,6 +282,40 @@ async function organize(torrent: any) {
} }
} }
// ── Organiser tout ─────────────────────────────────────────────
async function organizeAll() {
const toOrganize = doneTorrents.value.filter(t => t.organizeState !== 'done')
if (toOrganize.length === 0) {
toast('Tous les torrents sont déjà organisés', 'success')
return
}
organizingAll.value = true
let done = 0
let errors = 0
for (const t of toOrganize) {
try {
const res = await fetch('/api/organize', {
method : 'POST',
headers: { 'Content-Type': 'application/json' },
credentials: 'include',
body: JSON.stringify({ hash: t.hash, save_path: t.save_path, name: t.name })
})
if (res.ok) done++
else errors++
} catch {
errors++
}
}
organizingAll.value = false
await fetchTorrents()
if (errors === 0) toast(`${done} torrent(s) organisé(s) ✓`, 'success')
else toast(`${done} OK, ${errors} erreur(s)`, 'error')
}
// ── Helpers affichage ────────────────────────────────────────── // ── Helpers affichage ──────────────────────────────────────────
function stateBadge(state: string) { function stateBadge(state: string) {
const map: Record<string, { label: string; class: string }> = { const map: Record<string, { label: string; class: string }> = {
+31 -25
View File
@@ -27,7 +27,8 @@
<!-- Hero --> <!-- Hero -->
<div class="relative"> <div class="relative">
<div v-if="data.serie.fanart_image" class="absolute inset-0 h-72 overflow-hidden pointer-events-none"> <div v-if="data.serie.fanart_image" class="absolute inset-0 h-72 overflow-hidden pointer-events-none">
<img :src="data.serie.fanart_image" class="w-full h-full object-cover opacity-20" /> <img :src="data.serie.fanart_image" class="w-full h-full object-cover opacity-20"
@error="e => ((e.target as HTMLElement).closest('div') as HTMLElement).style.display = 'none'" />
<div class="absolute inset-0 bg-gradient-to-b from-transparent to-zinc-950" /> <div class="absolute inset-0 bg-gradient-to-b from-transparent to-zinc-950" />
</div> </div>
@@ -64,6 +65,7 @@
<button <button
v-for="(t, i) in data.torrents_integrale" v-for="(t, i) in data.torrents_integrale"
:key="i" :key="i"
:title="t.raw"
class="inline-flex items-center gap-2 px-4 py-2 text-sm font-medium rounded-lg transition" class="inline-flex items-center gap-2 px-4 py-2 text-sm font-medium rounded-lg transition"
:class="[ :class="[
t.label === 'Intégrale' t.label === 'Intégrale'
@@ -81,12 +83,10 @@
<!-- Barre progression intégrale --> <!-- Barre progression intégrale -->
<template v-for="(t, i) in data.torrents_integrale" :key="`prog-${i}`"> <template v-for="(t, i) in data.torrents_integrale" :key="`prog-${i}`">
<template v-if="torrentProgress(extractHash(t))"> <template v-if="torrentProgress(extractHash(t))">
<!-- Badge 100% -->
<span v-if="torrentProgress(extractHash(t))!.progress === 100" <span v-if="torrentProgress(extractHash(t))!.progress === 100"
class="mt-2 inline-flex items-center gap-1.5 text-[10px] px-2.5 py-1 rounded-full border bg-green-500/10 text-green-400 border-green-500/20"> class="mt-2 inline-flex items-center gap-1.5 text-[10px] px-2.5 py-1 rounded-full border bg-green-500/10 text-green-400 border-green-500/20">
✓ Téléchargé ✓ Téléchargé
</span> </span>
<!-- Barre en cours -->
<div v-else class="mt-2 w-full max-w-sm"> <div v-else class="mt-2 w-full max-w-sm">
<div class="flex items-center justify-between text-[10px] text-zinc-500 mb-1"> <div class="flex items-center justify-between text-[10px] text-zinc-500 mb-1">
<span>Téléchargement</span> <span>Téléchargement</span>
@@ -160,16 +160,15 @@
{{ season.organized_state === 'complete' ? 'Organisé ✓' : isAlreadyQueued(season.torrent) ? 'Déjà ajouté' : downloaded.has(`season-${season.id}`) ? 'Envoyé ✓' : 'Saison entière' }} {{ season.organized_state === 'complete' ? 'Organisé ✓' : isAlreadyQueued(season.torrent) ? 'Déjà ajouté' : downloaded.has(`season-${season.id}`) ? 'Envoyé ✓' : 'Saison entière' }}
</button> </button>
</div> </div>
<!-- Barre progression saison --> <!-- Barre progression saison -->
<template v-if="torrentProgress(extractHash(season.torrent))"> <template v-if="torrentProgress(extractHash(season.torrent))">
<!-- Badge 100% -->
<div v-if="torrentProgress(extractHash(season.torrent))!.progress === 100" <div v-if="torrentProgress(extractHash(season.torrent))!.progress === 100"
class="px-5 py-2 border-b border-white/5"> class="px-5 py-2 border-b border-white/5">
<span class="inline-flex items-center gap-1.5 text-[10px] px-2.5 py-1 rounded-full border bg-green-500/10 text-green-400 border-green-500/20"> <span class="inline-flex items-center gap-1.5 text-[10px] px-2.5 py-1 rounded-full border bg-green-500/10 text-green-400 border-green-500/20">
✓ Téléchargé ✓ Téléchargé
</span> </span>
</div> </div>
<!-- Barre en cours -->
<div v-else class="px-5 py-2 border-b border-white/5"> <div v-else class="px-5 py-2 border-b border-white/5">
<div class="flex items-center justify-between text-[10px] text-zinc-500 mb-1"> <div class="flex items-center justify-between text-[10px] text-zinc-500 mb-1">
<span>Téléchargement en cours</span> <span>Téléchargement en cours</span>
@@ -202,9 +201,9 @@
<!-- Info --> <!-- Info -->
<div class="flex-1 min-w-0"> <div class="flex-1 min-w-0">
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<span class="text-xs text-zinc-600 shrink-0 font-mono"> <span class="text-xs text-zinc-600 shrink-0 font-mono">
{{ season.season_number === 0 ? 'SP' : `E${String(ep.episode_number).padStart(2,'0')}` }} {{ season.season_number === 0 ? 'SP' : `E${String(ep.episode_number).padStart(2,'0')}` }}
</span> </span>
<span class="text-sm font-medium truncate">{{ ep.title || `Épisode ${ep.episode_number}` }}</span> <span class="text-sm font-medium truncate">{{ ep.title || `Épisode ${ep.episode_number}` }}</span>
</div> </div>
<div class="flex items-center gap-3 mt-0.5"> <div class="flex items-center gap-3 mt-0.5">
@@ -213,38 +212,48 @@
</div> </div>
</div> </div>
<!-- Bouton épisode (type episode uniquement) --> <!-- Badges + bouton download -->
<div class="shrink-0 flex items-center gap-2"> <div class="shrink-0 flex items-center gap-2">
<!-- Badge Hors Fankai (torrent manuel) -->
<span
v-if="ep.torrent?.manual"
title="Ce fichier ne provient pas du catalogue Fan-Kai officiel"
class="text-[10px] px-2 py-0.5 rounded-full border bg-purple-500/10 text-purple-400 border-purple-500/20"
>
Hors Fankai
</span>
<!-- Badge organisé --> <!-- Badge organisé -->
<span v-if="ep.organized" <span v-if="ep.organized"
class="text-[10px] px-2 py-0.5 rounded-full border bg-green-500/10 text-green-400 border-green-500/20"> class="text-[10px] px-2 py-0.5 rounded-full border bg-green-500/10 text-green-400 border-green-500/20">
✓ organisé ✓ organisé
</span> </span>
<!-- Badge téléchargé à 100% --> <!-- Badge téléchargé à 100% -->
<span v-if="torrentProgress(extractHash(ep.torrent))?.progress === 100" <span v-if="torrentProgress(extractHash(ep.torrent))?.progress === 100"
class="text-[10px] px-2 py-0.5 rounded-full border bg-green-500/10 text-green-400 border-green-500/20"> class="text-[10px] px-2 py-0.5 rounded-full border bg-green-500/10 text-green-400 border-green-500/20">
✓ téléchargé ✓ téléchargé
</span> </span>
<!-- Badge dispo/indispo --> <!-- Badge dispo/indispo -->
<span <span
class="inline-block text-[10px] px-2 py-0.5 rounded-full border" class="inline-block text-[10px] px-2 py-0.5 rounded-full border"
:class="ep.available :class="ep.available
? 'bg-blue-500/10 text-blue-400 border-blue-500/20' ? 'bg-blue-500/10 text-blue-400 border-blue-500/20'
: 'bg-white/5 text-zinc-600 border-white/8'" : 'bg-white/5 text-zinc-600 border-white/8'"
> >
{{ ep.available ? 'dispo' : 'indispo' }} {{ ep.available ? 'dispo' : 'indispo' }}
</span> </span>
<!-- Bouton download --> <!-- Bouton download -->
<button <button
class="inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded-lg border transition" class="inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded-lg border transition"
:class="[ :class="[
ep.torrent && !downloaded.has(`ep-${ep.id}`) && !isAlreadyQueued(ep.torrent) && !ep.organized ep.torrent && !downloaded.has(`ep-${ep.id}`) && !isAlreadyQueued(ep.torrent) && !ep.organized
? 'bg-orange-500/10 hover:bg-orange-500/20 text-orange-400 border-orange-500/20' ? 'bg-orange-500/10 hover:bg-orange-500/20 text-orange-400 border-orange-500/20'
: 'bg-white/[0.03] text-zinc-600 border-white/8 cursor-not-allowed' : 'bg-white/[0.03] text-zinc-600 border-white/8 cursor-not-allowed'
]" ]"
:disabled="!ep.torrent || downloading.has(`ep-${ep.id}`) || downloaded.has(`ep-${ep.id}`) || isAlreadyQueued(ep.torrent) || ep.organized" :disabled="!ep.torrent || downloading.has(`ep-${ep.id}`) || downloaded.has(`ep-${ep.id}`) || isAlreadyQueued(ep.torrent) || ep.organized"
@click="ep.torrent && download(`ep-${ep.id}`, ep.torrent.torrent_url, ep.torrent.magnet)" @click="ep.torrent && download(`ep-${ep.id}`, ep.torrent.torrent_url, ep.torrent.magnet)"
> >
@@ -317,7 +326,7 @@ const store = useSeriesStore()
const collapsedSeasons = ref<Set<number>>(new Set()) const collapsedSeasons = ref<Set<number>>(new Set())
const downloading = ref<Set<string>>(new Set()) const downloading = ref<Set<string>>(new Set())
const downloaded = ref<Set<string>>(new Set()) // envoyés avec succès → bloqués const downloaded = ref<Set<string>>(new Set())
const toast = ref<{ type: 'success' | 'error'; message: string } | null>(null) const toast = ref<{ type: 'success' | 'error'; message: string } | null>(null)
// ── Progression downloads ────────────────────────────────────── // ── Progression downloads ──────────────────────────────────────
@@ -339,13 +348,11 @@ async function fetchActiveDownloads() {
} catch {} } catch {}
} }
// Cherche si un torrent actif correspond à un hash donné
function torrentProgress(hash: string | null | undefined): ActiveTorrent | null { function torrentProgress(hash: string | null | undefined): ActiveTorrent | null {
if (!hash) return null if (!hash) return null
return activeTorrents.value.find(t => t.hash.toLowerCase() === hash.toLowerCase()) ?? null return activeTorrents.value.find(t => t.hash.toLowerCase() === hash.toLowerCase()) ?? null
} }
// Hash d'un torrent de saison ou d'épisode (extrait depuis magnet ou url)
function extractHash(torrent: { magnet?: string | null; torrent_url?: string | null } | null | undefined): string | null { function extractHash(torrent: { magnet?: string | null; torrent_url?: string | null } | null | undefined): string | null {
if (!torrent) return null if (!torrent) return null
const magnet = torrent.magnet ?? '' const magnet = torrent.magnet ?? ''
@@ -375,7 +382,6 @@ function showToast(type: 'success' | 'error', message: string) {
setTimeout(() => { toast.value = null }, 3500) setTimeout(() => { toast.value = null }, 3500)
} }
// Vérifie si un torrent est déjà en cours ou terminé dans qBittorrent
function isAlreadyQueued(torrent: { magnet?: string | null; torrent_url?: string | null } | null | undefined): boolean { function isAlreadyQueued(torrent: { magnet?: string | null; torrent_url?: string | null } | null | undefined): boolean {
const hash = extractHash(torrent) const hash = extractHash(torrent)
if (!hash) return false if (!hash) return false
+2 -2
View File
@@ -14,9 +14,9 @@ export default defineConfig({
outDir: 'dist/client' outDir: 'dist/client'
}, },
server: { server: {
port: 3000, port: 3000, // ou autre port fixe
proxy: { proxy: {
'/api': 'http://localhost:3001' '/api': 'http://localhost:9898'
} }
} }
}) })