From d5e4c7bbe7f9ea23ef2339a32e45bdc7c300da69 Mon Sep 17 00:00:00 2001 From: jesopo Date: Mon, 4 Apr 2016 18:40:39 +0100 Subject: added code to youtube.py to prevent a crash when a video has likes/dislikes disabled. --- modules/youtube.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/modules/youtube.py b/modules/youtube.py index 8cdd2b36..d73e5e34 100644 --- a/modules/youtube.py +++ b/modules/youtube.py @@ -49,9 +49,13 @@ class Module(object): video_uploader = snippet["channelTitle"] video_title = snippet["title"] video_views = statistics["viewCount"] - video_likes = statistics["likeCount"] - video_dislikes = statistics["dislikeCount"] + video_likes = statistics.get("likeCount") + video_dislikes = statistics.get("dislikeCount") video_duration = content["duration"] + video_opinions = "" + if video_likes and video_dislikes: + video_opinions = " (%s%s%s%s)" % (video_likes, ARROW_UP, + ARROW_DOWN, video_dislikes) match = re.match(REGEX_ISO8601, video_duration) video_duration = "" @@ -61,10 +65,9 @@ class Module(object): ) if match.group(2) else "00:" video_duration += "%s" % match.group(3)[:-1].zfill(2 ) if match.group(3) else "00" - return "%s (%s) uploaded by %s, %s views (%s%s%s%s) %s" % ( + return "%s (%s) uploaded by %s, %s views%s %s" % ( video_title, video_duration, video_uploader, "{:,}".format( - int(video_views)), video_likes, ARROW_UP, ARROW_DOWN, video_dislikes, - URL_YOUTUBESHORT % video_id) + int(video_views)), video_opinions, URL_YOUTUBESHORT % video_id) def yt(self, event): video_id = None -- cgit v1.3.1-10-gc9f91