Esempio n. 1
0
    def prepare(self):
        add_header("referer", "http://v.youku.com")
        ssl_context = HTTPSHandler(
            context=ssl.SSLContext(ssl.PROTOCOL_TLSv1))
        cookie_handler = HTTPCookieProcessor()
        opener = build_opener(ssl_context, cookie_handler)
        opener.addheaders = [('Cookie','__ysuid=%d' % time.time())]
        install_opener(opener)
        
        info = VideoInfo(self.name)        

        if self.url and 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=]+)',
                               '^video\.tudou\.com/v/([a-zA-Z0-9=]+)')

        self.logger.debug("VID: " + self.vid)
        api_url = 'https://ups.youku.com/ups/get.json?vid={}&ccode={}&client_ip=192.168.1.1&utid={}&client_ts={}'.format(self.vid, self.ccode, quote(fetch_cna()), int(time.time()))

        data = json.loads(get_content(api_url))
        assert data['e']['code'] == 0, data['e']['desc']
        data = data['data']
        assert 'stream' in data, data['error']['note']
        info.title = data['video']['title']
        streams = data['stream']
        for s in streams:
            self.logger.debug("stream> " + str(s))
            t = stream_code_to_id[s['stream_type']]
            urls = []
            for u in s['segs']:
                self.logger.debug("seg> " + str(u))
                if u['key'] != -1:
                    if 'cdn_url' in u:
                        urls.append(u['cdn_url'])
                else:
                    self.logger.warning("VIP video, ignore unavailable seg: {}".format(s['segs'].index(u)))
            if len(urls) == 0:
                urls = [s['m3u8_url']]
                c = 'm3u8'
            else:
                c = id_to_container[t]
            size = s['size']
            info.stream_types.append(t)
            info.streams[t] =  {
                    'container': c,
                    'video_profile': stream_code_to_profiles[t],
                    'size': size,
                    'src' : urls
                }
        info.stream_types = sorted(info.stream_types, key = ids.index)
        tmp = []
        for t in info.stream_types:
            if not t in tmp:
                tmp.append(t)
        info.stream_types = tmp
        return info
Esempio n. 2
0
    def prepare(self):
        info = VideoInfo(self.name)
        html = get_content(self.url)
        video_type = match1(html, 'VideoType":"([^"]+)"')
        if video_type == 'LIVE':
            info.live = True
        elif not video_type == 'VOD':
            raise NotImplementedError('Unknown_video_type')

        info.title = match1(html, '<title>([^<]+)').split("_")[0]
        if info.live:
            rtmp_id = match1(html, 'videoId":"([^"]+)"').replace('\\/', '/')
            real_url = self.live_base + '/' + rtmp_id + '.m3u8'
            info.stream_types, info.streams = load_m3u8_playlist(real_url)
        else:
            vod_m3u8 = self.vod_base + '/' + match1(
                html, 'VideoID":"([^"]+)').replace('\\/', '/')
            info.stream_types.append('current')
            info.streams['current'] = {
                'container': 'm3u8',
                'video_profile': 'current',
                'src': [vod_m3u8],
                'size': 0
            }
        return info
Esempio n. 3
0
File: live.py Progetto: wwqgtxx/ykdl
    def prepare(self):
        self.vid = match1(self.url, 'd=(\d+)', 'live/(\d+)')
        if '/izt/' in self.url:
            vid = self.vid
            if not vid:
                html = get_content(self.url)
                vid = match1(html, 'vid\s*:\s*"(\d+)",', 'vid="(\d+)"')
            return get_playback(vid)
        else:
            if not self.vid:
                html = get_content(self.url)
                self.vid = match1(html, 'liveId\s*:\s*"(\d+)"')

        live_data = json.loads(get_content('http://api.live.letv.com/v1/liveRoom/single/1001?id={}'.format(self.vid)))
        if live_data.get('status') != 2:
            return get_playback(live_data['recordingId'])

        # live video is dead, the followed code will not be used
        live_data = json.loads(get_content('http://player.pc.le.com/player/startup_by_pid/1001/{}?host=live.le.com'.format(self.vid)))

        info = VideoInfo(self.name, True)
        info.title = live_data['title']
        stream_data = live_data['rows']

        for s in stream_data:
            stream_id = self.stream_2_id[s['rateType']]
            stream_profile = self.stream_2_profile[s['rateType']]
            if not stream_id in info.stream_types:
                info.stream_types.append(stream_id)
                streamUrl = s['streamUrl'] + '&format=1&expect=2&termid=1&platid=10&playid=1&sign=live_web&splatid=1001&vkit=20161017&station={}'.format( self.vid)
                data = json.loads(get_content(streamUrl))
                src = data['location']
                info.streams[stream_id] = {'container': 'm3u8', 'video_profile': stream_profile, 'size' : float('inf'), 'src' : [src]}
        info.stream_types = sorted(info.stream_types, key = self.stream_ids.index)
        return info
Esempio n. 4
0
    def prepare(self):
        info = VideoInfo(self.name, True)
        html = get_content(self.url)
        info.title = match1(html, '<title>([^<]+)').split('_')[0]

        data = json.loads(match1(html, 'channelOneInfo = ({.+?});'))
        tag_from = 'huomaoh5room'
        tn = str(int(time.time()))
        sign_context = data['stream'] + tag_from + tn + SECRETKEY
        token = hashlib.md5(compact_bytes(sign_context, 'utf-8')).hexdigest()

        params = { 'streamtype':'live',
                   'VideoIDS': data['stream'],
                   'time': tn,
                   'cdns' : '1',
                   'from': tag_from,
                   'token': token
                }
        content = get_content(self.live_base, data=compact_bytes(urlencode(params), 'utf-8'), charset='utf-8')
        stream_data = json.loads(content)

        assert stream_data["roomStatus"] == "1", "The live stream is not online! "
        for stream in stream_data["streamList"]:
            if stream['default'] == 1:
                defstream = stream['list']

        for stream in defstream:
            info.stream_types.append(stream['type'])
            info.streams[stream['type']] = {'container': 'flv', 'video_profile': self.stream_2_profile[stream['type']], 'src' : [stream['url']], 'size': float('inf')}

        info.stream_types = sorted(info.stream_types, key = self.supported_stream_types.index)
        return info
Esempio n. 5
0
File: mgtv.py Progetto: flfq/ykdl
    def prepare(self):
        info = VideoInfo(self.name)
        if self.url and not self.vid:
            self.vid = match1(self.url, 'http://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+)')

        api_url = 'http://pcweb.api.mgtv.com/player/video?video_id={}'.format(self.vid)
        meta = json.loads(get_content(api_url))

        assert meta['code'] == 200, '[failed] status: {}, msg: {}'.format(meta['status'],meta['msg'])
        assert meta['data'], '[Failed] Video not found.'

        data = meta['data']

        info.title = data['info']['title']
        domain = data['stream_domain'][0]
        for lstream in data['stream']:
            if lstream['url']:
                url = json.loads(get_content(domain + lstream['url']))['info']
                info.streams[self.profile_2_types[lstream['name']]] = {'container': 'm3u8', 'video_profile': lstream['name'], 'src' : [url]}
                info.stream_types.append(self.profile_2_types[lstream['name']])
        info.stream_types= sorted(info.stream_types, key = self.supported_stream_types.index)
        return info
Esempio n. 6
0
    def prepare(self):
        info = VideoInfo(self.name)
        if not self.vid:
            self.vid = match1(self.url, '#([a-zA-Z0-9\-]+)',
                              '/([a-zA-Z0-9\-]+).shtml')

        xml = get_content(
            'http://v.ifeng.com/video_info_new/{}/{}/{}.xml'.format(
                self.vid[-2], self.vid[-2:], self.vid))
        doc = parseString(xml.encode('utf-8'))
        info.title = doc.getElementsByTagName('item')[0].getAttribute("Name")
        videos = doc.getElementsByTagName('videos')
        for v in videos[0].getElementsByTagName('video'):
            if v.getAttribute("mediaType") == 'mp4':
                _t = v.getAttribute("type")
                _u = v.getAttribute("VideoPlayUrl")
                stream_id = self.types_2_id[_t]
                stream_profile = self.types_2_profile[_t]
                info.stream_types.append(stream_id)
                info.streams[stream_id] = {
                    'container': 'mp4',
                    'video_profile': stream_profile,
                    'src': [_u],
                    'size': 0
                }

        info.stream_types = sorted(info.stream_types, key=self.ids.index)
        return info
Esempio n. 7
0
    def prepare(self):
        info = VideoInfo(self.name)
        if not self.vid:
            self.vid = match1(self.url, '/(\w+)\.html','vid=(\w+)')

        if self.vid and match1(self.url, '(^https?://film\.qq\.com)'):
            self.url = 'http://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:\s*[\"\'](\w+)', 'vid\s*=\s*[\"\']\s*(\w+)', 'vid=(\w+)')

            if not self.vid and '<body class="page_404">' in html:
                self.logger.warning('This video has been deleted!')
                return info

        for title, fmt_name, type_name, urls, size in self.get_streams_info():
            stream_id = self.stream_2_id[fmt_name]
            stream_profile = self.stream_2_profile[fmt_name]
            if not stream_id in info.stream_types:
                info.stream_types.append(stream_id)
                info.streams[stream_id] = {'container': type_name, 'video_profile': stream_profile, 'src' : urls, 'size': size}
        info.stream_types = sorted(info.stream_types, key = self.stream_ids.index)
        info.title = title

        if self.vip:
            self.logger.warning('This is a VIP video!')

        return info
Esempio n. 8
0
    def prepare(self):
        info = VideoInfo(self.name, True)
        if not self.vid:
            self.vid = match1(self.url, '/(\d+)')
        html = get_content('https://m.egame.qq.com/live?anchorid=' + self.vid)

        title = self.parse_unicode(match1(html, '"title":"([^"\{\}]*)"'))
        info.artist = artist = self.parse_unicode(match1(html, '"nickName":"([^"]+)"'))
        info.title = u'{} - {}'.format(title, artist)

        assert match1(html, 'isLive":(\d+)') == '1', 'error: live show is not on line!!'

        html = get_content(self.url)
        urlArray = json.loads(match1(html, '"urlArray":(\[[^\]]+\])'))
        self.logger.debug("urlArray => {}".format(urlArray))

        for u in urlArray:
            video_profile = u['desc']
            stream = self.profile_2_id[video_profile]
            info.stream_types.append(stream)
            info.streams[stream] = {
                'container': 'flv',
                'video_profile': video_profile,
                'src': [u['playUrl']],
                'size': float('inf')
            }

        info.stream_types = sorted(info.stream_types, key=self.stream_ids.index)
        return info
