Bug fix on the video research method and coverage improvement.

The bug was solved by changing the maximum value of the 'search index'. Actually Youtube doesn't allow to get more than 500 results. That's why we changed the value of YOUTUBE_MAX_START_INDEX from 1000 to 500.
This commit is contained in:
blckshrk 2013-11-03 12:06:04 +01:00 committed by Florent
commit 68a443768f
2 changed files with 7 additions and 5 deletions

View file

@ -118,7 +118,7 @@ class YoutubeBackend(BaseBackend, ICapVideo, ICapCollection):
def search_videos(self, pattern, sortby=ICapVideo.SEARCH_RELEVANCE, nsfw=False): def search_videos(self, pattern, sortby=ICapVideo.SEARCH_RELEVANCE, nsfw=False):
YOUTUBE_MAX_RESULTS = 50 YOUTUBE_MAX_RESULTS = 50
YOUTUBE_MAX_START_INDEX = 1000 YOUTUBE_MAX_START_INDEX = 500
yt_service = gdata.youtube.service.YouTubeService() yt_service = gdata.youtube.service.YouTubeService()
yt_service.ssl = True yt_service.ssl = True
@ -134,8 +134,7 @@ class YoutubeBackend(BaseBackend, ICapVideo, ICapCollection):
query.racy = 'include' if nsfw else 'exclude' query.racy = 'include' if nsfw else 'exclude'
query.max_results = YOUTUBE_MAX_RESULTS query.max_results = YOUTUBE_MAX_RESULTS
if start_index >= YOUTUBE_MAX_START_INDEX:
if start_index > YOUTUBE_MAX_START_INDEX:
return return
query.start_index = start_index query.start_index = start_index
start_index += YOUTUBE_MAX_RESULTS start_index += YOUTUBE_MAX_RESULTS
@ -148,7 +147,6 @@ class YoutubeBackend(BaseBackend, ICapVideo, ICapCollection):
if nb_yielded < YOUTUBE_MAX_RESULTS: if nb_yielded < YOUTUBE_MAX_RESULTS:
return return
def latest_videos(self): def latest_videos(self):
return self.search_videos(None, ICapVideo.SEARCH_DATE) return self.search_videos(None, ICapVideo.SEARCH_DATE)

View file

@ -42,7 +42,11 @@ class YoutubeTest(BackendTest):
v = self.backend.get_video('http://youtu.be/UxxajLWwzqY') v = self.backend.get_video('http://youtu.be/UxxajLWwzqY')
self.backend.fillobj(v, ('url',)) self.backend.fillobj(v, ('url',))
assert len(v.url) assert len(v.url)
try:
self.backend.browser.openurl(v.url) self.backend.browser.openurl(v.url)
except:
self.fail('can\'t open url')
def test_weirdchars(self): def test_weirdchars(self):
v = self.backend.get_video('https://www.youtube.com/watch?v=BaW_jenozKc') v = self.backend.get_video('https://www.youtube.com/watch?v=BaW_jenozKc')