Added --closest-resolution flag

This commit is contained in:
chu23465 2025-04-09 11:37:22 +05:30
parent 35dfeb8f7d
commit 49d2dcffd2
2 changed files with 17 additions and 2 deletions

View File

@ -126,7 +126,7 @@ def get_cdm(log, service, profile=None, cdm_name=None):
def get_service_config(service): def get_service_config(service):
"""Get both service config and service secrets as one merged dictionary.""" """Get both service config and service secrets as one merged dictionary."""
print(filenames.service_config.format(service=service.lower())) #print(filenames.service_config.format(service=service.lower())) # This line is probably where the error while loading config under Linux originates #TO-DO
service_config = load_yaml(filenames.service_config.format(service=service.lower())) service_config = load_yaml(filenames.service_config.format(service=service.lower()))
user_config = (load_yaml(filenames.user_service_config.format(service=service.lower())) or load_yaml(filenames.user_service_config.format(service=service))) user_config = (load_yaml(filenames.user_service_config.format(service=service.lower())) or load_yaml(filenames.user_service_config.format(service=service)))
@ -195,6 +195,8 @@ def get_credentials(service, profile="default"):
help="Profile to use when multiple profiles are defined for a service.") help="Profile to use when multiple profiles are defined for a service.")
@click.option("-q", "--quality", callback=quality_param, default=None, @click.option("-q", "--quality", callback=quality_param, default=None,
help="Download Resolution, defaults to best available.") help="Download Resolution, defaults to best available.")
@click.option("-cr", "--closest-resolution", is_flag=True, default=False,
help="If resolution specified not found, defaults to closest resolution available")
@click.option("-v", "--vcodec", callback=vcodec_param, default="H264", @click.option("-v", "--vcodec", callback=vcodec_param, default="H264",
help="Video Codec, defaults to H264.") help="Video Codec, defaults to H264.")
@click.option("-a", "--acodec", callback=acodec_param, default=None, @click.option("-a", "--acodec", callback=acodec_param, default=None,
@ -306,7 +308,7 @@ def dl(ctx, profile, cdm, *_, **__):
@dl.result_callback() @dl.result_callback()
@click.pass_context @click.pass_context
def result(ctx, service, quality, range_, wanted, alang, slang, audio_only, subs_only, chapters_only, audio_description, def result(ctx, service, quality, closest_resolution, range_, wanted, alang, slang, audio_only, subs_only, chapters_only, audio_description,
list_, keys, cache, no_cache, no_subs, no_audio, no_video, no_chapters, atmos, vbitrate: int, abitrate: int, no_mux, mux, selected, latest_episode, *_, **__): list_, keys, cache, no_cache, no_subs, no_audio, no_video, no_chapters, atmos, vbitrate: int, abitrate: int, no_mux, mux, selected, latest_episode, *_, **__):
def ccextractor(): def ccextractor():
log.info("Extracting EIA-608 captions from stream with CCExtractor") log.info("Extracting EIA-608 captions from stream with CCExtractor")
@ -390,6 +392,16 @@ def result(ctx, service, quality, range_, wanted, alang, slang, audio_only, subs
title.tracks.print() title.tracks.print()
try: try:
# Modified video track selection to choose closest resolution if exact match not found
if quality and closest_resolution:
available_resolutions = [int(track.height) for track in title.tracks.videos]
if not available_resolutions:
log.error(" - No video tracks available")
continue
if quality not in available_resolutions:
closest_res = min(available_resolutions, key=lambda x: abs(x - quality))
log.warning(f" - No {quality}p resolution available, using closest available: {closest_res}p")
quality = closest_res
#title.tracks.select_videos(by_quality=quality, by_range=range_, one_only=True) #title.tracks.select_videos(by_quality=quality, by_range=range_, one_only=True)
title.tracks.select_videos(by_quality=quality, by_vbitrate=vbitrate, by_range=range_, one_only=True) title.tracks.select_videos(by_quality=quality, by_vbitrate=vbitrate, by_range=range_, one_only=True)
title.tracks.select_audios(by_language=alang, by_bitrate=abitrate, with_descriptive=audio_description) title.tracks.select_audios(by_language=alang, by_bitrate=abitrate, with_descriptive=audio_description)
@ -507,6 +519,9 @@ def result(ctx, service, quality, range_, wanted, alang, slang, audio_only, subs
session_id=session_id session_id=session_id
) )
assert license assert license
# Convert bytes to string if necessary
if isinstance(license, bytes):
license_response = license_response.decode('utf-8')
ctx.obj.cdm.parse_license( ctx.obj.cdm.parse_license(
session_id, session_id,
license license

Binary file not shown.