Esempio n. 9
0
    def prepare(self):
        info = VideoInfo(self.name)
        html = get_content(self.url)
        self.vid = match1(html, 'webcfg\s*=\s*{"id":\s*(\d+)')
        param = "type%3dweb.fpp%26ahl_ver%3d1%26ahl_random%3d6c2b3072426c42253c754c4460624b76%26ahl_signa%3d8544ec938b8b6e4153320931d5079e7aadfbed5855a5ccc40c66d470338b7056%26userType%3d0%26o%3d0"
        xml = get_content(
            'http://web-play.pptv.com/webplay3-0-{}.xml?version=4&param={}&type=web.fpp&appplt=flp&appid=pptv.flashplayer.vod&appver=3.4.2.32'
            .format(self.vid, param))
        dom = parseString(compact_bytes(xml, 'utf-8'))
        info.title, m_items, m_streams, m_segs = parse_pptv_xml(dom)
        xml_streams = merge_meta(m_items, m_streams, m_segs)

        for stream_id in xml_streams:
            stream_data = xml_streams[stream_id]
            src = make_url(stream_data)
            s = self.supported_stream_types[int(stream_id)]
            info.stream_types.append(s)
            info.streams[s] = {
                'container': 'mp4',
                'video_profile': stream_data['res'],
                'size': int(stream_data['size']),
                'src': src
            }
        info.stream_types = sorted(info.stream_types,
                                   key=self.supported_stream_types.index)
        info.stream_types.reverse()
        return info
Esempio n. 10
0
    def prepare(self):
        info = VideoInfo(self.name, True)
        if not self.vid:
            self.vid = match1(self.url, 'channel=([\d]+)')

        live_data = json.loads(get_content('http://api.live.letv.com/v1/channel/letv/100/1001/{}'.format(self.vid)))['data']

        info.title = self.name + " " + live_data['channelName']

        stream_data = live_data['streams']

        for s in stream_data:
            stream_id = self.stream_2_id[s['rateType']]
            stream_profile = self.stream_2_profile[s['rateType']]
            if not stream_id in info.stream_types:
                info.stream_types.append(stream_id)
                date = datetime.datetime.now()
                streamUrl = s['streamUrl'] + '&format=1&expect=2&termid=1&hwtype=un&platid=10&splatid=1001&playid=1sign=live_web&&ostype={}&p1=1&p2=10&p3=-&vkit={}&station={}&tm={}'.format(platform.platform(), date.strftime("%Y%m%d"), self.vid, int(time.time()))
                data = json.loads(get_content(streamUrl))
                nodelist = data['nodelist']
                for node in nodelist:
                    src = node['location']
                    try:
                        get_content(src)
                        info.streams[stream_id] = {'container': 'm3u8', 'video_profile': stream_profile, 'size' : float('inf'), 'src' : [src]}
                    except:
                        continue
                    break
        info.stream_types = sorted(info.stream_types, key = self.stream_ids.index)
        return info
Esempio n. 11
0
    def prepare(self):
        info = VideoInfo(self.name)
        if not self.vid:
            self.vid = match1(self.url, 'http://\w+.yinyuetai.com/video/(\d+)')

        data = json.loads(
            get_content(
                'http://ext.yinyuetai.com/main/get-h-mv-info?json=true&videoId={}'
                .format(self.vid)))

        assert not data['error'], 'some error happens'

        video_data = data['videoInfo']['coreVideoInfo']

        info.title = video_data['videoName']
        info.artist = video_data['artistNames']
        for s in video_data['videoUrlModels']:
            stream_id = self.types_2_id[s['qualityLevel']]
            stream_profile = self.types_2_profile[s['qualityLevel']]
            info.stream_types.append(stream_id)
            info.streams[stream_id] = {
                'container': 'flv',
                'video_profile': stream_profile,
                'src': [s['videoUrl']],
                'size': s['fileSize']
            }

        info.stream_types = sorted(info.stream_types, key=self.ids.index)
        return info
Esempio n. 12
0
    def prepare(self):
        info = VideoInfo(self.name)

        html = get_content(self.url)

        info.title = match1(html, '<meta property="og:title" content="([^"]+)',
                            '<title>(.+?)</title>')

        url = match1(html, pattern) or match1(unquote(unescape(html)), pattern)

        if url:
            url = json.loads('"{url}"'.format(**vars()))
            url = match1(url, '.+(https?://.+)') or url  # redirect clear
            if url[0] == '/':
                url = self.url[:self.url.find('/')] + url
            ext = url_info(url)[1]
            if ext[:3] == 'm3u':
                info.stream_types, info.streams = load_m3u8_playlist(url)
            else:
                info.stream_types.append('current')
                info.streams['current'] = {
                    'container': ext,
                    'video_profile': 'current',
                    'src': [url],
                    'size': 0
                }
            self.info = info
            self.parser = self.pparser
            return info
Esempio n. 13
0
    def prepare(self):
        info = VideoInfo(self.name)
        if self.url and not self.vid:
            self.vid = match1(self.url, 'http://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+)')

        api_url = 'http://pcweb.api.mgtv.com/player/video?video_id={}'.format(
            self.vid)
        meta = json.loads(get_content(api_url))

        assert meta['code'] == 200, '[failed] status: {}, msg: {}'.format(
            meta['status'], meta['msg'])
        assert meta['data'], '[Failed] Video not found.'

        data = meta['data']

        info.title = data['info']['title']
        domain = data['stream_domain'][0]
        for lstream in data['stream']:
            if lstream['url']:
                url = json.loads(get_content(domain + lstream['url']))['info']
                info.streams[self.profile_2_types[lstream['name']]] = {
                    'container': 'm3u8',
                    'video_profile': lstream['name'],
                    'src': [url]
                }
                info.stream_types.append(self.profile_2_types[lstream['name']])
        info.stream_types = sorted(info.stream_types,
                                   key=self.supported_stream_types.index)
        return info
Esempio n. 14
0
    def prepare(self):
        info = VideoInfo(self.name)
        self.vid, self.embsig = self.vid

        api = "http://aauth-vod.cn-beijing.aliyuncs.com/acfun/web?vid={}&ct={}&time={}".format(
            self.vid, self.ct, int(time.time() * 1000))
        data = rc4(
            self.key,
            base64.b64decode(
                json.loads(get_content(api, charset='utf-8'))['data']))
        stream_data = json.loads(data)
        info.title = stream_data['video']['title']
        for s in stream_data['stream']:
            if 'segs' in s:
                stream_type = stream_code_to_id[s['stream_type']]
                stream_urls = [seg['url'] for seg in s['segs']]
                size = s['total_size']
                info.stream_types.append(stream_type)
                info.streams[stream_type] = {
                    'container': 'mp4',
                    'video_profile': stream_code_to_profiles[stream_type],
                    'src': stream_urls,
                    'size': size
                }
        info.stream_types = sorted(info.stream_types, key=ids.index)
        return info
Esempio n. 15
0
    def prepare(self):
        info = VideoInfo(self.name)
        vid, embsig = self.vid

        params = {
            'vid': vid,
            'ct': 85,
            'ev': 3,
            'sign': embsig,
            'time': int(time.time() * 1000)
        }
        api = 'https://player.acfun.cn/flash_data?' + urlencode(params)
        rc4_data = json.loads(get_content(api, charset='utf-8'))['data']
        data = rc4(self.key, base64.b64decode(rc4_data))
        stream_data = json.loads(data)
        info.title = stream_data['video']['title']
        for s in stream_data['stream']:
            if 'm3u8' in s['stream_type']:
                continue
            if 'segs' in s:
                stream_type = stream_code_to_id[s['stream_type']]
                stream_urls = [seg['url'] for seg in s['segs']]
                size = s['total_size']
                info.stream_types.append(stream_type)
                info.streams[stream_type] = {
                    'container': 'mp4',
                    'video_profile': stream_code_to_profiles[stream_type],
                    'src': stream_urls,
                    'size': size
                }
        info.stream_types = sorted(info.stream_types, key=ids.index)
        return info
Esempio n. 16
0
    def prepare(self):
        info = VideoInfo(self.name, True)

        if not self.vid:
            html = get_content(self.url)
            self.vid = match1(html, 'roomid: (\d+)')
            info.title = match1(html, '"title":"([^"]+)')
            info.artist = match1(html, '"Name":"([^"]+)')

        api_url = 'http://livestream.plu.cn/live/getlivePlayurl?roomId={}&{}'.format(
            self.vid, int(time.time()))

        data = json.loads(
            get_content(api_url))['playLines'][0]['urls']  #don't know index 1

        for i in data:
            if i['ext'] == 'flv':
                stream_id = self.supported_stream_types[i['rateLevel'] - 1]
                info.stream_types.append(stream_id)
                info.streams[stream_id] = {
                    'container': 'flv',
                    'video_profile': self.types_2_profile[stream_id],
                    'src': [i['securityUrl']],
                    'size': 0
                }

        #sort stream_types
        types = self.supported_stream_types
        types.reverse()
        info.stream_types = sorted(info.stream_types, key=types.index)
        return info
Esempio n. 17
0
    def prepare(self):
        info = VideoInfo(self.name, True)
        if not self.vid:
            self.vid = match1(self.url, '/(\d+)')
        if not self.url:
            self.url = 'https://egame.qq.com/' + self.vid
        html = get_content(self.url)

        title = match1(html, 'title:"([^"]*)"')
        info.artist = artist = match1(html, 'nickName:"([^"]+)"')
        info.title = u'{} - {}'.format(title, artist)

        playerInfo = match1(html, '_playerInfo = ({.+?});')
        self.logger.debug("playerInfo => %s" % (playerInfo))

        assert playerInfo, 'error: live show is not on line!!'
        playerInfo = json.loads(playerInfo)

        for u in playerInfo['urlArray']:
            video_profile = u['desc']
            stream = self.profile_2_id[video_profile]
            info.stream_types.append(stream)
            info.streams[stream] = {
                'container': 'flv',
                'video_profile': video_profile,
                'src': [u['playUrl']],
                'size': float('inf')
            }

        info.stream_types = sorted(info.stream_types, key=self.stream_ids.index)
        return info
