mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-10-29 18:00:15 +00:00
Switch to youtube API (#191)
* Switch to youtube API * Fix test failures * Minor fix
This commit is contained in:
committed by
Ritiek Malhotra
parent
57055eb65d
commit
4d664956cd
@@ -76,6 +76,10 @@ def get_arguments():
|
||||
'-d', '--dry-run', default=False,
|
||||
help='Show only track title and YouTube URL',
|
||||
action='store_true')
|
||||
parser.add_argument(
|
||||
'-mo', '--music-videos-only', default=False,
|
||||
help='Search only for music on Youtube',
|
||||
action='store_true')
|
||||
parser.add_argument(
|
||||
'-ll', '--log-level', default='INFO',
|
||||
choices=_LOG_LEVELS_STR,
|
||||
@@ -122,18 +126,6 @@ def generate_token():
|
||||
return token
|
||||
|
||||
|
||||
def generate_search_url(song, viewsort=False):
|
||||
""" Generate YouTube search URL for the given song. """
|
||||
# urllib.request.quote() encodes URL with special characters
|
||||
song = quote(song)
|
||||
if viewsort:
|
||||
url = u"https://www.youtube.com/results?q={0}".format(song)
|
||||
else:
|
||||
url = u"https://www.youtube.com/results?sp=EgIQAQ%253D%253D&q={0}".format(song)
|
||||
|
||||
return url
|
||||
|
||||
|
||||
def filter_path(path):
|
||||
if not os.path.exists(path):
|
||||
os.makedirs(path)
|
||||
@@ -142,14 +134,12 @@ def filter_path(path):
|
||||
os.remove(os.path.join(path, temp))
|
||||
|
||||
|
||||
def get_sec(time_str):
|
||||
v = time_str.split(':', 3)
|
||||
v.reverse()
|
||||
sec = 0
|
||||
if len(v) > 0: # seconds
|
||||
sec += int(v[0])
|
||||
if len(v) > 1: # minutes
|
||||
sec += int(v[1]) * 60
|
||||
if len(v) > 2: # hours
|
||||
sec += int(v[2]) * 3600
|
||||
return sec
|
||||
def videotime_from_seconds(time):
|
||||
if time<60:
|
||||
return str(time)
|
||||
if time<3600:
|
||||
return '{}:{}'.format(str(time//60), str(time%60).zfill(2))
|
||||
|
||||
return '{}:{}:{}'.format(str(time//60),
|
||||
str((time%60)//60).zfill(2),
|
||||
str((time%60)%60).zfill(2))
|
||||
|
||||
Reference in New Issue
Block a user