Exemplo n.º 1
0
def getlive(vid):
    tm = time.time()
    host = 'https://live.video.iqiyi.com'
    params = {
        'lp': vid,
        'src': '01010031010000000000',
        'uid': '',
        'rateVers': 'PC_QIYI_3',
        'k_uid': get_macid(24),
        'qdx': 'n',
        'qdv': 3,
        'qd_v': 1,
        'dfp': get_random_str(66),
        'v': 1,
        'k_err_retries': 0,
        'tm': int(tm + 1),
    }
    src = '/live?{}'.format(urlencode(params))
    vf = cmd5x(src)
    req_url = '{}{}&vf={}'.format(host, src, vf)
    st = int(tm * 1000)
    et = int((tm + 1296000) * 1000)
    c_dfp = '__dfp={}@{}@{}'.format(params['dfp'], et, st)
    add_header('Cookie', c_dfp)
    html = get_content(req_url)
    return json.loads(html)
Exemplo n.º 2
0
    def download_playlist(self, url, param):
        self.param = param
        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']

        for music in playlist:
            self.title = music['name']
            self.artist = music['artists'][0]['name']
            for st in self.supported_stream_types:
                if st in music:
                    self.stream_types = []
                    self.stream_types.append(st)
                    self.song_date[st] = music[st]
            self.download_normal()
Exemplo n.º 3
0
def get_extractor(url):
    if 'live.bilibili' in url:
        from . import live as s
        return s.site, url
    elif 'vc.bilibili' in url:
        from . import vc as s
        return s.site, url
    elif '/bangumi/' in url:
        from . import bangumi as s
        return s.site, url

    av_id = match1(url, '(?:/av|aid=)(\d+)')
    page_index = match1(url, '(?:page|\?p)=(\d+)', 'index_(\d+)\.') or '1'
    if page_index == '1':
        url = 'https://www.bilibili.com/av{}/'.format(av_id)
    else:
        url = 'https://www.bilibili.com/av{}/?p={}'.format(av_id, page_index)
    add_header('Referer', 'https://www.bilibili.com/')
    url = get_location(url)

    if '/bangumi/' in url:
        from . import bangumi as s
    else:
        from . import video as s

    return s.site, url
Exemplo n.º 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']

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

        assert self.vid, "can't play this video: {}".format(self.url)

        for q in self.supported_stream_profile:
            api_url = self.get_api_url(3 -
                                       self.supported_stream_profile.index(q))
            html = get_content(api_url)
            self.logger.debug("HTML> {}".format(html))
            code = match1(html, '<code>([^<])')
            assert not code, "can't play this video: {}".format(
                match1(html, 'CDATA\[([^\]]+)'))
            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
Exemplo n.º 5
0
    def prepare(self):

        info = VideoInfo(self.name)
        if self.url:
            self.vid = match1(self.url, '_(\d+)', 'm/(\d+)', 'v/(\d+)')

        add_header('Referer', 'http://m.video.baomihua.com/')
        html = get_content(
            'http://play.baomihua.com/getvideourl.aspx?flvid={}&datatype=json&devicetype=wap'
            .format(self.vid))
        data = json.loads(html)

        info.title = compact_unquote(data["title"])
        host = data['host']
        stream_name = data['stream_name']
        t = data['videofiletype']
        size = int(data['videofilesize'])

        hls = data['ishls']
        url = "http://{}/{}/{}.{}".format(host, hls, stream_name, t)
        info.stream_types.append('current')
        info.streams['current'] = {
            'video_profile': 'current',
            'container': t,
            'src': [url],
            'size': size
        }
        return info
Exemplo n.º 6
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
Exemplo n.º 7
0
    def prepare(self):
        info = VideoInfo(self.name)
        add_header('X-Requested-With', 'XMLHttpRequest')

        if self.url:
            self.vid = match1(self.url, 'show/(.*)')
        html = get_content(self.url)
        info.title = match1(html, u'title>(.+?)_斗鱼视频 - 最6的弹幕视频网站<')

        json_request_url = "https://vmobile.douyu.com/video/getInfo?vid={}".format(
            self.vid)
        html_content = get_content(json_request_url)
        self.logger.debug('video_data: ' + html_content)

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

        real_url = video_data['data']['video_url']
        info.stream_types.append('current')
        info.streams['current'] = {
            'container': 'm3u8',
            'video_profile': 'current',
            'src': [real_url],
            'size': 0
        }

        return info