Esempio n. 18
0
    def prepare(self):
        info = VideoInfo(self.name, True)
        html = get_content(self.url)
        info.title = match1(html, '<title>([^<]+)').split('_')[0]

        video_name = match1(html, '"stream":"([^"]+)')

        params = {'streamtype': 'live', 'VideoIDS': video_name, 'cdns': '1'}
        form = urlencode(params)
        content = get_content(self.live_base,
                              data=compact_bytes(form, 'utf-8'),
                              charset='utf-8')
        stream_data = json.loads(content)

        assert stream_data[
            "roomStatus"] == "1", "The live stream is not online! "
        for stream in stream_data["streamList"]:
            if stream['default'] == 1:
                defstream = stream['list']

        for stream in defstream:
            info.stream_types.append(stream['type'])
            info.streams[stream['type']] = {
                'container': 'flv',
                'video_profile': self.stream_2_profile[stream['type']],
                'src': [stream['url']],
                'size': float('inf')
            }

        info.stream_types = sorted(info.stream_types,
                                   key=self.supported_stream_types.index)
        return info
Esempio n. 19
0
    def prepare(self):
        info = VideoInfo(self.name, True)
        html = get_content(self.url)
        info.title = match1(html, '<title>([^<]+)').split('_')[0]

        video_name = match1(html, 'getFlash\("[0-9]+","([^"]+)')
        params = { 'streamtype':'live',
                   'VideoIDS': video_name,
                   'cdns' : '1'
                }
        form = urlencode(params)
        content = get_content(self.live_base,data=compact_bytes(form, 'utf-8'),charset = 'utf-8')
        stream_data = json.loads(content)

        assert stream_data["roomStatus"] == "1", "The live stream is not online! "
        for stream in stream_data["streamList"]:
            if stream['default'] == 1:
                defstream = stream['list']

        for stream in defstream:
            info.stream_types.append(stream['type'])
            info.streams[stream['type']] = {'container': 'flv', 'video_profile': self.stream_2_profile[stream['type']], 'src' : [stream['url']], 'size': float('inf')}

        info.stream_types = sorted(info.stream_types, key = self.supported_stream_types.index)
        return info
Esempio n. 20
0
    def prepare(self):
        info = VideoInfo(self.name)
        if not self.vid:
            self.vid = match1(self.url, 'play/(\d+)')
            info.title = self.name + str(self.vid)

        if not self.vid:
            html = get_content(self.url)
            self.vid = match1(html, 'data-vid="(\d+)')
            info.title = match1(html, '<title>([^<]+)').split('_')[0]

        api_url = 'http://playapi.v.duowan.com/index.php?vid={}&partner=&r=play%2Fvideo'.format(
            self.vid)
        data = json.loads(get_content(api_url))['result']['items']

        for i in data:
            d = i['transcode']
            s = i['task_name'][0:2]
            p = self.stream_2_profile[compact_str(s)]
            info.stream_types.append(p)
            info.streams[p] = {
                'container': 'mp4',
                'video_profile': s,
                'src': [d['urls'][0]],
                'size': int(d['size'])
            }

        info.stream_types = sorted(info.stream_types,
                                   key=self.supported_stream_types.index)
        return info
Esempio n. 21
0
    def prepare(self):
        info = VideoInfo(self.name, True)
        if not self.vid:
            self.vid = match1(self.url, 'channel=([\d]+)')

        live_data = json.loads(
            get_content(
                'http://player.pc.le.com/player/startup_by_channel_id/1001/{}?host=live.le.com'
                .format(self.vid)))

        info.title = live_data['channelName']

        stream_data = live_data['streams']

        for s in stream_data:
            stream_id = self.stream_2_id[s['rateType']]
            stream_profile = self.stream_2_profile[s['rateType']]
            if not stream_id in info.stream_types:
                info.stream_types.append(stream_id)
                streamUrl = s[
                    'streamUrl'] + '&format=1&expect=2&termid=1&platid=10&playid=1&sign=live_web&splatid=1001&vkit=20161017&station={}'.format(
                        self.vid)
                data = json.loads(get_content(streamUrl))
                src = data['location']
                info.streams[stream_id] = {
                    'container': 'm3u8',
                    'video_profile': stream_profile,
                    'size': float('inf'),
                    'src': [src]
                }
        info.stream_types = sorted(info.stream_types,
                                   key=self.stream_ids.index)
        return info
Esempio n. 22
0
    def prepare(self):
        info = VideoInfo(self.name)
        add_header('User-Agent', "")
        self.vid, self.embsig = self.vid

        api = "http://player.acfun.cn/flash_data?vid={}&ct={}&ev=3&sign={}&time={}".format(
            self.vid, self.ct, self.embsig, int(time.time() * 1000))
        data = rc4(
            self.key,
            base64.b64decode(
                json.loads(get_content(api, charset='utf-8'))['data']))
        stream_data = json.loads(data)
        info.title = stream_data['video']['title']
        for s in stream_data['stream']:
            if 'segs' in s:
                stream_type = stream_code_to_id[s['stream_type']]
                stream_urls = [seg['url'] for seg in s['segs']]
                size = s['total_size']
                info.stream_types.append(stream_type)
                info.streams[stream_type] = {
                    'container': 'mp4',
                    'video_profile': stream_code_to_profiles[stream_type],
                    'src': stream_urls,
                    'size': size
                }
        info.stream_types = sorted(info.stream_types, key=ids.index)
        return info
Esempio n. 23
0
    def prepare(self):
        info = VideoInfo(self.name)
        if self.url and not self.vid:
            vid = matchall(self.url, ['curid=([^_]+)_([\w]+)'])
            if vid:
                self.vid = vid[0]
                info_u = 'http://mixer.video.iqiyi.com/jp/mixin/videos/' + self.vid[
                    0]
                mixin = get_content(info_u)
                mixin_json = json.loads(mixin[len('var tvInfoJs='):])
                real_u = mixin_json['url']
                real_html = get_content(real_u)
                info.title = match1(real_html, '<title>([^<]+)').split('-')[0]

        if self.url and not self.vid:
            html = get_content(self.url)
            video_info = match1(html, ":video-info='(.+?)'")
            if video_info:
                video_info = json.loads(video_info)
                self.vid = str(video_info['tvId']), str(video_info['vid'])
                info.title = video_info['name']
            else:

                tvid = match1(html, 'data-player-tvid="([^"]+)"',
                              'tvid="(.+?)"', 'tvId:([^,]+)',
                              r'''param\['tvid'\]\s*=\s*"(.+?)"''',
                              r'"tvid":\s*"(\d+)"')
                videoid = match1(html, 'data-player-videoid="([^"]+)"',
                                 'vid="(.+?)"', 'vid:"([^"]+)',
                                 r'''param\['vid'\]\s*=\s*"(.+?)"''',
                                 r'"vid":\s*"(\w+)"')
                self.vid = (tvid, videoid)
                info.title = match1(html, '<title>([^<]+)').split('-')[0]

        tvid, vid = self.vid
        vps_data = getvps(tvid, vid)
        assert vps_data['code'] == 'A00000', 'can\'t play this video!!'
        url_prefix = vps_data['data']['vp']['du']
        stream = vps_data['data']['vp']['tkl'][0]
        vs_array = stream['vs']
        for vs in vs_array:
            bid = vs['bid']
            fs_array = vs['fs']
            real_urls = []
            for seg_info in fs_array:
                url = url_prefix + seg_info['l']
                json_data = json.loads(get_content(url))
                down_url = json_data['l']
                real_urls.append(down_url)
            stream = self.vd_2_id[bid]
            info.stream_types.append(stream)
            stream_profile = self.id_2_profile[stream]
            info.streams[stream] = {
                'video_profile': stream_profile,
                'container': 'flv',
                'src': real_urls,
                'size': 0
            }
        info.stream_types = sorted(info.stream_types, key=self.ids.index)
        return info
Esempio n. 24
0
    def prepare(self):
        info = VideoInfo(self.name)
        if not self.vid:
            self.vid = match1(self.url, '/(\w+)\.html', 'vid=(\w+)')

        if not self.vid or len(self.vid) != 11:
            html = get_content(self.url)
            self.vid = match1(html, 'vid:\s*\"([^\"]+)',
                              'vid\s*=\s*"\s*([^"]+)"', 'vid=(\w+)')

        for stream in self.supported_stream_types:
            title, fmt_name, type_name, urls, size = self.get_stream_info(
                stream)
            stream_id = self.stream_2_id[fmt_name]
            stream_profile = self.stream_2_profile[fmt_name]
            if not stream_id in info.stream_types:
                info.stream_types.append(stream_id)
                info.streams[stream_id] = {
                    'container': type_name,
                    'video_profile': stream_profile,
                    'src': urls,
                    'size': size
                }
        info.stream_types = sorted(info.stream_types,
                                   key=self.stream_ids.index)
        info.title = title
        return info
Esempio n. 25
0
    def prepare(self):
        info = VideoInfo(self.name, True)
        html = get_content(self.url)
        self.vid = match1(html, 'liveId\s*:\s*"(\d+)"') or match1(
            self.url, 'd=(\d+)')

        live_data = json.loads(
            get_content(
                'http://player.pc.le.com/player/startup_by_pid/1001/{}?host=live.le.com'
                .format(self.vid)))
        assert live_data[
            'status'] == 2, "Live show is finished, playback is not supported!"
        info.title = live_data['title']

        stream_data = live_data['rows']

        for s in stream_data:
            stream_id = self.stream_2_id[s['rateType']]
            stream_profile = self.stream_2_profile[s['rateType']]
            if not stream_id in info.stream_types:
                info.stream_types.append(stream_id)
                streamUrl = s[
                    'streamUrl'] + '&format=1&expect=2&termid=1&platid=10&playid=1&sign=live_web&splatid=1001&vkit=20161017&station={}'.format(
                        self.vid)
                data = json.loads(get_content(streamUrl))
                src = data['location']
                info.streams[stream_id] = {
                    'container': 'm3u8',
                    'video_profile': stream_profile,
                    'size': float('inf'),
                    'src': [src]
                }
        info.stream_types = sorted(info.stream_types,
                                   key=self.stream_ids.index)
        return info
