aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar jesopo2016-04-04 18:40:39 +0100
committerGravatar jesopo2016-04-04 18:40:39 +0100
commitd5e4c7bbe7f9ea23ef2339a32e45bdc7c300da69 (patch)
tree7775d9d7b5bcd4bee3e3faf5874525540124a5c4
parentfixed showing track tags in lastfm.py. (diff)
added code to youtube.py to prevent a crash when a video has likes/dislikes disabled.
-rw-r--r--modules/youtube.py13
1 files 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