Exemplo n.º 8
0
    def prepare_list(self):
        add_header("Referer", "http://music.163.com/")
        vid = match1(self.url, '\?id=(.*)')
        if "album" in self.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 self.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 self.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 self.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']

        return [p['id'] for p in playlist]
Exemplo n.º 9
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
Exemplo n.º 10
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
Exemplo n.º 11
0
    def prepare(self):
        info = VideoInfo(self.name)
        info.title = self.name + ' ' + str(self.vid)
        add_header('User-Agent', '')

        data = json.loads(
            get_content(
                'http://www.tudou.com/outplay/goto/getItemSegs.action?iid=%s' %
                self.vid))

        temp = max([data[i] for i in data if 'size' in data[i][0]],
                   key=lambda x: sum([part['size'] for part in x]))
        vids, size = [t["k"] for t in temp], sum([t["size"] for t in temp])

        urls = []
        for vid in vids:
            for i in parseString(
                    get_content('http://ct.v2.tudou.com/f?id=%s' %
                                vid)).getElementsByTagName('f'):
                urls.append(i.firstChild.nodeValue.strip())

        ext = match1(urls[0], 'http://[\w.]*/(\w+)/[\w.]*')
        info.stream_types.append('current')
        info.streams['current'] = {
            'container': ext,
            'video_profile': 'current',
            'src': urls,
            'size': size
        }
        return info
Exemplo n.º 12
0
Arquivo: live.py Projeto: PureTV/ykdl
 def __init__(self):
     SimpleExtractor.__init__(self)
     add_header('User-Agent', 'Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3')
     self.live = True
     self.title_pattern = 'liveRoomName = \"([^\"]+)'
     self.url_pattern = 'hasvedio: \'([^\']+)'
     self.artist_pattern = 'videoTitle = \"([^\"]+)'
Exemplo n.º 13
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
Exemplo n.º 14
0
Arquivo: live.py Projeto: wwqgtxx/ykdl
def getlive(vid):
    tm = time.time()
    host = 'https://live.video.iqiyi.com'
    params = {
        'lp': vid,
        'src': '01010031010000000000',
        'uid': '',
        'rateVers': 'PC_QIYI_3',
        'k_uid': get_macid(24),
        'qdx': 'n',
        'qdv': 3,
        'qd_v': 1,
        'dfp': get_random_str(66),
        'v': 1,
        'k_err_retries': 0,
        'tm': int(tm + 1),
    }
    src = '/live?{}'.format(urlencode(params))
    vf = cmd5x(src)
    req_url = '{}{}&vf={}'.format(host, src, vf)
    st = int(tm * 1000)
    et = int((tm + 1296000) * 1000)
    c_dfp = '__dfp={}@{}@{}'.format(params['dfp'], et, st)
    add_header('Cookie', c_dfp)
    html = get_content(req_url)
    return json.loads(html)
Exemplo n.º 15
0
    def prepare(self):
        info = VideoInfo(self.name)
        add_header('User-Agent', "")
        self.vid, self.embsig = self.vid

        api = "http://player.acfun.cn/flash_data?vid={}&ct={}&ev=3&sign={}&time={}".format(
            self.vid, self.ct, self.embsig, int(time.time() * 1000))
        data = rc4(
            self.key,
            base64.b64decode(
                json.loads(get_content(api, charset='utf-8'))['data']))
        stream_data = json.loads(data)
        info.title = stream_data['video']['title']
        for s in stream_data['stream']:
            if 'segs' in s:
                stream_type = stream_code_to_id[s['stream_type']]
                stream_urls = [seg['url'] for seg in s['segs']]
                size = s['total_size']
                info.stream_types.append(stream_type)
                info.streams[stream_type] = {
                    'container': 'mp4',
                    'video_profile': stream_code_to_profiles[stream_type],
                    'src': stream_urls,
                    'size': size
                }
        info.stream_types = sorted(info.stream_types, key=ids.index)
        return info
