本文整理汇总了Python中util.request函数的典型用法代码示例。如果您正苦于以下问题:Python request函数的具体用法?Python request怎么用?Python request使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了request函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: resolve
def resolve(self,item,captcha_cb=None,wait_cb=None):
item = item.copy()
url = self._url(item['url'])
item['surl'] = url
data = util.request(url)
link = re.search('<a class="stahnoutSoubor.+?href=\"([^\"]+)',data)
if link:
url = self._url(link.group(1))
data = util.request(url)
m = re.search('<img src=\"(?P<img>[^\"]+)\" alt=\"Captcha\"',data)
cap_id = re.search('<input type=\"hidden\" name=\"_uid_captcha.+?value=\"(?P<cid>[^\"]+)',data)
if m and cap_id:
cid = cap_id.group('cid')
img_data = m.group('img')[m.group('img').find('base64,')+7:]
if not os.path.exists(self.tmp_dir):
os.makedirs(self.tmp_dir)
tmp_image = os.path.join(self.tmp_dir,'captcha.png')
util.save_data_to_file(base64.b64decode(img_data),tmp_image)
code = captcha_cb({'id':cid,'img': tmp_image})
if not code:
return
data = util.post(url+'?do=stahnoutFreeForm-submit',{'_uid_captcha':cid,'captcha':code,'stahnoutSoubor':'Stáhnout'})
countdown = re.search('shortly\.getSeconds\(\) \+ (\d+)',data)
last_url = re.search('<a class=\"stahnoutSoubor2.+?href=\"([^\"]+)',data)
if countdown and last_url:
wait = int(countdown.group(1))
url = self._url(last_url.group(1))
wait_cb(wait)
req = urllib2.Request(url)
req.add_header('User-Agent',util.UA)
resp = urllib2.urlopen(req)
item['url'] = resp.geturl()
return item
示例2: _resolve_vod
def _resolve_vod(self, item):
resolved = []
data = util.request(self._url(item['url']))
video_id = re.search("LiveboxPlayer.archiv\(.+?videoId:\s*'([^']+)'", data, re.DOTALL).group(1)
#print "video_id", video_id
player_data = util.request("http://embed.livebox.cz/ta3_v2/vod-source.js", {'Referer':self._url(item['url'])})
#print "player_data", player_data
url_format = re.search(r'my.embedurl = \[\{"src" : "([^"]+)"', player_data).group(1)
#print "url_format", url_format
manifest_url = "https:" + url_format.format(video_id)
#print "manifest_url", manifest_url
manifest = util.request(manifest_url)
print "manifest", manifest
for m in re.finditer('#EXT-X-STREAM-INF:PROGRAM-ID=\d+,BANDWIDTH=(?P<bandwidth>\d+).*?(,RESOLUTION=(?P<resolution>\d+x\d+))?\s(?P<chunklist>[^\s]+)', manifest, re.DOTALL):
item = self.video_item()
item['surl'] = item['title']
item['quality'] = m.group('bandwidth')
item['url'] = manifest_url[:manifest_url.rfind('/')+1] + m.group('chunklist')
resolved.append(item)
resolved = sorted(resolved, key=lambda x:int(x['quality']), reverse=True)
if len(resolved) == 3:
qualities = ['720p', '480p', '360p']
for idx, item in enumerate(resolved):
item['quality'] = qualities[idx]
else:
for idx, item in enumerate(resolved):
item['quality'] += 'b/s'
return resolved
示例3: resolve
def resolve(self,item,captcha_cb=None):
item = item.copy()
url = item['url']
if url.startswith('http://www.ulozto.sk'):
url = 'http://www.ulozto.cz' + url[20:]
if url.startswith('#'):
ret = json.loads(util.request(url[1:]))
if not ret['result'] == 'null':
url = b64decode(ret['result'])
url = self._url(url)
if url.startswith('#'):
util.error('[uloz.to] - url was not correctly decoded')
return
self.init_urllib()
self.info('Resolving %s'% url)
logged_in = self.login()
if logged_in:
page = util.request(url)
else:
try:
request = urllib2.Request(url)
response = urllib2.urlopen(request)
page = response.read()
response.close()
except urllib2.HTTPError, e:
traceback.print_exc()
return
示例4: resolve
def resolve(self, item, captcha_cb=None, select_cb=None):
result = []
item = item.copy()
url = item['url']
if url.endswith('live.html'):
for quality in ['360','540','720']:
item = self.video_item()
item['quality'] = quality + 'p'
item['url'] = self.rtmp_url(fix_path(re.search('http://(\w+).joj.sk', url).group(1)) + '-' + quality, url)
result.append(item)
else:
data = util.request(url)
playerdata = re.search(r'<div\ class=\"jn-player\"(.+?)>',data).group(1)
pageid = re.search(r'data-pageid=[\'\"]([^\'\"]+)',playerdata).group(1)
basepath = re.search(r'data-basepath=[\'\"]([^\'\"]+)',playerdata).group(1)
videoid = re.search(r'data-id=[\'\"]([^\'\"]+)',playerdata).group(1)
playlisturl = basepath + 'services/Video.php?clip=' + videoid + 'pageId=' + pageid
playlist = fromstring(util.request(playlisturl))
balanceurl = basepath + 'balance.xml?nc=%d' % random.randint(1000, 9999)
balance = fromstring(util.request(balanceurl))
for video in playlist.find('files').findall('file'):
item = self.video_item()
item['img'] = playlist.attrib.get('large_image')
item['length'] = playlist.attrib.get('duration')
item['quality'] = video.attrib.get('quality')
item['url'] = self.rtmp_url(video.attrib.get('path'), playlist.attrib.get('url'), video.attrib.get('type'), balance)
result.append(item)
result.reverse()
return select_cb(result)
示例5: list
def list(self, url):
if url.find('zebricky/') == 0:
return self.list_top10(util.request(self.base_url+url))
if url.find("#related#") == 0:
return self.list_related(util.request(url[9:]))
else:
return self.list_content(util.request(self._url(url)), self._url(url))
示例6: resolve
def resolve(url):
data = util.extract_jwplayer_setup(util.request(url))
if data and 'sources' in data:
result = []
for source in data['sources']:
items = []
if source['file'].endswith('.smil'):
tree = ElementTree.fromstring(util.request(source['file']))
base_path = tree.find('./head/meta').get('base')
for video in tree.findall('./body/switch/video'):
items.append({
'url': '%s playpath=%s pageUrl=%s swfUrl=%s swfVfy=true' %
(base_path, video.get('src'), url,
'http://static.flashx.tv/player6/jwplayer.flash.swf'),
'quality': video.get('height') + 'p'
})
else:
items.append({'url': source['file']})
if len(data['tracks']) > 0:
for item in items:
for track in data['tracks']:
new_item = deepcopy(item)
new_item['subs'] = track['file']
new_item['lang'] = ' %s subtitles' % track['label']
result.append(new_item)
else:
result += items
return result
return None
示例7: resolve
def resolve(self,item,captcha_cb=None,select_cb=None):
item = item.copy()
url = self._url(item['url'])
data = util.request(self._url(item['url']))
data = util.substr(data,'<div class=\"video','</div')
sosac = re.search('\"(http\://[\w]+\.sosac\.ph[^\"]+)',data,re.DOTALL)
if sosac:
data = util.request(sosac.group(1))
resolved = resolver.findstreams(data,[
'<embed( )*flashvars=\"file=(?P<url>[^\"]+)',
'<embed( )src=\"(?P<url>[^\"]+)',
'<object(.+?)data=\"(?P<url>[^\"]+)',
'<iframe(.+?)src=[\"\' ](?P<url>.+?)[\'\" ]',
])
result = []
if not resolved:
self.error('Nothing resolved')
for i in resolved:
item = self.video_item()
item['title'] = i['name']
item['url'] = i['url']
item['quality'] = i['quality']
item['surl'] = i['surl']
item['subs'] = i['subs']
result.append(item)
if len(result)==1:
return result[0]
elif len(result) > 1 and select_cb:
return select_cb(result)
示例8: resolve
def resolve(self, item, captcha_cb=None, select_cb=None):
item = item.copy()
url = self._url(item["url"])
data = util.request(self._url(item["url"]))
data = util.substr(data, '<div class="video', "</div")
sosac = re.search('"(http\://[\w]+\.sosac\.ph[^"]+)', data, re.DOTALL)
if sosac:
data = util.request(sosac.group(1))
resolved = resolver.findstreams(
data,
[
'<embed( )*flashvars="file=(?P<url>[^"]+)',
'<embed( )src="(?P<url>[^"]+)',
'<object(.+?)data="(?P<url>[^"]+)',
"<iframe(.+?)src=[\"' ](?P<url>.+?)['\" ]",
"<object.*?data=(?P<url>.+?)</object>",
],
)
result = []
if not resolved:
self.error("Nothing resolved")
for i in resolved:
item = self.video_item()
item["title"] = i["name"]
item["url"] = i["url"]
item["quality"] = i["quality"]
item["surl"] = i["surl"]
item["subs"] = i["subs"]
item["headers"] = i["headers"]
result.append(item)
if len(result) == 1:
return result[0]
elif len(result) > 1 and select_cb:
return select_cb(result)
示例9: list_episodes
def list_episodes(self, url, page=0):
result = []
if url.find('ajax.json') != -1:
headers = {'X-Requested-With':'XMLHttpRequest',
'Referer':util.substr(url, url, url.split('/')[-1])
}
httpdata = util.request(url, headers)
httpdata = util.json.loads(httpdata)['content']
else:
httpdata = util.request(url)
httpdata = util.substr(httpdata, EPISODE_START, EPISODE_END)
entries = 0
skip_entries = MAX_PAGE_ENTRIES * page
for m in re.finditer(EPISODE_ITER_RE, httpdata, re.DOTALL | re.IGNORECASE):
entries += 1
if entries < skip_entries:
continue
item = self.video_item()
item['title'] = "%s. %s (%s)" % (m.group('episode'), m.group('title'), m.group('date'))
item['url'] = m.group('url')
self._filter(result, item)
if entries >= (skip_entries + MAX_PAGE_ENTRIES):
page += 1
item = self.dir_item()
item['type'] = 'next'
item['url'] = "#episodes##%d#" % (page) + url
result.append(item)
break
return result
示例10: resolve
def resolve(self, item, captcha_cb=None, select_cb=None):
item = item.copy()
url = self._url(item["url"])
data = util.request(url)
video_id = re.search(VIDEO_ID_RE, data, re.IGNORECASE | re.DOTALL).group(1)
headers = {"Referer": url}
keydata = util.request("http://embed.stv.livebox.sk/v1/tv-arch.js", headers)
rtmp_url_regex = "'(rtmp:\/\/[^']+)'\+videoID\+'([^']+)'"
m3u8_url_regex = "'(http:\/\/[^']+)'\+videoID\+'([^']+)'"
rtmp = re.search(rtmp_url_regex, keydata, re.DOTALL)
m3u8 = re.search(m3u8_url_regex, keydata, re.DOTALL)
m3u8_url = m3u8.group(1) + video_id + m3u8.group(2)
# rtmp[t][e|s]://hostname[:port][/app[/playpath]]
# tcUrl=url URL of the target stream. Defaults to rtmp[t][e|s]://host[:port]/app.
# rtmp url- fix podla mponline2 projektu
rtmp_url = rtmp.group(1) + video_id + rtmp.group(2)
stream_part = "mp4:" + video_id
playpath = rtmp_url[rtmp_url.find(stream_part) :]
tcUrl = rtmp_url[: rtmp_url.find(stream_part) - 1] + rtmp_url[rtmp_url.find(stream_part) + len(stream_part) :]
app = tcUrl[tcUrl.find("/", tcUrl.find("/") + 2) + 1 :]
# rtmp_url = rtmp_url+ ' playpath=' + playpath + ' tcUrl=' + tcUrl + ' app=' + app
rtmp_url = rtmp_url + " tcUrl=" + tcUrl + " app=" + app
item["url"] = rtmp_url
return item
示例11: resolve
def resolve(self, item, captcha_cb=None, select_cb=None):
result = []
item = item.copy()
url = item['url']
if url.endswith('live.html'):
channel = re.search(r'http://(\w+)\.joj\.sk', url).group(1)
for original, replacement in {'www': 'joj', 'plus': 'jojplus'}.items():
if channel == original:
channel = replacement
break
for quality, resolution in {'lq': '180p', 'mq': '360p', 'hq': '540p'}.items():
item = self.video_item()
item['quality'] = resolution
item['url'] = 'http://http-stream.joj.sk/joj/' + channel + '/index-' + quality + '.m3u8'
result.append(item)
else:
data = util.request(url)
playerdata = re.search(r'<div\ class=\"jn-player\"(.+?)>', data).group(1)
pageid = re.search(r'data-pageid=[\'\"]([^\'\"]+)', playerdata).group(1)
basepath = re.search(r'data-basepath=[\'\"]([^\'\"]+)', playerdata).group(1)
videoid = re.search(r'data-id=[\'\"]([^\'\"]+)', playerdata).group(1)
playlisturl = basepath + 'services/Video.php?clip=' + videoid + 'pageId=' + pageid
playlist = fromstring(util.request(playlisturl))
balanceurl = basepath + 'balance.xml?nc=%d' % random.randint(1000, 9999)
balance = fromstring(util.request(balanceurl))
for video in playlist.find('files').findall('file'):
item = self.video_item()
item['img'] = playlist.attrib.get('large_image')
item['length'] = playlist.attrib.get('duration')
item['quality'] = video.attrib.get('quality')
item['url'] = self.rtmp_url(video.attrib.get('path'), playlist.attrib.get('url'),
video.attrib.get('type'), balance)
result.append(item)
result.reverse()
return select_cb(result)
示例12: __init__
def __init__(self, username=None, password=None, filter=None, reverse_eps=False):
ContentProvider.__init__(self, name='sosac.ph', base_url=MOVIES_BASE_URL, username=username,
password=password, filter=filter)
util.init_urllib(self.cache)
cookies = self.cache.get(util.CACHE_COOKIES)
if not cookies or len(cookies) == 0:
util.request(self.base_url)
self.reverse_eps = reverse_eps
示例13: list
def list(self, url):
if url.find('subcat') == 0:
category_id = url.split("#")[1]
return self.list_subcategories(util.request(self.base_url), category_id)
elif url.find('calendar') == 0:
year, month = url.split("#")[1].split("|")
return self.calendar(int(year), int(month))
return self.list_content(util.request(self._url(url)))
示例14: resolve
def resolve(url):
refererurl = re.search(r'<iframe src="([^"]+)".*', util.request(url), re.I | re.S).group(1)
try:
data=[x for x in util.request(refererurl).splitlines() if 'file:' in x and '.mp4' in x][0]
except:
return None
streamurl = re.search(r'.*file:"([^"]+?)".*', data).group(1)
headers={'Referer': refererurl}
return [{'url': streamurl, 'headers': headers}]
示例15: list
def list(self,url):
if url.find('#film#') == 0:
return self.film(util.request(self._url(url[6:])))
if url.find('#rand#') == 0:
return self.film(util.request(self._url(url[6:])+'index.php?id=2236'))
if url.find('#last#') == 0:
return self.film(util.request(self._url(url[6:])))
else:
raise Expception("Invalid url, I do not know how to list it :"+url)