iamuz.py

Dans
Script python pour télécharger le contenu d’une archive en fonction de l’id sur Internet Archive,
❯ python3 iamuz2.py --help
usage: iamuz2.py [-h] [--id ID] [--debug] [--selftest]
Télécharge des MP3/OGG depuis archive.org
options:
-h, --help show this help message and exit
--id ID Identifiant Archive.org
--debug Mode debug
--selftest Test du script
~
- Création automatique des dossiers avec
dest.parent.mkdir(parents=True, exist_ok=True)
. - Détection des fichiers audio basée sur l’extension
.mp3
ou.ogg
. - Logs détaillés pour toutes les étapes : récupération, téléchargement, erreurs.
--selftest
pour vérifier que le script peut créer des dossiers correctement.
#!/usr/bin/env python3
import os
import sys
import requests
import argparse
from pathlib import Path
from time import time
DOWNLOAD_DIR = Path("downloads")
def log_debug(msg):
print(f"[DEBUG] {msg}")
def log_info(msg):
print(f"[INFO] {msg}")
def log_warn(msg):
print(f"[WARN] {msg}")
def fetch_metadata(identifier, session):
url = f"https://archive.org/metadata/{identifier}"
log_debug(f"Récupération des métadonnées pour {identifier} depuis {url}")
try:
response = session.get(url)
response.raise_for_status()
return response.json()
except requests.RequestException as e:
log_warn(f"Impossible de récupérer les métadonnées: {e}")
return None
def find_audio_files(metadata):
files = metadata.get("files", [])
audio_files = [f["name"] for f in files if f["name"].lower().endswith((".mp3", ".ogg"))]
log_info(f"{len(audio_files)} fichier(s) audio trouvé(s)")
for f in audio_files:
log_debug(f" → {f}")
return audio_files
def download_file(session, identifier, file_name):
url = f"https://archive.org/download/{identifier}/{file_name}"
dest = DOWNLOAD_DIR / file_name
dest.parent.mkdir(parents=True, exist_ok=True)
if dest.exists():
log_debug(f"Fichier déjà existant, skipping: {dest}")
return
log_info(f"Téléchargement de {file_name}")
try:
response = session.get(url, stream=True)
response.raise_for_status()
total_size = int(response.headers.get("content-length", 0))
downloaded = 0
start_time = time()
with open(dest, "wb") as f:
for chunk in response.iter_content(chunk_size=8192):
if chunk:
f.write(chunk)
downloaded += len(chunk)
if total_size > 0:
percent = downloaded / total_size * 100
elapsed = time() - start_time
speed = downloaded / 1024 / elapsed if elapsed > 0 else 0
print(f"\r{percent:6.2f}% | {downloaded/1024:.2f} KB / {total_size/1024:.2f} KB | {speed:.2f} KB/s", end="")
print() # nouvelle ligne après téléchargement
log_info(f"Téléchargé avec succès: {dest}")
except requests.HTTPError as e:
log_warn(f"Erreur HTTP lors du téléchargement de {file_name}: {e}")
except Exception as e:
log_warn(f"Erreur lors du téléchargement de {file_name}: {e}")
def process_identifier(identifier, session):
log_debug(f"Début traitement pour {identifier}")
metadata = fetch_metadata(identifier, session)
if not metadata:
return
audio_files = find_audio_files(metadata)
if not audio_files:
log_warn(f"Aucun fichier audio trouvé pour {identifier}")
return
for f in audio_files:
download_file(session, identifier, f)
def main():
parser = argparse.ArgumentParser(description="Télécharge des MP3/OGG depuis archive.org")
parser.add_argument("--id", help="Identifiant Archive.org", required=False)
parser.add_argument("--debug", action="store_true", help="Mode debug")
parser.add_argument("--selftest", action="store_true", help="Test du script")
args = parser.parse_args()
session = requests.Session()
if args.selftest:
log_info("Selftest: Vérification de la structure de téléchargement...")
(DOWNLOAD_DIR / "test_folder").mkdir(parents=True, exist_ok=True)
log_info("Selftest terminé avec succès")
return
if not args.id:
log_warn("Aucun identifiant fourni. Exemple pour tester metadata:")
print(" python3 iamuz.py --id LAROCCA13CLASSICS02 --debug")
return
process_identifier(args.id, session)
if __name__ == "__main__":
main()
~
❯ python3 iamuz2.py --id GLOBE_AFTER_CLUB
[DEBUG] Début traitement pour GLOBE_AFTER_CLUB
[DEBUG] Récupération des métadonnées pour GLOBE_AFTER_CLUB depuis https://archive.org/metadata/GLOBE_AFTER_CLUB
[INFO] 60 fichier(s) audio trouvé(s)
[DEBUG] → globe - after club/CD1/1.01. Energiya - Straight Kickin' (Original Mix).mp3
[DEBUG] → globe - after club/CD1/1.01. Energiya - Straight Kickin' (Original Mix).ogg
[DEBUG] → globe - after club/CD1/1.02. The Regulators - Berlin.mp3
[DEBUG] → globe - after club/CD1/1.02. The Regulators - Berlin.ogg
[DEBUG] → globe - after club/CD1/1.03. Groovezone - Eisbaer (Ice Remix).mp3
[DEBUG] → globe - after club/CD1/1.03. Groovezone - Eisbaer (Ice Remix).ogg
[DEBUG] → globe - after club/CD1/1.04. Moonman - First Light (Hole In One Mix).mp3
[DEBUG] → globe - after club/CD1/1.04. Moonman - First Light (Hole In One Mix).ogg
[DEBUG] → globe - after club/CD1/1.05. Team Deep - Spang.mp3
[DEBUG] → globe - after club/CD1/1.05. Team Deep - Spang.ogg
[DEBUG] → globe - after club/CD1/1.06. Da Hool - Freakstyle.mp3
[DEBUG] → globe - after club/CD1/1.06. Da Hool - Freakstyle.ogg
[DEBUG] → globe - after club/CD1/1.07. Afrowax - English 101 (Al Farist & A. Wooden Remix).mp3
[DEBUG] → globe - after club/CD1/1.07. Afrowax - English 101 (Al Farist & A. Wooden Remix).ogg
[DEBUG] → globe - after club/CD1/1.08. Silent Breed - Sync In.mp3
[DEBUG] → globe - after club/CD1/1.08. Silent Breed - Sync In.ogg
[DEBUG] → globe - after club/CD1/1.09. Antic - Pulse.mp3
[DEBUG] → globe - after club/CD1/1.09. Antic - Pulse.ogg
[DEBUG] → globe - after club/CD1/1.10. Cold Turkey - Freakstyle.mp3
[DEBUG] → globe - after club/CD1/1.10. Cold Turkey - Freakstyle.ogg
[DEBUG] → globe - after club/CD1/1.11. Snitzer & Mc Coy vs. Humate - Oh My Darling I Love You (Heavy Mix).mp3
[DEBUG] → globe - after club/CD1/1.11. Snitzer & Mc Coy vs. Humate - Oh My Darling I Love You (Heavy Mix).ogg
[DEBUG] → globe - after club/CD1/1.12. V.O.O.D.I. Traxx - Natural Trail (Club Quake vs. V.O.O.D.I. Mix).mp3
[DEBUG] → globe - after club/CD1/1.12. V.O.O.D.I. Traxx - Natural Trail (Club Quake vs. V.O.O.D.I. Mix).ogg
[DEBUG] → globe - after club/CD1/1.13. DJ Ablaze - One More.mp3
[DEBUG] → globe - after club/CD1/1.13. DJ Ablaze - One More.ogg
[DEBUG] → globe - after club/CD1/1.14. Chemistry - Outerspace.mp3
[DEBUG] → globe - after club/CD1/1.14. Chemistry - Outerspace.ogg
[DEBUG] → globe - after club/CD1/1.15. Yves Deruyter ft Zolex - The Limit.mp3
[DEBUG] → globe - after club/CD1/1.15. Yves Deruyter ft Zolex - The Limit.ogg
[DEBUG] → globe - after club/CD2/2.01. Insider - Saurian.mp3
[DEBUG] → globe - after club/CD2/2.01. Insider - Saurian.ogg
[DEBUG] → globe - after club/CD2/2.02. Loophole - Frontcut.mp3
[DEBUG] → globe - after club/CD2/2.02. Loophole - Frontcut.ogg
[DEBUG] → globe - after club/CD2/2.03. Chiapet - Tick Tock (Apocalypse Now Mix).mp3
[DEBUG] → globe - after club/CD2/2.03. Chiapet - Tick Tock (Apocalypse Now Mix).ogg
[DEBUG] → globe - after club/CD2/2.04. LSG - Netherworld (DJ Randy's Smoke Free Remix).mp3
[DEBUG] → globe - after club/CD2/2.04. LSG - Netherworld (DJ Randy's Smoke Free Remix).ogg
[DEBUG] → globe - after club/CD2/2.05. Literon - How Little Space.mp3
[DEBUG] → globe - after club/CD2/2.05. Literon - How Little Space.ogg
[DEBUG] → globe - after club/CD2/2.06. The Juice - Iron Man.mp3
[DEBUG] → globe - after club/CD2/2.06. The Juice - Iron Man.ogg
[DEBUG] → globe - after club/CD2/2.07. Deniro - Mind Of Man (Remix).mp3
[DEBUG] → globe - after club/CD2/2.07. Deniro - Mind Of Man (Remix).ogg
[DEBUG] → globe - after club/CD2/2.08. DJ Misjah - Karin's Paradox.mp3
[DEBUG] → globe - after club/CD2/2.08. DJ Misjah - Karin's Paradox.ogg
[DEBUG] → globe - after club/CD2/2.09. Dimitri Gelders - Cycle Mode.mp3
[DEBUG] → globe - after club/CD2/2.09. Dimitri Gelders - Cycle Mode.ogg
[DEBUG] → globe - after club/CD2/2.10. The X Factor - The Soul Shelter (Mr Marvin Native Percussion Mix).mp3
[DEBUG] → globe - after club/CD2/2.10. The X Factor - The Soul Shelter (Mr Marvin Native Percussion Mix).ogg
[DEBUG] → globe - after club/CD2/2.11. Speedy J - Pannik.mp3
[DEBUG] → globe - after club/CD2/2.11. Speedy J - Pannik.ogg
[DEBUG] → globe - after club/CD2/2.12. The Blunted Boy Wonder - Metropolis.mp3
[DEBUG] → globe - after club/CD2/2.12. The Blunted Boy Wonder - Metropolis.ogg
[DEBUG] → globe - after club/CD2/2.13. Sinus - The Blob (J Jam Remix).mp3
[DEBUG] → globe - after club/CD2/2.13. Sinus - The Blob (J Jam Remix).ogg
[DEBUG] → globe - after club/CD2/2.14. Innerdrive - Beat On My Drum.mp3
[DEBUG] → globe - after club/CD2/2.14. Innerdrive - Beat On My Drum.ogg
[DEBUG] → globe - after club/CD2/2.15. Tyrome - Bounce.mp3
[DEBUG] → globe - after club/CD2/2.15. Tyrome - Bounce.ogg
[INFO] Téléchargement de globe - after club/CD1/1.01. Energiya - Straight Kickin' (Original Mix).mp3
100.00% | 4143.65 KB / 4143.65 KB | 1090.96 KB/s
[INFO] Téléchargé avec succès: downloads/globe - after club/CD1/1.01. Energiya - Straight Kickin' (Original Mix).mp3
[INFO] Téléchargement de globe - after club/CD1/1.01. Energiya - Straight Kickin' (Original Mix).ogg
100.00% | 2986.52 KB / 2986.52 KB | 3810.46 KB/ss
[INFO] Téléchargé avec succès: downloads/globe - after club/CD1/1.01. Energiya - Straight Kickin' (Original Mix).ogg
[INFO] Téléchargement de globe - after club/CD1/1.02. The Regulators - Berlin.mp3
100.00% | 5578.72 KB / 5578.72 KB | 380.89 KB/s
[INFO] Téléchargé avec succès: downloads/globe - after club/CD1/1.02. The Regulators - Berlin.mp3
[INFO] Téléchargement de globe - after club/CD1/1.02. The Regulators - Berlin.ogg
100.00% | 3806.59 KB / 3806.59 KB | 2314.54 KB/s
[INFO] Téléchargé avec succès: downloads/globe - after club/CD1/1.02. The Regulators - Berlin.ogg
Auteur/autrice
sdgadmin@tux.ovh
Publications similaires


parse_dsk.py
Un script Python robuste pour analyser des images de disquette .dsk (Amstrad CPC), détecter le répertoire, reconstituer la liste des fichiers et...
Lire la suite
Dans
Blackjack
compter les cartes L’astuce : augmenter les mises quand le paquet est favorable, et miser peu quand il ne l’est pas.
Lire la suite
cpcdb.py
Le script va maintenant : ✅ Se connecter au serveur MySQL ✅ Créer la table dsk_games dans la base cpcdb ✅ Scanner...
Lire la suite
CPC.PY
✅ Fait quoi ? 📁 Arborescence produite : 📂 cpc_games/ ← Fichiers .dsk, .zip…📂 screenshots/ ← Captures d’écran (cover, title, etc.)📄 cpc_software_metadata.csv...
Lire la suite