PLease Help Me AS i am New to python,and working on my 2nd video Addon ,
And video links are on this site
http://ok.ru/videoembed/93942254125
and tihs link work only in browser but not in Vlc as a test
So:
How can i include this To My Addon
i found Answer But not sure how to include it in my Addon
Code:
import urllib, urllib2, urlparse, re, json
HEADERS = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Cache-Control': 'no-transform'
}
def http_req(url, getCookie=False, data=None, customHeader=None):
if data: data = urllib.urlencode(data)
req = urllib2.Request(url, data, HEADERS)
if customHeader:
req = urllib2.Request(url, data, customHeader)
response = urllib2.urlopen(req)
source = response.read()
response.close()
if getCookie:
cookie = response.headers.get('Set-Cookie')
return {'source': source, 'cookie': cookie}
return source
sources = []
mirrorUrl = 'http://www.ok.ru/videoembed/36530555610'
try:
id = re.search('\d+', mirrorUrl).group(0)
u = urlparse.urlparse(mirrorUrl)
hostUrl = '://'.join([u.scheme, u.netloc])
jsonUrl = 'http://ok.ru/dk?cmd=videoPlayerMetadata&mid=' + id
jsonSource = json.loads(http_req(jsonUrl))
quality = {
'mobile': '144p',
'lowest': '240p',
'low': '360p',
'sd': '480p',
'hd': '720p',
'full': '1080p'
}
for source in jsonSource['videos']:
q = source['name'].strip()
q = quality.get(q, None)
if not q:
continue
name = '%s %s' % ('[ok.ru]', q)
'User-Agent': HEADERS['User-Agent'],
'Referer': mirrorUrl,
'Origin': hostUrl
}
params = '&'.join(['%s=%s' % (k, urllib.quote_plus(v)) for k, v in params.iteritems()])
link = '%s|%s' % (source['url'], params)
item = {'name': name, 'url': link}
sources.append(item)
except:
pass
print sources
or shoulg i make it as util.pay and how to import it to my default.py