Exemple #1
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
Exemple #2
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
Exemple #3
0
    def prepare(self):
        info = VideoInfo(self.name, True)
        ID = match1(self.url, "/(\d+)")
        api1_data = json.loads(get_content("{}?id={}".format(api1_url, ID)))
        self.vid = api1_data["data"]["room_id"]
        api2_data = json.loads(get_content("{}?room_id={}&from=room".format(api2_url, self.vid)))
        info.title = api2_data["data"]["title"]
        assert api2_data["data"]["live_status"] == 1, u"主播正在觅食......"

        def get_live_info(q=0):
            data = json.loads(get_content("{}?player=1&cid={}&quality={}&otype=json".format(api_url, self.vid, q)))

            assert data["code"] == 0, data["msg"]

            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()
        return info
Exemple #4
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
Exemple #5
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+)')

        for stream in self.stream_ids:
            tt = int(time.time())
            rate = self.stream_id_2_rate[stream]
            signContent = 'lapi/live/thirdPart/getPlay/{}?aid=pcclient&rate={}&time={}9TUk5fjjUjg9qIMH3sdnh'.format(self.vid, rate , tt)
            sign = md5(signContent.encode('utf-8')).hexdigest()
            url = 'http://coapi.douyucdn.cn/lapi/live/thirdPart/getPlay/{}?rate={}'.format(self.vid, rate)

            html_content = get_content(url, headers = {		'auth': sign, 'time': str(tt), 'aid': 'pcclient' })
            live_data = json.loads(html_content)['data']

            real_url = live_data['live_url']

            info.stream_types.append(stream)
            info.streams[stream] = {'container': 'flv', 'video_profile': self.id_2_profile[stream], 'src' : [real_url], 'size': float('inf')}
            info.title = live_data['room_name']
        return info
Exemple #6
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
Exemple #7
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
Exemple #8
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
Exemple #9
0
    def parser_list(self, url):
        add_header("Referer", "http://music.163.com/")
        vid =  match1(url, 'id=(.*)')
        if "album" in url:
           api_url = "http://music.163.com/api/album/{}?id={}&csrf_token=".format(vid, vid)
           listdata = json.loads(get_content(api_url))
           playlist = listdata['album']['songs']
        elif "playlist" in url:
           api_url = "http://music.163.com/api/playlist/detail?id={}&csrf_token=".format(vid)
           listdata = json.loads(get_content(api_url))
           playlist = listdata['result']['tracks']
        elif "toplist" in url:
           api_url = "http://music.163.com/api/playlist/detail?id={}&csrf_token=".format(vid)
           listdata = json.loads(get_content(api_url))
           playlist = listdata['result']['tracks']
        elif "artist" in url:
           api_url = "http://music.163.com/api/artist/{}?id={}&csrf_token=".format(vid, vid)
           listdata = json.loads(get_content(api_url))
           playlist = listdata['hotSongs']

        info_list = []
        for music in playlist:
            info = VideoInfo(self.name)
            info.title = music['name']
            info.artist = music['artists'][0]['name']
            self.mp3_host = music['mp3Url'][8]
            for st in self.supported_stream_types:
                if st in music and music[st]:
                    info.stream_types.append(st)
                    self.song_date[st] = music[st]
            self.extract_song(info)
            info_list.append(info)
        return info_list
Exemple #10
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
Exemple #11
0
    def prepare(self):
        html = get_content(self.url)
        title = match1(html, u'<title>(.+?)丨嘀哩嘀哩</title>')
        source_url = match1(html, r'var sourceUrl\s?=\s?"(.+?)"', r'var Url\s?=\s?"(.+?)"')
        
        # First type, bangumi
        # http://www.dilidili.wang/watch3/72766/ or
        # http://www.dilidili.wang/watch3/52919/
        if source_url:
            ext = source_url.split('?')[0].split('.')[-1]
        
            # Dilidili hosts this video itself
            if ext in ('mp4', 'flv', 'f4v', 'm3u', 'm3u8'):
                self.build_videoinfo(title, ext, source_url)
        
            # It is an embedded video from other websites
            else:
                self.video_info['url'] = source_url
                self.video_info['title'] = title

        # Second type, user-uploaded videos
        # http://www.dilidili.wang/huiyuan/76983/
        else:
            player_url = match1(html, r'<iframe src="(.+?)"')
            html = get_content(player_url)
            video_url = match1(html, r'var main = "(.+?)"')
            video_url_full = '/'.join(player_url.split('/')[0:3]) + video_url
            ext = video_url.split('?')[0].split('.')[-1]
            self.build_videoinfo(title, ext, video_url_full)
