Пример #1
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
Пример #2
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
Пример #3
0
    def prepare(self):
        info = VideoInfo(self.name, True)
        html = get_content(self.url)
        t_a = match1(html, '"keywords" content="([^"]+)')
        info.title = t_a.split(',')[0]
        info.artist = t_a.split(',')[1]

        replay_url = match1(html, '"m3u8":"([^"]+)')
        if replay_url:
            replay_url = replay_url.replace('\/','/')
            info.live = False
            info.stream_types.append('current')
            info.streams['current'] = {'container': 'm3u8', 'video_profile': 'current', 'src' : [replay_url], 'size': float('inf')}
            return info

        self.vid = match1(html, '"sn":"([^"]+)')
        channel = match1(html, '"channel":"([^"]+)')
        api_url = 'http://g2.live.360.cn/liveplay?stype=flv&channel={}&bid=huajiao&sn={}&sid={}&_rate=xd&ts={}&r={}&_ostype=flash&_delay=0&_sign=null&_ver=13'.format(channel, self.vid, SID, time.time(),random.random())
        encoded_json = get_content(api_url)
        decoded_json = base64.decodestring(compact_bytes(encoded_json[0:3]+ encoded_json[6:], 'utf-8')).decode('utf-8')
        video_data = json.loads(decoded_json)
        live_url = video_data['main']
        info.live = True
        info.stream_types.append('current')
        info.streams['current'] = {'container': 'flv', 'video_profile': 'current', 'src' : [live_url], 'size': float('inf')}
        return info
Пример #4
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
Пример #5
0
    def prepare(self):
        info = VideoInfo(self.name)
        add_header("Referer", "http://music.163.com/")
        if not self.vid:
            self.vid =  match1(self.url, 'song/(\d+)', '\?id=(.*)')
        api_url = self.api_url.format(self.vid, self.vid)
        music = self.get_music(json.loads(get_content(api_url)))
        self.logger.debug("music info >" + str(music))
        info.title = music['name']
        info.artist = music['artists'][0]['name']

        real_id = music["id"]

        snd_key = random_string()
        if sys.version_info[0] == 3:
            encSecKey = RSA_string(snd_key)
        else:
            encSecKey = RSA_string(snd_key)[:-1]
        payload = netease_req(real_id, snd_key, encSecKey)

        mp3_info = json.loads(get_content(self.mp3_api, data=compact_bytes(urlencode(payload), 'utf-8')))['data'][0]
        self.logger.debug("mp3 > " + str(mp3_info))
        info.stream_types.append('current')
        info.streams['current'] =  {'container': mp3_info['type'], 'video_profile': 'current', 'src' : [mp3_info['url']], 'size': mp3_info['size']}
        return info
Пример #6
0
def getVMS(tvid, vid):
    t = int(time.time() * 1000)
    src = '76f90cbd92f94a2e925d83e8ccd22cb7'
    key = 'd5fb4bd9d50c4be6948c97edd7254b0e'
    sc = hashlib.new('md5', compact_bytes(str(t) + key  + vid, 'utf-8')).hexdigest()
    vmsreq= url = 'http://cache.m.iqiyi.com/tmts/{0}/{1}/?t={2}&sc={3}&src={4}'.format(tvid,vid,t,sc,src)
    return json.loads(get_content(vmsreq))
Пример #7
0
    def prepare(self):
        info = VideoInfo(self.name)
        add_header("Referer", "http://www.bilibili.com")
        info.extra["referer"] = "http://www.bilibili.com"
        info.extra["ua"] = fake_headers['User-Agent']
        if not self.vid:
            html = get_content(self.url)
            self.vid = match1(html, 'cid=(\d+)', 'cid=\"(\d+)')
            info.title = match1(html, '<title>([^<]+)').split("_")[0].strip(u" 番剧 bilibili 哔哩哔哩弹幕视频网")
            if not self.vid:
                eid = match1(self.url, 'anime/v/(\d+)', 'play#(\d+)') or match1(html, 'anime/v/(\d+)')
                if eid:
                    Episode_info = json.loads(get_content('http://bangumi.bilibili.com/web_api/episode/{}.json'.format(eid)))['result']['currentEpisode']
                    self.vid = Episode_info['danmaku']
                    info.title = info.title + ' ' + Episode_info['indexTitle'] + '.  ' + Episode_info['longTitle']

        assert self.vid, "can't play this video: {}".format(self.url)
        for q in self.supported_stream_profile:
            sign_this = hashlib.md5(compact_bytes('cid={}&from=miniplay&player=1&quality={}{}'.format(self.vid, 3-self.supported_stream_profile.index(q), SECRETKEY_MINILOADER), 'utf-8')).hexdigest()
            api_url = 'http://interface.bilibili.com/playurl?cid={}&player=1&quality={}&from=miniplay&sign={}'.format(self.vid, 3-self.supported_stream_profile.index(q), sign_this)
            html = get_content(api_url)
            self.logger.debug("HTML> {}".format(html))
            urls, size, ext = parse_cid_playurl(html)
            if ext == 'hdmp4':
                ext = 'mp4'

            info.stream_types.append(self.profile_2_type[q])
            info.streams[self.profile_2_type[q]] = {'container': ext, 'video_profile': q, 'src' : urls, 'size': size}
        return info
