Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def prepare(self):
add_header("Cookie", '__ysuid=%d' % time.time())
info = VideoInfo(self.name)
if not self.vid:
self.vid = match1(self.url.split('//', 1)[1],
'^v[^\.]?\.[^/]+/v_show/id_([a-zA-Z0-9=]+)',
'^player[^/]+/(?:player\.php/sid|embed)/([a-zA-Z0-9=]+)',
'^static.+loader\.swf\?VideoIDS=([a-zA-Z0-9=]+)',
'^(?:new-play|video)\.tudou\.com/v/([a-zA-Z0-9=]+)')
if not self.vid:
html = get_content(self.url)
self.vid = match1(html, r'videoIds?[\"\']?\s*[:=]\s*[\"\']?([a-zA-Z0-9=]+)')
if self.vid.isdigit():
import base64
vid = base64.b64encode(b'%d' % (int(self.vid) * 4))
if not isinstance(vid, str):
def prepare(self):
add_default_handler(HTTPCookieProcessor)
install_default_handlers()
info = VideoInfo(self.name, True)
html = get_content(self.url)
self.vid = match1(html, '"userNum":(\d+)')
live_id = match1(html, '"liveId":\s*(\d+)')
assert live_id, u"主播正在休息"
info.stream_types.append('current')
info.streams['current'] = {'container': 'mp4', 'src': ['http://extapi.live.netease.com/redirect/video/{}'.format(self.vid)], 'size' : float('inf')}
info.artist = match1(html, '"nick":"([^"]+)')
info.title = match1(html, '<title>([^<]+)').split('-')[0]
return info
</title>
danmaku_url = 'http://comment.bilibili.com/{}.xml'.format(self.vid)
return retVal
BiliBase.prepare = bilibase_prepare
# Patch jsonlize
from ykdl.videoinfo import VideoInfo
from ykdl.util.html import fake_headers
old_jsonlize = VideoInfo.jsonlize
def jsonlize(self):
retVal = old_jsonlize(self)
retVal['danmaku_url'] = danmaku_url
if retVal['extra']['ua'] == '':
retVal['extra']['ua'] = fake_headers['User-Agent']
return retVal
VideoInfo.jsonlize = jsonlize
# Run ykdl
from ykdl.common import url_to_module
from ykdl.compact import ProxyHandler, build_opener, install_opener
from ykdl.util.html import fake_headers, get_content
from ykdl.util.match import match1
from argparse import ArgumentParser
import socket
try:
from http.cookiejar import MozillaCookieJar
from urllib.request import HTTPCookieProcessor
except:
from cookielib import MozillaCookieJar
from urllib2 import HTTPCookieProcessor
def prepare(self):
info = VideoInfo(self.name, True)
html = get_content(self.url)
self.vid = match1(html, '"qipuId":(\d+),')
title = match1(html, '"roomTitle":"([^"]+)",')
artist = match1(html, '"anchorNickname":"([^"]+)",')
info.title = u'{} - {}'.format(title, artist)
info.artist = artist
data = getlive(self.vid)
self.logger.debug('data:\n' + str(data))
assert data['code'] == 'A00000', data.get('msg', 'can\'t play this live video!!')
data = data['data']
for stream in data['streams']:
stream_type = stream['steamType'] # typo 'streamType' to 'steamType'
stream_id = self.type_2_id[stream_type]
def prepare(self):
info = VideoInfo(self.name)
info.extra['referer'] = 'https://www.bilibili.com/'
info.extra['ua'] = fake_headers['User-Agent']
self.vid, info.title, info.artist = self.get_page_info()
assert self.vid, "can't play this video: {}".format(self.url)
def get_video_info(qn=0):
# need login with "qn=112"
if int(qn) > 80:
return
api_url = self.get_api_url(qn)
html = get_content(api_url)
self.logger.debug('HTML> ' + html)
code = match1(html, '<code>([^<])')</code>
def prepare(self):
info = VideoInfo(self.name)
pid = match1(self.url, 'show/(.*)')
if 'vmobile' in self.url:
self.url = 'https://v.douyu.com/show/' + pid
html = get_content(self.url)
info.title = match1(html, u'title>(.+?)_斗鱼视频 - 最6的弹幕视频网站<')
self.vid = match1(html, '"point_id":\s?(\d+)')
js_enc = get_h5enc(html, self.vid)
params = {'vid': pid}
ub98484234(js_enc, self, params)
add_header("Referer", self.url)
add_header('Cookie', 'dy_did={}'.format(params['did']))
data = urlencode(params)
def prepare(self):
add_default_handler(HTTPCookieProcessor)
install_default_handlers()
add_header('Referer', self.url)
add_header('User-Agent', ua)
info = VideoInfo(self.name)
if self.url and not self.vid:
self.vid = match1(self.url, 'https?://www.mgtv.com/b/\d+/(\d+).html')
if self.vid is None:
html = get_content(self.url)
self.vid = match1(html, 'vid=(\d+)', 'vid=\"(\d+)', 'vid: (\d+)')
did = str(uuid.uuid4())
tk2 = generate_tk2(did)
api_info_url = 'https://pcweb.api.mgtv.com/player/video?tk2={}&video_id={}&type=pch5'.format(tk2, self.vid)
meta = json.loads(get_content(api_info_url))
assert meta['code'] == 200, '[failed] code: {}, msg: {}'.format(meta['code'], meta['msg'])
assert meta['data'], '[Failed] Video info not found.'
pm2 = meta['data']['atc']['pm2']
def prepare(self):
info = VideoInfo(self.name)
if not self.vid:
self.vid = match1(self.url,
'vid=(\w+)',
'/(\w+)\.html',
'/(\w+)$')
if self.vid and match1(self.url, '(^https?://film\.qq\.com)'):
self.url = 'https://v.qq.com/x/cover/%s.html' % self.vid
if not self.vid or len(self.vid) != 11:
html = get_content(self.url)
self.vid = match1(html,
'&vid=(\w+)',
'vid:\s*[\"\'](\w+)',
'vid\s*=\s*[\"\']\s*(\w+)',
'"vid":"(\w+)"')
if self.url and not self.vid:
self.vid = match1(self.url, '\Wvid=(\d+)', '\Wid=(\d+)', '\Wbid=(\d+)', 'share_play.html#(\d+)_')
if not self.vid:
html = get_content(self.url)
self.vid = match1(html, '/(\d+)/v\.swf', 'vid="(\d+)"', '\&id=(\d+)')
self.logger.debug("VID> {}".format(self.vid))
info = json.loads(get_content(self.apiurl % self.vid))
self.logger.debug("info> {}".format(info))
if info['status'] == 6:
self.name = u'搜狐自媒体 (MySohu)'
self.apiurl = 'http://my.tv.sohu.com/play/videonew.do?vid=%s&referer=http://my.tv.sohu.com'
info = json.loads(get_content(self.apiurl % self.vid))
self.logger.debug("info> {}".format(info))
video = VideoInfo(self.name)
# this is needless now, uid well be registered in the the following code
#video.extra["header"] = "Range: "
if info['status'] == 1:
now = time.time()
uid = int(now * 1000)
params = {
'vid': self.vid,
'url': self.url,
'refer': self.url,
't': int(now),
'uid': uid,
#'nid': nid,
#'pid': pid,
#'screen': '1366x768',
#'channeled': channeled,
#'MTV_SRC': MTV_SRC,
def prepare(self):
info = VideoInfo(self.name, True)
add_header("Referer", 'https://www.douyu.com')
html = get_content(self.url)
self.vid = match1(html, '\$ROOM\.room_id\s*=\s*(\d+)',
'room_id\s*=\s*(\d+)',
'"room_id.?":(\d+)',
'data-onlineid=(\d+)')
title = match1(html, 'Title-headlineH2">([^<]+)<')
artist = match1(html, 'Title-anchorName" title="([^"]+)"')
if not title or not artist:
html = get_content('https://open.douyucdn.cn/api/RoomApi/room/' + self.vid)
room_data = json.loads(html)
if room_data['error'] == 0:
room_data = room_data['data']
title = room_data['room_name']