Exemple #12
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
Exemple #13
0
    def prepare(self):
        info = VideoInfo(self.name)
        if not self.vid:
            html = get_content(self.url)
            self.vid = match1(html, 'video_id:\'([^\']+)') or match1(self.url, '#(\d+)')

        assert self.vid, "can't get vid"

        api_url = 'http://s.video.sina.com.cn/video/h5play?video_id={}'.format(self.vid)
        data = json.loads(get_content(api_url))['data']
        info.title = data['title']
        for t in ['mp4', '3gp', 'flv']:
            if t in data['videos']:
                video_info = data['videos'][t]
                break

        for profile in video_info:
            if not profile in info.stream_types:
                v = video_info[profile]
                tp = v['type']
                url = v['file_api']+'?vid='+v['file_id']
                r_url = get_realurl(url)
                info.stream_types.append(profile)
                info.streams[profile] = {'container': tp, 'video_profile': profile, 'src': [r_url], 'size' : 0}
        return info
Exemple #14
0
    def prepare(self):
        info = VideoInfo(self.name, True)
        if not self.vid:
            self.vid = match1(self.url, '/(\d+)')
        if not self.vid:
            html = get_content(self.url)
            self.vid = match1(html, '"room_id":(\d+)')

        #from upstream!!
        api_url = 'http://www.qie.tv/api/v1/room/{}'.format(self.vid)

        metadata = json.loads(get_content(api_url))
        assert metadata['error'] == 0, 'error {}: {}'.format(metadata['error'], metadata['data'])

        livedata = metadata['data']
        assert livedata['show_status'] == '1', 'error: live show is not on line!!'

        info.title = livedata['room_name']
        info.artist = livedata['nickname']

        base_url = livedata['rtmp_url']

        if 'hls_url' in livedata:
            info.stream_types.append('BD')
            info.streams['BD'] = {'container': 'm3u8', 'video_profile': u'原画', 'src' : [livedata['hls_url']], 'size': float('inf')}

        mutli_stream = livedata['rtmp_multi_bitrate']
        for i in self.mutli_bitrate:
            if i in mutli_stream:
                info.stream_types.append(self.bitrate_2_type[i])
                info.streams[self.bitrate_2_type[i]] = {'container': 'flv', 'video_profile': self.bitrate_2_profile[i], 'src' : [base_url + '/' + mutli_stream[i]], 'size': float('inf')}
        return info
Exemple #15
0
    def prepare(self):
        info = VideoInfo(self.name)
        stream_temp = {'1080p': None , '1300': None, '1000':None , '720p': None, '350': None }
        self.__STREAM_TEMP__.append(stream_temp)
        if not self.vid:
            self.vid = match1(self.url, r'http://www.le.com/ptv/vplay/(\d+).html', '#record/(\d+)')

        #normal process
        info_url = 'http://api.le.com/mms/out/video/playJson?id={}&platid=1&splatid=101&format=1&tkey={}&domain=www.le.com'.format(self.vid, calcTimeKey(int(time.time())))
        r = get_content(info_url)
        data=json.loads(r)

        info.title = data['playurl']['title']
        available_stream_id = sorted(list(data["playurl"]["dispatch"].keys()), key = self.supported_stream_types.index)
        for stream in available_stream_id:
            s_url =data["playurl"]["domain"][0]+data["playurl"]["dispatch"][stream][0]
            s_url+="&ctv=pc&m3v=1&termid=1&format=1&hwtype=un&ostype=Linux&tag=le&sign=le&expect=3&tn={}&pay=0&iscpn=f9051&rateid={}".format(random.random(),stream)
            r2=get_content(s_url)
            data2=json.loads(r2)

            # hold on ! more things to do
            # to decode m3u8 (encoded)
            m3u8 = get_content(data2["location"], charset = 'ignore')
            m3u8_list = decode(m3u8)
            stream_id = self.stream_2_id[stream]
            info.streams[stream_id] = {'container': 'm3u8', 'video_profile': self.stream_2_profile[stream], 'size' : 0}
            stream_temp[stream] = compact_tempfile(mode='w+t', suffix='.m3u8')
            stream_temp[stream].write(m3u8_list)
            info.streams[stream_id]['src'] = [stream_temp[stream].name]
            stream_temp[stream].flush()
            info.stream_types.append(stream_id)
        return info
