1
0
Fork 0
LangPlayground/Python/MusicLibVisualizing/main.py

43 lines
1.3 KiB
Python

import os
import sys
import mutagen
if len(sys.argv) != 2:
print("Usage: python3 MusicLibVisualizing/main.py <path_to_your_music_library>")
sys.exit(1)
music_library = sys.argv[1]
music_data = []
from tqdm import tqdm
for root, dirs, files in tqdm(list(os.walk(music_library)), desc="Walking folders", unit="folders"):
for file in tqdm(files, desc=f"Processing folder {root}", unit="files"):
if file.endswith(('.mp3', '.flac', '.opus')):
try:
audio = mutagen.File(os.path.join(root, file))
#print(f"Processing {file}")
#print(audio.info)
music_data.append({
"title": audio.get('title', ['Unknown'])[0],
"artist": audio.get('artist', ['Unknown'])[0],
"album": audio.get('album', ['Unknown'])[0],
"genre": audio.get('genre', ['Unknown'])[0],
"length": audio.info.length,
#"bitrate": audio.info.bitrate
})
except Exception as e:
print(f"Error processing {file}: {e}")
print(f"Found a total of {len(music_data)} files.")
import pandas as pd
df = pd.DataFrame(music_data)
import seaborn as sns
import matplotlib.pyplot as plt