Create hulu.py
This commit is contained in:
parent
4e0a0b9d6d
commit
4fb4e3c1fb
25
plugins/hulu.py
Normal file
25
plugins/hulu.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
from util import hook, http, timeformat
|
||||
from urllib import urlencode
|
||||
import re
|
||||
|
||||
hulu_re = (r'(.*://)(www.hulu.com|hulu.com)(.*)', re.I)
|
||||
|
||||
|
||||
@hook.regex(*hulu_re)
|
||||
def hulu_url(match):
|
||||
data = http.get_json("http://www.hulu.com/api/oembed.json?url=http://www.hulu.com" + match.group(3))
|
||||
showname = data['title'].split("(")[-1].split(")")[0]
|
||||
title = data['title'].split(" (")[0]
|
||||
return "{}: {} - {}".format(showname, title, timeformat.timeformat(int(data['duration'])))
|
||||
|
||||
|
||||
@hook.command('hulu')
|
||||
def hulu_search(inp):
|
||||
result = http.get_soup("http://m.hulu.com/search?dp_identifier=hulu&{}&items_per_page=1&page=1".format(urlencode({'query': inp})))
|
||||
data = result.find('results').find('videos').find('video')
|
||||
showname = data.find('show').find('name').text
|
||||
title = data.find('title').text
|
||||
duration = timeformat.timeformat(int(float(data.find('duration').text)))
|
||||
description = data.find('description').text
|
||||
rating = data.find('content-rating').text
|
||||
return "{}: {} - {} - {} ({}) {}".format(showname, title, description, duration, rating, "http://www.hulu.com/watch/" + str(data.find('id').text))
|
Reference in a new issue