Skip to content

Commit

Permalink
update youku and fun
Browse files Browse the repository at this point in the history
  • Loading branch information
yfang1644 committed Aug 14, 2018
1 parent ae70b95 commit 6e65a4d
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 183 deletions.
4 changes: 2 additions & 2 deletions addons.xml
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@

<addon id="plugin.video.funshion"
name="风行视频(Funshion)"
version="2.0.0"
version="2.0.1"
provider-name="yfang1644">
<requires>
<import addon="script.module.xbmcswift2" version="2.4.0"/>
Expand Down Expand Up @@ -653,7 +653,7 @@

<addon id="plugin.video.cntv-video"
name="CNTV 视频"
version="1.1.6"
version="1.1.7"
provider-name="yfang1644">
<requires>
<import addon="script.module.beautifulsoup4" version="4.3.2"/>
Expand Down
2 changes: 1 addition & 1 deletion addons.xml.md5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ffcfa7ec60d0620ff566d74270a7ff54 addons.xml
e5ffed07518c719fe4e52ee3b509edbc addons.xml
2 changes: 1 addition & 1 deletion plugin.video.cntv-video/addon.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.cntv-video"
name="CNTV 视频"
version="1.1.6"
version="1.1.7"
provider-name="yfang1644">
<requires>
<import addon="script.module.beautifulsoup4" version="4.3.2"/>
Expand Down
55 changes: 22 additions & 33 deletions plugin.video.cntv-video/lib/funshion.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,21 @@
from common import get_html, r1
import base64
from urlparse import urlparse, urljoin
import string

class KBaseMapping:
def __init__(self, base=62):
self.base = base
mapping_table = [str(num) for num in range(10)]
for i in range(26):
mapping_table.append(chr(i + ord('a')))
for i in range(26):
mapping_table.append(chr(i + ord('A')))

self.mapping_table = mapping_table[:self.base]

def mapping(self, num):
res = []
while num > 0:
res.append(self.mapping_table[num % self.base])
num = num // self.base
return ''.join(res[::-1])
def mapping(num, base):
mapping_table = string.digits + string.ascii_letters
res = ''
while num > 0:
res = mapping_table[num % base] + res
num = num // base
return res

class Funshion():
stream_types = [
'sdvd', 'sdvd_h265', 'hd', 'hd_h265',
'dvd', 'dvd_h265', 'tv', 'tv_h265'
]
stream_types = ['sdvd', 'sdvd_h265', 'hd', 'hd_h265',
'dvd', 'dvd_h265', 'tv', 'tv_h265'
]
a_mobile_url = 'http://m.fun.tv/implay/?mid=302555'
video_ep = 'http://pv.funshion.com/v7/video/play/?id={}&cl=mweb&uc=111'
media_ep = 'http://pm.funshion.com/v7/media/play/?id={}&cl=mweb&uc=111'
Expand Down Expand Up @@ -78,10 +69,9 @@ def fetch_magic(self, url):
size = hit.group(3)
names = hit.group(4).split('|')

mapping = KBaseMapping(base=int(base))
sym_to_name = {}
for no in range(int(size), 0, -1):
no_in_base = mapping.mapping(no)
no_in_base = mapping(no, int(base))
val = names[no] if no < len(names) and names[no] else no_in_base
sym_to_name[no_in_base] = val

Expand Down Expand Up @@ -114,7 +104,7 @@ def funshion_decrypt(self, a_bytes, coeff):
res_list.append(n & 0xff)
pos += 2

return str(bytearray(res_list))
return str(bytearray(res_list))

def funshion_decrypt_str(self, a_str, coeff):
if len(a_str) == 28 and a_str[-1] == '0':
Expand All @@ -123,7 +113,6 @@ def funshion_decrypt_str(self, a_str, coeff):
return binascii.hexlify(clear.encode('utf8')).upper()

data_bytes = base64.b64decode(a_str[2:])
x = self.funshion_decrypt(data_bytes, coeff)
return self.funshion_decrypt(data_bytes, coeff)

def checksum(self, sha1_str):
Expand Down Expand Up @@ -167,9 +156,7 @@ def video_from_vid(self, vid, **kwargs):
for s in stream['playinfo']:
codec = 'h' + s['codec'][2:] # h.264 -> h264
for st in self.stream_types:
s_id = '{}_{}'.format(definition, codec)
if codec == 'h264':
s_id = definition
s_id = definition if codec == 'h264' else '{}_{}'.format(definition, codec)
if s_id == st:
clear_info = self.dec_playinfo(s, self.coeff)
cdn_list = self.get_cdninfo(clear_info['hashid'])
Expand All @@ -186,12 +173,14 @@ def video_from_url(self, url, **kwargs):
return self.video_from_vid(vid, single_video=True, **kwargs)
else:
vid = r1(r'https://www.fun.tv/vplay/.*v-(\w+)', url)
epid = r1(r'https://www.fun.tv/vplay/.*g-(\w+)', url)
url = 'http://pm.funshion.com/v5/media/episode?id={}&cl=mweb&uc=111'.format(vid)
html = get_html(url)
meta = loads(html)
if vid:
return self.video_from_vid(vid, **kwargs)
if not vid:
epid = r1(r'https://www.fun.tv/vplay/.*g-(\w+)', url)
url = 'http://pm.funshion.com/v5/media/episode?id={}&cl=mweb&uc=111'.format(epid)
html = get_html(url)
meta = loads(html)
vid = meta['episodes'][0]['id']
return self.video_from_vid(vid, **kwargs)


