Esempio n. 1
0
    def _convert_episode(self, episode):
        if not self._check_source(episode):
            return

        new_extension = self._get_new_extension()
        old_filename = episode.local_filename(create=False)
        filename, old_extension = os.path.splitext(old_filename)
        new_filename = filename + new_extension

        cmd = [self.command] + \
            [param % {'old_file': old_filename, 'new_file': new_filename}
                for param in self.command_param]

        if gpodder.ui.win32:
            ffmpeg = util.Popen(cmd)
            ffmpeg.wait()
            stdout, stderr = ("<unavailable>",) * 2
        else:
            ffmpeg = util.Popen(cmd, stdout=subprocess.PIPE,
                    stderr=subprocess.PIPE)
            stdout, stderr = ffmpeg.communicate()

        if ffmpeg.returncode == 0:
            util.rename_episode_file(episode, new_filename)
            os.remove(old_filename)

            logger.info('Converted video file to %(format)s.' % {'format': self.config.output_format})
            gpodder.user_extensions.on_notification_show(_('File converted'), episode.title)
        else:
            logger.warning('Error converting video file: %s / %s', stdout, stderr)
            gpodder.user_extensions.on_notification_show(_('Conversion failed'), episode.title)
Esempio n. 2
0
    def _convert_episode(self, episode):
        if episode.file_type() != 'audio':
            return

        filename = episode.local_filename(create=False)
        if filename is None:
            return

        basename, extension = os.path.splitext(filename)

        cmd = [CONVERT_COMMANDS.get(extension, 'normalize-audio'), filename]

        if gpodder.ui.win32:
            p = util.Popen(cmd)
            p.wait()
            stdout, stderr = ("<unavailable>",) * 2
        else:
            p = util.Popen(cmd, stdout=subprocess.PIPE,
                    stderr=subprocess.PIPE)
            stdout, stderr = p.communicate()

        if p.returncode == 0:
            logger.info('normalize-audio processing successful.')
            gpodder.user_extensions.on_notification_show(_('File normalized'),
                    episode.title)
        else:
            logger.warn('normalize-audio failed: %s / %s', stdout, stderr)
Esempio n. 3
0
    def _convert_mp4(self, episode, from_file):
        """Convert MP4 file to rockbox mpg file"""

        # generate new filename and check if the file already exists
        to_file = self._get_rockbox_filename(from_file)
        if to_file is None:
            return None
        if os.path.isfile(to_file):
            return to_file

        logger.info("Converting: %s", from_file)
        gpodder.user_extensions.on_notification_show("Converting",
                                                     episode.title)

        # calculationg the new screen resolution
        info = kaa.metadata.parse(from_file)
        resolution = self._calc_resolution(info.video[0].width,
                                           info.video[0].height,
                                           self.container.config.device_width,
                                           self.container.config.device_height)
        if resolution is None:
            logger.error("Error calculating the new screen resolution")
            return None

        convert_command = FFMPEG_CMD % {
            'from': from_file,
            'to': to_file,
            'width': str(resolution[0]),
            'height': str(resolution[1]),
            'options': self.container.config.ffmpeg_options
        }

        if gpodder.ui.win32:
            p = util.Popen(shlex.split(convert_command))
            p.wait()
            stdout, stderr = ("<unavailable>", ) * 2
        else:
            process = util.Popen(shlex.split(convert_command),
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
            stdout, stderr = process.communicate()
        if process.returncode != 0:
            logger.error(stderr)
            return None

        gpodder.user_extensions.on_notification_show("Converting finished",
                                                     episode.title)

        return to_file
Esempio n. 4
0
    def run_command(self, command, info):
        env = os.environ.copy()
        env.update(info)

        proc = util.Popen(command, shell=True, env=env, close_fds=True)
        proc.wait()
        if proc.returncode == 0:
            logger.info("%s succeeded", command)
        else:
            logger.warn("%s run with exit code %i", command, proc.returncode)
Esempio n. 5
0
 def convert():
     ffmpeg = util.Popen(['ffmpeg', '-f', 'concat', '-nostdin', '-y',
                          '-i', list_filename, '-c', 'copy', out_filename],
                         close_fds=True)
     result = ffmpeg.wait()
     util.delete_file(list_filename)
     util.idle_add(lambda: indicator.on_finished())
     util.idle_add(lambda: self.gpodder.show_message(
         _('Videos successfully converted') if result == 0 else
         _('Error converting videos'),
         _('Concatenation result'), important=True))
Esempio n. 6
0
    def _convert_episode(self, episode):
        if not self._check_source(episode):
            return

        new_extension = self._get_new_extension()
        old_filename = episode.local_filename(create=False)
        filename, old_extension = os.path.splitext(old_filename)
        new_filename = filename + new_extension

        cmd_param = self.CMD[self.command_without_ext][new_extension]
        cmd = [self.command] + \
            [param % {'old_file': old_filename, 'new_file': new_filename}
                for param in cmd_param]

            ffmpeg = util.Popen(cmd, stdout=subprocess.PIPE,
                    stderr=subprocess.PIPE)
            stdout, stderr = ffmpeg.communicate()
Esempio n. 7
0
 def open_files(self, filenames):
     for cmd in util.format_desktop_command(self.command, filenames):
         util.Popen(cmd, close_fds=True)
Esempio n. 8
0
 def open_files(self, filenames):
     util.Popen(self.command + filenames)
Esempio n. 9
0
 def on_load(self):
     logger.info('Starting Ubuntu Unity Integration.')
     os.environ['PYTHONPATH'] = os.pathsep.join(sys.path)
     self.process = util.Popen(['python', __file__],
                               stdin=subprocess.PIPE)