From 9356e4e9ca86785f245b5c81639ecc76c8592368 Mon Sep 17 00:00:00 2001 From: Steven Smith Date: Sat, 24 Aug 2013 16:44:22 +0800 Subject: [PATCH 1/5] Fix duration, add new function for timestamp formatting --- plugins/vimeo.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/plugins/vimeo.py b/plugins/vimeo.py index 6edb990..ee4c899 100755 --- a/plugins/vimeo.py +++ b/plugins/vimeo.py @@ -1,15 +1,21 @@ -from util import hook, http +from util import hook, http, timeformat @hook.regex(r'vimeo.com/([0-9]+)') def vimeo_url(match): "vimeo -- returns information on the Vimeo video at " - info = http.get_json('http://vimeo.com/api/v2/video/%s.json' - % match.group(1)) + info = http.get_json('http://vimeo.com/api/v2/video/%s.json' % match.group(1)) if info: - return ("\x02%(title)s\x02 - length \x02%(duration)ss\x02 - " - "\x02%(stats_number_of_likes)s\x02 likes - " - "\x02%(stats_number_of_plays)s\x02 plays - " - "\x02%(user_name)s\x02 on \x02%(upload_date)s\x02" - % info[0]) + info = info[0] + return ("\x02{title}\x02 - length \x02{duration}\x02 - " + "\x02{likes}\x02 likes - " + "\x02{plays}\x02 plays - " + "\x02{username}\x02 on \x02{uploaddate}\x02".format( + title=info["title"], + duration=timeformat.timeformat(info["duration"]), + likes=info["stats_number_of_likes"], + plays=info["stats_number_of_plays"], + username=info["user_name"], + uploaddate=info["upload_date"]) + ) From 15b2b259df821c886cdfe200f73dff9d7e5c89d1 Mon Sep 17 00:00:00 2001 From: Steven Smith Date: Sat, 24 Aug 2013 16:45:05 +0800 Subject: [PATCH 2/5] Create timeformat.py --- plugins/util/timeformat.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 plugins/util/timeformat.py diff --git a/plugins/util/timeformat.py b/plugins/util/timeformat.py new file mode 100644 index 0000000..fd31d1e --- /dev/null +++ b/plugins/util/timeformat.py @@ -0,0 +1,16 @@ +def timeformat(seconds): + if seconds < 60: + timestamp = str(seconds) + "s" + elif seconds >= 60 and seconds < 3600: + timestamp = "%s:%s" % (seconds/60, seconds%60) + elif seconds >= 3600 and seconds < 86400: + hours = seconds / 3600 + seconds = 3600*hours + timestamp = "%s:%s:%s" % (hours, seconds/60, seconds%60) + elif seconds >= 86400: + days = seconds / 86400 + seconds = 86400*days + hours = seconds / 3600 + seconds = 3600*hours + timestamp = "%s days, %s:%s:%s" % (days, hours, seconds/60, seconds%60) + return timestamp From 53d49a78f1ad945cde0d0948a0279cee394c9908 Mon Sep 17 00:00:00 2001 From: Steven Smith Date: Sat, 24 Aug 2013 17:11:21 +0800 Subject: [PATCH 3/5] Update timeformat.py --- plugins/util/timeformat.py | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/plugins/util/timeformat.py b/plugins/util/timeformat.py index fd31d1e..12b22d8 100644 --- a/plugins/util/timeformat.py +++ b/plugins/util/timeformat.py @@ -1,16 +1,14 @@ def timeformat(seconds): - if seconds < 60: - timestamp = str(seconds) + "s" - elif seconds >= 60 and seconds < 3600: - timestamp = "%s:%s" % (seconds/60, seconds%60) - elif seconds >= 3600 and seconds < 86400: - hours = seconds / 3600 - seconds = 3600*hours - timestamp = "%s:%s:%s" % (hours, seconds/60, seconds%60) - elif seconds >= 86400: - days = seconds / 86400 - seconds = 86400*days - hours = seconds / 3600 - seconds = 3600*hours - timestamp = "%s days, %s:%s:%s" % (days, hours, seconds/60, seconds%60) - return timestamp + days = seconds / 86400 + seconds -= 86400 * days + hours = seconds / 3600 + seconds -= 3600 * hours + minutes = seconds / 60 + seconds -= 60 * minutes + if days != 0: + return "%s, %02d:%02d:%02d" % (str(days) + " days" if days > 1 else str(days) + " day", hours, minutes, seconds) + elif hours == 0 and minutes != 0: + return "%02d:%02d" % (minutes, seconds) + elif hours == 0 and minutes == 0: + return "%02d" % seconds + return "%02d:%02d:%02d" % (hours, minutes, seconds) From 86be633213caae911e4542cd61d00206a7bfdb80 Mon Sep 17 00:00:00 2001 From: Steven Smith Date: Sat, 24 Aug 2013 17:15:54 +0800 Subject: [PATCH 4/5] Update timeformat.py --- plugins/util/timeformat.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/util/timeformat.py b/plugins/util/timeformat.py index 12b22d8..185fd36 100644 --- a/plugins/util/timeformat.py +++ b/plugins/util/timeformat.py @@ -6,9 +6,9 @@ def timeformat(seconds): minutes = seconds / 60 seconds -= 60 * minutes if days != 0: - return "%s, %02d:%02d:%02d" % (str(days) + " days" if days > 1 else str(days) + " day", hours, minutes, seconds) + return "%sd %sh %sm %ss" % (days, hours, minutes, seconds) elif hours == 0 and minutes != 0: - return "%02d:%02d" % (minutes, seconds) + return "%sm %ss" % (minutes, seconds) elif hours == 0 and minutes == 0: - return "%02d" % seconds - return "%02d:%02d:%02d" % (hours, minutes, seconds) + return "%ss" % seconds + return "%sh %sm %ss" % (hours, minutes, seconds) From b2b5270686c23b0fe4049a410b869f2fbed4f31e Mon Sep 17 00:00:00 2001 From: Steven Smith Date: Sat, 24 Aug 2013 17:23:15 +0800 Subject: [PATCH 5/5] Return vimeo.py to where it was before, but with better duration and comma-grouped likes and plays --- plugins/vimeo.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/plugins/vimeo.py b/plugins/vimeo.py index ee4c899..479a544 100755 --- a/plugins/vimeo.py +++ b/plugins/vimeo.py @@ -4,18 +4,17 @@ from util import hook, http, timeformat @hook.regex(r'vimeo.com/([0-9]+)') def vimeo_url(match): "vimeo -- returns information on the Vimeo video at " - info = http.get_json('http://vimeo.com/api/v2/video/%s.json' % match.group(1)) + info = http.get_json('http://vimeo.com/api/v2/video/%s.json' + % match.group(1)) if info: - info = info[0] - return ("\x02{title}\x02 - length \x02{duration}\x02 - " - "\x02{likes}\x02 likes - " - "\x02{plays}\x02 plays - " - "\x02{username}\x02 on \x02{uploaddate}\x02".format( - title=info["title"], - duration=timeformat.timeformat(info["duration"]), - likes=info["stats_number_of_likes"], - plays=info["stats_number_of_plays"], - username=info["user_name"], - uploaddate=info["upload_date"]) - ) + info[0]["duration"] = timeformat.timeformat(info[0]["duration"]) + info[0]["stats_number_of_likes"] = format( + info[0]["stats_number_of_likes"], ",d") + info[0]["stats_number_of_plays"] = format( + info[0]["stats_number_of_plays"], ",d") + return ("\x02%(title)s\x02 - length \x02%(duration)s\x02 - " + "\x02%(stats_number_of_likes)s\x02 likes - " + "\x02%(stats_number_of_plays)s\x02 plays - " + "\x02%(user_name)s\x02 on \x02%(upload_date)s\x02" + % info[0])