Esempio n. 26
0
    def prepare(self):
        info = VideoInfo(self.name, True)

        ID = match1(self.url, '/(\d+)')
        api1_data = json.loads(get_content(api1_url.format(ID)))
        if api1_data['code'] == 0:
            self.vid = api1_data['data']['room_id']
        else:
            self.logger.debug('Get room ID from API failed: %s', api1_data['msg'])
            self.vid = ID

        api2_data = json.loads(get_content(api2_url.format(self.vid)))
        assert api2_data['code'] == 0, api2_data['msg']
        api2_data = api2_data['data']
        assert api2_data['live_status'] == 1, u'主播正在觅食......'
        info.title = title = api2_data['title']

        api3_data = json.loads(get_content(api3_url.format(self.vid)))
        if api3_data['code'] == 0:
            info.artist = artist = api3_data['data']['info']['uname']
            info.title = '{} - {}'.format(title, artist)

        def get_live_info(q=0):
            params = {
                'player': 1,
                'cid': self.vid,
                'platform': 'html5',
                'quality': q,
                'otype': 'json'
            }
            data = json.loads(get_content(api_url + urlencode(params)))

            assert data['code'] == 0, data['message']

            data = data['data']
            urls = [random.choice(data['durl'])['url']]
            qlt = data['current_quality']
            aqlts = [int(x) for x in data['accept_quality']]
            size = float('inf')
            ext = 'flv'
            prf = self.supported_stream_profile[4 - qlt]
            st = self.profile_2_type[prf]
            if urls and st not in info.streams:
                info.stream_types.append(st)
                info.streams[st] = {
                    'container': ext,
                    'video_profile': prf,
                    'src' : urls,
                    'size': size
                }

            if q == 0:
                aqlts.remove(qlt)
                for aqlt in aqlts:
                    get_live_info(aqlt)

        get_live_info()
        info.stream_types = sorted(info.stream_types, key=self.sorted_format.index)
        return info
Esempio n. 27
0
    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))
        self.logger.debug('meta >\n%s', meta)

        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']
        info.title = meta['data']['info']['title'] + ' ' + meta['data'][
            'info']['desc']

        api_source_url = 'https://pcweb.api.mgtv.com/player/getSource?pm2={}&tk2={}&video_id={}&type=pch5'.format(
            pm2, tk2, self.vid)
        meta = json.loads(get_content(api_source_url))

        assert meta['code'] == 200, '[failed] code: {}, msg: {}'.format(
            meta['code'], meta['msg'])
        assert meta['data'], '[Failed] Video source not found.'

        data = meta['data']
        domain = data['stream_domain'][0]
        for lstream in data['stream']:
            lurl = lstream['url']
            if lurl:
                lurl = '{}{}&did={}'.format(domain, lurl, did)
                url = json.loads(get_content(lurl))['info']
                video_profile = lstream['name']
                stream = self.profile_2_types[video_profile]
                info.streams[stream] = {
                    'container': 'm3u8',
                    'video_profile': video_profile,
                    'src': [url]
                }
                info.stream_types.append(stream)
        info.stream_types = sorted(info.stream_types,
                                   key=self.supported_stream_types.index)
        info.extra['referer'] = self.url
        info.extra['ua'] = ua
        return info
Esempio n. 28
0
    def prepare(self):
        handlers = [HTTPCookieProcessor()]
        if default_proxy_handler:
            handlers += default_proxy_handler
        install_opener(build_opener(*handlers))
        add_header("Referer", self.url)

        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']
        info.title = meta['data']['info']['title']

        api_source_url = 'https://pcweb.api.mgtv.com/player/getSource?pm2={}&tk2={}&video_id={}&type=pch5'.format(
            pm2, tk2, self.vid)
        meta = json.loads(get_content(api_source_url))

        assert meta['code'] == 200, '[failed] code: {}, msg: {}'.format(
            meta['code'], meta['msg'])
        assert meta['data'], '[Failed] Video source not found.'

        data = meta['data']
        domain = data['stream_domain'][0]
        tk2 = generate_tk2(did)
        for lstream in data['stream']:
            lurl = lstream['url']
            if lurl:
                lurl = '{}{}&did={}'.format(domain, lurl, did)
                url = json.loads(get_content(lurl))['info']
                info.streams[self.profile_2_types[lstream['name']]] = {
                    'container': 'm3u8',
                    'video_profile': lstream['name'],
                    'src': [url]
                }
                info.stream_types.append(self.profile_2_types[lstream['name']])
        info.stream_types = sorted(info.stream_types,
                                   key=self.supported_stream_types.index)
        return info
Esempio n. 29
0
    def prepare(self):
        info = VideoInfo(self.name, True)
        html = get_content(self.url)
        self.vid = match1(html, '"user_id":"([^"]+)",')
        title = json.loads(match1(html, '"room_name":("[^"]*"),'))
        artist = json.loads(match1(html, '"nick_name":("[^"]+"),'))
        info.title = u'{} - {}'.format(title, artist)
        info.artist = artist

        def get_live_info(rate='source'):
            data = getlive(self.vid, rate)
            self.logger.debug('data:\n' + str(data))
            if data['code'] != 'A00000':
                return data.get('msg')

            data = data['data']
            url = data.get('https_flv') or data.get('flv') or data.get('rtmp')
            if url:
                url = url.replace('rtmp://', 'http://')
                ran = random.randrange(1e4)
                if '?' in url:
                    url = '{}&ran={}'.format(url, ran)
                else:
                    url = '{}?ran={}'.format(url, ran)
                stream_profile = self.rate_2_profile[rate]
                stream_id = self.rate_2_id[rate]
                info.stream_types.append(stream_id)
                info.streams[stream_id] = {
                    'video_profile': stream_profile,
                    'container': 'flv',
                    'src' : [url],
                    'size': float('inf')
                }

            error_msges = []
            if rate == 'source':
                rate_list = data['rate_list']
                if 'source' in rate_list:
                    rate_list.remove('source')
                    for rate in rate_list:
                        error_msg = get_live_info(rate)
                        if error_msg:
                            error_msges.append(error_msg)
            if error_msges:
                return ', '.join(error_msges)

        error_msg = get_live_info()
        if error_msg:
            self.logger.debug('error_msg:\n' + error_msg)
        assert len(info.stream_types), error_msg or 'can\'t play this live video!!'
        info.stream_types = sorted(info.stream_types, key=self.ids.index)

        return info
Esempio n. 30
0
    def prepare(self):
        info = VideoInfo(self.name)
        html = get_content(self.url)
        info.title, info.artist, sourceVid, m3u8Info = self.get_page_info(html)

        add_header('Referer', 'https://www.acfun.cn/')

        if m3u8Info is None:
            data = json.loads(
                get_content(
                    'https://www.acfun.cn/rest/pc-direct/play/playInfo/m3u8Auto?videoId={}'
                    .format(sourceVid)))
            m3u8Info = data['playInfo']['streams'][0]

        # some videos are broken of CDN, random choose one
        m3u8api = random.choice(m3u8Info['playUrls'])
        self.logger.warning(
            'Request m3u8 info via CDN: %s\nIf video has broken on this CDN, please retry.',
            m3u8api)
        lines = get_content(m3u8api)
        self.logger.debug('m3u8 api: %s', lines)
        lines = lines.split('\n')

        resolutions = None
        for line in lines:
            if resolutions is None:
                resolutions = match1(line, 'RESOLUTION=(\d+x\d+)')
                if resolutions:
                    resolutions = [int(q) for q in resolutions.split('x')]
            elif match1(line, '(\.m3u8)'):
                try:
                    quality = min(resolutions)
                    stream_type = self.quality1_2_id[quality]
                except:
                    quality = max(resolutions)
                    stream_type = self.quality2_2_id[quality]
                resolutions = None
                if line.startswith('http'):
                    url = line
                else:
                    url = urljoin(m3u8api, line)
                stream_profile = self.id_2_profile[stream_type]
                info.stream_types.append(stream_type)
                info.streams[stream_type] = {
                    'container': 'm3u8',
                    'video_profile': stream_profile,
                    'src': [url],
                    'size': 0
                }

        info.stream_types = sorted(info.stream_types,
                                   key=self.stream_ids.index)
        return info
Esempio n. 31
0
    def prepare(self):
        info = VideoInfo(self.name)

        self.vid = match1(self.url, 'play/(\d+)')
        html = get_content(self.url)
        if not self.vid:
            self.vid = match1(html, 'data-vid="(\d+)')
        title = match1(html, '<h1 class="video-title">(.+?)</h1>')
        info.artist = artist = match1(
            html, "<div class='video-author'>[\s\S]+?<h3>(.+?)</h3>")
        info.title = u'{} - {}'.format(title, artist)

        t1 = int(time.time() * 1000)
        t2 = t1 + random.randrange(5, 10)
        rnd = str(random.random()).replace('.', '')
        params = {
            'callback': 'jQuery1124{}_{}'.format(rnd, t1),
            'r': 'vhuyaplay/video',
            'vid': self.vid,
            'format': 'mp4,m3u8',
            '_': t2
        }
        api_url = 'https://v-api-player-ssl.huya.com/?' + urlencode(params)
        data = get_content(api_url)[len(params['callback']) + 1:-1]
        self.logger.debug('data:\n%s', data)

        data = json.loads(data)
        assert data['code'] == 1, data['message']
        data = data['result']['items']

        for stream_date in data:
            ext = stream_date['format']
            quality = min(
                int(q) for q in (stream_date['height'], stream_date['width']))
            stream = self.quality_2_id[quality]
            if stream not in info.stream_types:
                info.stream_types.append(stream)
            elif ext == 'm3u8':
                # prefer mp4
                continue
            video_profile = self.id_2_profile[stream]
            url = stream_date['transcode']['urls'][0]
            info.streams[stream] = {
                'container': ext,
                'video_profile': video_profile,
                'src': [url],
                'size': int(stream_date['size'])
            }

        info.stream_types = sorted(info.stream_types,
                                   key=self.supported_stream_types.index)
        return info
Esempio n. 32
0
    def prepare(self):
        # Get file type
        ext = self.url.split('?')[0].split('.')[-1]
        if ext not in extNames:
            ctype = self.resheader['Content-Type'].lower()
            if ctype.startswith('image/'):
                ext = ctype[6:]
            else:
                ext = contentTypes[ctype]

        # Get title
        title = self.resheader.get('Content-Disposition')
        if title:
            title = match1(title, 'attachment;.+?filename\*=([^;]+)')
            if title:
                encoding, _, title = title.strip('"').split("'")
                unquote(title, encoding=encoding)
            else:
                title = match1(title, 'attachment;.+?filename=([^;]+)')
                if title:
                    title = unquote(title.strip('"'))
        if title is None:
            title = self.url.split('?')[0].split('/')[-1]
        if title.endswith('.' + ext):
            title = title[0 : -len(ext) - 1]

        info = VideoInfo(self.name)  # ignore judge live status
        info.title = title
        if ext == 'm3u8':
            info.stream_types, info.streams = load_m3u8_playlist(self.url)
        else:
            info.stream_types = ['current']
            info.streams['current'] = {
                'container': ext,
                'video_profile': 'current',
                'src': [self.url],
                'size': int(self.resheader.get('Content-Length', 0))
            }
        return info
