From 1a7552c7c02be6cdbce028fe48904413068b9dd0 Mon Sep 17 00:00:00 2001 From: Jali Date: Sat, 7 May 2022 23:50:30 +0200 Subject: [PATCH] Add additional output to beautify things --- requirements.txt | 2 ++ scraper.py | 25 ++++++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/requirements.txt b/requirements.txt index 1bbcc49..6b8d767 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,3 @@ mutagen==1.45.1 +soundfile==0.8.0 +pyflac diff --git a/scraper.py b/scraper.py index dcc0f80..d400de2 100755 --- a/scraper.py +++ b/scraper.py @@ -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()