Exemplo n.º 16
0
    def prepare(self):
        add_default_handler(HTTPCookieProcessor)
        install_default_handlers()
        add_header('Referer', self.url)
        add_header('User-Agent', ua)

        info = VideoInfo(self.name)
        if self.url and not self.vid:
            self.vid = match1(self.url,
                              'https?://(?:www.)?mgtv.com/b/\d+/(\d+).html')
            if self.vid is None:
                html = get_content(self.url)
                self.vid = match1(html, 'vid=(\d+)', 'vid=\"(\d+)',
                                  'vid: (\d+)')

        did = str(uuid.uuid4())
        tk2 = generate_tk2(did)

        api_info_url = 'https://pcweb.api.mgtv.com/player/video?tk2={}&video_id={}&type=pch5'.format(
            tk2, self.vid)
        meta = json.loads(get_content(api_info_url))
        self.logger.debug('meta >\n%s', meta)

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

        pm2 = meta['data']['atc']['pm2']
        info.title = meta['data']['info']['title'] + ' ' + meta['data'][
            'info']['desc']

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

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

        data = meta['data']
        domain = data['stream_domain'][0]
        for lstream in data['stream']:
            lurl = lstream['url']
            if lurl:
                lurl = '{}{}&did={}'.format(domain, lurl, did)
                url = json.loads(get_content(lurl))['info']
                video_profile = lstream['name']
                stream = self.profile_2_types[video_profile]
                info.streams[stream] = {
                    'container': 'm3u8',
                    'video_profile': video_profile,
                    'src': [url]
                }
                info.stream_types.append(stream)
        info.stream_types = sorted(info.stream_types,
                                   key=self.supported_stream_types.index)
        info.extra['referer'] = self.url
        info.extra['ua'] = ua
        return info
Exemplo n.º 17
0
 def __init__(self):
     SimpleExtractor.__init__(self)
     add_header(
         'User-Agent',
         'Mozilla/5.0 (Linux; Android 4.4.2; Nexus 4 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.114 Mobile Safari/537.36'
     )
     self.url_pattern = '(?:data-url|video_src|controls src)=(?:\"|\')([^\"\']+)'
     self.title_pattern = '<title>([^<]+)</'
Exemplo n.º 18
0
    def prepare(self):
        add_header("referer", "http://v.youku.com")
        ssl_context = HTTPSHandler(
            context=ssl.SSLContext(ssl.PROTOCOL_TLSv1))
        cookie_handler = HTTPCookieProcessor()
        opener = build_opener(ssl_context, cookie_handler)
        opener.addheaders = [('Cookie','__ysuid=%d' % time.time())]
        install_opener(opener)
        
        info = VideoInfo(self.name)        

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

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

        data = json.loads(get_content(api_url))
        assert data['e']['code'] == 0, data['e']['desc']
        data = data['data']
        assert 'stream' in data, data['error']['note']
        info.title = data['video']['title']
        streams = data['stream']
        for s in streams:
            self.logger.debug("stream> " + str(s))
            t = stream_code_to_id[s['stream_type']]
            urls = []
            for u in s['segs']:
                self.logger.debug("seg> " + str(u))
                if u['key'] != -1:
                    if 'cdn_url' in u:
                        urls.append(u['cdn_url'])
                else:
                    self.logger.warning("VIP video, ignore unavailable seg: {}".format(s['segs'].index(u)))
            if len(urls) == 0:
                urls = [s['m3u8_url']]
                c = 'm3u8'
            else:
                c = id_to_container[t]
            size = s['size']
            info.stream_types.append(t)
            info.streams[t] =  {
                    'container': c,
                    'video_profile': stream_code_to_profiles[t],
                    'size': size,
                    'src' : urls
                }
        info.stream_types = sorted(info.stream_types, key = ids.index)
        tmp = []
        for t in info.stream_types:
            if not t in tmp:
                tmp.append(t)
        info.stream_types = tmp
        return info
Exemplo n.º 19
0
Arquivo: program.py Projeto: flfq/ykdl
    def prepare_list(self):

        add_header("Referer", "http://music.163.com/")
        vid =  match1(self.url, '\?id=([^&]+)')
        if "djradio" in self.url:
           api_url = "http://music.163.com/api/dj/program/byradio/?radioId={}&ids=[{}]&csrf_token=".format(vid, vid)
           listdata = json.loads(get_content(api_url))
           playlist = listdata['programs']
        return [p['id'] for p in playlist]
Exemplo n.º 20
0
 def __init__(self):
     SimpleExtractor.__init__(self)
     add_header(
         'User-Agent',
         'Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3'
     )
     self.live = True
     self.title_pattern = 'liveRoomName = \"([^\"]+)'
     self.url_pattern = 'hasvedio: \'([^\']+)'
     self.artist_pattern = 'videoTitle = \"([^\"]+)'