Esempio n. 33
0
    def prepare(self):
        ssl_context = HTTPSHandler(context=ssl.SSLContext(ssl.PROTOCOL_TLSv1))
        cookie_handler = HTTPCookieProcessor()
        opener = build_opener(ssl_context, cookie_handler)
        opener.addheaders = [('Cookie', '__ysuid=%d' % time.time())]
        install_opener(opener)

        info = VideoInfo(self.name)

        if self.url and not self.vid:
            self.vid = match1(self.url, 'youku\.com/v_show/id_([a-zA-Z0-9=]+)' ,\
                                        'player\.youku\.com/player\.php/sid/([a-zA-Z0-9=]+)/v\.swf',\
                                        'loader\.swf\?VideoIDS=([a-zA-Z0-9=]+)',\
                                        'loader\.swf\?VideoIDS=([a-zA-Z0-9=]+)',\
                                        'player\.youku\.com/embed/([a-zA-Z0-9=]+)',\
                                        'video.tudou.com/v/([a-zA-Z0-9=]+)')

        self.logger.debug("VID: " + self.vid)
        api_url = 'https://ups.youku.com/ups/get.json?vid={}&ccode={}&client_ip=192.168.1.1&utid={}&client_ts={}'.format(
            self.vid, self.ccode, quote(fetch_cna()), int(time.time()))

        data = json.loads(get_content(api_url))
        assert data['e']['code'] == 0, data['e']['desc']
        data = data['data']
        assert 'stream' in data, data['error']['note']
        info.title = data['video']['title']
        streams = data['stream']
        for s in streams:
            t = stream_code_to_id[s['stream_type']]
            urls = []
            for u in s['segs']:
                self.logger.debug("seg> " + str(u))
                if u['key'] != -1:
                    urls.append(
                        json.loads(
                            get_content(u['cdn_url'] +
                                        '&yxon=1&special=true'))[0]['server'])
                else:
                    self.logger.warning(
                        "VIP video, ignore unavailable seg: {}".format(
                            s['segs'].index(u)))
            size = s['size']
            info.stream_types.append(t)
            info.streams[t] = {
                'container': id_to_container[t],
                'video_profile': stream_code_to_profiles[t],
                'size': size,
                'src': urls
            }
        info.stream_types = sorted(info.stream_types, key=ids.index)
        return info
Esempio n. 34
0
    def prepare(self):
        info = VideoInfo(self.name)
        if not self.vid:
            self.vid = match1(self.url, 'vid=(\w+)', '/(\w+)\.html')

        if self.vid and match1(self.url, '(^https?://film\.qq\.com)'):
            self.url = 'http://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:\s*[\"\'](\w+)',
                              'vid\s*=\s*[\"\']\s*(\w+)', 'vid=(\w+)')

            if not self.vid and '<body class="page_404">' in html:
                self.logger.warning('This video has been deleted!')
                return info

        video_rate = {}
        for title, fmt_name, stream_profile, type_name, urls, size, rate in self.get_streams_info(
        ):
            stream_id = self.stream_2_id[fmt_name]
            if urls and stream_id not in info.stream_types:
                info.stream_types.append(stream_id)
                info.streams[stream_id] = {
                    'container': type_name,
                    'video_profile': stream_profile,
                    'src': urls,
                    'size': size
                }
                video_rate[stream_id] = rate

        assert len(info.stream_types), "can't play this video!!"
        info.stream_types = sorted(info.stream_types,
                                   key=self.stream_ids.index)
        info.title = title

        if self.vip:
            self.logger.warning('This is a VIP video!')
        elif self.iflag:
            # Downloading some videos is very slow, use multithreading range fetch to speed up.
            # Only for video players now.
            info.extra['rangefetch'] = {
                'first_size': 1024 * 16,
                'max_size': 1024 * 32,
                'threads': 10,
                'video_rate': video_rate
            }
            self.logger.warning('This is a slow video!')

        return info
Esempio n. 35
0
    def prepare(self):
        self.vid = match1(self.url, 'd=(\d+)', 'live/(\d+)')
        if '/izt/' in self.url:
            vid = self.vid
            if not vid:
                html = get_content(self.url)
                vid = match1(html, 'vid\s*:\s*"(\d+)",', 'vid="(\d+)"')
            return get_playback(vid)
        else:
            if not self.vid:
                html = get_content(self.url)
                self.vid = match1(html, 'liveId\s*:\s*"(\d+)"')

        live_data = json.loads(
            get_content(
                'http://api.live.letv.com/v1/liveRoom/single/1001?id={}'.
                format(self.vid)))
        if live_data.get('status') != 2:
            return get_playback(live_data['recordingId'])

        # live video is dead, the followed code will not be used
        live_data = json.loads(
            get_content(
                'http://player.pc.le.com/player/startup_by_pid/1001/{}?host=live.le.com'
                .format(self.vid)))

        info = VideoInfo(self.name, True)
        info.title = live_data['title']
        stream_data = live_data['rows']

        for s in stream_data:
            stream_id = self.stream_2_id[s['rateType']]
            stream_profile = self.stream_2_profile[s['rateType']]
            if not stream_id in info.stream_types:
                info.stream_types.append(stream_id)
                streamUrl = s[
                    'streamUrl'] + '&format=1&expect=2&termid=1&platid=10&playid=1&sign=live_web&splatid=1001&vkit=20161017&station={}'.format(
                        self.vid)
                data = json.loads(get_content(streamUrl))
                src = data['location']
                info.streams[stream_id] = {
                    'container': 'm3u8',
                    'video_profile': stream_profile,
                    'size': float('inf'),
                    'src': [src]
                }
        info.stream_types = sorted(info.stream_types,
                                   key=self.stream_ids.index)
        return info
Esempio n. 36
0
    def prepare(self):
        info = VideoInfo(self.name)
        if not self.vid:
            self.vid = match1(self.url, 'vid=(\w+)', '/(\w+)\.html')

        if self.vid and match1(self.url, '(^https?://film\.qq\.com)'):
            self.url = 'http://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+)')

            if not self.vid and '<body class="page_404">' in html:
                self.logger.warning('This video has been deleted!')
                return info

        video_rate = {}
        for _ in range(2):
            try:
                for title, fmt_name, stream_profile, type_name, urls, size, rate in self.get_streams_info():
                    stream_id = self.stream_2_id[fmt_name]
                    if urls and stream_id not in info.stream_types:
                        info.stream_types.append(stream_id)
                        info.streams[stream_id] = {'container': type_name, 'video_profile': stream_profile, 'src' : urls, 'size': size}
                        video_rate[stream_id] = rate
                break
            except AssertionError as e:
                if 'wrong vid' in str(e):
                    html = get_content(self.url)
                    self.vid = match1(html, '&vid=(\w+)', 'vid:\s*[\"\'](\w+)', 'vid\s*=\s*[\"\']\s*(\w+)')
                    continue
                raise e

        if self.vip:
            self.logger.warning('This is a VIP video!')
            self.slow = False

        assert len(info.stream_types), "can't play this video!!"
        info.stream_types = sorted(info.stream_types, key = self.stream_ids.index)
        info.title = title

        if self.slow:
            # Downloading some videos is very slow, use multithreading range fetch to speed up.
            # Only for video players now.
            info.extra['rangefetch'] = {'first_size': 1024 * 16, 'max_size': 1024 * 32, 'threads': 10, 'video_rate': video_rate}
            self.logger.warning('This is a slow video!')

        return info
Esempio n. 37
0
    def prepare(self):
        info = VideoInfo(self.name)
        add_header("Referer", "https://www.bilibili.com/")
        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>([^<])')
            if code:
                return

            urls, size, fmt, qlt, aqlts = parse_cid_playurl(html)
            if 'mp4' in fmt:
                ext = 'mp4'
            elif 'flv' in fmt:
                ext = 'flv'
            st, prf = self.format_2_type_profile[fmt]
            if urls and st not in info.streams:
                info.stream_types.append(st)
                info.streams[st] = {
                    'container': ext,
                    'video_profile': prf,
                    'src': urls,
                    'size': size
                }

            if qn == 0:
                aqlts.remove(qlt)
                for aqlt in aqlts:
                    get_video_info(aqlt)

        get_video_info()

        assert len(info.stream_types), "can't play this video!!"
        info.stream_types = sorted(info.stream_types,
                                   key=self.sorted_format.index)
        return info
Esempio n. 38
0
    def prepare(self):
        info = VideoInfo(self.name)
        self.vid, self.embsig = self.vid

        api = "http://aauth-vod.cn-beijing.aliyuncs.com/acfun/web?vid={}&ct={}&time={}&sign={}&ev=2".format(self.vid, self.ct,int(time.time()*1000), self.embsig)
        data = rc4(self.key, base64.b64decode(json.loads(get_content(api, charset='utf-8'))['data']))
        stream_data = json.loads(data)
        info.title = stream_data['video']['title']
        for s in stream_data['stream']:
            if 'segs' in s:
                stream_type = stream_code_to_id[s['stream_type']]
                stream_urls = [seg['url'] for seg in s['segs']]
                size = s['total_size']
                info.stream_types.append(stream_type)
                info.streams[stream_type] = {'container': 'mp4', 'video_profile': stream_code_to_profiles[stream_type], 'src': stream_urls, 'size' : size}
        info.stream_types = sorted(info.stream_types, key=ids.index)
        return info
Esempio n. 39
0
File: live.py Progetto: wwqgtxx/ykdl
    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']:
            # TODO: parse more format types.
            # Streams which use formatType 'TS' are slow,
            # and rolling playback use formatType 'HLFLV' with scheme 'hcdnlive://'.
            # Its host and path encoded as like:
            #   'AMAAAAD3PV2R2QI7MXRQ4L2BD5Y...'
            # the real url is:
            #   'https://hlslive.video.iqiyi.com/live/{hl_slid}.flv?{params}'
            # Request it, the response is a json data which contains CDN informations.
            if stream['formatType'] == 'TS':
                m3u8 = stream['url']
                # miswrote 'streamType' to 'steamType'
                stream_type = stream['steamType']
                stream_profile = stream['screenSize']
                stream_id = self.type_2_id[stream_type]
                info.stream_types.append(stream_id)
                info.streams[stream_id] = {
                    'video_profile': stream_profile,
                    'container': 'm3u8',
                    'src' : [m3u8],
                    'size': float('inf')
                }

        assert info.stream_types, 'can\'t play this live video!!'
        if len(info.stream_types) == 1:
            info.streams['current'] = info.streams.pop(info.stream_types[0])
            info.stream_types[0] = 'current'
        else:
            info.stream_types = sorted(info.stream_types, key=self.ids.index)

        return info
