Skip to content

Commit

Permalink
[qq] resolve conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
soimort committed Jun 12, 2018
2 parents b7603a4 + a10c98c commit 85782bc
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 20 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ Use `--url`/`-u` to get a list of downloadable resource URLs extracted from the
| 西瓜视频 | <https://www.ixigua.com/> || | |
| 快手 | <https://www.kuaishou.com/> ||| |
| 抖音 | <https://www.douyin.com/> || | |
| 中国体育(TV) | <http://v.zhibo.tv/> </br><http://video.zhibo.tv/> || | |

For all other sites not on the list, the universal extractor will take care of finding and downloading interesting resources from the page.

Expand Down
7 changes: 4 additions & 3 deletions src/you_get/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
SITES = {
'163' : 'netease',
'56' : 'w56',
'365yg' : 'toutiao',
'acfun' : 'acfun',
'archive' : 'archive',
'baidu' : 'baidu',
Expand Down Expand Up @@ -64,6 +65,7 @@
'iqiyi' : 'iqiyi',
'ixigua' : 'ixigua',
'isuntv' : 'suntv',
'iwara' : 'iwara',
'joy' : 'joy',
'kankanews' : 'bilibili',
'khanacademy' : 'khan',
Expand All @@ -82,6 +84,7 @@
'mixcloud' : 'mixcloud',
'mtv81' : 'mtv81',
'musicplayon' : 'musicplayon',
'miaopai' : 'yixia',
'naver' : 'naver',
'7gogo' : 'nanagogo',
'nicovideo' : 'nicovideo',
Expand Down Expand Up @@ -118,14 +121,12 @@
'xiaojiadianvideo' : 'fc2video',
'ximalaya' : 'ximalaya',
'yinyuetai' : 'yinyuetai',
'miaopai' : 'yixia',
'yizhibo' : 'yizhibo',
'youku' : 'youku',
'iwara' : 'iwara',
'youtu' : 'youtube',
'youtube' : 'youtube',
'zhanqi' : 'zhanqi',
'365yg' : 'toutiao',
'zhibo' : 'zhibo',
}

