mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-12-08 20:39:08 +00:00
Test YouTube track title
This commit is contained in:
@@ -101,10 +101,10 @@ def generate_token():
|
|||||||
token = creds.get_access_token()
|
token = creds.get_access_token()
|
||||||
return token
|
return token
|
||||||
|
|
||||||
def generate_search_URL(song):
|
def generate_search_url(song):
|
||||||
# urllib2.quote() encodes URL with special characters
|
# urllib2.quote() encodes URL with special characters
|
||||||
URL = "https://www.youtube.com/results?sp=EgIQAQ%253D%253D&q=" + quote(song)
|
url = "https://www.youtube.com/results?sp=EgIQAQ%253D%253D&q=" + quote(song)
|
||||||
return URL
|
return url
|
||||||
|
|
||||||
# fix encoding issues in python2
|
# fix encoding issues in python2
|
||||||
def fix_encoding(query):
|
def fix_encoding(query):
|
||||||
|
|||||||
12
spotdl.py
12
spotdl.py
@@ -57,12 +57,12 @@ def generate_metadata(raw_song):
|
|||||||
#pprint.pprint(spotify.album(meta_tags['album']['id']))
|
#pprint.pprint(spotify.album(meta_tags['album']['id']))
|
||||||
return meta_tags
|
return meta_tags
|
||||||
|
|
||||||
def generate_YouTube_URL(raw_song):
|
def generate_youtube_url(raw_song):
|
||||||
# decode spotify http link to "[artist] - [song]"
|
# decode spotify http link to "[artist] - [song]"
|
||||||
song = generate_songname(raw_song)
|
song = generate_songname(raw_song)
|
||||||
# generate direct search YouTube URL
|
# generate direct search YouTube URL
|
||||||
searchURL = misc.generate_search_URL(song)
|
search_url = misc.generate_search_url(song)
|
||||||
item = urllib2.urlopen(searchURL).read()
|
item = urllib2.urlopen(search_url).read()
|
||||||
#item = unicode(item, 'utf-8')
|
#item = unicode(item, 'utf-8')
|
||||||
items_parse = BeautifulSoup(item, "html.parser")
|
items_parse = BeautifulSoup(item, "html.parser")
|
||||||
check = 1
|
check = 1
|
||||||
@@ -97,12 +97,12 @@ def generate_YouTube_URL(raw_song):
|
|||||||
# parse track from YouTube
|
# parse track from YouTube
|
||||||
def go_pafy(raw_song):
|
def go_pafy(raw_song):
|
||||||
# video link of the video to extract audio from
|
# video link of the video to extract audio from
|
||||||
trackURL = generate_YouTube_URL(raw_song)
|
track_url = generate_youtube_url(raw_song)
|
||||||
if trackURL is None:
|
if track_url is None:
|
||||||
return None
|
return None
|
||||||
else:
|
else:
|
||||||
# parse the YouTube video
|
# parse the YouTube video
|
||||||
return pafy.new(trackURL)
|
return pafy.new(track_url)
|
||||||
|
|
||||||
# title of the YouTube video
|
# title of the YouTube video
|
||||||
def get_YouTube_title(content, number=None):
|
def get_YouTube_title(content, number=None):
|
||||||
|
|||||||
15
test/test_basic.py
Normal file
15
test/test_basic.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# -*- coding: UTF-8 -*-
|
||||||
|
|
||||||
|
import spotdl
|
||||||
|
|
||||||
|
raw_song = "http://open.spotify.com/track/2e0jnySVkYF1pvBlpoNX1Y"
|
||||||
|
|
||||||
|
def test_spotify():
|
||||||
|
expected_title = "David André Østby - Tilbake (SAEVIK Remix)"
|
||||||
|
title = spotdl.generate_songname(raw_song)
|
||||||
|
assert title == expected_title
|
||||||
|
|
||||||
|
def test_youtube_title():
|
||||||
|
expected_url = "youtube.com/watch?v=zkD4smbefbc"
|
||||||
|
url = spotdl.generate_youtube_url(raw_song)
|
||||||
|
assert url == expected_url
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
# -*- coding: UTF-8 -*-
|
|
||||||
|
|
||||||
import spotdl
|
|
||||||
|
|
||||||
def test_songname():
|
|
||||||
song = "http://open.spotify.com/track/2e0jnySVkYF1pvBlpoNX1Y"
|
|
||||||
expected_title = "David André Østby - Tilbake (SAEVIK Remix)"
|
|
||||||
title = spotdl.generate_songname(song)
|
|
||||||
assert title == expected_title
|
|
||||||
Reference in New Issue
Block a user