Esempio n. 40
0
File: acorig.py Progetto: flfq/ykdl
    def prepare(self):
        info = VideoInfo(self.name)
        add_header('User-Agent', "")
        self.vid, self.embsig = self.vid

        api = "http://player.acfun.cn/flash_data?vid={}&ct={}&ev=3&sign={}&time={}".format(self.vid, self.ct, self.embsig, int(time.time()*1000))
        data = rc4(self.key, base64.b64decode(json.loads(get_content(api, charset='utf-8'))['data']))
        stream_data = json.loads(data)
        info.title = stream_data['video']['title']
        for s in stream_data['stream']:
            if 'segs' in s:
                stream_type = stream_code_to_id[s['stream_type']]
                stream_urls = [seg['url'] for seg in s['segs']]
                size = s['total_size']
                info.stream_types.append(stream_type)
                info.streams[stream_type] = {'container': 'mp4', 'video_profile': stream_code_to_profiles[stream_type], 'src': stream_urls, 'size' : size}
        info.stream_types = sorted(info.stream_types, key=ids.index)
        return info
Esempio n. 41
0
File: mgtv.py Progetto: wwqgtxx/ykdl
    def prepare(self):
        handlers = [HTTPCookieProcessor()]
        if default_proxy_handler:
            handlers += default_proxy_handler
        install_opener(build_opener(*handlers))
        add_header("Referer", self.url)

        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']
        info.title = meta['data']['info']['title']

        api_source_url = 'https://pcweb.api.mgtv.com/player/getSource?pm2={}&tk2={}&video_id={}&type=pch5'.format(pm2, tk2, self.vid)
        meta = json.loads(get_content(api_source_url))

        assert meta['code'] == 200, '[failed] code: {}, msg: {}'.format(meta['code'], meta['msg'])
        assert meta['data'], '[Failed] Video source not found.'

        data = meta['data']
        domain = data['stream_domain'][0]
        tk2 = generate_tk2(did)
        for lstream in data['stream']:
            lurl = lstream['url']
            if lurl:
                lurl = '{}{}&did={}'.format(domain, lurl, did)
                url = json.loads(get_content(lurl))['info']
                info.streams[self.profile_2_types[lstream['name']]] = {'container': 'm3u8', 'video_profile': lstream['name'], 'src' : [url]}
                info.stream_types.append(self.profile_2_types[lstream['name']])
        info.stream_types= sorted(info.stream_types, key = self.supported_stream_types.index)
        return info
Esempio n. 42
0
    def prepare(self):
        info = VideoInfo(self.name)
        if not self.vid:
            self.vid = match1(self.url, 'vid=(\w+)')

        if not self.vid:
            html = get_content(self.url)
            self.vid = match1(html, 'vid:\"([^\"]+)')

        for stream in self.supported_stream_types:
            title, fmt_name, type_name, urls, size = self.get_stream_info(stream)
            stream_id = self.stream_2_id[fmt_name]
            stream_profile = self.stream_2_profile[fmt_name]
            if not stream_id in info.stream_types:
                info.stream_types.append(stream_id)
                info.streams[stream_id] = {'container': type_name, 'video_profile': stream_profile, 'src' : urls, 'size': size}
        info.stream_types = sorted(info.stream_types, key = self.stream_ids.index)
        info.title = title
        return info
Esempio n. 43
0
File: zhanqi.py Progetto: flfq/ykdl
    def prepare(self):
        info = VideoInfo(self.name)
        html = get_content(self.url)
        video_type = match1(html, 'VideoType":"([^"]+)"')
        if video_type == 'LIVE':
            info.live = True
        elif not video_type == 'VOD':
            raise NotImplementedError('Unknown_video_type')

        info.title = match1(html, '<title>([^<]+)').split("_")[0]
        if info.live:
            rtmp_id = match1(html, 'videoId":"([^"]+)"').replace('\\/','/')
            real_url = self.live_base+'/'+rtmp_id+'.m3u8'
            info.stream_types, info.streams = load_m3u8_playlist(real_url)
        else:
            vod_m3u8 = self.vod_base + '/' + match1(html, 'VideoID":"([^"]+)').replace('\\/','/')
            info.stream_types.append('current')
            info.streams['current'] = {'container': 'm3u8', 'video_profile': 'current', 'src' : [vod_m3u8], 'size': 0}
        return info
Esempio n. 44
0
    def prepare(self):
        info = VideoInfo(self.name)
        add_header("Referer", "https://www.bilibili.com/")
        info.extra["referer"] = "https://www.bilibili.com/"
        info.extra["ua"] = fake_headers['User-Agent']

        self.vid, info.title = self.get_vid_title()

        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>([^<])')
            if code:
                return

            urls, size, fmt, qlt, aqlts = parse_cid_playurl(html)
            if 'mp4' in fmt:
                ext = 'mp4'
            elif 'flv' in fmt:
                ext = 'flv'
            st, prf = self.format_2_type_profile[fmt]
            if urls and st not in info.streams:
                info.stream_types.append(st)
                info.streams[st] = {'container': ext, 'video_profile': prf, 'src' : urls, 'size': size}

            if qn == 0:
                aqlts.remove(qlt)
                for aqlt in aqlts:
                    get_video_info(aqlt)

        get_video_info()

        assert len(info.stream_types), "can't play this video!!"
        info.stream_types = sorted(info.stream_types, key = self.sorted_format.index) 
        return info
Esempio n. 45
0
File: ifeng.py Progetto: PureTV/ykdl
    def prepare(self):
        info = VideoInfo(self.name)
        if not self.vid:
            self.vid= match1(self.url, '#([a-zA-Z0-9\-]+)', '/([a-zA-Z0-9\-]+).shtml')

        xml = get_content('http://v.ifeng.com/video_info_new/{}/{}/{}.xml'.format(self.vid[-2], self.vid[-2:], self.vid))
        doc = parseString(xml.encode('utf-8'))
        info.title = doc.getElementsByTagName('item')[0].getAttribute("Name")
        videos = doc.getElementsByTagName('videos')
        for v in videos[0].getElementsByTagName('video'):
            if v.getAttribute("mediaType") == 'mp4':
                _t = v.getAttribute("type")
                _u = v.getAttribute("VideoPlayUrl")
                stream_id = self.types_2_id[_t]
                stream_profile = self.types_2_profile[_t]
                info.stream_types.append(stream_id)
                info.streams[stream_id] = {'container': 'mp4', 'video_profile': stream_profile, 'src' : [_u], 'size': 0}

        info.stream_types = sorted(info.stream_types, key = self.ids.index)
        return info
Esempio n. 46
0
    def prepare(self):
        info = VideoInfo(self.name)
        if not self.vid:
            self.vid = match1(self.url, 'http://\w+.yinyuetai.com/video/(\d+)')

        data = json.loads(get_content('http://ext.yinyuetai.com/main/get-h-mv-info?json=true&videoId={}'.format(self.vid)))

        assert not data['error'], 'some error happens'

        video_data = data['videoInfo']['coreVideoInfo']

        info.title = video_data['videoName']
        info.artist = video_data['artistNames']
        for s in video_data['videoUrlModels']:
            stream_id = self.types_2_id[s['qualityLevel']]
            stream_profile = self.types_2_profile[s['qualityLevel']]
            info.stream_types.append(stream_id)
            info.streams[stream_id] = {'container': 'flv', 'video_profile': stream_profile, 'src' : [s['videoUrl']], 'size': s['fileSize']}

        info.stream_types = sorted(info.stream_types, key = self.ids.index)
        return info
Esempio n. 47
0
    def prepare(self):
        info = VideoInfo(self.name)
        self.setup(info)
        self.streams_parameter = {}
        for stream in self.stream_data:
            stream_id = stream_code_to_id[stream['stream_type']]
            if not stream_id in info.stream_types:
                self.streams_parameter[stream_id] = {
                    'fileid': stream['stream_fileid'],
                    'segs': stream['segs']
                }
                info.streams[stream_id] = {
                    'container': id_to_container[stream_id],
                    'video_profile': stream_code_to_profiles[stream_id],
                    'size': stream['size']
                }
                info.stream_types.append(stream_id)
                self.extract_single(info, stream_id)

        info.stream_types = sorted(info.stream_types, key = ids.index)
        return info
Esempio n. 48
0
    def prepare(self):
        info = VideoInfo(self.name)
        if self.url and not self.vid:
            self.vid = match1(self.url, "/([0-9]+).html")

        rn = randint(0, 99999999)
        api_url = 'http://v.api.hunantv.com/player/video?video_id={}&random={}'.format(self.vid,rn)
        meta = json.loads(get_content(api_url))

        assert meta['status'] == 200, '[failed] status: {}, msg: {}'.format(meta['status'],meta['msg'])
        assert meta['data'], '[Failed] Video not found.'

        data = meta['data']

        info.title = data['info']['title']
        for lstream in data['stream']:
            url = json.loads(get_content(lstream['url']))['info']
            info.streams[self.profile_2_types[lstream['name']]] = {'container': 'm3u8', 'video_profile': lstream['name'], 'src' : [url]}
            info.stream_types.append(self.profile_2_types[lstream['name']])
        info.stream_types= sorted(info.stream_types, key = self.supported_stream_types.index)
        return info
Esempio n. 49
0
    def prepare(self):
        info = VideoInfo(self.name, True)
        if not self.vid:
            self.vid = match1(self.url, 'channel=([\d]+)')

        live_data = json.loads(get_content('http://player.pc.le.com/player/startup_by_channel_id/1001/{}?host=live.le.com'.format(self.vid)))

        info.title = live_data['channelName']

        stream_data = live_data['streams']

        for s in stream_data:
            stream_id = self.stream_2_id[s['rateType']]
            stream_profile = self.stream_2_profile[s['rateType']]
            if not stream_id in info.stream_types:
                info.stream_types.append(stream_id)
                streamUrl = s['streamUrl'] + '&format=1&expect=2&termid=1&platid=10&playid=1&sign=live_web&splatid=1001&vkit=20161017&station={}'.format( self.vid)
                data = json.loads(get_content(streamUrl))
                src = data['location']
                info.streams[stream_id] = {'container': 'm3u8', 'video_profile': stream_profile, 'size' : float('inf'), 'src' : [src]}
        info.stream_types = sorted(info.stream_types, key = self.stream_ids.index)
        return info