Exemplo n.º 21
0
    def prepare_list(self):

        add_header("Referer", "http://music.163.com/")
        vid = match1(self.url, '\?id=([^&]+)')
        if "djradio" in self.url:
            api_url = "http://music.163.com/api/dj/program/byradio/?radioId={}&ids=[{}]&csrf_token=".format(
                vid, vid)
            listdata = json.loads(get_content(api_url))
            playlist = listdata['programs']
        return [p['id'] for p in playlist]
Exemplo n.º 22
0
    def prepare(self):
        handlers = [HTTPCookieProcessor()]
        if default_proxy_handler:
            handlers += default_proxy_handler
        install_opener(build_opener(*handlers))
        add_header("Referer", self.url)

        info = VideoInfo(self.name)
        if self.url and not self.vid:
            self.vid = match1(self.url,
                              'https?://www.mgtv.com/b/\d+/(\d+).html')
            if self.vid is None:
                html = get_content(self.url)
                self.vid = match1(html, 'vid=(\d+)', 'vid=\"(\d+)',
                                  'vid: (\d+)')

        did = str(uuid.uuid4())
        tk2 = generate_tk2(did)

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

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

        pm2 = meta['data']['atc']['pm2']
        info.title = meta['data']['info']['title']

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

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

        data = meta['data']
        domain = data['stream_domain'][0]
        tk2 = generate_tk2(did)
        for lstream in data['stream']:
            lurl = lstream['url']
            if lurl:
                lurl = '{}{}&did={}'.format(domain, lurl, did)
                url = json.loads(get_content(lurl))['info']
                info.streams[self.profile_2_types[lstream['name']]] = {
                    'container': 'm3u8',
                    'video_profile': lstream['name'],
                    'src': [url]
                }
                info.stream_types.append(self.profile_2_types[lstream['name']])
        info.stream_types = sorted(info.stream_types,
                                   key=self.supported_stream_types.index)
        return info
Exemplo n.º 23
0
Arquivo: youku.py Projeto: PureTV/ykdl
    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!!')
Exemplo n.º 24
0
    def prepare(self):
        info = VideoInfo(self.name)
        html = get_content(self.url)
        info.title, info.artist, sourceVid, m3u8Info = self.get_page_info(html)

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

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

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

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

        info.stream_types = sorted(info.stream_types,
                                   key=self.stream_ids.index)
        return info
Exemplo n.º 25
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!!')
Exemplo n.º 26
0
def get_extractor(url):
    if '/v.' in url:
        add_header(
            'User-Agent',
            'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) '
            'AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 '
            'Mobile/15E148 Safari/604.1')
        url = get_location(url)
    if '/live.' in url or 'amemv.com' in url:
        from . import live as s
    else:
        from . import video as s

    return s.site, url
Exemplo n.º 27
0
Arquivo: video.py Projeto: PureTV/ykdl
    def prepare(self):
        info = VideoInfo(self.name)
        add_header('X-Requested-With', 'XMLHttpRequest')
        if self.url:
            self.vid = match1(self.url, 'show/(.*)')

        json_request_url = "https://vmobile.douyu.com/video/getInfo?vid={}".format(self.vid)

        video_data = json.loads(get_content(json_request_url))
        assert video_data['error'] == 0, video_data
        real_url = video_data['data']['video_url']
        info.stream_types.append('current')
        info.streams['current'] = {'container': 'm3u8', 'video_profile': 'current', 'src' : [real_url], 'size': 0}
        info.title = self.name + '_' + self.vid
        return info
Exemplo n.º 28
0
    def prepare(self):
        info = VideoInfo(self.name)
        add_header("Referer", "https://www.bilibili.com/")
        info.extra["referer"] = "https://www.bilibili.com/"
        info.extra["ua"] = fake_headers['User-Agent']

        self.vid, info.title, info.artist = self.get_page_info()

        assert self.vid, "can't play this video: {}".format(self.url)

        def get_video_info(qn=0):
            # need login with "qn=112"
            if int(qn) > 80:
                return

            api_url = self.get_api_url(qn)
            html = get_content(api_url)
            self.logger.debug('HTML> ' + html)
            code = match1(html, '<code>([^<])')
            if code:
                return

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

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

        get_video_info()

        assert len(info.stream_types), "can't play this video!!"
        info.stream_types = sorted(info.stream_types,
                                   key=self.sorted_format.index)
        return info
