Exemplo n.º 1
0
    def __init__(self, f, f_audio, info, session, referer, cw=None):
        self.f_audio = f_audio
        self.cw = cw
        self.title = title = info['title']
        self.id = info['id']
        self.url = f['url']
        self.artist = info.get('uploader')
        self.header = utils.capitalize(get_ie_key(info))
        self.session = session
        self.referer = referer

        self.url_thumb = info.get('thumbnail')
        self.thumb = BytesIO()
        if self.url_thumb:
            downloader.download(self.url_thumb, referer=referer, buffer=self.thumb, session=session)

        ext = get_ext_(self.url, session, referer)

        if not ext:
            print('empty ext')
            if f['_resolution']:
                ext = '.mp4'
            else:
                ext = '.mp3'

        if ext.lower() == '.m3u8':
            try:
                url = playlist2stream(self.url, referer, session=session, n_thread=4)
            except:
                url = M3u8_stream(self.url, referer=referer, session=session, n_thread=4)
            ext = '.mp4'
        else:
            url = self.url
        self.url = LazyUrl(referer, lambda x: url, self, pp=self.pp)
        self.filename = format_filename(title, self.id, ext, header=self.header)
Exemplo n.º 2
0
    def get(self, url):
        if self._url:
            return self._url

        ydl = youtube_dl.YoutubeDL()
        info = ydl.extract_info(url)

        # get best video
        fs = info['formats']
        fs = sorted(fs, key=lambda x: int(x['width']), reverse=True)
        f = fs[0]
        url_video = f['url']

        # thumb
        self.thumb_url = info['thumbnails'][0]['url']
        self.thumb = BytesIO()
        downloader.download(self.thumb_url, buffer=self.thumb)

        # m3u8
        print(f['protocol'])
        if 'm3u8' in f['protocol']:
            url_video = M3u8_stream(url_video, referer=url)

        # title & filename
        format = self.format.replace('title',
                                     '###title').replace('id', '###id')
        self.title = format.replace('###title', info['title']).replace(
            '###id', u'{}'.format(info['id']))
        ext = '.mp4'
        self.filename = clean_title(self.title, n=-len(ext)) + ext

        self._url = url_video

        return self._url
    def get(self, _):
        if self._url_cache:
            return self._url_cache
        print_ = get_print(self.cw)
        for try_ in range(self.try_n):
            try:
                d = ytdl.YoutubeDL()
                info = d.extract_info(self._url)

                url = info['url']
                ext = get_ext(url)
                self.ext = ext
                print_('get_video: {} {}'.format(url, ext))
                if ext.lower() == '.m3u8':
                    url = M3u8_stream(url,
                                      n_thread=self.n_thread,
                                      post_processing=True)
                self._url_cache = url
                return url
            except Exception as e:
                e_ = e
                msg = print_error(e)[(-1)]
                print_('\nTwitter video Error:\n{}'.format(msg))
                if try_ < self.try_n - 1:
                    sleep(10, self.cw)
        else:
            raise e_
Exemplo n.º 4
0
    def get(self, url):
        if self._url:
            return self._url

        ydl = ytdl.YoutubeDL()
        info = ydl.extract_info(url)

        # get best video
        fs = info['formats']
        fs = sorted(fs, key=lambda x: int(x['width']), reverse=True)
        f = fs[0]
        url_video = f['url']

        # thumb
        self.thumb_url = info['thumbnails'][0]['url']
        self.thumb = BytesIO()
        downloader.download(self.thumb_url, buffer=self.thumb)

        # m3u8
        print(f['protocol'])
        if 'm3u8' in f['protocol']:
            url_video = M3u8_stream(url_video, referer=url)

        # title & filename
        self.title = info['title']
        self.filename = format_filename(self.title, info['id'], '.mp4')

        self._url = url_video

        return self._url
def get_video(url, cw=None):
    print_ = get_print(cw)

    if cw and not cw.alive:
        return

    html = downloader.read_html(url)
    soup = Soup(html)

    data = cw.data
    if not isinstance(data, bytes):
        data = data.encode('utf8')
    s = base64.b64decode(data).decode('utf8')
    urls = json.loads(s)

    print_(u'\n'.join(urls[:4]))

    referer_seg = 'auto' if 'referer=force' in urls[0] else None  # 1718

    stream = M3u8_stream(url, urls=urls, n_thread=4, referer_seg=referer_seg)

    url_thumb = soup.find('meta', {'property': 'og:image'}).attrs['content']
    title = soup.find('meta', {
        'property': 'og:title'
    }).attrs['content'].strip()

    video = Video(stream, url_thumb, url, title)

    return video