Esempio n. 50
0
File: pptv.py Progetto: wwqgtxx/ykdl
 def prepare(self):
     info = VideoInfo(self.name)
     self.vid = match1(self.url, '\.pptv\.com/vod/(\d+)')
     if not self.vid:
         html = get_content(self.url)
         self.vid = match1(html, 'webcfg\s*=\s*{"id":\s*(\d+)')
      # API修改
     # param = "type%3dppbox.launcher%26ahl_ver%3d1%26ahl_random%3d6c2b3072426c42253c754c4460624b76%26ahl_signa%3d8544ec938b8b6e4153320931d5079e7aadfbed5855a5ccc40c66d470338b7056%26userType%3d0%26o%3d0"
     # xml = get_content('http://web-play.pptv.com/webplay3-0-{}.xml?version=4&param={}&type=web.fpp&appplt=flp&appid=pptv.flashplayer.vod&appver=3.4.2.32'.format(self.vid,param))
     xml = get_content('https://web-play.pptv.com/webplay3-0-{}.xml?zone=8&version=4&username=&ppi=302c3333&type=ppbox.launcher&pageUrl=http%3A%2F%2Fv.pptv.com&o=0&referrer=&kk=&scver=1&appplt=flp&appid=pptv.flashplayer.vod&appver=3.4.3.3&nddp=1'.format(self.vid))
     dom = parseString(compact_bytes(xml, 'utf-8'))
     info.title, m_items, m_streams, m_segs = parse_pptv_xml(dom)
     xml_streams = merge_meta(m_items, m_streams, m_segs)
     for stream_id in xml_streams:
         stream_data = xml_streams[stream_id]
         src = make_url(stream_data)
         s = self.supported_stream_types[int(stream_id)]
         info.stream_types.append(s)
         info.streams[s] = { 'container': 'mp4', 'video_profile': stream_data['res'], 'size': int(stream_data['size']), 'src': src}
     info.stream_types = sorted(info.stream_types, key = self.supported_stream_types.index)
     info.stream_types.reverse()
     return info
Esempio n. 51
0
    def prepare(self):
        info = VideoInfo(self.name)

        html = get_content(self.url)
        self.vid = match1(html, "(\d+)\.swf")

        xml = get_content("http://cloud.video.taobao.com/videoapi/info.php?vid={}".format(self.vid))

        doc = parseString(xml)
        videos = doc.getElementsByTagName("videos")[0]

        n = 0
        for video in videos.getElementsByTagName('video'):
            if not n % 2:
                lenth = video.getElementsByTagName('length')[0].firstChild.nodeValue
                url = video.getElementsByTagName('video_url')[0].firstChild.nodeValue
                profile = self.stream_2_id[video.getElementsByTagName('type')[0].firstChild.nodeValue]
                info.stream_types.append(profile)
                info.streams[profile] = {'container': 'flv', 'video_profile': profile, 'src' : [url+'/start_0/end_{}/1.flv'.format(lenth)], 'size': int(lenth)}

        info.stream_types = sorted(info.stream_types, key = self.stream_ids.index)
        return info
Esempio n. 52
0
File: video.py Progetto: PureTV/ykdl
    def prepare(self):
        info = VideoInfo(self.name)
        if not self.vid:
            self.vid = match1(self.url, 'play/(\d+)')
            info.title = self.name + str(self.vid)

        if not self.vid:
            html = get_content(self.url)
            self.vid = match1(html, 'data-vid="(\d+)')
            info.title = match1(html, '<title>([^<]+)').split('_')[0]

        api_url = 'http://playapi.v.duowan.com/index.php?vid={}&partner=&r=play%2Fvideo'.format(self.vid)
        data = json.loads(get_content(api_url))['result']['items']

        for i in data:
            d = i['transcode']
            s = i['task_name'][0:2]
            p = self.stream_2_profile[compact_str(s)]
            info.stream_types.append(p)
            info.streams[p] = {'container': 'mp4', 'video_profile': s, 'src': [d['urls'][0]], 'size' : int(d['size'])}

        info.stream_types = sorted(info.stream_types, key = self.supported_stream_types.index)
        return info
Esempio n. 53
0
File: iqiyi.py Progetto: PureTV/ykdl
    def prepare(self):
        info = VideoInfo(self.name)
        if self.url and not self.vid:
            vid = matchall(self.url, ['curid=([^_]+)_([\w]+)'])
            if vid:
                self.vid = vid[0]
                info.title = self.name + '_' + str(self.vid)

        if self.url and not self.vid:
            html = get_content(self.url)
            tvid = match1(html, 'data-player-tvid="([^"]+)"', 'tvid=([^&]+)' , 'tvId:([^,]+)')
            videoid = match1(html, 'data-player-videoid="([^"]+)"', 'vid=([^&]+)', 'vid:"([^"]+)')
            self.vid = (tvid, videoid)
            info.title = match1(html, '<title>([^<]+)').split('-')[0]

        tvid, vid = self.vid
        vps_data = getvps(tvid, vid)
        assert vps_data['code'] == 'A00000', 'can\'t play this video!!'
        url_prefix = vps_data['data']['vp']['du']
        stream = vps_data['data']['vp']['tkl'][0]
        vs_array = stream['vs']
        for vs in vs_array:
            bid = vs['bid']
            fs_array = vs['fs']
            real_urls = []
            for seg_info in fs_array:
                url = url_prefix + seg_info['l']
                json_data=json.loads(get_content(url))
                down_url = json_data['l']
                real_urls.append(down_url)
            stream = self.vd_2_id[bid]
            info.stream_types.append(stream)
            stream_profile = self.id_2_profile[stream]
            info.streams[stream] = {'video_profile': stream_profile, 'container': 'flv', 'src': real_urls, 'size' : 0}
        info.stream_types = sorted(info.stream_types, key = self.ids.index)
        return info
Esempio n. 54
0
    def prepare(self):
        info = VideoInfo(self.name, True)

        if not self.vid:
            html = get_content(self.url)
            self.vid = match1(html, 'roomid: (\d+)', '__ROOMID = \'(\d+)\';', '"RoomId":(\d+)')
            info.title = match1(html, '"title":"([^"]+)', '<title>([^>]+)<')
            info.artist = match1(html, '"Name":"([^"]+)')

        api_url = 'http://livestream.plu.cn/live/getlivePlayurl?roomId={}&{}'.format(self.vid, int(time.time()))

        data = json.loads(get_content(api_url))['playLines'][0]['urls'] #don't know index 1

        for i in data:
            if i['ext'] == 'flv':
                stream_id = self.supported_stream_types[i['rateLevel'] -1]
                info.stream_types.append(stream_id)
                info.streams[stream_id] = {'container': 'flv', 'video_profile': self.types_2_profile[stream_id], 'src' : [i['securityUrl']], 'size': 0}

        #sort stream_types
        types = self.supported_stream_types
        types.reverse()
        info.stream_types = sorted(info.stream_types, key=types.index)
        return info
Esempio n. 55
0
    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):
                vid = vid.decode()
            self.vid = 'X' + vid
        self.logger.debug("VID: " + self.vid)

        utid = fetch_cna()
        for ccode, ref, ckey in self.params:
            add_header("Referer", ref)
            if len(ccode) > 4:
               _utid = generateUtdid()
            else:
               _utid = utid
            params = {
                'vid': self.vid,
                'ccode': ccode,
                'utid': _utid,
                'ckey': ckey,
                'client_ip': '192.168.1.1',
                'client_ts': int(time.time()),
            }
            data = None
            while data is None:
                e1 = 0
                e2 = 0
                data = json.loads(get_content('https://ups.youku.com/ups/get.json?' + urlencode(params)))
                self.logger.debug("data: " + str(data))
                e1 = data['e']['code']
                e2 = data['data'].get('error')
                if e2:
                    e2 = e2['code']
                if e1 == 0 and e2 in (-2002, -2003):
                    from getpass import getpass
                    data = None
                    if e2 == -2002:
                        self.logger.warning('This video has protected!')
                    elif e2 == -2003:
                        self.logger.warning('Your password [{}] is wrong!'.format(params['password']))
                    params['password'] = getpass('Input password:'******'e']['desc']
        data = data['data']
        assert 'stream' in data, data['error']['note']

        info.title = data['video']['title']
        audio_lang = 'default'
        if 'dvd' in data and 'audiolang' in data['dvd']:
            for l in data['dvd']["audiolang"]:
                if l['vid'].startswith(self.vid):
                    audio_lang = l['langcode']
                    break

        streams = data['stream']
        for s in streams:
            if not audio_lang == s['audio_lang']:
                continue
            self.logger.debug("stream> " + str(s))
            t = stream_code_to_id[s['stream_type']]
            urls = []
            for u in s['segs']:
                self.logger.debug("seg> " + str(u))
                if u['key'] != -1:
                    if 'cdn_url' in u:
                        urls.append(u['cdn_url'])
                else:
                    self.logger.warning("VIP video, ignore unavailable seg: {}".format(s['segs'].index(u)))
            if len(urls) == 0:
                urls = [s['m3u8_url']]
                c = 'm3u8'
            else:
                c = id_to_container[t]
            size = s['size']
            info.stream_types.append(t)
            info.streams[t] =  {
                    'container': c,
                    'video_profile': stream_code_to_profiles[t],
                    'size': size,
                    'src' : urls
                }

        info.stream_types = sorted(info.stream_types, key = ids.index)
        tmp = []
        for t in info.stream_types:
            if not t in tmp:
                tmp.append(t)
        info.stream_types = tmp

        return info
