mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-10-29 18:00:15 +00:00
Small fixes
This commit is contained in:
@@ -2,11 +2,13 @@ from mutagen.easyid3 import EasyID3
|
||||
from mutagen.id3 import ID3, APIC
|
||||
from mutagen.mp4 import MP4, MP4Cover
|
||||
|
||||
# urllib2 is urllib.request in python3
|
||||
try:
|
||||
import urllib2
|
||||
except ImportError:
|
||||
import urllib.request as urllib2
|
||||
|
||||
# check if input file title matches with expected title
|
||||
def compare(file, metadata):
|
||||
try:
|
||||
if file.endswith('.mp3'):
|
||||
@@ -33,11 +35,13 @@ def embed(music_file, meta_tags, output_ext):
|
||||
print('Cannot embed meta-tags into given output extension')
|
||||
|
||||
def embed_mp3(music_file, meta_tags, output_ext):
|
||||
#EasyID3 is fun to use ;)
|
||||
artists = []
|
||||
for artist in meta_tags['artists']:
|
||||
artists.append(artist['name'])
|
||||
audiofile = EasyID3('Music/' + music_file + output_ext)
|
||||
audiofile['artist'] = artists
|
||||
#audiofile['artist'] = artists
|
||||
audiofile['artist'] = ', '.join(artists)
|
||||
audiofile['albumartist'] = meta_tags['artists'][0]['name']
|
||||
audiofile['album'] = meta_tags['album']['name']
|
||||
audiofile['title'] = meta_tags['name']
|
||||
@@ -65,7 +69,6 @@ def embed_mp3(music_file, meta_tags, output_ext):
|
||||
audiofile.save(v2_version=3)
|
||||
|
||||
def embed_m4a(music_file, meta_tags, output_ext):
|
||||
# eyed serves only mp3 not aac so using mutagen
|
||||
# Apple has specific tags - see mutagen docs -
|
||||
# http://mutagen.readthedocs.io/en/latest/api/mp4.html
|
||||
tags = {'album': '\xa9alb',
|
||||
@@ -89,7 +92,8 @@ def embed_m4a(music_file, meta_tags, output_ext):
|
||||
for artist in meta_tags['artists']:
|
||||
artists.append(artist['name'])
|
||||
audiofile = MP4('Music/' + music_file + output_ext)
|
||||
audiofile[tags['artist']] = artists
|
||||
#audiofile[tags['artist']] = artists
|
||||
audiofile[tags['artist']] = ', '.join(artists)
|
||||
audiofile[tags['albumartist']] = meta_tags['artists'][0]['name']
|
||||
audiofile[tags['album']] = meta_tags['album']['name']
|
||||
audiofile[tags['title']] = meta_tags['name']
|
||||
|
||||
@@ -9,6 +9,7 @@ try:
|
||||
except:
|
||||
from urllib.request import quote
|
||||
|
||||
# method to input (user playlists) and (track when using manual mode)
|
||||
def input_link(links):
|
||||
while True:
|
||||
try:
|
||||
@@ -22,6 +23,7 @@ def input_link(links):
|
||||
except ValueError:
|
||||
print('Choose a valid number!')
|
||||
|
||||
# remove first song from .txt
|
||||
def trim_song(file):
|
||||
with open(file, 'r') as fin:
|
||||
data = fin.read().splitlines(True)
|
||||
@@ -62,13 +64,15 @@ def is_spotify(raw_song):
|
||||
else:
|
||||
return False
|
||||
|
||||
# generate filename of the song to be downloaded
|
||||
def generate_filename(title):
|
||||
raw_title = title.replace(' ', '_')
|
||||
# slugify removes any special characters
|
||||
filename = slugify(raw_title, ok='-_()[]{}', lower=False)
|
||||
return fix_encoding(filename)
|
||||
|
||||
# please respect this user token :)
|
||||
def generate_token():
|
||||
# Please respect this user token :)
|
||||
creds = oauth2.SpotifyClientCredentials(
|
||||
client_id='4fe3fecfe5334023a1472516cc99d805',
|
||||
client_secret='0f02b7c483c04257984695007a4a8d5c')
|
||||
@@ -79,6 +83,7 @@ def generate_search_URL(song):
|
||||
URL = "https://www.youtube.com/results?sp=EgIQAQ%253D%253D&q=" + quote(song)
|
||||
return URL
|
||||
|
||||
# fix encoding issues in python2
|
||||
def fix_encoding(query):
|
||||
if sys.version_info > (3, 0):
|
||||
return query
|
||||
|
||||
Reference in New Issue
Block a user