Exemplo n.º 6
0
def get_video(url, cw=None):
    print_ = get_print(cw)

    check_alive(cw)

    data = cw.data_
    version = data['version']
    print_('version: {}'.format(version))
    if version == '0.1':
        raise errors.OutdatedExtension()
    data = data['data']
    if not isinstance(data, bytes):
        data = data.encode('utf8')
    s = base64.b64decode(data).decode('utf8')
    urls = json.loads(s)

    print_(u'\n'.join(urls[:4]))

    referer_seg = 'auto' if 'referer=force' in urls[0] else None  # 1718

    stream = M3u8_stream(url, urls=urls, n_thread=4, referer_seg=referer_seg)

    html = downloader.read_html(url)
    soup = Soup(html)

    url_thumb = soup.find('meta', {'property': 'og:image'}).attrs['content']
    title = soup.find('meta', {
        'property': 'og:title'
    }).attrs['content'].strip()

    video = Video(stream, url_thumb, url, title)

    return video
Exemplo n.º 7
0
    def get(self, url):
        print_ = get_print(self.cw)
        if self._url:
            return self._url
        ydl = ytdl.YoutubeDL(cw=self.cw)
        try:
            info = ydl.extract_info(url)
        except Exception as e:
            ex = type(ytdl.get_extractor(url))(ydl)
            _download_info = getattr(ex, '_download_info', None)
            if _download_info is not None:
                vod_id = ex._match_id(url)
                info = _download_info(vod_id)
                print_(info)
            raise
        video_best = info['formats'][-1]
        video = video_best['url']

        ext = get_ext(video)
        self.title = info['title']
        id = info['display_id']

        if ext.lower() == '.m3u8':
            video = M3u8_stream(video, n_thread=4, alter=alter)
            ext = '.mp4'
        self.filename = format_filename(self.title, id, ext)
        self.url_thumb = info['thumbnail']
        self.thumb = BytesIO()
        downloader.download(self.url_thumb, buffer=self.thumb)
        self._url = video
        return self._url
Exemplo n.º 8
0
 def get(self, referer):
     ext = downloader.get_ext(self._url, referer=referer)
     if ext == '.m3u8':
         video = M3u8_stream(self._url, n_thread=4)
     else:
         video = self._url
     return video
Exemplo n.º 9
0
 def __init__(self, url):
     try:
         m = playlist2stream(url)
     except:
         m = M3u8_stream(url)
     self.url = LazyUrl(url, lambda _: m, self)
     self.title = os.path.splitext(os.path.basename(url))[0]
     self.filename = clean_title(self.title, n=-4) + '.mp4'
 def __init__(self, src, referer, title, session):
     ext = get_ext(src)
     if ext == '.m3u8':
         _src = src
         src = M3u8_stream(_src, referer=referer, session=session)
         ext = '.mp4'
     self.url = LazyUrl(referer, lambda _: src, self)
     self.filename = '{}{}'.format(clean_title(title), ext)
Exemplo n.º 11
0
def _get_stream(url_m3u8):
    print('_get_stream', url_m3u8)
    try:
        stream = playlist2stream(url_m3u8)
    except Exception as e:
        print(e)
        stream = M3u8_stream(url_m3u8)
    return stream
