mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-10-29 18:00:15 +00:00
Fix encoding problems in python2
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,4 +1,4 @@
|
|||||||
*.pyc
|
*.pyc
|
||||||
/core/__pycache__/
|
__pycache__/
|
||||||
/Music/
|
/Music/
|
||||||
/*.txt
|
/*.txt
|
||||||
|
|||||||
19
core/misc.py
19
core/misc.py
@@ -78,12 +78,14 @@ def feed_tracks(file, tracks):
|
|||||||
|
|
||||||
# generate filename of the song to be downloaded
|
# generate filename of the song to be downloaded
|
||||||
def generate_filename(title):
|
def generate_filename(title):
|
||||||
raw_title = title.replace(' ', '_')
|
# IMO python2 sucks dealing with unicode
|
||||||
|
title = fix_encoding(title, decode=True)
|
||||||
|
title = title.replace(' ', '_')
|
||||||
# slugify removes any special characters
|
# slugify removes any special characters
|
||||||
filename = slugify(raw_title, ok='-_()[]{}', lower=False)
|
filename = slugify(title, ok='-_()[]{}', lower=False)
|
||||||
return filename
|
return filename
|
||||||
|
|
||||||
# please respect this user token :)
|
# please respect these credentials :)
|
||||||
def generate_token():
|
def generate_token():
|
||||||
creds = oauth2.SpotifyClientCredentials(
|
creds = oauth2.SpotifyClientCredentials(
|
||||||
client_id='4fe3fecfe5334023a1472516cc99d805',
|
client_id='4fe3fecfe5334023a1472516cc99d805',
|
||||||
@@ -97,11 +99,12 @@ def generate_search_URL(song):
|
|||||||
return URL
|
return URL
|
||||||
|
|
||||||
# fix encoding issues in python2
|
# fix encoding issues in python2
|
||||||
def fix_encoding(query):
|
def fix_encoding(query, decode=False):
|
||||||
if sys.version_info > (3, 0):
|
if sys.version_info < (3, 0):
|
||||||
return query
|
query = query.encode('utf-8')
|
||||||
else:
|
if decode:
|
||||||
return query.encode('utf-8')
|
query = query.decode('utf-8')
|
||||||
|
return query
|
||||||
|
|
||||||
def grace_quit():
|
def grace_quit():
|
||||||
print('')
|
print('')
|
||||||
|
|||||||
@@ -297,8 +297,7 @@ def grab_single(raw_song, number=None):
|
|||||||
# otherwise print "[artist] - [song]"
|
# otherwise print "[artist] - [song]"
|
||||||
print(get_YouTube_title(content, number))
|
print(get_YouTube_title(content, number))
|
||||||
# generate file name of the song to download
|
# generate file name of the song to download
|
||||||
title = misc.fix_encoding(content.title)
|
music_file = misc.generate_filename(content.title)
|
||||||
music_file = misc.generate_filename(title)
|
|
||||||
if not check_exists(music_file, raw_song, islist=islist):
|
if not check_exists(music_file, raw_song, islist=islist):
|
||||||
download_song(content)
|
download_song(content)
|
||||||
print('')
|
print('')
|
||||||
|
|||||||
1
test/.cache/v/cache/lastfailed
vendored
Normal file
1
test/.cache/v/cache/lastfailed
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{}
|
||||||
6
test/test_sample.py
Normal file
6
test/test_sample.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# content of test_sample.py
|
||||||
|
def func(x):
|
||||||
|
return x + 1
|
||||||
|
|
||||||
|
def test_answer():
|
||||||
|
assert func(3) == 4
|
||||||
Reference in New Issue
Block a user