This commit is contained in:
GuanFoxyier 2019-05-23 10:49:07 +08:00
parent fc10ea1d06
commit 5ef3d2dc55

View File

@ -2,19 +2,22 @@
__all__ = ['letv_download', 'letvcloud_download', 'letvcloud_download_by_vu']
import json
import base64
import hashlib
import random
import xml.etree.ElementTree as ET
import base64, hashlib, urllib, time, re
import urllib
from ..common import *
# @DEPRECATED
def get_timestamp():
tn = random.random()
url = 'http://api.letv.com/time?tn={}'.format(tn)
result = get_content(url)
return json.loads(result)['stime']
# @DEPRECATED
def get_key(t):
for s in range(0, 8):
@ -24,6 +27,7 @@ def get_key(t):
t += e
return t ^ 185025305
def calcTimeKey(t):
ror = lambda val, r_bits,: ((val & (2 ** 32 - 1)) >> r_bits % 32) | (val << (32 - (r_bits % 32)) & (2 ** 32 - 1))
magic = 185025305
@ -48,18 +52,15 @@ def decode(data):
return ''.join([chr(i) for i in loc7])
else:
# directly return
return data
return str(data)
def video_info(vid, **kwargs):
url = 'http://player-pc.le.com/mms/out/video/playJson?id={}&platid=1&splatid=101&format=1&tkey={}&domain=www.le.com&region=cn&source=1000&accesyx=1'.format(vid,calcTimeKey(int(time.time())))
url = 'http://player-pc.le.com/mms/out/video/playJson?id={}&platid=1&splatid=105&format=1&tkey={}&domain=www.le.com&region=cn&source=1000&accesyx=1'.format(vid, calcTimeKey(int(time.time())))
r = get_content(url, decoded=False)
info = json.loads(str(r, "utf-8"))
info = info['msgs']
stream_id = None
support_stream_id = info["playurl"]["dispatch"].keys()
if "stream_id" in kwargs and kwargs["stream_id"].lower() in support_stream_id:
@ -86,9 +87,10 @@ def video_info(vid,**kwargs):
suffix = '&r=' + str(int(time.time() * 1000)) + '&appid=500'
m3u8 = get_content(info2["location"] + suffix, decoded=False)
m3u8_list = decode(m3u8)
urls = re.findall(r'^[^#][^\r]*',m3u8_list,re.MULTILINE)
urls = re.findall(r'(http.*?)#', m3u8_list, re.MULTILINE)
return ext, urls
def letv_download_by_vid(vid, title, output_dir='.', merge=True, info_only=False, **kwargs):
ext, urls = video_info(vid, **kwargs)
size = 0
@ -100,6 +102,7 @@ def letv_download_by_vid(vid,title, output_dir='.', merge=True, info_only=False,
if not info_only:
download_urls(urls, title, ext, size, output_dir=output_dir, merge=merge)
def letvcloud_download_by_vu(vu, uu, title=None, output_dir='.', merge=True, info_only=False):
# ran = float('0.' + str(random.randint(0, 9999999999999999))) # For ver 2.1
# str2Hash = 'cfflashformatjsonran{ran}uu{uu}ver2.2vu{vu}bie^#@(%27eib58'.format(vu = vu, uu = uu, ran = ran) #Magic!/ In ver 2.1
@ -121,6 +124,7 @@ def letvcloud_download_by_vu(vu, uu, title=None, output_dir='.', merge=True, inf
if not info_only:
download_urls(urls, title, ext, size, output_dir=output_dir, merge=merge)
def letvcloud_download(url, output_dir='.', merge=True, info_only=False):
qs = parse.urlparse(url).query
vu = match1(qs, r'vu=([\w]+)')
@ -128,6 +132,7 @@ def letvcloud_download(url, output_dir='.', merge=True, info_only=False):
title = "LETV-%s" % vu
letvcloud_download_by_vu(vu, uu, title=title, output_dir=output_dir, merge=merge, info_only=info_only)
def letv_download(url, output_dir='.', merge=True, info_only=False, **kwargs):
url = url_locations([url])[0]
if re.match(r'http://yuntv.letv.com/', url):
@ -145,6 +150,7 @@ def letv_download(url, output_dir='.', merge=True, info_only=False ,**kwargs):
title = match1(html, r'name="irTitle" content="(.*?)"')
letv_download_by_vid(vid, title=title, output_dir=output_dir, merge=merge, info_only=info_only, **kwargs)
site_info = "Le.com"
download = letv_download
download_playlist = playlist_not_supported('letv')