-
Notifications
You must be signed in to change notification settings - Fork 1
/
sina.py
69 lines (61 loc) · 2.38 KB
/
sina.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# -*- coding: utf-8 -*-
import lxml.etree
import lxml.html
import httplib2
import cStringIO
import urllib2
import gluon.contrib.simplejson as sj
import base64
import re
import applications.downloader.modules.common as common
def download():
if not common.check_verify(request,session,db):
return redirect('/')
c = {}
c['url'] = request.vars.url or ''
if c['url']:
headers = {'User-Agent':request.env.http_user_agent}
http = httplib2.Http()
try:
resp, content = http.request(c['url'], headers = headers)
except:
return redirect('/')
try:
videoid = ''.join(re.findall("vid='(.*)'",content))
if not videoid:
videoid = ''.join(re.findall("vid :'(.*)'",content))
if not videoid:
return sj.dumps(['error'])
flv_id = videoid.split("|")[0]
if len(videoid.split("|")) > 1:
hp_id = videoid.split("|")[1]
resp, content = http.request('http://v.iask.com/v_play.php?vid=%s' % (flv_id), headers = headers)
movie = re.findall('<url>.*</url>', content)
c['title'] = re.findall('<vname>.*</vname>', content)
c['title'] = c['title'][0][16:-11]
c['movies'] = []
c['screen'] = []
c['sound'] = []
c['container'] = []
c['encoding'] = []
c['rate'] = []
for x in movie:
c['movies'].append(x[14:-9])
c['screen'].append('640x480')
c['sound'].append('stereo')
c['container'].append('FLV')
c['encoding'].append('H.264/AVC Video')
c['rate'].append('22050 Hz')
if len(videoid.split("|")) > 1:
resp, content = http.request('http://v.iask.com/v_play.php?vid=%s' % (hp_id), headers = headers)
movie = re.findall('<url>.*</url>', content)
for x in movie:
c['movies'].append(x[14:-9])
c['screen'].append('640x480')
c['sound'].append('stereo')
c['container'].append('FLV')
c['encoding'].append('H.264/AVC Video')
c['rate'].append('44100 Hz')
return sj.dumps(c)
except:
return sj.dumps(['error'])