Пример #8
0
    def prepare(self):
        info = VideoInfo(self.name, True)

        if not self.vid:
            html = get_content(self.url)
            room = match1(html, 'var $ROOM = ([^;]+)')
            self.vid = match1(html, '"room_id.?":(\d+)')
            info.title = json.loads("{\"room_name\" : \"" + match1(html, '"room_name.?":"([^"]+)') + "\"}")['room_name']
            info.artist = json.loads("{\"name\" : \"" + match1(html, '"owner_name.?":"([^"]+)') + "\"}")['name']
        api_url = 'https://www.douyu.com/lapi/live/getPlay/{}'.format(self.vid)
        tt = str(int(time.time() / 60))
        rnd_md5 = hashlib.md5(str(random.random()).encode('utf8'))
        did = rnd_md5.hexdigest().upper()
        to_sign = ''.join([self.vid, did, API_KEY, tt])
        sign = stupidMD5(to_sign)
        for stream in self.stream_ids:
            rate = self.stream_id_2_rate[stream]
            params = {"ver" : VER, "sign" : sign, "did" : did, "rate" : rate, "tt" : tt, "cdn" : "ws"}
            form = urlencode(params)
            html_content = get_content(api_url, data=compact_bytes(form, 'utf-8'))
            live_data = json.loads(html_content)
            assert live_data["error"] == 0, "live show is offline"
            live_data = live_data["data"]
            real_url = '/'.join([live_data['rtmp_url'], live_data['rtmp_live']])

            info.stream_types.append(stream)
            info.streams[stream] = {'container': 'flv', 'video_profile': self.id_2_profile[stream], 'src' : [real_url], 'size': float('inf')}

        return info
Пример #9
0
def qq_get_final_url(url, fmt_name, type_name, br, form, fn):

    content = get_content('http://vv.video.qq.com/getkey',data=compact_bytes(form, 'utf-8'), charset = 'ignore')
    tree = ET.fromstring(content)

    vkey = tree.find('./key')
    if vkey is None:
        return
    else:
        vkey = vkey.text

    level = tree.find('./level').text
    sp = tree.find('./sp').text

    params = {
        'stdfrom': 'v1090',
        'type': type_name,
        'vkey': vkey,
        'level': level,
        'platform': PLAYER_PLATFORM,
        'br': br,
        'fmt': fmt_name,
        'sp': sp,
    }
    form = urlencode(params)
    return "%s?%s" % (url, form)
Пример #10
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
Пример #11
0
    def prepare(self):
        info = VideoInfo(self.name, True)
        if self.url:
            self.vid = match1(self.url, '/(\d+)')

        if not self.vid:
            html = get_content(self.url)
            self.vid = match1(html, '"room_id.?":(\d+)')
            info.title = match1(html, '<title>([^<]+)').split('-')[0]
        if not info.title:
            info.title = self.name + '-' + str(self.vid)
        tt = int(time.time() / 60)
        did = uuid.uuid4().hex.upper()
        sign_content = '{room_id}{did}A12Svb&%1UUmf@hC{tt}'.format(room_id = self.vid, did = did, tt = tt)
        sign = hashlib.md5(sign_content.encode('utf-8')).hexdigest()

        json_request_url = "http://www.douyu.com/lapi/live/getPlay/{}".format(self.vid)
        for stream in self.stream_ids:
            payload = {'cdn': 'ws', 'rate': self.stream_id_2_rate[stream], 'tt': tt, 'did': did, 'sign': sign}

            request_form = urlencode(payload)
            html_content = get_content(json_request_url, data = compact_bytes(request_form, 'utf-8'))

            live_data = json.loads(html_content)
            assert live_data['error'] == 0, '%s: live show is not on line or server error!' % self.name
            real_url = live_data['data']['rtmp_url'] + '/' + live_data['data']['rtmp_live']

            info.stream_types.append(stream)
            info.streams[stream] = {'container': 'flv', 'video_profile': self.id_2_profile[stream], 'src' : [real_url], 'size': float('inf')}
        return info
