mirror of
https://github.com/KevinMidboe/spotify-downloader.git
synced 2025-10-29 18:00:15 +00:00
Show complete list of tracks if metadata not found in manual mode (#266)
* Show complete list of tracks if metadata not found in manual mode * Add regression test
This commit is contained in:
@@ -159,7 +159,7 @@ class GenerateYouTubeURL:
|
||||
|
||||
return url
|
||||
|
||||
def scrape(self, tries_remaining=5):
|
||||
def scrape(self, bestmatch=True, tries_remaining=5):
|
||||
""" Search and scrape YouTube to return a list of matching videos. """
|
||||
|
||||
# prevents an infinite loop but allows for a few retries
|
||||
@@ -187,18 +187,21 @@ class GenerateYouTubeURL:
|
||||
videotime = x.find('span', class_="video-time").get_text()
|
||||
except AttributeError:
|
||||
log.debug('Could not find video duration on YouTube, retrying..')
|
||||
return generate_youtube_url(self.raw_song, self.meta_tags, tries_remaining - 1)
|
||||
return self.scrape(self.raw_song,
|
||||
self.meta_tags,
|
||||
tries_remaining=tries_remaining-1)
|
||||
|
||||
youtubedetails = {'link': link, 'title': title, 'videotime': videotime,
|
||||
'seconds': internals.get_sec(videotime)}
|
||||
videos.append(youtubedetails)
|
||||
if self.meta_tags is None:
|
||||
break
|
||||
|
||||
if bestmatch:
|
||||
return self._best_match(videos)
|
||||
|
||||
return videos
|
||||
|
||||
def api(self):
|
||||
|
||||
def api(self, bestmatch=True):
|
||||
""" Use YouTube API to search and return a list of matching videos. """
|
||||
|
||||
query = { 'part' : 'snippet',
|
||||
@@ -232,7 +235,8 @@ class GenerateYouTubeURL:
|
||||
'videotime':internals.videotime_from_seconds(duration_s),
|
||||
'seconds': duration_s}
|
||||
videos.append(youtubedetails)
|
||||
if not self.meta_tags:
|
||||
break
|
||||
|
||||
if bestmatch:
|
||||
return self._best_match(videos)
|
||||
|
||||
return videos
|
||||
|
||||
@@ -36,6 +36,25 @@ def test_metadata():
|
||||
assert metadata == expect_metadata
|
||||
|
||||
|
||||
class TestArgsManualResultCount:
|
||||
# Regresson test for issue #264
|
||||
def test_scrape(self):
|
||||
const.args.manual = True
|
||||
url = youtube_tools.GenerateYouTubeURL("she is still sleeping",
|
||||
meta_tags=None)
|
||||
video_ids = url.scrape(bestmatch=False)
|
||||
# Web scraping gives us all videos on the 1st page
|
||||
assert len(video_ids) == 20
|
||||
|
||||
def test_api(self):
|
||||
url = youtube_tools.GenerateYouTubeURL("she is still sleeping",
|
||||
meta_tags=None)
|
||||
video_ids = url.api(bestmatch=False)
|
||||
const.args.manual = False
|
||||
# API gives us 50 videos (or as requested)
|
||||
assert len(video_ids) == 50
|
||||
|
||||
|
||||
class TestYouTubeURL:
|
||||
def test_only_music_category(self):
|
||||
# YouTube keeps changing its results
|
||||
|
||||
Reference in New Issue
Block a user