From 8d539baa2a10152aa8bfbfeaa1147a5f4034e8f3 Mon Sep 17 00:00:00 2001 From: lpozo Date: Tue, 26 Sep 2017 22:41:59 -0400 Subject: [PATCH] Code reuse by extracting method Refactor Converter.__init__ and add Converter._init_codecs method to initialize the codecs --- converter/__init__.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/converter/__init__.py b/converter/__init__.py index 73430d7..31d493f 100644 --- a/converter/__init__.py +++ b/converter/__init__.py @@ -30,22 +30,22 @@ def __init__(self, ffmpeg_path=None, ffprobe_path=None): self.subtitle_codecs = {} self.formats = {} - for cls in audio_codec_list: - name = cls.codec_name - self.audio_codecs[name] = cls - - for cls in video_codec_list: - name = cls.codec_name - self.video_codecs[name] = cls - - for cls in subtitle_codec_list: - name = cls.codec_name - self.subtitle_codecs[name] = cls + self._init_codecs(codec_list=audio_codec_list, + codecs=self.audio_codecs) + self._init_codecs(codec_list=video_codec_list, + codecs=self.video_codecs) + self._init_codecs(codec_list=subtitle_codec_list, + codecs=self.subtitle_codecs) for cls in format_list: name = cls.format_name self.formats[name] = cls + def _init_codecs(self, codec_list, codecs): + for cls in codec_list: + name = cls.codec_name + codecs[name] = cls + def parse_options(self, opt, twopass=None): """ Parse format/codec options and prepare raw ffmpeg option list.