|
''' |
|
Takes all the mp3 in the current directory, replace all the id3 tags inside |
|
using the file name as title and the info in tags.json for almbum and artist |
|
generates the track number from the position in the file list. |
|
It also generates a playlist with the entire folder. |
|
I use it for audiobooks. |
|
|
|
The tags.json file is something like: |
|
{ |
|
"album" : "name of the album", |
|
"artist" : "name of the artist", |
|
"album_artist" : "name of the album artist" |
|
} |
|
|
|
**NOTES ON INSTALLATION** |
|
It requires eyed3, you can install it with `pip install eyed3`. If python-magic is |
|
broken you can try to force the right version with |
|
pip uninstall python-magic |
|
pip install python-magic-bin |
|
''' |
|
|
|
import json |
|
import glob |
|
import eyed3 |
|
import os |
|
import urllib |
|
|
|
tags={} |
|
with open('tags.json') as json_file: |
|
tags = json.load(json_file) |
|
|
|
print(tags) |
|
|
|
p=urllib.parse.quote_plus(f"{tags['album']} {tags['artist']}")+".m3u" |
|
playlist= open(p,"w+") |
|
playlist.write("#EXTM3U\n") |
|
files = sorted(list(glob.glob("*.mp3"))) |
|
|
|
for n,f in enumerate(files): |
|
print(f) |
|
audiofile = eyed3.load(f) |
|
duration = audiofile.info.time_secs |
|
audiofile.initTag() |
|
audiofile.tag.artist = tags['artist'] |
|
audiofile.tag.album = tags['album'] |
|
audiofile.tag.album_artist = tags['album_artist'] |
|
if ('titles' in tags.keys()) and (f in tags['titles']): |
|
audiofile.tag.title = tags['titles'][f] |
|
else: |
|
audiofile.tag.title = os.path.splitext(f)[0] |
|
audiofile.tag.track_num = n+1 |
|
audiofile.tag.save() |
|
playlist.write(f"\n#EXTINF:123, {tags['artist']} - {audiofile.tag.title}\n") |
|
playlist.write(f+"\n") |
|
|
|
playlist.close() |