refactor vimeo plugin, PEP8
This commit is contained in:
parent
0ed4fcfff4
commit
faa68b6af5
|
@ -1,27 +1,15 @@
|
||||||
|
|
||||||
from util import http,hook
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
video_regex = (r'(?i)http://(?:www\.)?vimeo.com/([A-Za-z0-9\-]+)')
|
from util import http,hook
|
||||||
r'([a-zA-Z]+://|www\.)[^ ]+'
|
|
||||||
video_request_base = "http://vimeo.com/api/v2/video/%s.json"
|
|
||||||
|
|
||||||
video_info = "\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"
|
@hook.regex(r'vimeo.com/([0-9]+)')
|
||||||
|
def vimeo_url(match):
|
||||||
|
info = http.get_json('http://vimeo.com/api/v2/video/%s.json'
|
||||||
|
% match.group(1))
|
||||||
|
|
||||||
|
if info:
|
||||||
def viemo_video_info(video_id):
|
return ("\x02%(title)s\x02 - length \x02%(duration)ss\x02 - "
|
||||||
|
"\x02%(stats_number_of_likes)s\x02 likes - "
|
||||||
json_url = video_request_base % (video_id,)
|
"\x02%(stats_number_of_plays)s\x02 plays - "
|
||||||
|
"\x02%(user_name)s\x02 on \x02%(upload_date)s\x02"
|
||||||
json_responses = http.get_json(json_url)
|
% info[0])
|
||||||
|
|
||||||
if json_responses:
|
|
||||||
|
|
||||||
video_details = json_responses[0]
|
|
||||||
|
|
||||||
return video_info % video_details
|
|
||||||
|
|
||||||
|
|
||||||
@hook.regex(video_regex)
|
|
||||||
def viemo_url(url_match):
|
|
||||||
return viemo_video_info(url_match.group(1))
|
|
||||||
|
|
Loading…
Reference in New Issue