site = Funshion()
video_from_url = site.video_from_url
62 changes: 27 additions & 35 deletions plugin.video.cntv-video/lib/youku.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,24 @@
import ssl
import time
import urllib2 as request
import urllib
from urllib import quote
from json import loads
from common import get_html, match1
import re

####################
cookies = None

def fetch_cna():
def quote_cna(val):
if '%' in val:
return val
return urllib.quote(val)

if cookies:
for cookie in cookies:
if cookie.name == 'cna' and cookie.domain == '.youku.com':
print('Found cna in imported cookies. Use it')
return quote_cna(cookie.value)
url = 'http://log.mmstat.com/eg.js'
url = 'https://gm.mmstat.com/yt/ykcomment.play.commentInit?cna='
req = request.urlopen(url)
header = req.info().dict
try:
n_v = header['set-cookie']
value = re.compile('cna=(.+?);').findall(n_v)[0]
except:
value = 'DOG4EdW4qzsCAbZyXbU+t7Jt'

return quote_cna(value)
cookies = req.info()['Set-Cookie']
cna = match1(cookies, "cna=([^;]+)")
return cna if cna else "oqikEO1b7CECAbfBdNNf1PM1"

class Youku():
name = "优酷 (Youku)"
ckey_default = quote("DIl58SLFxFNndSV1GFNnMQVYkx1PP5tKe1siZu/86PR1u/Wh1Ptd+WOZsHHWxysSfAOhNJpdVWsdVJNsfJ8Sxd8WKVvNfAS8aS8fAOzYARzPyPc3JvtnPHjTdKfESTdnuTW6ZPvk2pNDh4uFzotgdMEFkzQ5wZVXl2Pf1/Y6hLK0OnCNxBj3+nb0v72gZ6b0td+WOZsHHWxysSo/0y9D2K42SaB8Y/+aD2K42SaB8Y/+ahU+WOZsHcrxysooUeND")
ckey_mobile = quote("7B19C0AB12633B22E7FE81271162026020570708D6CC189E4924503C49D243A0DE6CD84A766832C2C99898FC5ED31F3709BB3CDD82C96492E721BDD381735026")

# Last updated: 2015-11-24
stream_types = [
Expand All @@ -51,10 +37,12 @@ class Youku():
]

def __init__(self, *args):
self.ccode = '0519'
# Found in http://g.alicdn.com/player/ykplayer/0.5.28/youku-player.min.js
# grep -oE '"[0-9a-zA-Z+/=]{256}"' youku-player.min.js
self.ckey = 'DIl58SLFxFNndSV1GFNnMQVYkx1PP5tKe1siZu/86PR1u/Wh1Ptd+WOZsHHWxysSfAOhNJpdVWsdVJNsfJ8Sxd8WKVvNfAS8aS8fAOzYARzPyPc3JvtnPHjTdKfESTdnuTW6ZPvk2pNDh4uFzotgdMEFkzQ5wZVXl2Pf1/Y6hLK0OnCNxBj3+nb0v72gZ6b0td+WOZsHHWxysSo/0y9D2K42SaB8Y/+aD2K42SaB8Y/+ahU+WOZsHcrxysooUeND'
self.params = {
('0808', self.ckey_mobile),
('0590', self.ckey_default)
}

self.title = ''

Expand Down Expand Up @@ -89,18 +77,22 @@ def video_from_vid(self, vid, **kwargs):
self.download_playlist_by_url(self.url, **kwargs)
exit(0)

api_url = 'https://ups.youku.com/ups/get.json?'
api_url += 'vid=' + self.vid
api_url += '&ccode=' + self.ccode
api_url += '&client_ip=192.168.1.1'
api_url += '&utid=' + fetch_cna()
api_url += '&client_ts=' + str(int(time.time()))
api_url += '&ckey=' + urllib.quote(self.ckey)

data = loads(get_html(
api_url,
headers={'Referer': 'http://v.youku.com'}
))
for ccode, ckey in self.params:
api_url = 'https://ups.youku.com/ups/get.json?'
api_url += 'vid=' + self.vid
api_url += '&ccode=' + ccode
api_url += '&client_ip=192.168.1.1'
api_url += '&utid=' + quote(fetch_cna())
api_url += '&client_ts=' + str(int(time.time()))
api_url += '&ckey=' + ckey

data = loads(get_html(
api_url,
headers={'Referer': 'https://v.youku.com'}
))

if data['e']['code'] == 0 and 'stream' in data['data']:
break

data = data['data']
self.title = data['video'].get('title')
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion plugin.video.funshion/addon.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.funshion"
name="风行视频(Funshion)"
version="2.0.0"
version="2.0.1"
provider-name="yfang1644">
<requires>
<import addon="script.module.xbmcswift2" version="2.4.0"/>
Expand Down
Loading

0 comments on commit 6e65a4d

Please sign in to comment.