Add: py script to get stats of music files
This commit is contained in:
parent
0b832a3364
commit
e150e47b91
1 changed files with 43 additions and 0 deletions
43
Python/MusicLibVisualizing/main.py
Normal file
43
Python/MusicLibVisualizing/main.py
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
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
|
||||||
|
|
Loading…
Reference in a new issue