mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-12-08 20:39:08 +00:00
Add skip song option when downloading manually
This commit is contained in:
21
spotdl.py
21
spotdl.py
@@ -26,7 +26,7 @@ open('list.txt', 'a').close()
|
|||||||
|
|
||||||
spotify = spotipy.Spotify()
|
spotify = spotipy.Spotify()
|
||||||
|
|
||||||
# Set up agruments
|
# Set up arguments
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("-n", "--no-convert", help="skip the conversion process and meta-tags", action="store_true")
|
parser.add_argument("-n", "--no-convert", help="skip the conversion process and meta-tags", action="store_true")
|
||||||
parser.add_argument("-m", "--manual", help="choose the song to download manually", action="store_true")
|
parser.add_argument("-m", "--manual", help="choose the song to download manually", action="store_true")
|
||||||
@@ -50,12 +50,13 @@ def getInputLink(links):
|
|||||||
try:
|
try:
|
||||||
the_chosen_one = int(raw_input('>> Choose your number: '))
|
the_chosen_one = int(raw_input('>> Choose your number: '))
|
||||||
if the_chosen_one >= 1 and the_chosen_one <= len(links):
|
if the_chosen_one >= 1 and the_chosen_one <= len(links):
|
||||||
break
|
return links[the_chosen_one-1]
|
||||||
|
elif the_chosen_one == 0:
|
||||||
|
return None
|
||||||
else:
|
else:
|
||||||
print('Choose a valid number!')
|
print('Choose a valid number!')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print('Choose a valid number!')
|
print('Choose a valid number!')
|
||||||
return links[the_chosen_one-1]
|
|
||||||
|
|
||||||
def isSpotify(raw_song):
|
def isSpotify(raw_song):
|
||||||
if (len(raw_song) == 22 and raw_song.replace(" ", "%20") == raw_song) or (raw_song.find('spotify') > -1):
|
if (len(raw_song) == 22 and raw_song.replace(" ", "%20") == raw_song) or (raw_song.find('spotify') > -1):
|
||||||
@@ -92,6 +93,7 @@ def generateYouTubeURL(raw_song):
|
|||||||
links = []
|
links = []
|
||||||
print(song)
|
print(song)
|
||||||
print('')
|
print('')
|
||||||
|
print('0. Skip downloading this song')
|
||||||
for x in items_parse.find_all('h3', {'class':'yt-lockup-title'}):
|
for x in items_parse.find_all('h3', {'class':'yt-lockup-title'}):
|
||||||
if not x.find('channel') == -1 or not x.find('googleads') == -1:
|
if not x.find('channel') == -1 or not x.find('googleads') == -1:
|
||||||
print(str(check) + '. ' + x.get_text())
|
print(str(check) + '. ' + x.get_text())
|
||||||
@@ -99,6 +101,8 @@ def generateYouTubeURL(raw_song):
|
|||||||
check += 1
|
check += 1
|
||||||
print('')
|
print('')
|
||||||
result = getInputLink(links)
|
result = getInputLink(links)
|
||||||
|
if result == None:
|
||||||
|
return None
|
||||||
else:
|
else:
|
||||||
result = items_parse.find_all(attrs={'class':'yt-uix-tile-link'})[0]['href']
|
result = items_parse.find_all(attrs={'class':'yt-uix-tile-link'})[0]['href']
|
||||||
while not result.find('channel') == -1 or not result.find('googleads') == -1:
|
while not result.find('channel') == -1 or not result.find('googleads') == -1:
|
||||||
@@ -109,6 +113,9 @@ def generateYouTubeURL(raw_song):
|
|||||||
|
|
||||||
def goPafy(raw_song):
|
def goPafy(raw_song):
|
||||||
trackURL = generateYouTubeURL(raw_song)
|
trackURL = generateYouTubeURL(raw_song)
|
||||||
|
if trackURL == None:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
return pafy.new(trackURL)
|
return pafy.new(trackURL)
|
||||||
|
|
||||||
def getYouTubeTitle(content, number):
|
def getYouTubeTitle(content, number):
|
||||||
@@ -183,6 +190,8 @@ def grabSingle(raw_song, number):
|
|||||||
else:
|
else:
|
||||||
islist = False
|
islist = False
|
||||||
content = goPafy(raw_song)
|
content = goPafy(raw_song)
|
||||||
|
if content == None:
|
||||||
|
return
|
||||||
print(getYouTubeTitle(content, number))
|
print(getYouTubeTitle(content, number))
|
||||||
music_file = generateFileName(content)
|
music_file = generateFileName(content)
|
||||||
if not checkExists(music_file, raw_song, islist=islist):
|
if not checkExists(music_file, raw_song, islist=islist):
|
||||||
@@ -204,6 +213,7 @@ def grabList(file):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
print('Total songs in list = ' + str(len(lines)) + ' songs')
|
print('Total songs in list = ' + str(len(lines)) + ' songs')
|
||||||
|
# Count the number of song being downloaded
|
||||||
number = 1
|
number = 1
|
||||||
for raw_song in lines:
|
for raw_song in lines:
|
||||||
try:
|
try:
|
||||||
@@ -226,7 +236,7 @@ def graceQuit():
|
|||||||
print('Exitting..')
|
print('Exitting..')
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
while True:
|
def main():
|
||||||
for m in os.listdir('Music/'):
|
for m in os.listdir('Music/'):
|
||||||
if m.endswith('.m4a.temp'):
|
if m.endswith('.m4a.temp'):
|
||||||
os.remove('Music/' + m)
|
os.remove('Music/' + m)
|
||||||
@@ -237,3 +247,6 @@ while True:
|
|||||||
initializeInput(command)
|
initializeInput(command)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
graceQuit()
|
graceQuit()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user