def read(self):
     cw = self.customWidget
     res = re.find(CHANNEL_PATTERN, self.url)
     if res:
         header, username = res
         info = read_channel(self.url, cw)
         p2f = get_p2f(cw)
         if p2f:
             self.single = False
             videos = [Video(url) for url in info['urls']]
             self.urls = [video.url for video in videos]
             videos[0].url()
             self.title = clean_title('[Channel] {}'.format(info['name']))
             self.setIcon(videos[0].thumb)
             return
         else:
             cw.gal_num = self.url = info['urls'].pop(0)
             if info['urls'] and cw.alive:
                 s = ', '.join(info['urls'])
                 self.exec_queue.put((s, 'downButton(customWidget)'))
     video = Video(self.url)
     video.url()
     self.title = video.title
     self.setIcon(video.thumb)
     self.urls.append(video.url)
    def read(self):
        ui_setting = self.ui_setting
        cw = self.customWidget
        print_ = get_print(cw)
        if self.yt_type == 'video':
            res = get_resolution()
            info = get_videos(self.url,
                              type=self.yt_type,
                              max_res=res,
                              only_mp4=False,
                              audio_included=not True,
                              cw=cw)
        else:
            abr = get_abr()
            info = get_videos(self.url, type=self.yt_type, max_abr=abr, cw=cw)
        videos = info['videos']

        cw.enableSegment(overwrite=True)

        # first video must be valid
        while videos:
            video = videos[0]
            try:
                video.url()
                break
            except Exception as e:
                print(e)
                videos.remove(video)
        else:
            raise Exception('No videos')

        if len(videos) > 1:
            p2f = get_p2f(cw)
            if p2f:
                self.single = False
                self.title = clean_title(info['title'])
                self.urls = [video.url for video in videos]
                video = videos[0]
                self.setIcon(video.thumb)
                return
            else:
                video = videos.pop(0)
                cw.gal_num = cw.url = video.url._url
                if videos and cw.alive:
                    s = u', '.join(video.url._url for video in videos)
                    self.exec_queue.put(([s, {
                        'youtube': cw.format
                    }], 'downButton(cw[0], format_selector=cw[1])'))

        self.urls.append(video.url)
        self.artist = video.username
        self.setIcon(video.thumb)

        self.title = video.title
示例#3
0
    def read(self):
        cw = self.customWidget
        ui_setting = self.ui_setting
        format = compatstr(
            ui_setting.youtubeFormat.currentText()).lower().strip()
        cw.enableSegment(1024 * 1024 // 2)
        thumb = BytesIO()

        if '/users/' in self.url:
            info = read_channel(self.url, cw)
            urls = info['urls']
            p2f = get_p2f(cw)
            if p2f:
                self.single = False
                self.title = clean_title(info['title'])
                videos = [Video(url, format) for url in info['urls']]
                self.urls = [video.url for video in videos]
                video = videos[0]
                video.url()
                downloader.download(video.info['thumbnail'], buffer=thumb)
                self.setIcon(thumb)
                return
            else:
                cw.gal_num = self.url = urls.pop(0)
                if urls and cw.alive:
                    s = u', '.join(urls)
                    self.exec_queue.put((s, 'downButton(customWidget)'))
        elif '/photos/gallery/' in self.url:
            info = read_gallery(self.url, cw)
            for img in info['imgs']:
                self.urls.append(img.url)
            self.single = False
            self.title = clean_title(info['title'])
            self.url = info['url']
            cw.disableSegment()
            return
        else:
            urls = []
        video = Video(self.url, format)
        video.url()
        self.urls.append(video.url)

        downloader.download(video.info['thumbnail'], buffer=thumb)
        self.setIcon(thumb)
        self.title = video.title
    def read(self):
        ui_setting = self.ui_setting
        cw = self.customWidget
        print_ = get_print(cw)
        format = compatstr(
            ui_setting.youtubeFormat.currentText()).lower().strip()
        if self.yt_type == 'video':
            res_text = compatstr(ui_setting.youtubeCombo_res.currentText())
            res = {
                '720p': 720,
                '1080p': 1080,
                '2K': 1440,
                '4K': 2160,
                '8K': 4320
            }[res_text]
            info = get_videos(self.url,
                              type=self.yt_type,
                              max_res=res,
                              only_mp4=False,
                              audio_included=not True,
                              format=format,
                              cw=cw)
        else:
            abr_text = compatstr(ui_setting.youtubeCombo_abr.currentText())
            abr = int(abr_text.replace('k', ''))
            info = get_videos(self.url,
                              type=self.yt_type,
                              max_abr=abr,
                              format=format,
                              cw=cw)
        videos = info['videos']

        cw.enableSegment(overwrite=True)

        # first video must be valid
        while videos:
            video = videos[0]
            try:
                video.url()
                break
            except Exception as e:
                print(e)
                videos.remove(video)
        else:
            raise Exception('No videos')

        if len(videos) > 1:
            p2f = get_p2f(cw)
            if p2f:
                self.single = False
                self.title = clean_title(info['title'])
                self.urls = [video.url for video in videos]
                video = videos[0]
                self.setIcon(video.thumb)
                return
            else:
                video = videos.pop(0)
                cw.gal_num = cw.url = video.url._url
                if videos and cw.alive:
                    s = u', '.join(video.url._url for video in videos)
                    self.exec_queue.put(([s, {
                        'youtube': cw.format
                    }], 'downButton(cw[0], format_selector=cw[1])'))

        self.urls.append(video.url)
        cw.artist = video.username
        self.setIcon(video.thumb)

        self.title = video.title