mirror of
https://github.com/soimort/you-get.git
synced 2025-02-03 00:33:58 +03:00
Sina: key algorithm #298
This commit is contained in:
parent
0ae948d757
commit
39adc8f563
@ -4,9 +4,19 @@ __all__ = ['sina_download', 'sina_download_by_vid', 'sina_download_by_vkey']
|
||||
|
||||
from ..common import *
|
||||
|
||||
def video_info(id):
|
||||
xml = get_content('http://interface.bilibili.tv/playurl?vid=%s' % id, headers=fake_headers, decoded=True)
|
||||
#xml = get_content('http://www.tucao.cc/api/sina.php?vid=%s' % id, headers=fake_headers, decoded=True)
|
||||
from hashlib import md5
|
||||
from random import randint
|
||||
from time import time
|
||||
|
||||
def get_k(vid, rand):
|
||||
t = str(int('{0:b}'.format(int(time()))[:-6], 2))
|
||||
return md5((vid + 'Z6prk18aWxP278cVAH' + t + rand).encode('utf-8')).hexdigest()[:16] + t
|
||||
|
||||
def video_info(vid):
|
||||
rand = "0.{0}{1}".format(randint(10000, 10000000), randint(10000, 10000000))
|
||||
url = 'http://v.iask.com/v_play.php?vid={0}&ran={1}&p=i&k={2}'.format(vid, rand, get_k(vid, rand))
|
||||
xml = get_content(url, headers=fake_headers, decoded=True)
|
||||
|
||||
urls = re.findall(r'<url>(?:<!\[CDATA\[)?(.*?)(?:\]\]>)?</url>', xml)
|
||||
name = match1(xml, r'<vname>(?:<!\[CDATA\[)?(.+?)(?:\]\]>)?</vname>')
|
||||
vstr = match1(xml, r'<vstr>(?:<!\[CDATA\[)?(.+?)(?:\]\]>)?</vstr>')
|
||||
@ -16,7 +26,7 @@ def sina_download_by_vid(vid, title=None, output_dir='.', merge=True, info_only=
|
||||
"""Downloads a Sina video by its unique vid.
|
||||
http://video.sina.com.cn/
|
||||
"""
|
||||
|
||||
|
||||
urls, name, vstr = video_info(vid)
|
||||
title = title or name
|
||||
assert title
|
||||
@ -24,7 +34,7 @@ def sina_download_by_vid(vid, title=None, output_dir='.', merge=True, info_only=
|
||||
for url in urls:
|
||||
_, _, temp = url_info(url)
|
||||
size += temp
|
||||
|
||||
|
||||
print_info(site_info, title, 'flv', size)
|
||||
if not info_only:
|
||||
download_urls(urls, title, 'flv', size, output_dir = output_dir, merge = merge)
|
||||
@ -33,10 +43,10 @@ def sina_download_by_vkey(vkey, title=None, output_dir='.', merge=True, info_onl
|
||||
"""Downloads a Sina video by its unique vkey.
|
||||
http://video.sina.com/
|
||||
"""
|
||||
|
||||
|
||||
url = 'http://video.sina.com/v/flvideo/%s_0.flv' % vkey
|
||||
type, ext, size = url_info(url)
|
||||
|
||||
|
||||
print_info(site_info, title, 'flv', size)
|
||||
if not info_only:
|
||||
download_urls([url], title, 'flv', size, output_dir = output_dir, merge = merge)
|
||||
@ -44,7 +54,7 @@ def sina_download_by_vkey(vkey, title=None, output_dir='.', merge=True, info_onl
|
||||
def sina_download(url, output_dir='.', merge=True, info_only=False):
|
||||
"""Downloads Sina videos by URL.
|
||||
"""
|
||||
|
||||
|
||||
vid = match1(url, r'vid=(\d+)')
|
||||
if vid is None:
|
||||
video_page = get_content(url)
|
||||
@ -52,7 +62,7 @@ def sina_download(url, output_dir='.', merge=True, info_only=False):
|
||||
if hd_vid == '0':
|
||||
vids = match1(video_page, r'[^\w]vid\s*:\s*\'([^\']+)\'').split('|')
|
||||
vid = vids[-1]
|
||||
|
||||
|
||||
if vid:
|
||||
title = match1(video_page, r'title\s*:\s*\'([^\']+)\'')
|
||||
sina_download_by_vid(vid, title=title, output_dir=output_dir, merge=merge, info_only=info_only)
|
||||
|
Loading…
Reference in New Issue
Block a user