Request how to use this code in my plugin

Dr_Tharwat

New member
Sep 14, 2016
3
0
0
hi Dears,
i am suffering here as a beginner in python world,
am trying to make a video plugin for site most of its links external on

and i found some code to get the encripted link as :
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)
        params = {
            '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
so how can i use it in my addon to play it