Exemple #16
0
    def prepare(self):

        if not self.vid:
            self.vid = match1(self.url, r'http://www.le.com/ptv/vplay/(\d+).html', '#record/(\d+)')

        #normal process
        info_url = 'http://api.le.com/mms/out/video/playJson?id={}&platid=1&splatid=101&format=1&tkey={}&domain=www.le.com'.format(self.vid, calcTimeKey(int(time.time())))
        r = get_content(info_url)
        info=json.loads(r)

        self.title = info['playurl']['title']
        available_stream_id = info["playurl"]["dispatch"].keys()
        for stream in self.supported_stream_types:
            if stream in available_stream_id:
                s_url =info["playurl"]["domain"][0]+info["playurl"]["dispatch"][stream][0]
                s_url+="&ctv=pc&m3v=1&termid=1&format=1&hwtype=un&ostype=Linux&tag=le&sign=le&expect=3&tn={}&pay=0&iscpn=f9051&rateid={}".format(random.random(),stream)
                r2=get_content(s_url)
                info2=json.loads(r2)

                # hold on ! more things to do
                # to decode m3u8 (encoded)
                m3u8 = get_content(info2["location"], charset = 'ignore')
                m3u8_list = decode(m3u8)
                self.streams[stream] = {'container': 'm3u8', 'video_profile': stream, 'size' : 0}
                import tempfile
                self.streams[stream]['tmp'] = tempfile.NamedTemporaryFile(mode='w+t', suffix='.m3u8')
                self.streams[stream]['tmp'].write(m3u8_list)
                self.streams[stream]['src'] = [self.streams[stream]['tmp'].name]
                self.streams[stream]['tmp'].flush()
                self.stream_types.append(stream)
Exemple #17
0
    def prepare(self):
        info = VideoInfo(self.name)
        if not self.vid:
            self.vid = match1(self.url, '/show(?:/channel)?/([^\./]+)',
                                        '/media/([^\./]+)')
        if not self.vid:
            html = get_content(self.url)
            self.vid = match1(html, 's[cm]id ?= ?[\'"]([^\'"]+)[\'"]')
        assert self.vid, "No VID match!"

        data = json.loads(get_content('https://n.miaopai.com/api/aj_media/info.json?smid={}'.format(self.vid)))
        if 'status' in data:
            if data['status'] != 200:
                data = json.loads(get_content('http://api.miaopai.com/m/v2_channel.json?fillType=259&scid={}&vend=miaopai'.format(self.vid)))

            assert data['status'] == 200, data['msg']

            data = data['result']
            info.title = data['ext']['t'] or self.name + '_' + self.vid
            url = data['stream']['base']
            ext = data['stream']['and']
        else:
            assert data['code'] == 200, data['msg']

            data = data['data']
            info.title = data['description'] or self.name + '_' + self.vid
            url = data['meta_data'][0]['play_urls']['m']
            _, ext, _ = url_info(url)

        info.stream_types.append('current')
        info.streams['current'] = {'container': ext or 'mp4', 'src': [url], 'size' : 0}
        return info
Exemple #18
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
Exemple #19
0
 def prepare_list(self):
     html = get_content(self.url)
     video_list = matchall(html, ['<option value=\'([^\']*)\''])
     if video_list:
         return ['http://www.bilibili.com'+v for v in video_list]
     sid = match1(html, 'var season_id = "(\d+)";')
     j_ = get_content("http://bangumi.bilibili.com/jsonp/seasoninfo/{}.ver".format(sid))
     s_data = json.loads(j_)
     urls = [e['webplay_url'] for e in sorted(s_data['result']['episodes'], key=lambda e: e['index'])]
     return urls