Пример #12
0
    def prepare(self):
        info = VideoInfo(self.name)
        add_header("Referer", "http://music.163.com/")
        if not self.vid:
            self.vid = match1(self.url, 'song/(\d+)', '\?id=(.*)')
        api_url = self.api_url.format(self.vid, self.vid)
        music = self.get_music(json.loads(get_content(api_url)))
        self.logger.debug("music info >" + str(music))
        info.title = music['name']
        info.artist = music['artists'][0]['name']

        real_id = music["id"]

        snd_key = random_string()
        if sys.version_info[0] == 3:
            encSecKey = RSA_string(snd_key)
        else:
            encSecKey = RSA_string(snd_key)[:-1]
        payload = netease_req(real_id, snd_key, encSecKey)

        mp3_info = json.loads(
            get_content(self.mp3_api,
                        data=compact_bytes(urlencode(payload),
                                           'utf-8')))['data'][0]
        self.logger.debug("mp3 > " + str(mp3_info))
        info.stream_types.append('current')
        info.streams['current'] = {
            'container': mp3_info['type'],
            'video_profile': 'current',
            'src': [mp3_info['url']],
            'size': mp3_info['size']
        }
        return info
Пример #13
0
def getVMS(tvid, vid):
    t = int(time.time() * 1000)
    src = '76f90cbd92f94a2e925d83e8ccd22cb7'
    key = 'd5fb4bd9d50c4be6948c97edd7254b0e'
    sc = hashlib.new('md5', compact_bytes(str(t) + key + vid,
                                          'utf-8')).hexdigest()
    vmsreq = url = 'http://cache.m.iqiyi.com/tmts/{0}/{1}/?t={2}&sc={3}&src={4}'.format(
        tvid, vid, t, sc, src)
    return json.loads(get_content(vmsreq))
Пример #14
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
Пример #15
0
 def get_api_url(self, q):
     if "movie" in self.url:
         mod = "movie"
     else:
         mod = "bangumi"
     ts = str(int(time.time()))
     params_str = 'cid={}&module={}&player=1&quality={}&ts={}'.format(
         self.vid, mod, q, ts)
     chksum = hashlib.md5(compact_bytes(params_str + SEC2,
                                        'utf8')).hexdigest()
     return bangumi_api_url + params_str + '&sign=' + chksum
Пример #16
0
    def prepare(self):
        info = VideoInfo(self.name)
        if not self.vid:
            self.vid = match1(self.url, 'sid=(\d+)')

        params = {"source": "", "sids": self.vid, "ck": ""}
        form = urlencode(params)
        data = json.loads(
            get_content('https://music.douban.com/j/artist/playlist',
                        data=compact_bytes(form, 'utf-8')))
        self.song_info = data['songs'][0]
        self.extract_song(info)
        return info
Пример #17
0
 def getVMS(self):
     #tm ->the flash run time for md5 usage
     #um -> vip 1 normal 0
     #authkey -> for password protected video ,replace '' with your password
     #puid user.passportid may empty?
     #TODO: support password protected video
     tvid, vid = self.vid
     tm, sc, src = mix(tvid)
     uid = self.gen_uid
     vmsreq='http://cache.video.qiyi.com/vms?key=fvip&src=1702633101b340d8917a69cf8a4b8c7' +\
             "&tvId="+tvid+"&vid="+vid+"&vinfo=1&tm="+tm+\
             "&enc="+sc+\
             "&qyid="+uid+"&tn="+str(random()) +"&um=1" +\
             "&authkey="+hashlib.new('md5',compact_bytes(hashlib.new('md5', b'').hexdigest()+str(tm)+tvid,'utf-8')).hexdigest()
     return json.loads(get_content(vmsreq))
Пример #18
0
    def prepare(self):
        info = VideoInfo(self.name, True)
        self.vid = match1(self.url, '(\d+).htm')
        api_url = "https://chushou.tv/live-room/get-play-url.htm"
        t = get_content("https://chushou.tv/timestamp/get.htm")
        sign_context = "_t={}&protocols=1,2&roomId={}".format(t,self.vid)
        sign = hashlib.md5(compact_bytes(SECKEY+'&'+sign_context, 'utf-8')).hexdigest()

        data = json.loads(get_content(api_url+'?'+sign_context+'&_sign={}'.format(sign)))

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

        info.stream_types.append("current")
        info.streams["current"] = {'container': 'flv', 'video_profile': 'current', 'src' : [data["data"][0]['shdPlayUrl']], 'size': float('inf')}

        return info
Пример #19
0
    def parser_list(self, url):

        sids = match1(url, 'sid=([0-9,]+)')

        params = {"source": "", "sids": sids, "ck": ""}
        form = urlencode(params)
        data = json.loads(
            get_content('https://music.douban.com/j/artist/playlist',
                        data=compact_bytes(form, 'utf-8')))

        info_list = []
        for s in data['songs']:
            info = VideoInfo(self.name)
            self.song_info = s
            self.extract_song(info)
            info_list.append(info)
        return info_list
Пример #20
0
    def prepare(self):
        info = VideoInfo(self.name)
        html = get_content(self.url)
        self.vid = match1(html, 'webcfg\s*=\s*{"id":\s*(\d+)')
        xml = get_content('http://web-play.pptv.com/webplay3-0-{}.xml?type=web.fpp&version=4'.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
Пример #21
0
def qq_get_final_url(url, fmt_name, type_name, br, form, fn):

    content = get_content('http://vv.video.qq.com/getkey',data=compact_bytes(form, 'utf-8'), charset = 'ignore')
    tree = ET.fromstring(content)

    vkey = tree.find('./key').text
    level = tree.find('./level').text
    sp = tree.find('./sp').text

    params = {
        'stdfrom': 'v1090',
        'type': type_name,
        'vkey': vkey,
        'level': level,
        'platform': PLAYER_PLATFORM,
        'br': br,
        'fmt': fmt_name,
        'sp': sp,
    }
    form = urlencode(params)
    return "%s?%s" % (url, form)
Пример #22
0
    def prepare(self):
        info = VideoInfo(self.name)
        if not self.vid:
            html = get_content(self.url)
            self.vid = match1(html, 'cid=(\d+)', 'cid=\"(\d+)')
            if not self.vid:
                eid = match1(self.url, 'anime/v/(\d+)') or match1(
                    html, 'anime/v/(\d+)')
                if eid:
                    self.vid = str(
                        json.loads(
                            get_content(
                                'http://bangumi.bilibili.com/web_api/episode/get_source?episode_id={}'
                                .format(eid)))['result']['cid'])
            info.title = match1(html, '<title>([^<]+)').split("_")[0]
            if 'bilibili' in info.title:
                info.title = info.title.strip(u" 番剧 bilibili 哔哩哔哩弹幕视频网")

        assert self.vid, "can't play this video: {}".format(self.url)
        for q in self.supported_stream_profile:
            sign_this = hashlib.md5(
                compact_bytes(
                    'cid={}&from=miniplay&player=1&quality={}{}'.format(
                        self.vid, 3 - self.supported_stream_profile.index(q),
                        SECRETKEY_MINILOADER), 'utf-8')).hexdigest()
            api_url = 'http://interface.bilibili.com/playurl?cid={}&player=1&quality={}&from=miniplay&sign={}'.format(
                self.vid, 3 - self.supported_stream_profile.index(q),
                sign_this)
            html = get_content(api_url)
            urls, size = parse_cid_playurl(html)
            ext = 'flv'

            info.stream_types.append(self.profile_2_type[q])
            info.streams[self.profile_2_type[q]] = {
                'container': ext,
                'video_profile': q,
                'src': urls,
                'size': size
            }
        return info
Пример #23
0
    def prepare(self):
        info = VideoInfo(self.name, True)
        html = get_content(self.url)
        t_a = match1(html, '"keywords" content="([^"]+)')
        info.title = t_a.split(',')[0]
        info.artist = t_a.split(',')[1]

        replay_url = match1(html, '"m3u8":"([^"]+)')
        if replay_url:
            replay_url = replay_url.replace('\/', '/')
            info.live = False
            info.stream_types.append('current')
            info.streams['current'] = {
                'container': 'm3u8',
                'video_profile': 'current',
                'src': [replay_url],
                'size': float('inf')
            }
            return info

        self.vid = match1(html, '"sn":"([^"]+)')
        channel = match1(html, '"channel":"([^"]+)')
        api_url = 'http://g2.live.360.cn/liveplay?stype=flv&channel={}&bid=huajiao&sn={}&sid={}&_rate=xd&ts={}&r={}&_ostype=flash&_delay=0&_sign=null&_ver=13'.format(
            channel, self.vid, SID, time.time(), random.random())
        encoded_json = get_content(api_url)
        decoded_json = base64.decodestring(
            compact_bytes(encoded_json[0:3] + encoded_json[6:],
                          'utf-8')).decode('utf-8')
        video_data = json.loads(decoded_json)
        live_url = video_data['main']

        info.stream_types.append('current')
        info.streams['current'] = {
            'container': 'flv',
            'video_profile': 'current',
            'src': [live_url],
            'size': float('inf')
        }
        return info
Пример #24
0
 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
Пример #25
0
    def prepare(self):

        if not self.vid:
            self.vid = match1(self.url, 'http://music.baidu.com/song/([\d]+)')

        param = urlencode({'songIds': self.vid})

        song_data = json.loads(
            get_content('http://play.baidu.com/data/music/songlink',
                        data=compact_bytes(param,
                                           'utf-8')))['data']['songList'][0]

        self.title = song_data['songName']
        self.artist = song_data['artistName']

        self.stream_types.append('current')
        self.streams['current'] = {
            'container': song_data['format'],
            'video_profile': 'current',
            'src': [song_data['songLink']],
            'size': song_data['size']
        }
Пример #26
0
    def get_vid_title(self):
        self.url = get_location(self.url)
        html = get_content(self.url)
        title = match1(html, '<h1 title="([^"]+)', '<title>([^<]+)').strip()

        if "movie" in self.url:
            aid = match1(html, 'aid=(\d+)', 'aid=\"(\d+)')
            form = {"movie_aid": aid}
            vid = json.loads(
                get_content("https://bangumi.bilibili.com/web_api/get_source",
                            data=compact_bytes(urlencode(form),
                                               'utf-8')))["result"]["cid"]
        else:
            eid = match1(self.url, 'anime/v/(\d+)', 'play#(\d+)',
                         'ep(\d+)') or match1(html, 'anime/v/(\d+)')
            Episode_info = json.loads(
                get_content(
                    'http://bangumi.bilibili.com/web_api/episode/{}.json'.
                    format(eid)))['result']['currentEpisode']
            vid = Episode_info['danmaku']
            title = title + ' ' + Episode_info[
                'indexTitle'] + '.  ' + Episode_info['longTitle']

        return vid, title
Пример #27
0
    def prepare(self):
        info = VideoInfo(self.name, True)
        self.vid = match1(self.url, '(\d+).htm')
        api_url = "https://chushou.tv/live-room/get-play-url.htm"
        t = get_content("https://chushou.tv/timestamp/get.htm")
        sign_context = "_t={}&protocols=1,2&roomId={}".format(t, self.vid)
        sign = hashlib.md5(compact_bytes(SECKEY + '&' + sign_context,
                                         'utf-8')).hexdigest()

        data = json.loads(
            get_content(api_url + '?' + sign_context +
                        '&_sign={}'.format(sign)))

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

        info.stream_types.append("current")
        info.streams["current"] = {
            'container': 'flv',
            'video_profile': 'current',
            'src': [data["data"][0]['shdPlayUrl']],
            'size': float('inf')
        }

        return info
Пример #28
0
    def download_playlist(self, url, param):
        self.param = param
        sids = match1(url, 'sid=([0-9,]+)')

        params = {
            "source" : "",
            "sids" : sids,
            "ck" : ""
        }
        form = urlencode(params)
        data = json.loads(get_content('https://music.douban.com/j/artist/playlist', data = compact_bytes(form, 'utf-8')))

        for s in data['songs']:
           self.song_info = s
           self.download_normal()
Пример #29
0
def sign_api_url(api_url, params_str, skey):
    chksum = hashlib.md5(compact_bytes(params_str + skey, 'utf8')).hexdigest()
    return '{}?{}&sign={}'.format(api_url, params_str, chksum)
Пример #30
0
    def prepare(self):

        if not self.vid:
            self.vid = match1(self.url, 'http://music.baidu.com/song/([\d]+)')

        param = urlencode({'songIds': self.vid})

        song_data = json.loads(get_content('http://play.baidu.com/data/music/songlink', data=compact_bytes(param, 'utf-8')))['data']['songList'][0]

        self.title = song_data['songName']
        self.artist = song_data['artistName']

        self.stream_types.append('current')
        self.streams['current'] = {'container': song_data['format'], 'video_profile': 'current', 'src' : [song_data['songLink']], 'size': song_data['size']}
Пример #31
0
 def test_compact_bytes(self):
     self.assertEqual(compact_bytes('abc', 'utf-8'), 'abc'.encode('utf-8'))
     self.assertEqual(compact_bytes(u'你好', 'utf-8'), u'你好'.encode('utf-8'))
Пример #32
0
def AES_128_CBC_b64_wrapper(data, key, iv):
    obj = AES.new(compact_bytes(key, 'utf-8'), AES.MODE_CBC, compact_bytes(iv, 'utf-8'))
    input_data = pksc7_padding(data)
    out = obj.encrypt(compact_bytes(input_data, 'utf-8'))
    return base64.b64encode(out).decode('utf8')
Пример #33
0
def sign_api_url(api_url, params_str, skey):
    chksum = hashlib.md5(compact_bytes(params_str + skey, 'utf8')).hexdigest()
    return '{}?{}&sign={}'.format(api_url, params_str, chksum)
Пример #34
0
def getDispathKey(rid):
    tp=")(*&^flash@#$%a"  #magic from swf
    time=json.loads(get_content("http://data.video.qiyi.com/t?tn="+str(random())))["t"]
    t=str(int(floor(int(time)/(10*60.0))))
    return hashlib.new("md5",compact_bytes(t+tp+rid,"utf-8")).hexdigest()
Пример #35
0
    def prepare(self):
        info = VideoInfo(self.name)
        if not self.vid:
            self.vid = match1(self.url, 'sid=(\d+)')

        params = {
            "source" : "",
            "sids" : self.vid,
            "ck" : ""
        }
        form = urlencode(params)
        data = json.loads(get_content('https://music.douban.com/j/artist/playlist', data = compact_bytes(form, 'utf-8')))
        self.song_info = data['songs'][0]
        self.extract_song(info)
        return info
Пример #36
0
def md5(s):
    return hashlib.md5(compact_bytes(s, 'utf8')).hexdigest()
Пример #37
0
 def test_compact_bytes(self):
     self.assertEqual(compact_bytes('abc', 'utf-8'), 'abc'.encode('utf-8'))
     self.assertEqual(compact_bytes(u'你好', 'utf-8'), u'你好'.encode('utf-8'))
Пример #38
0
    def get_stream_info(self, profile):


        player_pid = uuid.uuid4().hex.upper()

        params = {
            'fp2p': 1,
            'pid': player_pid,
            'otype': 'xml',
            'defn': profile,
            'platform': 1,
            'fhdswitch': 0,
            'charge': 0,
            'ckey' : "",
            'vid': self.vid,
            'defnpayver': 1,
            'encryptVer': "",
            'speed': random.randint(512, 1024),
            'ran': random.random(),
            'appver': PLAYER_VERSION,
            'defaultfmt': profile,
            'utype': -1,
            'vids': self.vid
        }

        form = urlencode(params)
        content = get_content('http://vv.video.qq.com/getinfo',data=compact_bytes(form, 'utf-8'), charset = 'ignore')
        tree = ET.fromstring(content)
        fmt_id = None
        fmt_name = None
        fmt_br = None
        for fmt in tree.findall('./fl/fi'):
            sl = int(fmt.find('./sl').text)
            if sl:
                fmt_id = fmt.find('./id').text
                fmt_name = fmt.find('./name').text
                fmt_br = fmt.find('./br').text

        video = tree.find('./vl/vi')
        filename = video.find('./fn').text
        title = video.find('./ti').text

        cdn = video.find('./ul/ui')
        cdn_url = cdn.find('./url').text
        filetype = int(cdn.find('./dt').text)
        vt = cdn.find('./vt').text
        if filetype == 1:
            type_name = 'flv'
        elif filetype == 2:
            type_name = 'mp4'
        else:
            type_name = 'unknown'

        num_clips = len(video.findall('./cl/ci'))
        size = int(video.find('./fs').text)

        fns = os.path.splitext(filename)

        #may have preformence issue when info_only
        urls =[]

        if num_clips == 0:
            params = {
                'ran': random.random(),
                'appver': PLAYER_VERSION,
                'otype': 'xml',
                'encryptVer': "",
                'platform': 1,
                'filename': filename,
                'vid': self.vid,
                'vt': vt,
                'charge': 0,
                'format': fmt_id,
                'cKey': "",
            }

            form = urlencode(params)
            clip_url = '%s%s' % (cdn_url, filename)
            urls.append(qq_get_final_url(clip_url, fmt_name, type_name, fmt_br, form, filename))

        else:
            for idx in range(1, num_clips+1):
                fn = '%s.%d%s' % (fns[0], idx, fns[1])
                params = {
                    'ran': random.random(),
                    'appver': PLAYER_VERSION,
                    'otype': 'xml',
                    'encryptVer': "",
                    'platform': 1,
                    'filename': fn,
                    'vid': self.vid,
                    'vt': vt,
                    'charge': 0,
                    'format': fmt_id,
                    'cKey': "",
                }
                form = urlencode(params)
                clip_url = '%s%s' % (cdn_url, fn)
                urls.append(qq_get_final_url(clip_url, fmt_name, type_name, fmt_br, form, fn))

        return title, fmt_name, type_name, urls, size
Пример #39
0
def mix(tvid):
    salt = '4a1caba4b4465345366f28da7c117d20'
    tm = str(randint(2000,4000))
    sc = hashlib.new('md5', compact_bytes(salt + tm + tvid, 'utf-8')).hexdigest()
    return tm, sc, 'eknas'
Пример #40
0
    def get_streams_info(self, profile='shd'):

        player_pid = uuid.uuid4().hex.upper()

        params = {
            'fp2p': 1,
            'pid': player_pid,
            'otype': 'xml',
            'defn': profile,
            'platform': PLAYER_PLATFORM,
            'fhdswitch': 0,
            'charge': 0,
            'ckey' : "",
            'vid': self.vid,
            'defnpayver': 1,
            'encryptVer': "",
            'speed': random.randint(512, 1024),
            'ran': random.random(),
            'appver': PLAYER_VERSION,
            'defaultfmt': profile,
            'utype': -1,
            'vids': self.vid
        }

        form = urlencode(params)
        content = get_content('http://vv.video.qq.com/getinfo',data=compact_bytes(form, 'utf-8'), charset = 'ignore')
        if profile == 'shd' and b'<name>shd' not in content:
            for infos in self.get_streams_info('hd'):
                yield infos
            return
        else:
            tree = ET.fromstring(content)

        video = tree.find('./vl/vi')
        filename = video.find('./fn').text
        title = video.find('./ti').text

        cdn = video.find('./ul/ui')
        cdn_url = cdn.find('./url').text
        filetype = int(cdn.find('./dt').text)
        vt = cdn.find('./vt').text
        if filetype == 1:
            type_name = 'flv'
        elif filetype == 2:
            type_name = 'mp4'
        else:
            type_name = 'unknown'

        _num_clips = int(video.find('./cl/fc').text)

        fmt_id = None
        fmt_name = None
        fmt_br = None
        for fmt in tree.findall('./fl/fi'):
            fmt_id = fmt.find('./id').text
            fmt_name = fmt.find('./name').text
            fmt_br = fmt.find('./br').text
            size = int(fmt.find('./fs').text)
            #sl = int(fmt.find('./sl').text)

            fns = filename.split('.')
            fmt_id_num = int(fmt_id)
            fmt_id_prefix = None
            num_clips = 0
            if fmt_id_num > 100000:
                fmt_id_prefix = 'm'
            elif fmt_id_num > 10000:
                fmt_id_prefix = 'p'
                num_clips = _num_clips or 1
            if fmt_id_prefix:
                fmt_id_name = fmt_id_prefix + str(fmt_id_num % 10000)
                if fns[1][0] in ('p', 'm') and not fns[1].startswith('mp'):
                    fns[1] = fmt_id_name
                else:
                    fns.insert(1, fmt_id_name)
            elif fns[1][0] in ('p', 'm') and not fns[1].startswith('mp'):
                del fns[1]

            #may have preformence issue when info_only
            urls =[]

            if num_clips == 0:
                fn = '.'.join(fns)
                params = {
                    'ran': random.random(),
                    'appver': PLAYER_VERSION,
                    'otype': 'xml',
                    'encryptVer': "",
                    'platform': PLAYER_PLATFORM,
                    'filename': fn,
                    'vid': self.vid,
                    'vt': vt,
                    'charge': 0,
                    'format': fmt_id,
                    'cKey': "",
                }

                form = urlencode(params)
                clip_url = '%s%s' % (cdn_url, fn)
                urls.append(qq_get_final_url(clip_url, fmt_name, type_name, fmt_br, form, fn))

            else:
                fns.insert(-1, '1')
                for idx in range(1, num_clips+1):
                    fns[-2] = str(idx)
                    fn = '.'.join(fns)
                    params = {
                        'ran': random.random(),
                        'appver': PLAYER_VERSION,
                        'otype': 'xml',
                        'encryptVer': "",
                        'platform': PLAYER_PLATFORM,
                        'filename': fn,
                        'vid': self.vid,
                        'vt': vt,
                        'charge': 0,
                        'format': fmt_id,
                        'cKey': "",
                    }
                    form = urlencode(params)
                    clip_url = '%s%s' % (cdn_url, fn)
                    url = qq_get_final_url(clip_url, fmt_name, type_name, fmt_br, form, fn)
                    if url:
                        urls.append(url)
                    else:
                        self.vip = True
                        break

            yield title, fmt_name, type_name, urls, size
Пример #41
0
 def get_api_url(self, q):
     sign_this = hashlib.md5(compact_bytes('cid={}&from=miniplay&player=1&quality={}{}'.format(self.vid, q, SECRETKEY_MINILOADER), 'utf-8')).hexdigest()
     return 'http://interface.bilibili.com/playurl?cid={}&player=1&quality={}&from=miniplay&sign={}'.format(self.vid, q, sign_this)
Пример #42
0
    def get_stream_info(self, profile):

        player_pid = uuid.uuid4().hex.upper()

        params = {
            'fp2p': 1,
            'pid': player_pid,
            'otype': 'xml',
            'defn': profile,
            'platform': 1,
            'fhdswitch': 0,
            'charge': 0,
            'ckey': "",
            'vid': self.vid,
            'defnpayver': 1,
            'encryptVer': "",
            'speed': random.randint(512, 1024),
            'ran': random.random(),
            'appver': PLAYER_VERSION,
            'defaultfmt': profile,
            'utype': -1,
            'vids': self.vid
        }

        form = urlencode(params)
        content = get_content('http://vv.video.qq.com/getinfo',
                              data=compact_bytes(form, 'utf-8'),
                              charset='ignore')
        tree = ET.fromstring(content)
        fmt_id = None
        fmt_name = None
        fmt_br = None
        for fmt in tree.findall('./fl/fi'):
            sl = int(fmt.find('./sl').text)
            if sl:
                fmt_id = fmt.find('./id').text
                fmt_name = fmt.find('./name').text
                fmt_br = fmt.find('./br').text

        video = tree.find('./vl/vi')
        filename = video.find('./fn').text
        title = video.find('./ti').text

        cdn = video.find('./ul/ui')
        cdn_url = cdn.find('./url').text
        filetype = int(cdn.find('./dt').text)
        vt = cdn.find('./vt').text
        if filetype == 1:
            type_name = 'flv'
        elif filetype == 2:
            type_name = 'mp4'
        else:
            type_name = 'unknown'

        num_clips = len(video.findall('./cl/ci'))
        size = int(video.find('./fs').text)

        fns = os.path.splitext(filename)

        #may have preformence issue when info_only
        urls = []

        if num_clips == 0:
            params = {
                'ran': random.random(),
                'appver': PLAYER_VERSION,
                'otype': 'xml',
                'encryptVer': "",
                'platform': 1,
                'filename': filename,
                'vid': self.vid,
                'vt': vt,
                'charge': 0,
                'format': fmt_id,
                'cKey': "",
            }

            form = urlencode(params)
            clip_url = '%s%s' % (cdn_url, filename)
            urls.append(
                qq_get_final_url(clip_url, fmt_name, type_name, fmt_br, form,
                                 filename))

        else:
            for idx in range(1, num_clips + 1):
                fn = '%s.%d%s' % (fns[0], idx, fns[1])
                params = {
                    'ran': random.random(),
                    'appver': PLAYER_VERSION,
                    'otype': 'xml',
                    'encryptVer': "",
                    'platform': 1,
                    'filename': fn,
                    'vid': self.vid,
                    'vt': vt,
                    'charge': 0,
                    'format': fmt_id,
                    'cKey': "",
                }
                form = urlencode(params)
                clip_url = '%s%s' % (cdn_url, fn)
                urls.append(
                    qq_get_final_url(clip_url, fmt_name, type_name, fmt_br,
                                     form, fn))

        return title, fmt_name, type_name, urls, size
Пример #43
0
def md5(s):
    return hashlib.md5(compact_bytes(s, 'utf8')).hexdigest()
Пример #44
0
def AES_128_CBC_b64_wrapper(data, key, iv):
    obj = AES.new(compact_bytes(key, 'utf-8'), AES.MODE_CBC,
                  compact_bytes(iv, 'utf-8'))
    input_data = pksc7_padding(data)
    out = obj.encrypt(compact_bytes(input_data, 'utf-8'))
    return base64.b64encode(out).decode('utf8')
Пример #45
0
    def parser_list(self, url):

        sids = match1(url, 'sid=([0-9,]+)')

        params = {
            "source" : "",
            "sids" : sids,
            "ck" : ""
        }
        form = urlencode(params)
        data = json.loads(get_content('https://music.douban.com/j/artist/playlist', data = compact_bytes(form, 'utf-8')))

        info_list = []
        for s in data['songs']:
            info = VideoInfo(self.name)
            self.song_info = s
            self.extract_song(info)
            info_list.append(info)
        return info_list