From d612599e278243c1e84ff53744943439e9b11b97 Mon Sep 17 00:00:00 2001 From: rlaphoenix Date: Fri, 10 Feb 2023 21:10:09 +0000 Subject: [PATCH] Add Audio Channels Selection option to dl command CLI Sub-channel layouts like 5.1, 7.1, will match with e.g., 6.0 and 8.0 respectively. Closes #9. --- devine/commands/dl.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/devine/commands/dl.py b/devine/commands/dl.py index 880a209..8dd75b5 100644 --- a/devine/commands/dl.py +++ b/devine/commands/dl.py @@ -2,6 +2,7 @@ from __future__ import annotations import html import logging +import math import random import re import sys @@ -71,6 +72,9 @@ class dl: @click.option("-r", "--range", "range_", type=click.Choice(Video.Range, case_sensitive=False), default=Video.Range.SDR, help="Video Color Range, defaults to SDR.") + @click.option("-c", "--channels", type=float, + default=None, + help="Audio Channel(s) to download. Matches sub-channel layouts like 5.1 with 6.0 implicitly.") @click.option("-w", "--wanted", type=SEASON_RANGE, default=None, help="Wanted episodes, e.g. `S01-S05,S07`, `S01E01-S02E03`, `S02-S02E03`, e.t.c, defaults to all.") @click.option("-l", "--lang", type=LANGUAGE_RANGE, default="en", @@ -243,6 +247,7 @@ class dl: vbitrate: int, abitrate: int, range_: Video.Range, + channels: float, wanted: list[str], lang: list[str], v_lang: list[str], @@ -370,6 +375,11 @@ class dl: title.tracks.select_audio(lambda x: x.bitrate and x.bitrate // 1000 == abitrate) if not title.tracks.audio: self.log.error(f"There's no {abitrate}kbps Audio Track...") + if channels: + title.tracks.select_audio(lambda x: math.ceil(x.channels) == math.ceil(channels)) + if not title.tracks.audio: + self.log.error(f"There's no {channels} Audio Track...") + sys.exit(1) if lang and "all" not in lang: title.tracks.audio = title.tracks.select_per_language(title.tracks.audio, lang)