mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-10-29 18:00:15 +00:00
Some small fixes
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import spotipy.oauth2 as oauth2
|
||||||
|
|
||||||
def input_link(links):
|
def input_link(links):
|
||||||
while True:
|
while True:
|
||||||
@@ -55,6 +56,14 @@ def is_spotify(raw_song):
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def generate_token():
|
||||||
|
# Please respect this user token :)
|
||||||
|
creds = oauth2.SpotifyClientCredentials(
|
||||||
|
client_id='4fe3fecfe5334023a1472516cc99d805',
|
||||||
|
client_secret='0f02b7c483c04257984695007a4a8d5c')
|
||||||
|
token = creds.get_access_token()
|
||||||
|
return token
|
||||||
|
|
||||||
def generate_search_URL(song):
|
def generate_search_URL(song):
|
||||||
URL = "https://www.youtube.com/results?sp=EgIQAQ%253D%253D&q=" + \
|
URL = "https://www.youtube.com/results?sp=EgIQAQ%253D%253D&q=" + \
|
||||||
song.replace(" ", "%20")
|
song.replace(" ", "%20")
|
||||||
|
|||||||
70
spotdl.py
70
spotdl.py
@@ -5,6 +5,7 @@ from core.misc import input_link
|
|||||||
from core.misc import trim_song
|
from core.misc import trim_song
|
||||||
from core.misc import get_arguments
|
from core.misc import get_arguments
|
||||||
from core.misc import is_spotify
|
from core.misc import is_spotify
|
||||||
|
from core.misc import generate_token
|
||||||
from core.misc import generate_search_URL
|
from core.misc import generate_search_URL
|
||||||
from core.misc import fix_encoding
|
from core.misc import fix_encoding
|
||||||
from core.misc import grace_quit
|
from core.misc import grace_quit
|
||||||
@@ -157,11 +158,11 @@ def convert_with_libav(music_file):
|
|||||||
else:
|
else:
|
||||||
level = '0'
|
level = '0'
|
||||||
|
|
||||||
print([avconv_path,
|
#print([avconv_path,
|
||||||
'-loglevel', level,
|
# '-loglevel', level,
|
||||||
'-i', 'Music/' + music_file + args.input_ext,
|
# '-i', 'Music/' + music_file + args.input_ext,
|
||||||
'-ab', '192k',
|
# '-ab', '192k',
|
||||||
'Music/' + music_file + args.output_ext])
|
# 'Music/' + music_file + args.output_ext])
|
||||||
|
|
||||||
subprocess.call([avconv_path,
|
subprocess.call([avconv_path,
|
||||||
'-loglevel', level,
|
'-loglevel', level,
|
||||||
@@ -207,10 +208,10 @@ def convert_with_FFmpeg(music_file):
|
|||||||
print('Unknown formats. Unable to convert.', args.input_ext, args.output_ext)
|
print('Unknown formats. Unable to convert.', args.input_ext, args.output_ext)
|
||||||
return
|
return
|
||||||
|
|
||||||
command = (ffmpeg_pre +
|
#command = (ffmpeg_pre +
|
||||||
'-i "Music/' + music_file + args.input_ext + '"' +
|
# '-i "Music/' + music_file + args.input_ext + '"' +
|
||||||
ffmpeg_params +
|
# ffmpeg_params +
|
||||||
'"Music/' + music_file + args.output_ext + '"').split(' ')
|
# '"Music/' + music_file + args.output_ext + '"').split(' ')
|
||||||
|
|
||||||
commandos = (ffmpeg_pre +
|
commandos = (ffmpeg_pre +
|
||||||
'-i "Music/' + music_file + args.input_ext + '" ' +
|
'-i "Music/' + music_file + args.input_ext + '" ' +
|
||||||
@@ -312,26 +313,7 @@ def fix_metadata_m4a(music_file, meta_tags):
|
|||||||
albumart.close()
|
albumart.close()
|
||||||
audiofile.save()
|
audiofile.save()
|
||||||
|
|
||||||
# Logic behind preparing the song to download to finishing meta-tags
|
|
||||||
def grab_single(raw_song, number=None):
|
|
||||||
if number:
|
|
||||||
islist = True
|
|
||||||
else:
|
|
||||||
islist = False
|
|
||||||
content = go_pafy(raw_song)
|
|
||||||
if content is None:
|
|
||||||
return
|
|
||||||
print(get_YouTube_title(content, number))
|
|
||||||
music_file = generate_filename(content)
|
|
||||||
if not check_exists(music_file, raw_song, islist=islist):
|
|
||||||
download_song(content)
|
|
||||||
print('')
|
|
||||||
convert_song(music_file)
|
|
||||||
meta_tags = generate_metadata(raw_song)
|
|
||||||
if not args.no_metadata:
|
|
||||||
fix_metadata(music_file, meta_tags)
|
|
||||||
|
|
||||||
# Fix python2 encoding issues
|
|
||||||
def grab_list(file):
|
def grab_list(file):
|
||||||
lines = open(file, 'r').read()
|
lines = open(file, 'r').read()
|
||||||
lines = lines.splitlines()
|
lines = lines.splitlines()
|
||||||
@@ -359,6 +341,24 @@ def grab_list(file):
|
|||||||
myfile.write(raw_song)
|
myfile.write(raw_song)
|
||||||
print('Failed to download song. Will retry after other songs.')
|
print('Failed to download song. Will retry after other songs.')
|
||||||
|
|
||||||
|
# Logic behind preparing the song to download to finishing meta-tags
|
||||||
|
def grab_single(raw_song, number=None):
|
||||||
|
if number:
|
||||||
|
islist = True
|
||||||
|
else:
|
||||||
|
islist = False
|
||||||
|
content = go_pafy(raw_song)
|
||||||
|
if content is None:
|
||||||
|
return
|
||||||
|
print(get_YouTube_title(content, number))
|
||||||
|
music_file = generate_filename(content)
|
||||||
|
if not check_exists(music_file, raw_song, islist=islist):
|
||||||
|
download_song(content)
|
||||||
|
print('')
|
||||||
|
convert_song(music_file)
|
||||||
|
meta_tags = generate_metadata(raw_song)
|
||||||
|
if not args.no_metadata:
|
||||||
|
fix_metadata(music_file, meta_tags)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
@@ -370,23 +370,11 @@ if __name__ == '__main__':
|
|||||||
if not os.path.exists("Music"):
|
if not os.path.exists("Music"):
|
||||||
os.makedirs("Music")
|
os.makedirs("Music")
|
||||||
|
|
||||||
# Please respect this user token :)
|
token = generate_token()
|
||||||
oauth2 = oauth2.SpotifyClientCredentials(
|
|
||||||
client_id='4fe3fecfe5334023a1472516cc99d805',
|
|
||||||
client_secret='0f02b7c483c04257984695007a4a8d5c')
|
|
||||||
token = oauth2.get_access_token()
|
|
||||||
spotify = spotipy.Spotify(auth=token)
|
spotify = spotipy.Spotify(auth=token)
|
||||||
|
|
||||||
# Set up arguments
|
# Set up arguments
|
||||||
args = get_arguments()
|
args = get_arguments()
|
||||||
print(args)
|
|
||||||
|
|
||||||
#if args.ffmpeg:
|
|
||||||
# input_ext = args.input_ext
|
|
||||||
# output_ext = args.output_ext
|
|
||||||
#else:
|
|
||||||
# input_ext = '.m4a'
|
|
||||||
# output_ext = '.mp3'
|
|
||||||
|
|
||||||
if args.song:
|
if args.song:
|
||||||
grab_single(raw_song=args.song)
|
grab_single(raw_song=args.song)
|
||||||
|
|||||||
Reference in New Issue
Block a user