Exemple #20
0
    def setup(self, info):
        # Hot-plug cookie handler
        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)

        add_header('Referer', 'v.youku.com')

        install_acode('4', '1', 'b4et', 'boa4', 'o0b', 'poz')
        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=]+)')

        api_url = 'http://play.youku.com/play/get.json?vid=%s&ct=12' % self.vid
        api_url1 = 'http://play.youku.com/play/get.json?vid=%s&ct=10' % self.vid
        try:
            meta = json.loads(get_content(api_url))
            meta1 = json.loads(get_content(api_url1))
            data = meta['data']
            data1 = meta1['data']
            assert 'stream' in data1
        except:
            if 'error' in data1:
                if data1['error']['code'] == -202:
                    # Password protected
                    self.password_protected = True
                    self.password = input(log.sprint('Password: '******'&pwd={}'.format(self.password)
                    api_url1 += '&pwd={}'.format(self.password)
                    meta1 = json.loads(get_content(api_url1))
                    meta = json.loads(get_content(api_url))
                    data1 = meta1['data']
                    data = meta['data']
                else:
                    raise AssertionError('[Failed] ' + data1['error']['note'])
            else:
                raise AssertionError('[Failed] Video not found.')

        info.title = data['video']['title']
        self.ep = data['security']['encrypt_string']
        self.ip = data['security']['ip']
        try:
            self.stream_data = data1['stream']
        except:
            if self.password_protected:
                raise AssertionError('incorrect password!!')
            else:
                raise AssertionError('No Stream found!!')
Exemple #21
0
    def prepare(self):
        if not self.vid:
            self.vid = match1(self.url, 'yinyue/(\d+)')

        html = get_content("http://player.kuwo.cn/webmusic/st/getNewMuiseByRid?rid=MUSIC_{}".format(self.vid))
        self.title = match1(html, "<name>(.*)</name>")
        self.artist = match1(html, "<artist>(.*)</artist>")
        for t in self.supported_stream_types:
            url=get_content("http://antiserver.kuwo.cn/anti.s?format={}&rid=MUSIC_{}&type=convert_url&response=url".format(t, self.vid))

            self.stream_types.append(t)
            self.streams[t] = {'container': t, 'video_profile': 'current', 'src' : [url], 'size': 0}
Exemple #22
0
    def prepare(self):
        self.live = True
        if not self.vid:
            html = get_content(self.url)
            self.vid = match1(html, "anchorCcId : \'([^\']+)")
            self.title = match1(html, "title: \'([^\']+)")
            self.artist = match1(html, "anchorName : \'([^\']+)")

        info = json.loads(get_content("http://cgi.v.cc.163.com/video_play_url/{}".format(self.vid)))

        self.stream_types.append("current")
        self.streams["current"] = {'container': 'flv', 'video_profile': "current", 'src' : [info["videourl"]], 'size': 0}
Exemple #23
0
    def prepare(self):

        if not self.vid:
            html = get_content(self.url)
            self.vid = match1(html, 'cid=([^&]+)')
            self.title = match1(html, '<title>([^<]+)').split("_")[0]
        for q in self.supported_stream_profile:
            api_url = 'http://interface.bilibili.com/playurl?appkey=' + appkey + '&cid=' + self.vid + '&quality=' + str(3-self.supported_stream_profile.index(q))
            urls, size = parse_cid_playurl(get_content(api_url))
            ext = 'flv'

            self.stream_types.append(self.profile_2_type[q])
            self.streams[self.profile_2_type[q]] = {'container': ext, 'video_profile': q, 'src' : urls, 'size': size}
Exemple #24
0
    def prepare(self):
        info = VideoInfo(self.name, True)
        if not self.vid:
            html = get_content(self.url)
            self.vid = match1(html, "anchorCcId\s*:\s*\'([^\']+)")
            info.title = match1(html, "title:\s*\'([^\']+)")
            info.artist = match1(html, "anchorName\s*:\s*\'([^\']+)")

        data = json.loads(get_content("http://cgi.v.cc.163.com/video_play_url/{}".format(self.vid)))

        info.stream_types.append("current")
        info.streams["current"] = {'container': 'flv', 'video_profile': "current", 'src' : [data["videourl"]], 'size': 0}
        return info
Exemple #25
0
    def prepare(self):
        info = VideoInfo(self.name)
        if not self.vid:
            self.vid = match1(self.url, 'http://www.xiami.com/song/(\d+)', 'http://www.xiami.com/song/detail/id/(\d+)')

        if not self.vid or len(self.vid) < 10:
            html = get_content(self.url)
            line = match1(html, '(.*)立即播放</a>')
            self.vid = match1(line, 'play\(\'(\d+)')

        xml = get_content('http://www.xiami.com/song/playlist/id/{}/object_name/default/object_id/0'.format(self.vid) , charset = 'ignore')
        doc = parseString(xml)
        self.song_data = doc.getElementsByTagName("track")[0]
        self.extract_song(info)
        return info
Exemple #26
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
Exemple #27
0
 def get_vid(url):
     vid = match1(url, 'http://www.mgtv.com/b/\d+/(\d+).html')
     if vid is None:
         html = get_content(url)
         vid = match1(html, 'vid=(\d+)', 'vid=\"(\d+)') or \
             match1(html, r'vid: (\d+)')
     return vid
Exemple #28
0
 def letvcloud_download_by_vu(self):
     info = VideoInfo(self.name)
     #ran = float('0.' + str(random.randint(0, 9999999999999999))) # For ver 2.1
     #str2Hash = 'cfflashformatjsonran{ran}uu{uu}ver2.2vu{vu}bie^#@(%27eib58'.format(vu = vu, uu = uu, ran = ran)  #Magic!/ In ver 2.1
     vu, uu = self.vid
     argumet_dict ={'cf' : 'flash', 'format': 'json', 'ran': str(int(time.time())), 'uu': str(uu),'ver': '2.2', 'vu': str(vu), }
     sign_key = '2f9d6924b33a165a6d8b5d3d42f4f987'  #ALL YOUR BASE ARE BELONG TO US
     str2Hash = ''.join([i + argumet_dict[i] for i in sorted(argumet_dict)]) + sign_key
     sign = hashlib.md5(str2Hash.encode('utf-8')).hexdigest()
     html = get_content('http://api.letvcloud.com/gpc.php?' + '&'.join([i + '=' + argumet_dict[i] for i in argumet_dict]) + '&sign={sign}'.format(sign = sign), charset= 'utf-8')
     data = json.loads(html)
     assert data['code'] == 0, data['message']
     video_name = data['data']['video_info']['video_name']
     if '.' in video_name:
         ext = video_name.split('.')[-1]
         info.title = video_name[0:-len(ext)-1]
     else:
         ext = 'mp4'
         info.title = video_name
     available_stream_type = data['data']['video_info']['media'].keys()
     for stream in self.supported_stream_types:
         if stream in available_stream_type:
             urls = [base64.b64decode(data['data']['video_info']['media'][stream]['play_url']['main_url']).decode("utf-8")]
             info.stream_types.append(stream)
             info.streams[stream] = {'container': ext, 'video_profile': stream, 'src': urls, 'size' : 0}
     return info
Exemple #29
0
    def prepare(self):
        if not self.vid:
            self.vid = match1(self.url, 'http://www.xiami.com/song/(\d+)', 'http://www.xiami.com/song/detail/id/(\d+)')

        xml = get_content('http://www.xiami.com/song/playlist/id/{}/object_name/default/object_id/0'.format(self.vid) , charset = 'ignore')
        doc = parseString(xml)
        self.song_data = doc.getElementsByTagName("track")[0]
Exemple #30
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))
Exemple #31
0
 def prepare_list(self):
     sid = match1(html, 'var season_id = "(\d+)";')
     j_ = get_content(
         "http://bangumi.bilibili.com/jsonp/seasoninfo/{}.ver".format(sid))
     s_data = json.loads(j_)
     urls = [
         e['webplay_url'] for e in sorted(s_data['result']['episodes'],
                                          key=lambda e: e['index'])
     ]
     return urls
