From 0bf089c4a57f9edbd9ad85c50519f747d04db4d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Koh=C3=A1nyi=20R=C3=B3bert?= Date: Sat, 25 Jul 2015 17:39:36 +0200 Subject: [PATCH] Update YoutubeDL.select_format to consider --audio-format parameter. --- youtube_dl/YoutubeDL.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index 702a6ad50..3fb8ee0ae 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -916,6 +916,23 @@ class YoutubeDL(object): return (new_format_spec, new_formats) + def _bestaudio_for_lossless_extract(self, audio_formats): + pps = self.params["postprocessors"] + if not pps: + return None + [pp for pp in pps if pp["key"] == "FFmpegExtractAudio"] + if not pp: + return None + pc = pp["preferredcodec"] + if pc == "m4a": + pc = "aac" + if not pc: + return None + for af in audio_formats: + if af["acodec"] == pc: + return af + return None + def select_format(self, format_spec, available_formats): while format_spec.endswith(']'): format_spec, available_formats = self._apply_format_filter( @@ -939,6 +956,9 @@ class YoutubeDL(object): f for f in available_formats if f.get('vcodec') == 'none'] if audio_formats: + af = self._bestaudio_for_lossless_extract(audio_formats) + if af: + return af return audio_formats[-1] elif format_spec == 'worstaudio': audio_formats = [