Esempio n. 56
0
    def prepare(self):
        info = VideoInfo(self.name)

        if self.url and not self.vid:
            vid = matchall(self.url, ['curid=([^_]+)_([\w]+)'])
            if vid:
                self.vid = vid[0]
                info_u = 'http://pcw-api.iqiyi.com/video/video/playervideoinfo?tvid=' + self.vid[0]
                try:
                    info_json = json.loads(get_content(info_u))
                    info.title = info_json['data']['vn']
                except:
                    self.vid = None

        def get_vid():
            html = get_content(self.url)
            video_info = match1(html, ":video-info='(.+?)'")

            if video_info:
                video_info = json.loads(video_info)
                self.vid = str(video_info['tvId']), str(video_info['vid'])
                info.title = video_info['name']

            else:
                tvid = match1(html,
                              'tvId:\s*"([^"]+)',
                              'data-video-tvId="([^"]+)',
                              '''\['tvid'\]\s*=\s*"([^"]+)''',
                              '"tvId":\s*([^,]+)')
                videoid = match1(html,
                                'data-video-vid="([^"]+)',
                                'vid:\s*"([^"]+)',
                                '''\['vid'\]\s*=\s*"([^"]+)''',
                                '"vid":\s*([^,]+)')
                if not (tvid and videoid):
                    url = match1(html, '(www\.iqiyi\.com/v_\w+\.html)')
                    if url:
                        self.url = 'https://' + url
                        return get_vid()
                self.vid = (tvid, videoid)
                info.title = match1(html, '<title>([^<]+)').split('-')[0]

        if self.url and not self.vid:
            get_vid()
        tvid, vid = self.vid
        assert tvid and vid, 'can\'t play this video!!'

        def push_stream_vd(vs):
            vd = vs['vd']
            stream = self.vd_2_id[vd]
            if not stream in info.streams:
                info.stream_types.append(stream)
            elif int(vd) < 10: 
                return
            m3u8 = vs['m3utx']
            stream_profile = self.id_2_profile[stream]
            info.streams[stream] = {
                'video_profile': stream_profile,
                'container': 'm3u8',
                'src': [m3u8],
                'size': 0
            }

        def push_stream_bid(bid, container, fs_array, size):
            stream = self.vd_2_id[bid]
            if stream in info.streams:
                return
            real_urls = []
            for seg_info in fs_array:
                url = url_prefix + seg_info['l']
                json_data = json.loads(get_content(url))
                down_url = json_data['l']
                real_urls.append(down_url)
            info.stream_types.append(stream)
            stream_profile = self.id_2_profile[stream]
            info.streams[stream] = {
                'video_profile': stream_profile,
                'container': container,
                'src': real_urls,
                'size': size
            }

        try:
            # try use tmts first
            # less http requests, get results quickly
            tmts_data = gettmts(tvid, vid)
            self.logger.debug('tmts_data:\n' + str(tmts_data))
            assert tmts_data['code'] == 'A00000', 'can\'t play this video!!'
            vs_array = tmts_data['data']['vidl']
            for vs in vs_array:
                push_stream_vd(vs)
            vip_conf = tmts_data['data'].get('ctl', {}).get('configs')
            if vip_conf:
                for vds in (('10', '19'), ('18', '5')):
                    for vd in vds:
                        if vd in vip_conf:
                            tmts_data = gettmts(tvid, vip_conf[vd]['vid'])
                            if tmts_data['code'] == 'A00000':
                                push_stream_vd(tmts_data['data'])
                                break

        except:
            try:
                # use vps as preferred fallback
                vps_data = getvps(tvid, vid)
                self.logger.debug('vps_data:\n' + str(vps_data))
                assert vps_data['code'] == 'A00000', 'can\'t play this video!!'
                url_prefix = vps_data['data']['vp']['du']
                vs_array = vps_data['data']['vp']['tkl'][0]['vs']
                for vs in vs_array:
                    bid = vs['bid']
                    fs_array = vs['fs']
                    size = vs['vsize']
                    push_stream_bid(bid, 'flv', fs_array, size)

            except:
                # use dash as fallback
                for bid in (500, 300, 200, 100):
                    dash_data = getdash(tvid, vid, bid)
                    self.logger.debug('dash_data:\n' + str(dash_data))
                    assert dash_data['code'] == 'A00000', 'can\'t play this video!!'
                    url_prefix = dash_data['data']['dd']
                    streams = dash_data['data']['program']['video']
                    for stream in streams:
                        if 'fs' in stream:
                            _bid = stream['bid']
                            container = stream['ff']
                            fs_array = stream['fs']
                            size = stream['vsize']
                            break
                    push_stream_bid(_bid, container, fs_array, size)

        info.stream_types = sorted(info.stream_types, key=self.ids.index)
        return info
Esempio n. 57
0
File: live.py Progetto: wwqgtxx/ykdl
    def prepare(self):
        assert javascript_is_supported, "No JS Interpreter found, can't parse douyu live!"

        info = VideoInfo(self.name, True)
        add_header("Referer", 'https://www.douyu.com')

        title = None
        artist = None
        html_room_info = None
        self.vid = match1(self.url, 'douyu.com/(\d+)')

        if self.vid:
            try:
                html_room_info = get_content('https://open.douyucdn.cn/api/RoomApi/room/' + self.vid)
            except:
                self.vid = None

        if not self.vid:
            html = get_content(self.url)
            self.vid = match1(html, 'room_id\s*=\s*(\d+)', '"room_id.?":(\d+)', 'data-onlineid=(\d+)')
            title = match1(html, 'Title-headlineH2">([^<]+)<')
            artist = match1(html, 'Title-anchorName" title="([^"]+)"')

        if not artist:
            html_room_info = html_room_info or get_content('https://open.douyucdn.cn/api/RoomApi/room/' + self.vid)
            data = json.loads(html_room_info)
            if data['error'] == 0:
                title = data['data']['room_name']
                artist = data['data']['owner_name']

        info.title = u'{} - {}'.format(title, artist)
        info.artist = artist

        html_h5enc = get_content('https://www.douyu.com/swf_api/homeH5Enc?rids=' + self.vid)
        data = json.loads(html_h5enc)
        assert data['error'] == 0, data['msg']
        js_enc = data['data']['room' + self.vid]

        try:
            # try load local .js file first
            # from https://cdnjs.com/libraries/crypto-js
            from pkgutil import get_data
            js_md5 = get_data(__name__, 'crypto-js-md5.min.js')
            if isinstance(js_md5, bytes):
                js_md5 = js_md5.decode()
        except IOError:
            js_md5 = get_content('https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.9-1/crypto-js.min.js')

        js_ctx = JSEngine(js_md5)
        js_ctx.eval(js_enc)
        did = uuid.uuid4().hex
        tt = str(int(time.time()))
        ub98484234 = js_ctx.call('ub98484234', self.vid, did, tt)
        self.logger.debug('ub98484234: ' + ub98484234)
        params = {
            'v': match1(ub98484234, 'v=(\d+)'),
            'did': did,
            'tt': tt,
            'sign': match1(ub98484234, 'sign=(\w{32})'),
            'cdn': '',
            'iar': 0,
            'ive': 0
        }

        def get_live_info(rate=0):
            params['rate'] = rate
            data = urlencode(params)
            if not isinstance(data, bytes):
                data = data.encode()
            html_content = get_content('https://www.douyu.com/lapi/live/getH5Play/{}'.format(self.vid), data=data)
            self.logger.debug(html_content)

            live_data = json.loads(html_content)
            if live_data['error']:
                return live_data['msg']

            live_data = live_data["data"]
            real_url = '{}/{}'.format(live_data['rtmp_url'], live_data['rtmp_live'])
            rate_2_profile = dict((rate['rate'], rate['name']) for rate in live_data['multirates'])
            video_profile = rate_2_profile[live_data['rate']]
            stream = self.profile_2_id[video_profile]
            if stream in info.streams:
                return
            info.stream_types.append(stream)
            info.streams[stream] = {
                'container': 'flv',
                'video_profile': video_profile,
                'src' : [real_url],
                'size': float('inf')
            }

            
            error_msges = []
            if rate == 0:
                rate_2_profile.pop(0, None)
                rate_2_profile.pop(live_data['rate'], None)
                for rate in rate_2_profile:
                    error_msg = get_live_info(rate)
                    if error_msg:
                        error_msges.append(error_msg)
            if error_msges:
                return ', '.join(error_msges)

        error_msg = get_live_info()
        assert len(info.stream_types), error_msg
        info.stream_types = sorted(info.stream_types, key=self.stream_ids.index)
        return info
Esempio n. 58
0
    def prepare(self):
        info = VideoInfo(self.name)
        if self.url and not self.vid:
            vid = matchall(self.url, ['curid=([^_]+)_([\w]+)'])
            if vid:
                self.vid = vid[0]

        if self.url and not self.vid:
            html = get_content(self.url)
            tvid = match1(html, 'data-player-tvid="([^"]+)"', 'tvid=([^&]+)' , 'tvId:([^,]+)')
            videoid = match1(html, 'data-player-videoid="([^"]+)"', 'vid=([^&]+)', 'vid:"([^"]+)')
            self.vid = (tvid, videoid)
            info.title = match1(html, '<title>([^<]+)').split('-')[0]

        tvid, vid = self.vid
        data = getVMS(tvid, vid)
        if not data['code'] == 'A00000':
            for bid in self.id_h5:
                h5_data = geth5VMS(tvid, vid, bid)
                if h5_data["code"] == "A00000":
                    stream = self.vd_2_id[bid]
                    profile = self.id_2_profile[stream]
                    info.title = h5_data['data']['playInfo']['vn']
                    info.stream_types.append(stream)
                    info.streams[stream] = {'container': 'mp4', 'video_profile': profile, 'src' : [h5_data['data']['m3u']], 'size' : 0}
            return info

        for stream in data['data']['vidl']:
            try:
                stream_id = self.vd_2_id[stream['vd']]
                if stream_id in info.stream_types or stream_id in self.id_ignore:
                    continue
                stream_profile = self.id_2_profile[stream_id]
                info.stream_types.append(stream_id)
                info.streams[stream_id] = {'video_profile': stream_profile, 'container': 'm3u8', 'src': [stream['m3u']], 'size' : 0}
            except:
                log.i("vd: {} is not handled".format(stream['vd']))
                log.i("info is {}".format(stream))

        # why I need do below???
        try:
            vip_vds = data['data']['ctl']['vip']['bids']
            vip_conf = data['data']['ctl']['configs']
        except:
            info.stream_types = sorted(info.stream_types, key = self.ids.index)
            return info

        if not 'BD' in info.stream_types:
            p1080_vids = []
            if 5 in vip_vds:
                p1080_vids.append(vip_conf['5']['vid'])
            for v in p1080_vids:
                p1080_info = getVMS(tvid, v)
                if p1080_info['code'] == 'A00000':
                    p1080_url = p1080_info['data']['m3u']
                    info.stream_types.append('BD')
                    info.streams['BD'] = {'video_profile': '1080p', 'container': 'm3u8', 'src': [p1080_url], 'size' : 0}
                    break

        if not '4k' in info.stream_types:
            k4_vids = []
            if 10 in vip_vds:
                k4_vids.append(vip_conf['10']['vid'])
            for v in k4_vids:
                k4_info = getVMS(tvid, v)
                if k4_info['code'] == 'A00000':
                    k4_url = k4_info['data']['m3u']
                    info.stream_types.append('4k')
                    info.streams['4k'] = {'video_profile': '4k', 'container': 'm3u8', 'src': [k4_url], 'size' : 0}
                    break

        info.stream_types = sorted(info.stream_types, key = self.ids.index)
        return info