Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# -*- coding: utf-8 -*-
from ykdl.util.html import get_location, get_content
from ykdl.util.match import match1, matchall
from ykdl.compact import urlencode
import json
from .bilibase import BiliBase, sign_api_url
APPKEY = '84956560bc028eb7'
SECRETKEY = '94aba54af9065f71de72f5508f1cd42e'
api_url = 'https://bangumi.bilibili.com/player/web_api/v2/playurl'
class BiliBan(BiliBase):
name = u'哔哩哔哩 番剧 (Bilibili Bangumi)'
def list_only(self):
return '/play/ss' in self.url
def get_page_info(self):
html = get_content(self.url)
date = json.loads(match1(html, '__INITIAL_STATE__=({.+?});'))
title = date.get('h1Title') or match1(html, '<title>(.+?)_番剧_bilibili_哔哩哔哩<')
vid = date['epInfo']['cid']
mediaInfo = date['mediaInfo']
self.seasonType = mediaInfo.get('season_type') or mediaInfo.get('ssType')
upInfo = mediaInfo.get('upInfo')
artist = upInfo and upInfo.get('name')
return vid, title, artist</title>
# Init environment and import module
if platform.system() == 'Darwin':
_srcdir = '%s/Library/Application Support/MoonPlayer/ykdl/' % os.getenv('HOME')
elif platform.system() == 'Linux' or platform.system() == 'FreeBSD':
_srcdir = '%s/moonplayer/ykdl/' % os.getenv('XDG_DATA_HOME', os.getenv('HOME') + '/.local/share')
else:
_srcdir = expanduser(r'~\AppData\Local\MoonPlayer\ykdl')
_filepath = os.path.dirname(sys.argv[0])
sys.path.insert(0, _srcdir)
# Patch bilibase
danmaku_url = ''
from ykdl.extractors.bilibili.bilibase import BiliBase
old_bilibase_prepare = BiliBase.prepare
def bilibase_prepare(self):
retVal = old_bilibase_prepare(self)
global danmaku_url
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'] == '':
# -*- coding: utf-8 -*-
from ykdl.util.html import get_content
from ykdl.util.match import match1, matchall
from ykdl.compact import urlencode
from .bilibase import BiliBase, sign_api_url
import json
APPKEY = 'iVGUTjsxvpLeuDCf'
SECRETKEY = 'aHRmhWMLkdeMuILqORnYZocwMBpMEOdt'
api_url = 'https://interface.bilibili.com/v2/playurl'
class BiliVideo(BiliBase):
name = u'哔哩哔哩 (Bilibili)'
def get_page_info(self):
page_index = match1(self.url, '\?p=(\d+)', 'index_(\d+)\.') or '1'
html = get_content(self.url)
date = json.loads(match1(html, '__INITIAL_STATE__=({.+?});'))['videoData']
title = date['title']
artist = date['owner']['name']
pages = date['pages']
for page in pages:
index = str(page['page'])
subtitle = page['part']
if index == page_index:
vid = page['cid']
if len(pages) > 1:
title = u'{} - {} - {}'.format(title, index, subtitle)
else:
_srcdir = expanduser(r'~\AppData\Local\MoonPlayer\ykdl')
_filepath = os.path.dirname(sys.argv[0])
sys.path.insert(0, _srcdir)
# Patch bilibase
danmaku_url = ''
from ykdl.extractors.bilibili.bilibase import BiliBase
old_bilibase_prepare = BiliBase.prepare
def bilibase_prepare(self):
retVal = old_bilibase_prepare(self)
global danmaku_url
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