How to use the ykdl.videoinfo.VideoInfo function in ykdl

To help you get started, we’ve selected a few ykdl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ForgQi / bilibiliupload / ykdl / extractors / youku.py View on Github external
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):
github ForgQi / bilibiliupload / ykdl / extractors / bobo.py View on Github external
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>([^&lt;]+)').split('-')[0]
        return info
</title>
github coslyk / moonplayer / src / plugins / ykdl_patched.py View on Github external
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
github ForgQi / bilibiliupload / ykdl / extractors / iqiyi / live.py View on Github external
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]
github ForgQi / bilibiliupload / ykdl / extractors / bilibili / bilibase.py View on Github external
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) &gt; 80:
                return

            api_url = self.get_api_url(qn)
            html = get_content(api_url)
            self.logger.debug('HTML&gt; ' + html)
            code = match1(html, '<code>([^&lt;])')</code>
github ForgQi / bilibiliupload / ykdl / extractors / douyu / video.py View on Github external
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&gt;(.+?)_斗鱼视频 - 最6的弹幕视频网站&lt;')
        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)
github ForgQi / bilibiliupload / ykdl / extractors / mgtv.py View on Github external
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']
github ForgQi / bilibiliupload / ykdl / extractors / qq / video.py View on Github external
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+)"')
github ForgQi / bilibiliupload / ykdl / extractors / sohu / sohubase.py View on Github external
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,
github ForgQi / bilibiliupload / ykdl / extractors / douyu / live.py View on Github external
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"&gt;([^&lt;]+)&lt;')
        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']