feat(dl): Fix track selection to support combining -V, -A, -S flags

Previously, using multiple track selection flags like `-S -A` would not work
as expected. The flags were treated as mutually exclusive, resulting in only
one type of track being downloaded.

This change refactors the track selection logic to properly handle combinations:

- Multiple "only" flags now work together (e.g., `-S -A` downloads both)
- Exclusion flags (`--no-*`) continue to work and override selections
- Default behavior (no flags) remains unchanged

Fixes #10
This commit is contained in:
Andy
2025-08-05 15:48:17 +00:00
parent 8dbdde697d
commit 4dff597af2

View File

@@ -783,23 +783,26 @@ class dl:
sys.exit(1) sys.exit(1)
if video_only or audio_only or subs_only or chapters_only or no_subs or no_audio or no_chapters: if video_only or audio_only or subs_only or chapters_only or no_subs or no_audio or no_chapters:
# Determine which track types to keep based on the flags keep_videos = False
keep_videos = True keep_audio = False
keep_audio = True keep_subtitles = False
keep_subtitles = True keep_chapters = False
keep_chapters = True
# Handle exclusive flags (only keep one type) if video_only or audio_only or subs_only or chapters_only:
if video_only: if video_only:
keep_audio = keep_subtitles = keep_chapters = False keep_videos = True
elif audio_only: if audio_only:
keep_videos = keep_subtitles = keep_chapters = False keep_audio = True
elif subs_only: if subs_only:
keep_videos = keep_audio = keep_chapters = False keep_subtitles = True
elif chapters_only: if chapters_only:
keep_videos = keep_audio = keep_subtitles = False keep_chapters = True
else:
keep_videos = True
keep_audio = True
keep_subtitles = True
keep_chapters = True
# Handle exclusion flags (remove specific types)
if no_subs: if no_subs:
keep_subtitles = False keep_subtitles = False
if no_audio: if no_audio:
@@ -807,7 +810,6 @@ class dl:
if no_chapters: if no_chapters:
keep_chapters = False keep_chapters = False
# Build the kept_tracks list without duplicates
kept_tracks = [] kept_tracks = []
if keep_videos: if keep_videos:
kept_tracks.extend(title.tracks.videos) kept_tracks.extend(title.tracks.videos)