Exemple #32
0
    def prepare(self):
        info = VideoInfo(self.name)
        pid = match1(self.url, 'show/(.*)')
        if 'vmobile' in self.url:
            self.url = 'https://v.douyu.com/show/' + pid

        html = get_content(self.url)
        info.title = match1(html, u'title>(.+?)_斗鱼视频 - 最6的弹幕视频网站<')
        self.vid = match1(html, '"point_id":\s?(\d+)')

        js_enc = get_h5enc(html, self.vid)
        params = {'vid': pid}
        ub98484234(js_enc, self, params)

        add_header("Referer", self.url)
        add_header('Cookie', 'dy_did={}'.format(params['did']))

        data = urlencode(params)
        if not isinstance(data, bytes):
            data = data.encode()
        html_content = get_content(
            'https://v.douyu.com/api/stream/getStreamUrl', data=data)
        self.logger.debug('video_data: ' + html_content)

        video_data = json.loads(html_content)
        assert video_data['error'] == 0, video_data

        for video_profile, stream_date in video_data['data'][
                'thumb_video'].items():
            if not stream_date:
                continue
            stream = self.profile_2_id[video_profile]
            info.stream_types.append(stream)
            info.streams[stream] = {
                'container': 'm3u8',
                'video_profile': video_profile,
                'src': [stream_date['url']],
                'size': 0
            }

        info.stream_types = sorted(info.stream_types,
                                   key=self.stream_ids.index)
        return info
Exemple #33
0
    def prepare(self):

        if not self.vid:
            html = get_content(self.url)
            self.vid = match1(html, 'cid=([^&]+)')
            self.title = match1(html, '<title>([^<]+)').split("_")[0]
        for q in self.supported_stream_profile:
            api_url = 'http://interface.bilibili.com/playurl?appkey=' + appkey + '&cid=' + self.vid + '&quality=' + str(
                3 - self.supported_stream_profile.index(q))
            urls, size = parse_cid_playurl(get_content(api_url))
            ext = 'flv'

            self.stream_types.append(self.profile_2_type[q])
            self.streams[self.profile_2_type[q]] = {
                'container': ext,
                'video_profile': q,
                'src': urls,
                'size': size
            }
Exemple #34
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
Exemple #35
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
Exemple #36
0
    def prepare(self):

        if not self.vid:
            self.vid = match1(self.url,
                              r'http://www.le.com/ptv/vplay/(\d+).html',
                              '#record/(\d+)')

        #normal process
        info_url = 'http://api.le.com/mms/out/video/playJson?id={}&platid=1&splatid=101&format=1&tkey={}&domain=www.le.com'.format(
            self.vid, calcTimeKey(int(time.time())))
        r = get_content(info_url)
        info = json.loads(r)

        self.title = info['playurl']['title']
        available_stream_id = info["playurl"]["dispatch"].keys()
        for stream in self.supported_stream_types:
            if stream in available_stream_id:
                s_url = info["playurl"]["domain"][0] + info["playurl"][
                    "dispatch"][stream][0]
                s_url += "&ctv=pc&m3v=1&termid=1&format=1&hwtype=un&ostype=Linux&tag=le&sign=le&expect=3&tn={}&pay=0&iscpn=f9051&rateid={}".format(
                    random.random(), stream)
                r2 = get_content(s_url)
                info2 = json.loads(r2)

                # hold on ! more things to do
                # to decode m3u8 (encoded)
                m3u8 = get_content(info2["location"], charset='ignore')
                m3u8_list = decode(m3u8)
                self.streams[stream] = {
                    'container': 'm3u8',
                    'video_profile': stream,
                    'size': 0
                }
                import tempfile
                self.streams[stream]['tmp'] = tempfile.NamedTemporaryFile(
                    mode='w+t', suffix='.m3u8')
                self.streams[stream]['tmp'].write(m3u8_list)
                self.streams[stream]['src'] = [
                    self.streams[stream]['tmp'].name
                ]
                self.streams[stream]['tmp'].flush()
                self.stream_types.append(stream)