Exemplo n.º 12
0
    def get(self, url):
        print_ = get_print(self.cw)
        if self._url:
            return self._url
        ydl = ytdl.YoutubeDL(cw=self.cw)
        try:
            info = ydl.extract_info(url)
        except Exception as e:
            ex = type(ytdl.get_extractor(url))(ydl)
            _download_info = getattr(ex, '_download_info', None)
            if _download_info is not None:
                vod_id = ex._match_id(url)
                info = _download_info(vod_id)
                print_(info)
            if 'HTTPError 403' in str(e):
                raise errors.LoginRequired()
            raise

        def print_video(video):
            print_('[{}] [{}] [{}] {}'.format(video['format_id'],
                                              video.get('height'),
                                              video.get('tbr'), video['url']))

        videos = [video for video in info['formats'] if video.get('height')]

        videos = sorted(videos,
                        key=lambda video:
                        (video.get('height', 0), video.get('tbr', 0)),
                        reverse=True)

        for video in videos:
            print_video(video)

        for video in videos:
            if video.get('height', 0) <= get_resolution():  #3723
                video_best = video
                break
        else:
            video_best = videos[-1]
        print_video(video)

        video = video_best['url']

        ext = get_ext(video)
        self.title = info['title']
        id = info['display_id']

        if ext.lower() == '.m3u8':
            video = M3u8_stream(video, n_thread=4, alter=alter)
            ext = '.mp4'
        self.filename = format_filename(self.title, id, ext)
        self.url_thumb = info['thumbnail']
        self.thumb = BytesIO()
        downloader.download(self.url_thumb, buffer=self.thumb)
        self._url = video
        return self._url
Exemplo n.º 13
0
 def __init__(self, url, n_thread):
     try:
         m = playlist2stream(url, n_thread=n_thread)
     except:
         m = M3u8_stream(url, n_thread=n_thread)
     self.url = LazyUrl(url, lambda _: m, self)
     self.title = os.path.splitext(os.path.basename(url))[0]
     self.id_ = md5(url.encode('utf8')).hexdigest()[:8]
     tail = ' ({}).mp4'.format(self.id_)
     self.filename = clean_title(self.title, n=-len(tail)) + tail
Exemplo n.º 14
0
    def get(self, url):
        print_ = get_print(self.cw)
        if self._url:
            return self._url
        info = extract_info(url, self.cw)

        def print_video(video):
            print_(video)  #
            print_('{}[{}] [{}] [{}] {}'.format('LIVE ', video['format_id'],
                                                video.get('height'),
                                                video.get('tbr'),
                                                video['url']))

        videos = [video for video in info['formats'] if video.get('height')]

        videos = sorted(videos,
                        key=lambda video:
                        (video.get('height', 0), video.get('tbr', 0)),
                        reverse=True)

        for video in videos:
            print_video(video)

        for video in videos:
            if video.get('height', 0) <= get_resolution():  #3723
                video_best = video
                break
        else:
            video_best = videos[-1]
        print_video(video)

        video = video_best['url']

        ext = get_ext(video)
        self.title = info['title']
        id = info['display_id']

        if self._live:
            video = utils.LiveStream(video,
                                     headers=video_best.get('http_headers'))
            ext = '.mp4'
        else:
            if ext.lower() == '.m3u8':
                video = M3u8_stream(video, n_thread=4, alter=alter)
                ext = '.mp4'
        self.filename = format_filename(self.title, id, ext)
        self.url_thumb = info['thumbnail']
        self.thumb = BytesIO()
        downloader.download(self.url_thumb, buffer=self.thumb)
        self._url = video
        return self._url
Exemplo n.º 15
0
    def get(self, url):
        print_ = get_print(self.cw)
        if self._url:
            return self._url

        info = self.info

        ##        ydl = ytdl.YoutubeDL()
        ##        info = ydl.extract_info(url)

        formats = info['formats']
        print(formats)
        formats = sorted(formats,
                         key=lambda x: int(x.get('abr', 0)),
                         reverse=True)
        url_audio = None

        for format in formats:
            protocol = format['protocol']
            print_(u'【{}】 format【{}】 abr【{}】'.format(protocol,
                                                     format['format'],
                                                     format.get('abr', 0)))
            if not url_audio and protocol in ['http', 'https']:
                url_audio = format['url']

        if not url_audio:
            url_audio = M3u8_stream(formats[0]['url'])
            self.album_art = False  #

        self.username = info['uploader']
        self.title = u'{} - {}'.format(self.username, info['title'])
        self.filename = u'{}{}'.format(
            clean_title(self.title, allow_dot=True, n=-4), '.mp3')

        thumb = None
        for t in info['thumbnails'][::-1]:
            width = t.get('width', 1080)
            if not 100 <= width <= 500:
                continue
            url_thumb = t['url']
            thumb = BytesIO()
            try:
                downloader.download(url_thumb, buffer=thumb)
                break
            except Exception as e:
                print(e)
                thumb = None
        self.thumb = thumb

        self._url = url_audio
        return self._url
    def __init__(self, f, info):
        self.title = title = info['title']
        self.id = info['id']
        self.url = f['url']

        self.thumb = BytesIO()
        downloader.download(info['thumbnail'], buffer=self.thumb)

        ext = get_ext(self.url)
        if ext.lower() == '.m3u8':
            raise NotImplementedError('stream')  #
            url = M3u8_stream(self.url, n_thread=4)
        else:
            url = self.url
        self.url = LazyUrl(self.url, lambda x: url, self)
        self.filename = format_filename(title, self.id, ext)
