Skip to content

Commit

Permalink
improved compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
jason136 committed Sep 27, 2021
1 parent 741ceed commit 11fb9e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
3 changes: 2 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
from requests.exceptions import ConnectionError

import mp3_dl
import tokens

def process_input(link):
if 'open.spotify.com' in link:
mp3_dl.spotipy_initialize()
mp3_dl.spotipy_initialize(tokens.SPOTIPY_CLIENT_ID, tokens.SPOTIPY_CLIENT_SECRET)
if 'open.spotify.com/track/' in link:
try:
track = mp3_dl.sp.track(track_id=link)
Expand Down
14 changes: 7 additions & 7 deletions mp3_dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from youtube_dl.utils import DownloadError
from requests.exceptions import HTTPError

import tokens

root = os.getcwd()

q = queue.Queue()
Expand Down Expand Up @@ -73,6 +71,7 @@ def dl_yt_playlist(link, silent=False):
print('Playlist download complete!')
count = 0
total = 0
return True

def dl_yt_video(link, silent=True, recurse=0):
try:
Expand All @@ -96,7 +95,7 @@ def dl_yt_video(link, silent=True, recurse=0):
return
if recurse >= 4:
print('Retry unsucessful!')
return None
return
else:
print('ERROR: Download of: \"{}\" failed. Retrying...'.format(link))
dl_yt_video(link, silent=True, recurse=recurse+1)
Expand All @@ -106,7 +105,7 @@ def dl_yt_video(link, silent=True, recurse=0):
return filename
except UnboundLocalError as e:
if str(e) == 'local variable \'filename\' referenced before assignment':
return None
return

def dl_query(query, silent=True, duration=None, recurse=0):
try:
Expand Down Expand Up @@ -206,6 +205,7 @@ def dl_spotify(input_link, silent=False):
os.chdir(root + '/out')
count = 0
total = 0
return True

def dl_sp_track(track, silent=True, album=None):
if not sp:
Expand Down Expand Up @@ -289,12 +289,12 @@ def legalize_chars(filename):
filename = filename.replace(char, '')
return filename

def spotipy_initialize():
def spotipy_initialize(SPOTIPY_CLIENT_ID, SPOTIPY_CLIENT_SECRET):
global sp
sp = spotipy.Spotify(
auth_manager=SpotifyOAuth(
client_id=tokens.SPOTIPY_CLIENT_ID,
client_secret=tokens.SPOTIPY_CLIENT_SECRET,
client_id=SPOTIPY_CLIENT_ID,
client_secret=SPOTIPY_CLIENT_SECRET,
redirect_uri='http://localhost:8000',
scope='user-library-read',
cache_path='{}/OAuthCache.txt'.format(root)
Expand Down

0 comments on commit 11fb9e5

Please sign in to comment.