Exemplo n.º 29
0
    def prepare(self):
        add_header("Referer", "http://music.163.com/")
        if not self.vid:
            self.vid = match1(self.url, 'id=(.*)')

        api_url = "http://music.163.com/api/song/detail/?id={}&ids=[{}]&csrf_token=".format(
            self.vid, self.vid)
        music = json.loads(get_content(api_url))['songs'][0]

        self.title = music['name']
        self.artist = music['artists'][0]['name']

        for st in self.supported_stream_types:
            if st in music:
                self.stream_types.append(st)
                self.song_date[st] = music[st]
Exemplo n.º 30
0
    def prepare(self):
        add_header("Referer", "http://music.163.com/")
        video = VideoInfo(self.name)
        if not self.vid:
            self.vid =  match1(self.url, 'id=(.*)')

        api_url = "http://music.163.com/api/mv/detail/?id={}&ids=[{}]&csrf_token=".format(self.vid, self.vid)
        mv = json.loads(get_content(api_url))['data']
        video.title = mv['name']
        video.artist = mv['artistName']
        for code in self.supported_stream_code:
            if code in mv['brs']:
                stream_id = self.code_2_id[code]
                stream_profile = self.code_2_profile[code]
                video.stream_types.append(stream_id)
                video.streams[stream_id] = {'container': 'mp4', 'video_profile': stream_profile, 'src' : [mv['brs'][code]], 'size': 0}
        return video
Exemplo n.º 31
0
Arquivo: mv.py Projeto: PureTV/ykdl
    def prepare(self):
        add_header("Referer", "http://music.163.com/")
        video = VideoInfo(self.name)
        if not self.vid:
            self.vid =  match1(self.url, '\?id=(.*)', 'mv/(\d+)')

        api_url = "http://music.163.com/api/mv/detail/?id={}&ids=[{}]&csrf_token=".format(self.vid, self.vid)
        mv = json.loads(get_content(api_url))['data']
        video.title = mv['name']
        video.artist = mv['artistName']
        for code in self.supported_stream_code:
            if code in mv['brs']:
                stream_id = self.code_2_id[code]
                stream_profile = self.code_2_profile[code]
                video.stream_types.append(stream_id)
                video.streams[stream_id] = {'container': 'mp4', 'video_profile': stream_profile, 'src' : [mv['brs'][code]], 'size': 0}
        return video
Exemplo n.º 32
0
Arquivo: acorig.py Projeto: flfq/ykdl
    def prepare(self):
        info = VideoInfo(self.name)
        add_header('User-Agent', "")
        self.vid, self.embsig = self.vid

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

        info = VideoInfo(self.name)
        if self.url and not self.vid:
            self.vid = match1(self.url, 'https?://www.mgtv.com/b/\d+/(\d+).html')
            if self.vid is None:
                html = get_content(self.url)
                self.vid = match1(html, 'vid=(\d+)', 'vid=\"(\d+)', 'vid: (\d+)')

        did = str(uuid.uuid4())
        tk2 = generate_tk2(did)

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

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

        pm2 = meta['data']['atc']['pm2']
        info.title = meta['data']['info']['title']

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

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

        data = meta['data']
        domain = data['stream_domain'][0]
        tk2 = generate_tk2(did)
        for lstream in data['stream']:
            lurl = lstream['url']
            if lurl:
                lurl = '{}{}&did={}'.format(domain, lurl, did)
                url = json.loads(get_content(lurl))['info']
                info.streams[self.profile_2_types[lstream['name']]] = {'container': 'm3u8', 'video_profile': lstream['name'], 'src' : [url]}
                info.stream_types.append(self.profile_2_types[lstream['name']])
        info.stream_types= sorted(info.stream_types, key = self.supported_stream_types.index)
        return info
