Don't view sort results if metadata not found

This commit is contained in:
ritiek
2017-08-02 17:49:16 +05:30
parent 606e55bb1e
commit 67f594c7b0
2 changed files with 10 additions and 5 deletions

View File

@@ -98,11 +98,14 @@ def generate_token():
return token
def generate_search_url(song):
def generate_search_url(song, viewsort=False):
"""Generate YouTube search URL for the given song."""
# urllib.request.quote() encodes URL with special characters
url = u"https://www.youtube.com/results?q={0}&sp=CAMSAhABUBQ%253D".format(
quote(song))
song = quote(song)
if viewsort:
url = u"https://www.youtube.com/results?q={0}&sp=CAMSAhABUBQ%253D".format(song)
else:
url = u"https://www.youtube.com/results?sp=EgIQAQ%253D%253D&q={0}".format(song)
return url