Esempio n. 1
0
 def pp(self, filename):
     if self.thumb and self.album_art:
         self.thumb.seek(0)  #
         ffmpeg.add_cover(filename,
                          self.thumb, {
                              'artist': self.username,
                              'title': self.info['title']
                          },
                          cw=self.cw)
    def pp(self, filename):
        cw = self.cw
        print_ = get_print(cw)
        ui_setting = utils.ui_setting
        ext = os.path.splitext(filename)[1].lower()
        if not os.path.isfile(filename):
            print('no file: {}'.format(filename))
            return
        
        filename_new = None
        if self.type == 'video' and (self.audio is not None or ext != '.mp4') and not self.stream.live: # UHD or non-mp4
            if self.audio is not None: # merge
                print_('Download audio: {}'.format(self.audio))
                hash = uuid()
                path = os.path.join(os.path.dirname(filename), '{}_a.tmp'.format(hash))
                if cw is not None:
                    cw.trash_can.append(path)
                if constants.FAST:
                    downloader_v3.download(self.audio, chunk=1024*1024, n_threads=2, outdir=os.path.dirname(path), fileName=os.path.basename(path), customWidget=cw, overwrite=True)
                else:
                    downloader.download(self.audio, outdir=os.path.dirname(path), fileName=os.path.basename(path), customWidget=cw, overwrite=True)
                ext, out = ffmpeg.merge(filename, path, cw=cw, vcodec=self.vcodec)
                #print(out)
                name, ext_old = os.path.splitext(filename)
                if ext_old.lower() != ext.lower():
                    print_('rename ext {} --> {}'.format(ext_old, ext))
                    filename_new = '{}{}'.format(name, ext)
                    if os.path.isfile(filename_new):
                        os.remove(filename_new)
                    os.rename(filename, filename_new)
            else: # convert non-mp4 video -> mp4
                name, ext_old = os.path.splitext(filename)
                filename_new = '{}.mp4'.format(name)
                print_('Convert video: {} -> {}'.format(filename, filename_new))
                ffmpeg.convert(filename, filename_new, cw=cw)
        elif self.type == 'audio' and ext != '.mp3': # convert non-mp3 audio -> mp3
            name, ext_old = os.path.splitext(filename)
            filename_new = '{}.mp3'.format(name)
            ffmpeg.convert(filename, filename_new, '-shortest -preset ultrafast -b:a {}k'.format(get_abr()), cw=cw)

        if self.type == 'audio' and ui_setting.albumArt.isChecked():
            try:
                self.thumb.seek(0)#
                ffmpeg.add_cover(filename_new, self.thumb, {'artist':self.username, 'title':self.title}, cw=cw)
            except Exception as e:
                s = print_error(e)[-1]
                print_(s)

        utils.pp_subtitle(self, filename, cw)

        return filename_new
Esempio n. 3
0
    def pp(self, filename):
        if self.format == 'mp4':
            return
        name, ext_old = os.path.splitext(filename)
        filename_new = '{}.mp3'.format(name)
        ffmpeg.convert(filename,
                       filename_new,
                       '-shortest -preset ultrafast -b:a {}k'.format(
                           get_abr()),
                       cw=self.cw)

        if utils.ui_setting.albumArt.isChecked():
            self.thumb.seek(0)  #
            ffmpeg.add_cover(filename_new,
                             self.thumb, {
                                 'artist': self.username,
                                 'title': self.title
                             },
                             cw=self.cw)

        return filename_new
    def _pp(self, filename):
        cw = self.cw
        print_ = get_print(cw)
        ui_setting = utils.ui_setting
        ext = os.path.splitext(filename)[1].lower()
        if not os.path.isfile(filename):
            print(u'no file: {}'.format(filename))
            return

        filename_new = None
        if self.type == 'video' and (self.audio is not None
                                     or ext != '.mp4'):  # UHD or non-mp4
            if self.audio is not None:  # merge
                print_(u'Download audio: {}'.format(self.audio))
                hash = uuid()
                path = os.path.join(os.path.dirname(filename),
                                    '{}_a.tmp'.format(hash))
                if cw is not None:
                    cw.trash_can.append(path)
                if constants.FAST:
                    downloader_v3.download(self.audio,
                                           chunk=1024 * 1024,
                                           n_threads=2,
                                           outdir=os.path.dirname(path),
                                           fileName=os.path.basename(path),
                                           customWidget=cw,
                                           overwrite=True)
                else:
                    downloader.download(self.audio,
                                        outdir=os.path.dirname(path),
                                        fileName=os.path.basename(path),
                                        customWidget=cw,
                                        overwrite=True)
                ext, out = ffmpeg.merge(filename,
                                        path,
                                        cw=cw,
                                        vcodec=self.vcodec)
                #print(out)
                name, ext_old = os.path.splitext(filename)
                if ext_old.lower() != ext.lower():
                    print_(u'rename ext {} --> {}'.format(ext_old, ext))
                    filename_new = u'{}{}'.format(name, ext)
                    if os.path.isfile(filename_new):
                        os.remove(filename_new)
                    os.rename(filename, filename_new)
            else:  # convert non-mp4 video -> mp4
                name, ext_old = os.path.splitext(filename)
                filename_new = u'{}.mp4'.format(name)
                print_(u'Convert video: {} -> {}'.format(
                    filename, filename_new))
                ffmpeg.convert(filename, filename_new, cw=cw)
        elif self.type == 'audio' and ext != '.mp3':  # convert non-mp3 audio -> mp3
            name, ext_old = os.path.splitext(filename)
            filename_new = u'{}.mp3'.format(name)
            ffmpeg.convert(filename,
                           filename_new,
                           '-shortest -preset ultrafast -b:a {}k'.format(
                               get_abr()),
                           cw=cw)

        if self.type == 'audio' and ui_setting.albumArt.isChecked():
            try:
                self.thumb.seek(0)  #
                ffmpeg.add_cover(filename_new,
                                 self.thumb, {
                                     'artist': self.username,
                                     'title': self.title
                                 },
                                 cw=cw)
            except Exception as e:
                s = print_error(e)[-1]
                print_(s)

        if ui_setting and ui_setting.subtitle.isChecked():
            lang = {
                'korean': 'ko',
                'english': 'en',
                'japanese': 'ja'
            }[compatstr(ui_setting.subtitleCombo.currentText()).lower()]
            if lang in self.subtitles:
                try:
                    subtitle = self.subtitles[lang]
                    filename_sub = u'{}.vtt'.format(
                        os.path.splitext(filename)[0])
                    downloader.download(
                        subtitle,
                        os.path.dirname(filename_sub),
                        fileName=os.path.basename(filename_sub),
                        overwrite=True)
                    filename_sub_new = u'{}.srt'.format(
                        os.path.splitext(filename_sub)[0])
                    cw.imgs.append(filename_sub_new)
                    cw.dones.add(
                        os.path.realpath(filename_sub_new).replace(
                            '\\\\?\\', ''))
                    srt_converter.convert(filename_sub, filename_sub_new)
                    cw.setSubtitle(True)
                finally:
                    try:
                        os.remove(filename_sub)
                    except:
                        pass

        return filename_new