Add additional output to beautify things

This commit is contained in:
2022-05-07 23:50:30 +02:00
parent ac3a71c274
commit 1a7552c7c0
2 changed files with 18 additions and 9 deletions

View File

@@ -1 +1,3 @@
mutagen==1.45.1
soundfile==0.8.0
pyflac

View File

@@ -2,14 +2,16 @@
# ex: set filetype=python
import argparse
from mutagen.mp3 import MP3
from mutagen.easyid3 import EasyID3
import mutagen.id3
from mutagen.id3 import ID3, TIT2, TIT3, TALB, TRCK, TYER
import os
from shutil import copyfile
import soundfile as sf
import urllib.parse
import xml.etree.cElementTree as xml
from mutagen.easyid3 import EasyID3
from mutagen.id3 import ID3, TIT2, TIT3, TALB, TRCK, TYER
from mutagen.mp3 import MP3
from shutil import copyfile
class Track():
@@ -36,14 +38,14 @@ def parseXml(xml_file):
return tracks
def copy_file(track: Track, targetFolder) -> str:
def copy_file(track: Track, targetFolder, cnt, max) -> str:
"""
Copies a track from its source to the destination folder
"""
path = urllib.parse.unquote(track.Location[7:])
dst = os.path.join(targetFolder, os.path.basename(path))
if (os.path.exists(path)):
print('Copying file {0}'.format(path))
print('Copying file {0} [{1}/{2}]'.format(path,cnt,max))
copyfile(path, dst)
else:
print('File {0} not found.'.format(path))
@@ -51,15 +53,15 @@ def copy_file(track: Track, targetFolder) -> str:
return dst
def tag_file(track: Track, file_name: str):
def tag_file(track: Track, file_name: str, cnt, max):
"""
Adds ID3 tags to a file.
"""
if not file_name.endswith('.mp3'):
print('Skipping file {0}. It\'s not an mp3 file.'.format(file_name))
print('Skipping file {0}. It\'s not an mp3 file. [{1}/{2}]'.format(file_name, cnt, max))
return
print('Tagging file {0}'.format(file_name))
print('Tagging file {0} [{1}/{2}]'.format(file_name, cnt, max))
mp3file = MP3(file_name, ID3=EasyID3)
if hasattr(track, 'Album'):
mp3file['album'] = track.Album
@@ -109,10 +111,15 @@ def main():
if not os.path.isdir(args.target):
os.mkdir(args.target)
count = 0
maxcount = len(tracks)
for t in tracks:
count += 1
new_file = copy_file(t, args.target)
if new_file is not None:
tag_file(t, new_file)
print('Done. Copied {0} of {1} files.'.format(count, maxcount))
if __name__ == "__main__":
main()