Exemple #37
0
 def prepare_list(self):
     html = get_content(self.url)
     eplist = matchall(html, ['"epList":(\[.*?\])'])
     if eplist:
         eplist = sum(
             map(matchall, eplist, [['"(?:ep_)?id":(\d+),']] * len(eplist)),
             [])
         return [
             'https://www.bilibili.com/bangumi/play/ep{}'.format(eid)
             for eid in eplist
         ]
Exemple #38
0
    def prepare_list(self):

        album_id = match1(self.url, 'http://music.baidu.com/album/([\d]+)')
        data = json.loads(
            get_content(
                'http://play.baidu.com/data/music/box/album?albumId={}&type=album&_={}'
                .format(album_id, time.time())))

        print('album:		%s' % data['data']['albumName'])

        return data['data']['songIdList']
Exemple #39
0
    def prepare(self):
        info = VideoInfo(self.name, True)
        if not self.vid:
            html = get_content(self.url)
            self.vid = match1(html, "anchorCcId\s*:\s*\'([^\']+)")
            info.title = match1(html, "title:\s*\'([^\']+)")
            info.artist = match1(html, "anchorName\s*:\s*\'([^\']+)")

        data = json.loads(
            get_content("http://cgi.v.cc.163.com/video_play_url/{}".format(
                self.vid)))

        info.stream_types.append("current")
        info.streams["current"] = {
            'container': 'flv',
            'video_profile': "current",
            'src': [data["videourl"]],
            'size': 0
        }
        return info
Exemple #40
0
 def prepare(self):
     info = VideoInfo(self.name)
     id1 = match1(self.url, 'a/([^\.]+)\.')
     api1 = 'http://www.kankanews.com/vxml/{}.xml'.format(id1)
     video_data1 = get_content(api1)
     self.vid = match1(video_data1, '<omsid>([^<]+)<')
     if self.vid == '0' or not self.vid:
         html = get_content(self.url)
         id1 = match1(html, 'xmlid=([^\"]+)') or match1(html, 'embed/([^\"]+)').replace('_', '/')
         api1 = 'http://www.kankanews.com/vxml/{}.xml'.format(id1)
         video_data1 = get_content(api1)
         self.vid = match1(video_data1, '<omsid>([^<]+)<')
     assert self.vid != '0' and self.vid, self.url + ': Not a video news link!'
     api2 = 'http://v.kankanews.com/index.php?app=api&mod=public&act=getvideo&id={}'.format(self.vid)
     video_data2 = get_content(api2)
     urls = matchall(video_data2, ['<videourl><!\[CDATA\[([^\]]+)'])
     info.title = match1(video_data2, '<otitle><!\[CDATA\[([^\]]+)')
     info.stream_types.append('current')
     info.streams['current'] = {'container': 'mp4', 'video_profile': 'current', 'src' : urls, 'size': 0}
     return info
