mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-10-29 18:00:15 +00:00
Add command line option for target folder (-f)
This commit is contained in:
@@ -2,20 +2,20 @@ import subprocess
|
||||
import os
|
||||
|
||||
|
||||
def song(input_song, output_song, avconv=False, verbose=False):
|
||||
def song(input_song, output_song, folder, avconv=False, verbose=False):
|
||||
"""Do the audio format conversion."""
|
||||
if not input_song == output_song:
|
||||
print('Converting {0} to {1}'.format(
|
||||
input_song, output_song.split('.')[-1]))
|
||||
if avconv:
|
||||
exit_code = convert_with_avconv(input_song, output_song, verbose)
|
||||
exit_code = convert_with_avconv(input_song, output_song, folder, verbose)
|
||||
else:
|
||||
exit_code = convert_with_ffmpeg(input_song, output_song, verbose)
|
||||
exit_code = convert_with_ffmpeg(input_song, output_song, folder, verbose)
|
||||
return exit_code
|
||||
return 0
|
||||
|
||||
|
||||
def convert_with_avconv(input_song, output_song, verbose):
|
||||
def convert_with_avconv(input_song, output_song, folder, verbose):
|
||||
"""Convert the audio file using avconv."""
|
||||
if os.name == 'nt':
|
||||
avconv_path = '..\\Scripts\\avconv.exe'
|
||||
@@ -31,12 +31,12 @@ def convert_with_avconv(input_song, output_song, verbose):
|
||||
'-loglevel', level,
|
||||
'-i', 'Music/' + input_song,
|
||||
'-ab', '192k',
|
||||
'Music/' + output_song]
|
||||
os.path.join(folder, output_song)]
|
||||
|
||||
return subprocess.call(command)
|
||||
|
||||
|
||||
def convert_with_ffmpeg(input_song, output_song, verbose):
|
||||
def convert_with_ffmpeg(input_song, output_song, folder, verbose):
|
||||
"""Convert the audio file using FFMpeg.
|
||||
|
||||
What are the differences and similarities between ffmpeg, libav, and avconv?
|
||||
@@ -73,7 +73,7 @@ def convert_with_ffmpeg(input_song, output_song, verbose):
|
||||
elif output_ext == 'm4a':
|
||||
ffmpeg_params = '-cutoff 20000 -c:a libfdk_aac -b:a 192k -vn '
|
||||
|
||||
command = '{0}-i Music/{1} {2}Music/{3}'.format(
|
||||
ffmpeg_pre, input_song, ffmpeg_params, output_song).split(' ')
|
||||
command = '{0}-i {1} {2}{3}'.format(
|
||||
ffmpeg_pre, os.path.join(folder, input_song), ffmpeg_params, os.path.join(folder, output_song)).split(' ')
|
||||
|
||||
return subprocess.call(command)
|
||||
|
||||
@@ -10,12 +10,12 @@ def compare(music_file, metadata):
|
||||
already_tagged = False
|
||||
try:
|
||||
if music_file.endswith('.mp3'):
|
||||
audiofile = EasyID3('Music/' + music_file)
|
||||
audiofile = EasyID3(music_file)
|
||||
# fetch track title metadata
|
||||
already_tagged = audiofile['title'][0] == metadata['name']
|
||||
elif music_file.endswith('.m4a'):
|
||||
tags = {'title': '\xa9nam'}
|
||||
audiofile = MP4('Music/' + music_file)
|
||||
audiofile = MP4(music_file)
|
||||
# fetch track title metadata
|
||||
already_tagged = audiofile[tags['title']] == metadata['name']
|
||||
except (KeyError, TypeError):
|
||||
@@ -42,7 +42,7 @@ def embed(music_file, meta_tags):
|
||||
def embed_mp3(music_file, meta_tags):
|
||||
"""Embed metadata to MP3 files."""
|
||||
# EasyID3 is fun to use ;)
|
||||
audiofile = EasyID3('Music/' + music_file)
|
||||
audiofile = EasyID3(music_file)
|
||||
audiofile['artist'] = meta_tags['artists'][0]['name']
|
||||
audiofile['albumartist'] = meta_tags['artists'][0]['name']
|
||||
audiofile['album'] = meta_tags['album']['name']
|
||||
@@ -66,7 +66,7 @@ def embed_mp3(music_file, meta_tags):
|
||||
if meta_tags['copyright']:
|
||||
audiofile['copyright'] = meta_tags['copyright']
|
||||
audiofile.save(v2_version=3)
|
||||
audiofile = ID3('Music/' + music_file)
|
||||
audiofile = ID3(music_file)
|
||||
albumart = urllib.request.urlopen(meta_tags['album']['images'][0]['url'])
|
||||
audiofile["APIC"] = APIC(encoding=3, mime='image/jpeg', type=3,
|
||||
desc=u'Cover', data=albumart.read())
|
||||
@@ -96,7 +96,7 @@ def embed_m4a(music_file, meta_tags):
|
||||
'copyright': 'cprt',
|
||||
'tempo': 'tmpo'}
|
||||
|
||||
audiofile = MP4('Music/' + music_file)
|
||||
audiofile = MP4(music_file)
|
||||
audiofile[tags['artist']] = meta_tags['artists'][0]['name']
|
||||
audiofile[tags['albumartist']] = meta_tags['artists'][0]['name']
|
||||
audiofile[tags['album']] = meta_tags['album']['name']
|
||||
|
||||
@@ -5,6 +5,7 @@ import spotipy.oauth2 as oauth2
|
||||
from urllib.request import quote
|
||||
from slugify import slugify
|
||||
|
||||
|
||||
def input_link(links):
|
||||
"""Let the user input a number."""
|
||||
while True:
|
||||
@@ -51,6 +52,9 @@ def get_arguments():
|
||||
'-a', '--avconv', default=False,
|
||||
help='Use avconv for conversion otherwise set defaults to ffmpeg',
|
||||
action='store_true')
|
||||
parser.add_argument(
|
||||
'-f', '--folder', default='Music/',
|
||||
help='path to folder where files will stored in')
|
||||
parser.add_argument(
|
||||
'-v', '--verbose', default=False, help='show debug output',
|
||||
action='store_true')
|
||||
@@ -105,7 +109,7 @@ def filter_path(path):
|
||||
os.makedirs(path)
|
||||
for temp in os.listdir(path):
|
||||
if temp.endswith('.temp'):
|
||||
os.remove('{0}/{1}'.format(path, temp))
|
||||
os.remove(os.path.join(path, temp))
|
||||
|
||||
|
||||
def grace_quit():
|
||||
|
||||
Reference in New Issue
Block a user