From 578b7f2754f99171382fe7b4f11aafd4f54af784 Mon Sep 17 00:00:00 2001 From: Johan Andersson Date: Thu, 9 Jun 2022 21:55:53 +0200 Subject: [PATCH] add support for only audio when its one media file --- lib/svtplay_dl/fetcher/hls.py | 2 +- lib/svtplay_dl/postprocess/__init__.py | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/svtplay_dl/fetcher/hls.py b/lib/svtplay_dl/fetcher/hls.py index 76a65b3..c1d9a7f 100644 --- a/lib/svtplay_dl/fetcher/hls.py +++ b/lib/svtplay_dl/fetcher/hls.py @@ -214,7 +214,7 @@ class HLS(VideoRetriever): if self.audio and not self.config.get("only_video"): # self._download(self.audio, file_name=(copy.copy(self.output), "audio.ts")) self._download(self.audio, True) - if not self.config.get("only_audio"): + if not self.audio or not self.config.get("only_audio"): self._download(self.url) else: diff --git a/lib/svtplay_dl/postprocess/__init__.py b/lib/svtplay_dl/postprocess/__init__.py index a32f7c9..f5ccf9e 100644 --- a/lib/svtplay_dl/postprocess/__init__.py +++ b/lib/svtplay_dl/postprocess/__init__.py @@ -48,7 +48,7 @@ class postprocess: audio_filename = orig_filename.with_suffix(".m4a") cmd = [self.detect] - if self.config.get("only_video") or not self.config.get("only_audio"): + if self.config.get("only_video") or (not self.config.get("only_audio") or (not self.stream.audio and self.config.get("only_audio"))): cmd += ["-i", str(orig_filename)] if self.stream.audio and self.config.get("only_audio") or not self.config.get("only_video"): cmd += ["-i", str(audio_filename)] @@ -62,13 +62,19 @@ class postprocess: logging.info("Merge audio and video into %s", new_name.name) tempfile = orig_filename.with_suffix(".temp") - arguments = ["-c:v", "copy", "-c:a", "copy", "-f", "matroska" if self.config.get("output_format") == "mkv" else "mp4"] + + arguments = [] + if self.config.get("only_audio"): + arguments += ["-vn"] + if self.config.get("only_video"): + arguments += ["-an"] + arguments += ["-c:v", "copy", "-c:a", "copy", "-f", "matroska" if self.config.get("output_format") == "mkv" else "mp4"] if ext == ".ts": if audiotrack and "aac" in _getcodec(streams, audiotrack): arguments += ["-bsf:a", "aac_adtstoasc"] cmd = [self.detect] - if self.config.get("only_video") or not self.config.get("only_audio"): + if self.config.get("only_video") or (not self.config.get("only_audio") or (not self.stream.audio and self.config.get("only_audio"))): cmd += ["-i", str(orig_filename)] if (self.stream.audio and self.config.get("only_audio")) or (self.stream.audio and not self.config.get("only_video")): cmd += ["-i", str(audio_filename)] @@ -116,7 +122,7 @@ class postprocess: return logging.info("Merging done, removing old files.") - if self.config.get("only_video") or not self.config.get("only_audio"): + if self.config.get("only_video") or (not self.config.get("only_audio") or (not self.stream.audio and self.config.get("only_audio"))): os.remove(orig_filename) if (self.stream.audio and self.config.get("only_audio")) or (self.stream.audio and not self.config.get("only_video")): os.remove(audio_filename)