Exemplo n.º 34
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
Exemplo n.º 35
0
    def prepare(self):
        info = VideoInfo(self.name)
        info.title = self.name + ' ' + str(self.vid)
        add_header('User-Agent', '')

        data = json.loads(get_content('http://www.tudou.com/outplay/goto/getItemSegs.action?iid=%s' % self.vid))

        temp = max([data[i] for i in data if 'size' in data[i][0]], key=lambda x:sum([part['size'] for part in x]))
        vids, size = [t["k"] for t in temp], sum([t["size"] for t in temp])

        urls = []
        for vid in vids:
            for i in parseString(get_content('http://ct.v2.tudou.com/f?id=%s' % vid)).getElementsByTagName('f'):
                urls.append(i.firstChild.nodeValue.strip())

        ext = match1(urls[0], 'http://[\w.]*/(\w+)/[\w.]*')
        info.stream_types.append('current')
        info.streams['current'] = {'container': ext, 'video_profile': 'current', 'src' : urls, 'size': size}
        return info
Exemplo n.º 36
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)))

        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)
        return info
Exemplo n.º 37
0
    def prepare(self):
        info = VideoInfo(self.name)
        add_header("Referer", "https://www.bilibili.com/")
        info.extra["referer"] = "https://www.bilibili.com/"
        info.extra["ua"] = fake_headers['User-Agent']

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

        assert self.vid, "can't play this video: {}".format(self.url)

        def get_video_info(qn=0):
            # need login with "qn=112"
            if int(qn) > 80:
                return

            api_url = self.get_api_url(qn)
            html = get_content(api_url)
            self.logger.debug('HTML> ' + html)
            code = match1(html, '<code>([^<])')
            if code:
                return

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

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

        get_video_info()

        assert len(info.stream_types), "can't play this video!!"
        info.stream_types = sorted(info.stream_types, key = self.sorted_format.index) 
        return info
Exemplo n.º 38
0
    def prepare(self):
        info = VideoInfo(self.name)
        add_header("Referer", "http://music.163.com/")
        if not self.vid:
            self.vid =  match1(self.url, 'id=(.*)')

        api_url = self.api_url.format(self.vid, self.vid)
        music = self.get_music(json.loads(get_content(api_url)))

        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)
        return info
Exemplo n.º 39
0
    def prepare(self):
        info = VideoInfo(self.name)
        add_header('X-Requested-With', 'XMLHttpRequest')

        if self.url:
            self.vid = match1(self.url, 'show/(.*)')
        html = get_content(self.url)
        info.title = match1(html, u'title>(.+?)_斗鱼视频 - 最6的弹幕视频网站<')

        json_request_url = "https://vmobile.douyu.com/video/getInfo?vid={}".format(self.vid)
        html_content = get_content(json_request_url)
        self.logger.debug('video_data: ' + html_content)

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

        real_url = video_data['data']['video_url']
        info.stream_types.append('current')
        info.streams['current'] = {'container': 'm3u8', 'video_profile': 'current', 'src' : [real_url], 'size': 0}

        return info
Exemplo n.º 40
0
    def prepare(self):
        info = VideoInfo(self.name)
        add_header('X-Requested-With', 'XMLHttpRequest')
        if self.url:
            self.vid = match1(self.url, 'show/(.*)')

        json_request_url = "https://vmobile.douyu.com/video/getInfo?vid={}".format(
            self.vid)

        video_data = json.loads(get_content(json_request_url))
        assert video_data['error'] == 0, video_data
        real_url = video_data['data']['video_url']
        info.stream_types.append('current')
        info.streams['current'] = {
            'container': 'm3u8',
            'video_profile': 'current',
            'src': [real_url],
            'size': 0
        }
        info.title = self.name + '_' + self.vid
        return info
Exemplo n.º 41
0
    def prepare(self):

        info = VideoInfo(self.name)
        if self.url:
            self.vid = match1(self.url, '_(\d+)', 'm/(\d+)', 'v/(\d+)')

        add_header('Referer', 'http://m.video.baomihua.com/')
        html = get_content('http://play.baomihua.com/getvideourl.aspx?flvid={}&datatype=json&devicetype=wap'.format(self.vid))
        data = json.loads(html)

        info.title = compact_unquote(data["title"])
        host = data['host']
        stream_name = data['stream_name']
        t = data['videofiletype']
        size = int(data['videofilesize'])

        hls = data['ishls']
        url = "http://{}/{}/{}.{}".format(host, hls, stream_name, t)
        info.stream_types.append('current')
        info.streams['current'] = {'video_profile': 'current', 'container': t, 'src': [url], 'size' : size}
        return info
