From 68a443768f2e5eaaddbf21562638f2b0288d13d1 Mon Sep 17 00:00:00 2001 From: blckshrk Date: Sun, 3 Nov 2013 12:06:04 +0100 Subject: [PATCH] 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. --- modules/youtube/backend.py | 6 ++---- modules/youtube/test.py | 6 +++++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/youtube/backend.py b/modules/youtube/backend.py index 87d729d3..5934e4a1 100644 --- a/modules/youtube/backend.py +++ b/modules/youtube/backend.py @@ -118,7 +118,7 @@ class YoutubeBackend(BaseBackend, ICapVideo, ICapCollection): def search_videos(self, pattern, sortby=ICapVideo.SEARCH_RELEVANCE, nsfw=False): YOUTUBE_MAX_RESULTS = 50 - YOUTUBE_MAX_START_INDEX = 1000 + YOUTUBE_MAX_START_INDEX = 500 yt_service = gdata.youtube.service.YouTubeService() yt_service.ssl = True @@ -134,8 +134,7 @@ class YoutubeBackend(BaseBackend, ICapVideo, ICapCollection): query.racy = 'include' if nsfw else 'exclude' query.max_results = YOUTUBE_MAX_RESULTS - - if start_index > YOUTUBE_MAX_START_INDEX: + if start_index >= YOUTUBE_MAX_START_INDEX: return query.start_index = start_index start_index += YOUTUBE_MAX_RESULTS @@ -148,7 +147,6 @@ class YoutubeBackend(BaseBackend, ICapVideo, ICapCollection): if nb_yielded < YOUTUBE_MAX_RESULTS: return - def latest_videos(self): return self.search_videos(None, ICapVideo.SEARCH_DATE) diff --git a/modules/youtube/test.py b/modules/youtube/test.py index fa1cbada..a18a9e96 100644 --- a/modules/youtube/test.py +++ b/modules/youtube/test.py @@ -42,7 +42,11 @@ class YoutubeTest(BackendTest): v = self.backend.get_video('http://youtu.be/UxxajLWwzqY') self.backend.fillobj(v, ('url',)) assert len(v.url) - self.backend.browser.openurl(v.url) + + try: + self.backend.browser.openurl(v.url) + except: + self.fail('can\'t open url') def test_weirdchars(self): v = self.backend.get_video('https://www.youtube.com/watch?v=BaW_jenozKc')