[tree_stream] Utilisation du MIMEtype (0.1.1)
All checks were successful
/ 🐍 Build & Publish Python Packages (push) Successful in 1m1s

This commit is contained in:
lionel
2025-09-11 17:28:49 +02:00
parent 3cc07f2b86
commit 0668d82464
2 changed files with 10 additions and 3 deletions

View File

@ -2,7 +2,7 @@ from setuptools import setup, find_packages
setup(
name="tree-stream",
version="0.1.0",
version="0.1.1",
description="Affiche une arborescence enrichie des fichiers vidéo avec chapitres et flux",
author="TonNom",
packages=find_packages(),

View File

@ -4,6 +4,7 @@ import os
import sys
import argparse
import ffmpeg
import mimetypes
# Codes des couleurs ANSI
NOIR = "\033[30m"
@ -31,11 +32,17 @@ SOULIGNE = "\033[4m" # Souligné
CLIGNOTANT = "\033[5m" # Clignotant
INVERSE = "\033[7m" # Inversé (texte clair sur fond sombre)
def est_fichier_video(chemin):
"""
Vérifie si le fichier est de type vidéo en se basant sur son type MIME.
"""
type_mime, _ = mimetypes.guess_type(chemin)
return type_mime is not None and type_mime.startswith("video/")
def couleur(nom_fichier, est_dossier):
if est_dossier:
return BLEU + nom_fichier + NORMAL
elif nom_fichier.lower().endswith(('.mp4', '.mkv', '.avi')):
elif est_fichier_video(nom_fichier):
return VIOLET + nom_fichier + NORMAL # 💜 fichier vidéo
else:
return nom_fichier
@ -209,7 +216,7 @@ def afficher_arborescence(dossier, prefixe="", tout_afficher=False, niveau_max=N
niveau_max=niveau_max,
niveau_actuel=niveau_actuel + 1
)
elif nom.lower().endswith(('.mp4', '.mkv', '.avi')):
elif est_fichier_video(chemin_complet):
infos = analyser_fichier_video(chemin_complet)
for i, ligne in enumerate(infos):
print(prefixe + sous_prefixe + ("└── " if i == len(infos) - 1 else "├── ") + ligne)