mirror-yt: Support limiting video height

Users might want to download not the biggest version of a video, so we
support passing a video height limit into yt-dlp.
This commit is contained in:
MasterofJOKers 2025-09-30 18:47:20 +02:00
parent bbc8180aa2
commit e7583336b2
1 changed files with 7 additions and 2 deletions

View File

@ -11,8 +11,10 @@ import click
help='Error out if one of the directories from the given list does not exist') help='Error out if one of the directories from the given list does not exist')
@click.option('--base-dir', type=Path, default='.', show_default=True, @click.option('--base-dir', type=Path, default='.', show_default=True,
help='Base directory where the channel directories get created') help='Base directory where the channel directories get created')
@click.option('--max-video-height', type=int,
help='Maximum height of the video e.g. 720 or 1080 to filter video formats by')
@click.argument('CHANNEL_FILE', required=True) @click.argument('CHANNEL_FILE', required=True)
def download(allow_unknown, base_dir, channel_file): def download(allow_unknown, base_dir, max_video_height, channel_file):
"""Mirror channels from YouTube """Mirror channels from YouTube
The list of channels needs to be provided via CHANNEL_FILE. The format of the file should be one channel per line. The list of channels needs to be provided via CHANNEL_FILE. The format of the file should be one channel per line.
@ -58,8 +60,11 @@ def download(allow_unknown, base_dir, channel_file):
'--download-archive', target_dir / '.archive', '--download-archive', target_dir / '.archive',
'--break-on-existing', '--break-on-existing',
'--write-thumbnail', '--write-thumbnail',
url '--embed-thumbnail',
] ]
if max_video_height:
cmd.extend(['-f', f"bv*[height<={max_video_height}]+ba"])
cmd.append(url)
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=target_dir) p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=target_dir)
prev_output = '' prev_output = ''
while p.poll() is None: while p.poll() is None: