Ejemplo n.º 1
0
    def __extract__(self):
        self.program = self.res_json['vinfo']['vl']['vi'][0]

        # target video urls
        m3u8 = self.getM3U8()
        if not m3u8:
            _step = self.program['ul']['ui'][0]['url'].split('/')
            url = self.program['ul']['ui'][0]['url']
            if _step[-1] and 'm3u8' in _step[-1]:
                self.extract_m3u8_url(url)
            elif self.program['ul']['ui'][0].get('hls'):
                url = urljoin(url, self.program['ul']['ui'][0]['hls']['pt'])
                self.extract_m3u8_url(url)
            else:
                self._target_video_urls = []
                base_name, ext = os.path.splitext(self.program['fn'])
                format_name = base_name + '.%d' + ext
                filenames = [
                    format_name % (i + 1)
                    for i in range(len(self.program['cl']['ci']))
                ]
                vkeys, _ = self.get_all_vkey(filenames,
                                             self.program['ul']['ui'][0]['vt'])
                for i, j in enumerate(vkeys):
                    url = urljoin(url, filenames[i])
                    query = {
                        'vkey': j,
                        'sdtfrom': self.extra_info.sdtfrom,
                        'guid': self.extra_info.guid,
                    }
                    url = make_query(url, query)
                    self._target_video_urls.append(url)
        else:
            self.extract_m3u8(m3u8)
Ejemplo n.º 2
0
    def __extract_m3u8__(self, m3u8):
        if m3u8:
            m3u8_parts = re.compile('#EXTINF:([\d\.]+),\s+(http://data.video.iqiyi.com/videos/\S+)').findall(m3u8)
            rex_filename = re.compile('/([a-z|A-Z|0-9]+)\.([A-Z|a-z|0-9]+)\?')

            filenames = []
            reverse_parts = m3u8_parts[::-1]
            reverse_part_tails = []

            video_len_counter = 0
            for i in reverse_parts:
                video_len_counter += int(i[0])

                res = rex_filename.search(i[1])
                if res.group(1) not in filenames:
                    filenames.append(res.group(1))
                    reverse_part_tails.append(i[1])

            self._video_len = video_len_counter * 1000
            # complete total file
            part_tails = reverse_part_tails[::-1]
            ret = []
            for i in part_tails:
                ret.append(make_query(i, {'start': '0'}))

            return ret
        return []
Ejemplo n.º 3
0
    def api_parse(self, base_params, add_params):
        """from api: https://api.bilibili.com/x/player/playurl?
        """
        req_params = base_params.copy()

        req_params.update(add_params)
        playurl = make_query(API['durl'], req_params)

        text = self.request(playurl)

        return json.loads(text)
Ejemplo n.º 4
0
    def auth_refresh(self):
        add_params = logintoken_auth_refresh.copy()
        add_params['_'] = str(int(time.time() * 1000))
        add_params['type'] = self.user.main_login

        new_url = make_query(AUTH_REFRESH_URL, add_params)

        res = self.requestRaw(url=new_url)
        raw = res.read()
        text = raw_decompress(raw, res.info())

        res.close()
        res_josn = json.loads(text[text.index('{'):])

        if res_josn['errcode'] != 0:
            raise Exception('导入的cookie不正确,返回:', res_josn['msg'])

        self.user.extract_headers(res.info().get_all('set-cookie'))
        new_cookie_str = self.user.dumps()
        self.saveCookie(new_cookie_str)
        self.loadCookie(new_cookie_str)
        return True
Ejemplo n.º 5
0
    def make_dispatch_urls(self, fs):
        rex_filename = re.compile('/([a-z|A-Z|0-9]+)\.([A-Z|a-z|0-9]+)\?')
        paths = []
        filenames = []
        t_s = []

        boss = self.get_boss()
        albumid = self.get_albumid()
        tvid = self.get_tvid()
        vid = self.get_vid()
        qyid = self.parent.user.k_uid
        qypid = '%s__02020031010000000000' % tvid

        for i, j in enumerate(fs):
            paths.append(j['l'])
            filenames.append(rex_filename.search(paths[i]).group(1))
            t_s.append(str(boss.get('data', {}).get('t', '')) if boss else '')

        ibts_tmp = []
        with PyJSCaller.Sesson('js/iqiyi.js') as sess:
            cmd5x = sess.require('cmd5x')
            for i in range(len(fs)):
                ibt = cmd5x(str(t_s[i] + filenames[i]))
                ibts_tmp.append(ibt)
                sess.call(ibt)

        ibts = [i.getValue() for i in ibts_tmp]
        all_res = []
        for i in range(len(fs)):
            if boss and boss.get(
                    'data', {}).get('prv') == 1 and boss['previewTime'] == 1:
                ptime = int(60 * 1 * 1e3)
            else:
                ptime = 0

            QY00001 = boss.get('data', {}).get('u', '') if boss else ''

            params = {
                'cross-domain': '1',
                'qyid': qyid,
                'qypid': qypid,
                't': t_s[i],
                'cid': 'afbe8fd3d73448c9',
                'vid': vid,
                'QY00001': QY00001,
                'ibt': ibts[i],
                'ib': '4',
                'ptime': ptime,  # pcweb.js: getPreviewTime: function(e)
                'su': qyid,
                'client': '',  # pcweb.js: e.currentUserIP
                'z': '',  # pcweb.js: e.preDispatchArea
                'bt': '',  # pcweb.js: e.preDefinition
                'ct': '5',  # pcweb.js: e.currentDefinition
                # pcweb.js: mi: "tv_" + t.albumId + "_" + t.tvid + "_" + t.vid,
                'mi': 'tv_%s_%s_%s' % (albumid, tvid, vid),
                'e': '',
                'pv': '0.1',
                'tn': str(random.random()),
            }

            path = make_query(paths[i], params)
            text = self.parent.request(
                'https://data.video.iqiyi.com/videos/%s' % path.lstrip('/'))
            msg = json.loads(text)
            all_res.append(msg)

        return all_res