Add additional output to beautify things
This commit is contained in:
@@ -1 +1,3 @@
|
|||||||
mutagen==1.45.1
|
mutagen==1.45.1
|
||||||
|
soundfile==0.8.0
|
||||||
|
pyflac
|
||||||
|
|||||||
25
scraper.py
25
scraper.py
@@ -2,14 +2,16 @@
|
|||||||
# ex: set filetype=python
|
# ex: set filetype=python
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
from mutagen.mp3 import MP3
|
|
||||||
from mutagen.easyid3 import EasyID3
|
|
||||||
import mutagen.id3
|
import mutagen.id3
|
||||||
from mutagen.id3 import ID3, TIT2, TIT3, TALB, TRCK, TYER
|
|
||||||
import os
|
import os
|
||||||
from shutil import copyfile
|
import soundfile as sf
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import xml.etree.cElementTree as xml
|
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():
|
class Track():
|
||||||
@@ -36,14 +38,14 @@ def parseXml(xml_file):
|
|||||||
return tracks
|
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
|
Copies a track from its source to the destination folder
|
||||||
"""
|
"""
|
||||||
path = urllib.parse.unquote(track.Location[7:])
|
path = urllib.parse.unquote(track.Location[7:])
|
||||||
dst = os.path.join(targetFolder, os.path.basename(path))
|
dst = os.path.join(targetFolder, os.path.basename(path))
|
||||||
if (os.path.exists(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)
|
copyfile(path, dst)
|
||||||
else:
|
else:
|
||||||
print('File {0} not found.'.format(path))
|
print('File {0} not found.'.format(path))
|
||||||
@@ -51,15 +53,15 @@ def copy_file(track: Track, targetFolder) -> str:
|
|||||||
return dst
|
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.
|
Adds ID3 tags to a file.
|
||||||
"""
|
"""
|
||||||
if not file_name.endswith('.mp3'):
|
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
|
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)
|
mp3file = MP3(file_name, ID3=EasyID3)
|
||||||
if hasattr(track, 'Album'):
|
if hasattr(track, 'Album'):
|
||||||
mp3file['album'] = track.Album
|
mp3file['album'] = track.Album
|
||||||
@@ -109,10 +111,15 @@ def main():
|
|||||||
if not os.path.isdir(args.target):
|
if not os.path.isdir(args.target):
|
||||||
os.mkdir(args.target)
|
os.mkdir(args.target)
|
||||||
|
|
||||||
|
count = 0
|
||||||
|
maxcount = len(tracks)
|
||||||
for t in tracks:
|
for t in tracks:
|
||||||
|
count += 1
|
||||||
new_file = copy_file(t, args.target)
|
new_file = copy_file(t, args.target)
|
||||||
if new_file is not None:
|
if new_file is not None:
|
||||||
tag_file(t, new_file)
|
tag_file(t, new_file)
|
||||||
|
|
||||||
|
print('Done. Copied {0} of {1} files.'.format(count, maxcount))
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user