dry_run = False
Expand Down
1 change: 1 addition & 0 deletions src/you_get/extractors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,4 @@
from .khan import *
from .zhanqi import *
from .kuaishou import *
from .zhibo import *
2 changes: 1 addition & 1 deletion src/you_get/extractors/acfun.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def acfun_download_by_vid(vid, title, output_dir='.', merge=True, info_only=Fals
elif sourceType == 'tudou':
tudou_download_by_iid(sourceId, title, output_dir=output_dir, merge=merge, info_only=info_only)
elif sourceType == 'qq':
qq_download_by_vid(sourceId, title, output_dir=output_dir, merge=merge, info_only=info_only)
qq_download_by_vid(sourceId, title, True, output_dir=output_dir, merge=merge, info_only=info_only)
elif sourceType == 'letv':
letvcloud_download_by_vu(sourceId, '2d8c027396', title, output_dir=output_dir, merge=merge, info_only=info_only)
elif sourceType == 'zhuzhan':
Expand Down
2 changes: 1 addition & 1 deletion src/you_get/extractors/bilibili.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def entry(self, **kwargs):
tc_flashvars = tc_flashvars.group(1)
if tc_flashvars is not None:
self.out = True
qq_download_by_vid(tc_flashvars, self.title, output_dir=kwargs['output_dir'], merge=kwargs['merge'], info_only=kwargs['info_only'])
qq_download_by_vid(tc_flashvars, self.title, True, output_dir=kwargs['output_dir'], merge=kwargs['merge'], info_only=kwargs['info_only'])
return

has_plist = re.search(r'"page":2', self.page)
Expand Down
37 changes: 22 additions & 15 deletions src/you_get/extractors/qq.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@
from .qie_video import download_by_url as qie_video_download
from urllib.parse import urlparse,parse_qs

def qq_download_by_vid(vid, title, output_dir='.', merge=True, info_only=False):
def qq_download_by_vid(vid, title, default_from, output_dir='.', merge=True, info_only=False):

if default_from:
platform = 11
else:
# fix return {,"msg":"cannot play outside"}
platform = 4100201

info_api = 'http://vv.video.qq.com/getinfo?otype=json&appver=3.2.19.333&platform=11&defnpayver=1&defn=shd&vid={}'.format(vid)
info = get_content(info_api)
video_json = json.loads(match1(info, r'QZOutputJson=(.*)')[:-1])
Expand All @@ -17,29 +24,22 @@ def qq_download_by_vid(vid, title, output_dir='.', merge=True, info_only=False):
title = video_json['vl']['vi'][0]['ti']
host = video_json['vl']['vi'][0]['ul']['ui'][0]['url']
streams = video_json['fl']['fi']
seg_cnt = video_json['vl']['vi'][0]['cl']['fc']
seg_cnt = fc_cnt = video_json['vl']['vi'][0]['cl']['fc']

filename = video_json['vl']['vi'][0]['fn']
if seg_cnt == 0:
seg_cnt = 1
else:
fn_pre, magic_str, video_type = filename.split('.')

best_quality = streams[-1]['name']
#part_format_id = streams[-1]['id']

part_urls= []
total_size = 0
for part in range(1, seg_cnt+1):
#if seg_cnt == 1 and video_json['vl']['vi'][0]['vh'] <= 480:
# filename = fn_pre + '.mp4'
#else:
# filename = fn_pre + '.p' + str(part_format_id % 10000) + '.' + str(part) + '.mp4'
#filename = fn_pre + '.p' + str(part_format_id % 10000) + '.' + str(part) + '.mp4'

# fix some error cases("check vid&filename failed" and "format invalid")
# https://v.qq.com/x/page/q06058th9ll.html
# https://v.qq.com/x/page/t060789a21e.html
if seg_cnt == 1:
if fc_cnt == 0:
# fix json parsing error
# example:https://v.qq.com/x/page/w0674l9yrrh.html
part_format_id = video_json['vl']['vi'][0]['cl']['keyid'].split('.')[-1]
else:
part_format_id = video_json['vl']['vi'][0]['cl']['ci'][part - 1]['keyid'].split('.')[1]
Expand Down Expand Up @@ -112,6 +112,8 @@ def kg_qq_download_by_shareid(shareid, output_dir='.', info_only=False, caption=

def qq_download(url, output_dir='.', merge=True, info_only=False, **kwargs):
""""""
default_from = True

if re.match(r'https?://egame.qq.com/live\?anchorid=(\d+)', url):
from . import qq_egame
qq_egame.qq_egame_download(url, output_dir=output_dir, merge=merge, info_only=info_only, **kwargs)
Expand All @@ -134,7 +136,7 @@ def qq_download(url, output_dir='.', merge=True, info_only=False, **kwargs):
content = get_content(url)
vids = matchall(content, [r'\?vid=(\w+)'])
for vid in vids:
qq_download_by_vid(vid, vid, output_dir, merge, info_only)
qq_download_by_vid(vid, vid, default_from, output_dir, merge, info_only)
return

if 'kuaibao.qq.com' in url or re.match(r'http://daxue.qq.com/content/content/id/\d+', url):
Expand Down Expand Up @@ -165,7 +167,12 @@ def qq_download(url, output_dir='.', merge=True, info_only=False, **kwargs):
title = match1(content, r'"title":"([^"]+)"') if not title else title
title = vid if not title else title #general fallback

qq_download_by_vid(vid, title, output_dir, merge, info_only)
if 'v.sports.qq.com' in url:
# fix url forbidden
# example:http://v.sports.qq.com/#/cover/t0fqsm1y83r8v5j/a0026nvw5jr
default_from = False

qq_download_by_vid(vid, title, default_from, output_dir, merge, info_only)

site_info = "QQ.com"
download = qq_download
Expand Down
52 changes: 52 additions & 0 deletions src/you_get/extractors/zhibo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python

__all__ = ['zhibo_download']

from ..common import *

def zhibo_vedio_download(url, output_dir = '.', merge = True, info_only = False, **kwargs):
# http://video.zhibo.tv/video/details/d103057f-663e-11e8-9d83-525400ccac43.html

html = get_html(url)
title = r1(r'<title>([\s\S]*)</title>', html)
total_size = 0
part_urls= []

video_html = r1(r'<script type="text/javascript">([\s\S]*)</script></head>', html)

# video_guessulike = r1(r"window.xgData =([s\S'\s\.]*)\'\;[\s\S]*window.vouchData", video_html)
video_url = r1(r"window.vurl = \'([s\S'\s\.]*)\'\;[\s\S]*window.imgurl", video_html)
part_urls.append(video_url)
ext = video_url.split('.')[-1]

print_info(site_info, title, ext, total_size)
if not info_only:
download_urls(part_urls, title, ext, total_size, output_dir=output_dir, merge=merge)


def zhibo_download(url, output_dir = '.', merge = True, info_only = False, **kwargs):
if 'video.zhibo.tv' in url:
zhibo_vedio_download(url, output_dir=output_dir, merge=merge, info_only=info_only, **kwargs)
return

# if 'v.zhibo.tv' in url:
# http://v.zhibo.tv/31609372
html = get_html(url)
title = r1(r'<title>([\s\S]*)</title>', html)
is_live = r1(r"window.videoIsLive=\'([s\S'\s\.]*)\'\;[\s\S]*window.resDomain", html)
if is_live is not "1":
raise ValueError("The live stream is not online! (Errno:%s)" % is_live)

ourStreamName = r1(r"window.ourStreamName=\'([s\S'\s\.]*)\'\;[\s\S]*window.rtmpDefaultSource", html)
rtmpPollUrl = r1(r"window.rtmpPollUrl=\'([s\S'\s\.]*)\'\;[\s\S]*window.hlsDefaultSource", html)

#real_url = 'rtmp://220.194.213.56/live.zhibo.tv/8live/' + ourStreamName
real_url = rtmpPollUrl + ourStreamName

print_info(site_info, title, 'flv', float('inf'))
if not info_only:
download_url_ffmpeg(real_url, title, 'flv', params={}, output_dir=output_dir, merge=merge)

site_info = "zhibo.tv"
download = zhibo_download
download_playlist = playlist_not_supported('zhibo')

0 comments on commit 85782bc

Please sign in to comment.