From dabd81608d2702d07c1bc775818ac171a9cd0622 Mon Sep 17 00:00:00 2001 From: Samuel Clay Date: Wed, 29 Apr 2015 17:16:15 -0700 Subject: [PATCH] Fixing three youtube issues: broken usernames/urls (non-uploads), 404 pages, and over-expanding content due to fixvid. --- utils/feed_fetcher.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/utils/feed_fetcher.py b/utils/feed_fetcher.py index 5c2173820..3c54a6878 100644 --- a/utils/feed_fetcher.py +++ b/utils/feed_fetcher.py @@ -131,10 +131,17 @@ class FetchFeed: def fetch_youtube(self, address): try: - username = re.search('gdata.youtube.com/feeds/\w+/users/(\w+)/uploads', address).group(1) + username_groups = re.search('gdata.youtube.com/feeds/\w+/users/(\w+)/uploads', address) + if not username_groups: + return + username = username_groups.group(1) except IndexError: return + video_ids_xml = requests.get("https://www.youtube.com/feeds/videos.xml?user=%s" % username) + if video_ids_xml.status_code != 200: + return + video_ids_soup = BeautifulSoup(video_ids_xml.content) video_ids = [] for video_id in video_ids_soup.findAll('yt:videoid'): @@ -160,11 +167,14 @@ class FetchFeed: thumbnail = video['snippet']['thumbnails'].get('high') if not thumbnail: thumbnail = video['snippet']['thumbnails'].get('medium') - content = """
%s

%s
""" % ( + content = """
%s
+
%s
+ """ % ( video['player']['embedHtml'], linebreaks(video['snippet']['description']), thumbnail['url'] if thumbnail else "", ) + link = "http://www.youtube.com/watch?v=%s&feature=youtube_gdata" % video['id'] story_data = { 'title': video['snippet']['title'],