Exemplo n.º 42
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)
Exemplo n.º 43
0
    def parser_list(self, url):

        add_header("Referer", "http://music.163.com/")
        vid =  match1(url, 'id=([^&]+)')
        if "djradio" in url:
           api_url = "http://music.163.com/api/dj/program/byradio/?radioId={}&ids=[{}]&csrf_token=".format(vid, vid)
           listdata = json.loads(get_content(api_url))
           playlist = listdata['programs']

        info_list = []
        for music in playlist:
            info = VideoInfo(self.name)
            info.title = music['name']
            data = music['mainSong']
            self.mp3_host = data['mp3Url'][8]
            for st in self.supported_stream_types:
                if st in data and data[st]:
                    info.stream_types.append(st)
                    self.song_date[st] = data[st]
            self.extract_song(info)
            info_list.append(info)
        return info_list
Exemplo n.º 44
0
    def prepare(self):
        info = VideoInfo(self.name)
        add_header('User-Agent', 'abcd')
        add_header('Referer', 'https://www.acfun.cn/')
        self.vid, self.embsig = self.vid

        params = {
            'vid': self.vid,
            'ct': self.ct,
            'ev': 3,
            'sign': self.embsig,
            'time': int(time.time() * 1000)
        }
        api = 'https://player.acfun.cn/flash_data?' + urlencode(params)
        data = rc4(
            self.key,
            base64.b64decode(
                json.loads(get_content(api, charset='utf-8'))['data']))
        stream_data = json.loads(data)
        info.title = stream_data['video']['title']
        for s in stream_data['stream']:
            if 'm3u8' in s['stream_type']:
                continue
            if 'segs' in s:
                stream_type = stream_code_to_id[s['stream_type']]
                stream_urls = [seg['url'] for seg in s['segs']]
                size = s['total_size']
                info.stream_types.append(stream_type)
                info.streams[stream_type] = {
                    'container': 'mp4',
                    'video_profile': stream_code_to_profiles[stream_type],
                    'src': stream_urls,
                    'size': size
                }
        info.stream_types = sorted(info.stream_types, key=ids.index)
        info.extra['ua'] = 'abcd'
        return info
Exemplo n.º 45
0
 def __init__(self):
     SimpleExtractor.__init__(self)
     add_header('User-Agent', 'Mozilla/5.0 (Linux; Android 4.4.2; Nexus 4 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.114 Mobile Safari/537.36')
Exemplo n.º 46
0
Arquivo: weibo.py Projeto: Yu1984/ykdl
 def __init__(self):
     SimpleExtractor.__init__(self)
     add_header('User-Agent', 'Mozilla/5.0 (Linux; Android 4.4.2; Nexus 4 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.114 Mobile Safari/537.36')
     self.url_pattern = '<video src="(.*?)\"\W'
     self.title_pattern = '<meta name="description" content="([\s\S]*?)\"\W'
Exemplo n.º 47
0
Arquivo: weibo.py Projeto: PureTV/ykdl
 def __init__(self):
     SimpleExtractor.__init__(self)
     add_header('User-Agent', 'Mozilla/5.0 (Linux; Android 4.4.2; Nexus 4 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.114 Mobile Safari/537.36')
     self.url_pattern = 'data-url=\"([^\"]+)'
     self.title_pattern = '<title>([^<]+)</'
Exemplo n.º 48
0
    def prepare(self):
        add_header("Cookie", '__ysuid=%d' % time.time())

        info = VideoInfo(self.name)

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

        if not self.vid:
            html = get_content(self.url)
            self.vid = match1(html, r'videoIds?[\"\']?\s*[:=]\s*[\"\']?([a-zA-Z0-9=]+)')

        if self.vid.isdigit():
            import base64
            vid = base64.b64encode(b'%d' % (int(self.vid) * 4))
            if not isinstance(vid, str):
                vid = vid.decode()
            self.vid = 'X' + vid
        self.logger.debug("VID: " + self.vid)

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

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

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

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

        return info
Exemplo n.º 49
0
Arquivo: live.py Projeto: wwqgtxx/ykdl
    def prepare(self):
        assert javascript_is_supported, "No JS Interpreter found, can't parse douyu live!"

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

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

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

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

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

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

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

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

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

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

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

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

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

        error_msg = get_live_info()
        assert len(info.stream_types), error_msg
        info.stream_types = sorted(info.stream_types, key=self.stream_ids.index)
        return info