Exemple #41
0
 def prepare(self):
     info = VideoInfo(self.name)
     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('http://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
Exemple #42
0
    def get_vid_title(self):

        html = get_content(self.url)
        title = match1(html, '<h1 title="([^"]+)', '<title>([^<]+)').strip()

        eid = match1(self.url, 'anime/v/(\d+)', 'play#(\d+)', 'ep(\d+)',
                     '\d#(\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']
            vid = Episode_info['currentEpisode']['danmaku']
            title = Episode_info['season']['title'] + ' ' + Episode_info[
                'currentEpisode']['indexTitle'] + '.  ' + Episode_info[
                    'currentEpisode']['longTitle']
        else:
            vid = match1(html, 'cid=(\d+)', 'cid=\"(\d+)', '\"cid\":(\d+)')

        return vid, title
Exemple #43
0
    def get_vid_title(self):
        if "#page=" in self.url:
            page_index = match1(self.url, '#page=(\d+)')
            av_id = match1(self.url, '\/(av\d+)')
            self.url = 'http://www.bilibili.com/{}/index_{}.html'.format(av_id, page_index)
        if not self.vid:
            html = get_content(self.url)
            vid = match1(html, 'cid=(\d+)', 'cid=\"(\d+)')
            title = match1(html, '<h1 title="([^"]+)', '<title>([^<]+)').strip()

        return vid, title
Exemple #44
0
    def get_path_list(self):
        html = get_content(self.url)
        albumId = match1(self.url, '/a[ab](\d+)')
        groupId = match1(html, '"groups":[{[^}]*?"id":(\d+)')
        contentsCount = int(match1(html, '"contentsCount":(\d+)'))
        params = {
            'albumId': albumId,
            'groupId': groupId,
            'num': 1,
            'size': max(contentsCount, 20),
            '_': int(time.time() * 1000),
        }
        data = json.loads(get_content('https://www.acfun.cn/album/abm/bangumis/video?' + urlencode(params)))
        videos = []
        for c in data['data']['content']:
            vid = c['videos'][0]['id']
            v = '/bangumi/ab{}_{}_{}'.format(albumId, groupId, vid)
            videos.append(v)

        return videos
Exemple #45
0
    def prepare(self):
        info = VideoInfo(self.name, True)
        ID = match1(self.url, "/(\d+)")
        api1_data = json.loads(get_content("{}?id={}".format(api1_url, ID)))
        self.vid = api1_data["data"]["room_id"]
        api2_data = json.loads(
            get_content("{}?room_id={}&from=room".format(api2_url, self.vid)))
        info.title = api2_data["data"]["title"]
        assert api2_data["data"]["live_status"] == 1, u"主播正在觅食......"

        def get_live_info(q=0):
            data = json.loads(
                get_content("{}?player=1&cid={}&quality={}&otype=json".format(
                    api_url, self.vid, q)))

            assert data["code"] == 0, data["msg"]

            data = data["data"]
            urls = [data["durl"][0]["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()
        return info
Exemple #46
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+)')
            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[
                        'index'] + '.  ' + 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)
            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
Exemple #47
0
    def prepare(self):
        info = VideoInfo(self.name)
        if not self.vid:
            self.vid = match1(self.url, '/show(?:/channel)?/([^\./]+)',
                                        '/media/([^\./]+)')
        if not self.vid:
            html = get_content(self.url)
            self.vid = match1(html, 's[cm]id ?= ?[\'"]([^\'"]+)[\'"]')
        assert self.vid, "No VID match!"

        data = json.loads(get_content('https://n.miaopai.com/api/aj_media/info.json?smid={}'.format(self.vid)))
        assert data['code'] == 200, data['msg']

        data = data['data']
        info.title = data['description'] or self.name + '_' + self.vid
        url = data['meta_data'][0]['play_urls']['m']
        _, ext, _ = url_info(url)

        info.stream_types.append('current')
        info.streams['current'] = {'container': ext or 'mp4', 'src': [url], 'size' : 0}
        return info
Exemple #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
Exemple #49
0
    def prepare(self):
        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]
