mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-10-29 18:00:15 +00:00
Add metadata test
This commit is contained in:
@@ -7,12 +7,11 @@ def song(input_song, output_song, avconv=False, verbose=False):
|
|||||||
output_song = output_song.encode('utf-8')
|
output_song = output_song.encode('utf-8')
|
||||||
print('Converting ' + input_song + ' to ' + output_song.split('.')[-1])
|
print('Converting ' + input_song + ' to ' + output_song.split('.')[-1])
|
||||||
if avconv:
|
if avconv:
|
||||||
convert_with_avconv(input_song, output_song, verbose)
|
exit_code = convert_with_avconv(input_song, output_song, verbose)
|
||||||
else:
|
else:
|
||||||
convert_with_FFmpeg(input_song, output_song, verbose)
|
exit_code = convert_with_FFmpeg(input_song, output_song, verbose)
|
||||||
os.remove('Music/' + input_song)
|
return exit_code
|
||||||
return True
|
return None
|
||||||
return False
|
|
||||||
|
|
||||||
def convert_with_avconv(input_song, output_song, verbose):
|
def convert_with_avconv(input_song, output_song, verbose):
|
||||||
# different path for windows
|
# different path for windows
|
||||||
|
|||||||
@@ -30,14 +30,17 @@ def embed(music_file, meta_tags):
|
|||||||
music_file = music_file.encode('utf-8')
|
music_file = music_file.encode('utf-8')
|
||||||
if meta_tags is None:
|
if meta_tags is None:
|
||||||
print('Could not find meta-tags')
|
print('Could not find meta-tags')
|
||||||
|
return None
|
||||||
elif music_file.endswith('.m4a'):
|
elif music_file.endswith('.m4a'):
|
||||||
print('Fixing meta-tags')
|
print('Fixing meta-tags')
|
||||||
embed_m4a(music_file, meta_tags)
|
return embed_m4a(music_file, meta_tags)
|
||||||
|
return True
|
||||||
elif music_file.endswith('.mp3'):
|
elif music_file.endswith('.mp3'):
|
||||||
print('Fixing meta-tags')
|
print('Fixing meta-tags')
|
||||||
embed_mp3(music_file, meta_tags)
|
return embed_mp3(music_file, meta_tags)
|
||||||
else:
|
else:
|
||||||
print('Cannot embed meta-tags into given output extension')
|
print('Cannot embed meta-tags into given output extension')
|
||||||
|
return False
|
||||||
|
|
||||||
def embed_mp3(music_file, meta_tags):
|
def embed_mp3(music_file, meta_tags):
|
||||||
# EasyID3 is fun to use ;)
|
# EasyID3 is fun to use ;)
|
||||||
@@ -69,6 +72,7 @@ def embed_mp3(music_file, meta_tags):
|
|||||||
audiofile["APIC"] = APIC(encoding=3, mime='image/jpeg', type=3, desc=u'Cover', data=albumart.read())
|
audiofile["APIC"] = APIC(encoding=3, mime='image/jpeg', type=3, desc=u'Cover', data=albumart.read())
|
||||||
albumart.close()
|
albumart.close()
|
||||||
audiofile.save(v2_version=3)
|
audiofile.save(v2_version=3)
|
||||||
|
return True
|
||||||
|
|
||||||
def embed_m4a(music_file, meta_tags):
|
def embed_m4a(music_file, meta_tags):
|
||||||
# Apple has specific tags - see mutagen docs -
|
# Apple has specific tags - see mutagen docs -
|
||||||
@@ -107,3 +111,4 @@ def embed_m4a(music_file, meta_tags):
|
|||||||
audiofile[tags['albumart']] = [ MP4Cover(albumart.read(), imageformat=MP4Cover.FORMAT_JPEG) ]
|
audiofile[tags['albumart']] = [ MP4Cover(albumart.read(), imageformat=MP4Cover.FORMAT_JPEG) ]
|
||||||
albumart.close()
|
albumart.close()
|
||||||
audiofile.save()
|
audiofile.save()
|
||||||
|
return True
|
||||||
|
|||||||
@@ -254,6 +254,7 @@ def grab_single(raw_song, number=None):
|
|||||||
output_song,
|
output_song,
|
||||||
avconv=args.avconv,
|
avconv=args.avconv,
|
||||||
verbose=args.verbose)
|
verbose=args.verbose)
|
||||||
|
os.remove('Music/' + input_song)
|
||||||
meta_tags = generate_metadata(raw_song)
|
meta_tags = generate_metadata(raw_song)
|
||||||
if not args.no_metadata:
|
if not args.no_metadata:
|
||||||
metadata.embed(output_song, meta_tags)
|
metadata.embed(output_song, meta_tags)
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ def test_download():
|
|||||||
assert download == expect_download
|
assert download == expect_download
|
||||||
|
|
||||||
def test_convert():
|
def test_convert():
|
||||||
expect_convert = True
|
# exit code None = success
|
||||||
|
expect_convert = None
|
||||||
content = spotdl.go_pafy(raw_song)
|
content = spotdl.go_pafy(raw_song)
|
||||||
music_file = spotdl.misc.generate_filename(content.title)
|
music_file = spotdl.misc.generate_filename(content.title)
|
||||||
music_file = spotdl.misc.fix_decoding(music_file)
|
music_file = spotdl.misc.fix_decoding(music_file)
|
||||||
@@ -43,3 +44,13 @@ def test_convert():
|
|||||||
output_song = music_file + spotdl.args.output_ext
|
output_song = music_file + spotdl.args.output_ext
|
||||||
convert = spotdl.convert.song(input_song, output_song)
|
convert = spotdl.convert.song(input_song, output_song)
|
||||||
assert convert == expect_convert
|
assert convert == expect_convert
|
||||||
|
|
||||||
|
def test_metadata():
|
||||||
|
expect_metadata = True
|
||||||
|
content = spotdl.go_pafy(raw_song)
|
||||||
|
music_file = spotdl.misc.generate_filename(content.title)
|
||||||
|
music_file = spotdl.misc.fix_decoding(music_file)
|
||||||
|
output_song = music_file + spotdl.args.output_ext
|
||||||
|
meta_tags = spotdl.generate_metadata(raw_song)
|
||||||
|
metadata = spotdl.metadata.embed(output_song, meta_tags)
|
||||||
|
assert metadata == expect_metadata
|
||||||
Reference in New Issue
Block a user