Exemplo n.º 17
0
 def __init__(self, info, stream):
     self.info = info
     self.id = info['id']
     self.title = info['name']
     self.brand = info['brand']
     self.url = stream['url']
     self.url_thumb = info['poster_url']
     self.thumb = IO()
     downloader.download(self.url_thumb, buffer=self.thumb)
     ext = os.path.splitext(self.url.split('?')[0].split('#')[0])[1]
     if ext.lower() == '.m3u8':
         print('read m3u8:', self.url)
         ext = '.mp4'
         self.url = M3u8_stream(self.url, deco=decrypt, n_thread=4)
     else:
         size = downloader.get_size(self.url)
         if size <= 0:
             raise Exception('Size is 0')
     self.filename = format_filename('[{}] {}'.format(self.brand, self.title), self.id, ext)
Exemplo n.º 18
0
 def __init__(self, id_, title, url, url_thumb):
     self.id_ = id_
     self.title = clean_title('{}'.format(title))
     self.url = url
     
     ext = get_ext(self.url)
     if ext.lower() == '.m3u8':
         try:
             self.url = playlist2stream(self.url, n_thread=4)
         except:
             self.url = M3u8_stream(self.url, n_thread=4)
         
     self.url_thumb = url_thumb
     self.thumb = BytesIO()
     downloader.download(self.url_thumb, buffer=self.thumb)
     
     if ext.lower() == '.m3u8':
         ext = '.mp4'
     self.filename = format_filename(self.title, self.id_, ext)
     print('filename:', self.filename)
    def __init__(self, img):
        self.id = img['id']
        print(self.id)
        videos = img.get('videos')
        if videos and 'video_list' in videos:
            src = list(videos['video_list'].values())[0]['url']
        else:
            src = img['images']['orig']['url']

        ext = get_ext(src)
        if ext.lower() == '.m3u8':
            try:
                src = playlist2stream(src)
            except:
                src = M3u8_stream(src)
            ext = '.mp4'

        self.url = LazyUrl(('{}/pin/{}/').format(BASE_URL, self.id),
                           lambda _: src, self)
        self.filename = ('{}{}').format(self.id, ext)
Exemplo n.º 20
0
    def get(self, url):
        if self._url:
            return self._url
        ydl = ytdl.YoutubeDL()
        info = ydl.extract_info(url)
        video_best = info['formats'][-1]
        video = video_best['url']

        ext = get_ext(video)
        self.title = info['title']
        id = info['display_id']

        if ext.lower() == '.m3u8':
            video = M3u8_stream(video, n_thread=4)
            ext = '.mp4'
        self.filename = format_filename(self.title, id, ext)
        self.url_thumb = info['thumbnail']
        self.thumb = BytesIO()
        downloader.download(self.url_thumb, buffer=self.thumb)
        self._url = video
        return self._url
Exemplo n.º 21
0
def get_video(url, format='title'):
    options = {}
    ydl = youtube_dl.YoutubeDL(options)
    info = ydl.extract_info(url)
    video_best = info['formats'][(-1)]
    video = video_best['url']
    print(video)
    ext = os.path.splitext(video.split('?')[0])[1].lower()[1:]
    title = info['title']
    id = info['display_id']
    format = format.replace('title', '###title*').replace('id', '###id*')
    title = format.replace('###title*', title).replace('###id*',
                                                       (u'{}').format(id))
    title = clean_title(title, allow_dot=True)

    if ext == 'm3u8':
        video = M3u8_stream(video, n_thread=4)
        video = Video(video, url, u'{}.{}'.format(title, 'mp4'))
    else:
        video = Video(video, url, u'{}.{}'.format(title, ext))
    return info, video