Exemple #50
0
    def extract_single(self, stream_id):

        date = datetime.datetime.now()

        streamUrl = self.streams[stream_id][
            '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))

        self.streams[stream_id]['src'] = [data['location']]
Exemple #51
0
    def get_page_info(self):
        html = get_content(self.url)
        date = json.loads(match1(html, '__INITIAL_STATE__=({.+?});'))
        vid = date['epInfo']['cid']
        mediaInfo = date['mediaInfo']
        self.seasonType = mediaInfo.get('ssType')
        title = date.get('h1Title') or \
                match1(html, '<title>(.+?)[_-]\w+[_-]bilibili[_-]哔哩哔哩<')
        upInfo = mediaInfo.get('upInfo')
        artist = upInfo and upInfo.get('name')

        return vid, title, artist
Exemple #52
0
    def download_playlist(self, url, param):

        album_id = match1(url, 'http://music.baidu.com/album/([\d]+)')
        data = json.loads(
            get_content(
                'http://play.baidu.com/data/music/box/album?albumId={}&type=album&_={}'
                .format(album_id, time.time())))

        print('album:		%s' % data['data']['albumName'])

        for s in data['data']['songIdList']:
            self.download(s, param)
Exemple #53
0
 def prepare_list(self):
     # backup https://api.bilibili.com/x/player/pagelist?bvid=
     vid = match1(self.url, '/(av\d+|BV[0-9A-Za-z]{10})')
     if vid[:2] == 'av':
         vid = av2bv(vid)
     html = get_content(self.url)
     video_list = matchall(html, ['"page":(\d+),'])
     if video_list:
         return [
             'https://www.bilibili.com/video/{}?p={}'.format(vid, p)
             for p in video_list
         ]
Exemple #54
0
    def prepare(self):
        if not self.vid:
            self.vid = match1(self.url, 'yinyue/(\d+)')

        html = get_content(
            "http://player.kuwo.cn/webmusic/st/getNewMuiseByRid?rid=MUSIC_{}".
            format(self.vid))
        self.title = match1(html, "<name>(.*)</name>")
        self.artist = match1(html, "<artist>(.*)</artist>")
        for t in self.supported_stream_types:
            url = get_content(
                "http://antiserver.kuwo.cn/anti.s?format={}&rid=MUSIC_{}&type=convert_url&response=url"
                .format(t, self.vid))

            self.stream_types.append(t)
            self.streams[t] = {
                'container': t,
                'video_profile': 'current',
                'src': [url],
                'size': 0
            }
Exemple #55
0
    def prepare(self):
        video = VideoInfo(self.name)
        if self.url and not self.vid:
            html = get_content(self.url)
            self.vid = match1(html, '\/([0-9]+)\/v\.swf', '\&id=(\d+)',
                              'vid=\"(\d+)\"')
        self.logger.debug("VID> {}".format(self.vid))
        info = json.loads(get_content(self.apiurl % self.vid))
        self.logger.debug("info> {}".format(info))
        if info['status'] == 1:
            data = info['data']
            video.title = data['tvName']
            for stream in self.supported_stream_types:
                lvid = data[stream]
                if lvid == 0 or not lvid:
                    continue
                if lvid != self.vid:
                    info = json.loads(get_content(self.apiurl % lvid))

                self.parser_info(video, info, stream, lvid)
        return video
Exemple #56
0
 def prepare_data(self):
     html = get_content(self.url)
     js = match1(html, 'window\.__NUXT__=(.+);</script>')
     js_ctx = JSEngine()
     data = js_ctx.eval(js)
     self.logger.debug('video_data: \n%s', data)
     try:
         self.url = data['data'][0]['playUrl']
     except KeyError:
         self.data = data
     else:
         self.prepare_data()
Exemple #57
0
 def download_playlist(self, url, param):
     # like this http://www.lizhi.fm/#/31365/
     #api desc: s->start l->length band->some radio
     #http://www.lizhi.fm/api/radio_audios?s=0&l=100&band=31365
     self.param = param
     band_id = match1(url, '/(\d+)')
     #try to get a considerable large l to reduce html parsing task.
     api_url = 'http://www.lizhi.fm/api/radio_audios?s=0&l=65535&band=' + band_id
     content_json = json.loads(get_content(api_url))
     for sound in content_json:
         self.audio_content = sound
         self.download_normal()
Exemple #58
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:
            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)
        return info
Exemple #59
0
    def prepare(self):
        html = get_content(self.url)
        title, artist, sourceVid = self.get_page_info(html)

        add_header('Referer', 'https://www.acfun.cn/')
        try:
            data = json.loads(
                get_content(
                    'https://www.acfun.cn/video/getVideo.aspx?id={}'.format(
                        sourceVid)))

            sourceType = data['sourceType']
            sourceId = data['sourceId']
            if sourceType == 'zhuzhan':
                sourceType = 'acfun.zhuzhan'
                encode = data['encode']
                sourceId = (sourceId, encode)
            elif sourceType == 'letv':
                #workaround for letv, because it is letvcloud
                sourceType = 'le.letvcloud'
                sourceId = (sourceId, '2d8c027396')
            elif sourceType == 'qq':
                sourceType = 'qq.video'

            self.video_info = {
                'site': sourceType,
                'vid': sourceId,
                'title': title,
                'artist': artist
            }
        except IOError:
            # TODO: get more qualities
            data = json.loads(
                get_content(
                    'https://www.acfun.cn/rest/pc-direct/play/playInfo/m3u8Auto?videoId={}'
                    .format(sourceVid)))
            stream = data['playInfo']['streams'][0]
            size = stream['size']
            urls = stream['playUrls']
            self.build_videoinfo(title, artist, size, urls)
Exemple #60
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'.format(
                self.vid))

        host = match1(xml, '<sh>([^<>]+)</sh>')
        k = match1(xml, '<key expire=[^<>]+>([^<>]+)</key>')
        rid = match1(xml, 'rid="([^"]+)"')
        info.title = match1(xml, 'nm="([^"]+)"')

        st = match1(xml, '<st>([^<>]+)</st>')[:-4]
        st = time.mktime(
            time.strptime(st)) * 1000 - 60 * 1000 - time.time() * 1000
        st += time.time() * 1000
        st = st / 1000
        key = constructKey(st)

        pieces = matchall(xml, ['<sgm no="(\d+)"[^<>]+fs="(\d+)"'])

        numbers, fs = zip(*pieces)
        urls = [
            "http://{}/{}/{}?key={}&fpp.ver=1.3.0.4&k={}&type=web.fpp".format(
                host, i, rid, key, k)
            for i in range(max(map(int, numbers)) + 1)
        ]

        total_size = sum(map(int, fs))

        info.stream_types.append('current')
        info.streams['current'] = {
            'container': 'mp4',
            'video_profile': 'current',
            'src': urls,
            'size': total_size
        }

        return info