You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an issue with some videos being a varied height resulting in a "list index out of range" error.
Chat gippity provided some code to get the nearest resolution it could with this rewrite:
def parse_resolution(metadata, resolution, filename):
try:
with open(metadata, "r") as file:
res = json.load(file)
resolution_mapping = {
"1080p": 1080,
"720p": 720,
"540p": 540,
"480p": 480,
"360p": 360,
}
selected_resolution = resolution_mapping.get(resolution, 1080)
# Find the closest available resolution
available_resolutions = [(x["height"], x["url"]) for x in res]
available_resolutions.sort(key=lambda x: abs(x[0] - selected_resolution))
if available_resolutions:
closest_resolution = available_resolutions[0]
video_url = closest_resolution[1]
download_video(video_url, filename + ".mp4")
else:
print("No video URLs found.")
except Exception as e:
print(e)
sys.exit(0)
The text was updated successfully, but these errors were encountered:
I have an issue with some videos being a varied height resulting in a "list index out of range" error.
Chat gippity provided some code to get the nearest resolution it could with this rewrite:
def parse_resolution(metadata, resolution, filename):
try:
with open(metadata, "r") as file:
res = json.load(file)
The text was updated successfully, but these errors were encountered: