Hi,
i want to understand and learn, i’ve json files that generate all formats in videos like this
[
{
“format_id”:“sb3”,
“format_note”:“storyboard”,
“ext”:“mhtml”,
“protocol”:“mhtml”,
“acodec”:“none”,
“vcodec”:“none”,
“url”:"
“width”:48,
“height”:27,
“fps”:0.12150668286755771,
“rows”:10,
“columns”:10,
“fragments”:[
{
“url”:
}
],
“audio_ext”:“none”,
“video_ext”:“none”,
“format”:“sb3 - 48x27 (storyboard)”,
“resolution”:“48x27”,
“http_headers”:{
“User-Agent”:“Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36”,
“Accept”:“text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8”,
“Accept-Language”:“en-us,en;q=0.5”,
“Sec-Fetch-Mode”:“navigate”
}
},
{
“format_id”:“sb2”,
“format_note”:“storyboard”,
“ext”:“mhtml”,
“protocol”:“mhtml”,
“acodec”:“none”,
“vcodec”:“none”,
“url”:“,
“width”:60,
“height”:45,
“fps”:0.20170109356014582,
“rows”:10,
“columns”:10,
“fragments”:[
{
“url”:”“,
“duration”:495.7831325301205
},
{
“url”:”,
“duration”:327.2168674698795
}
],
“audio_ext”:“none”,
“video_ext”:“none”,
“format”:“sb2 - 60x45 (storyboard)”,
“resolution”:“60x45”,
“http_headers”:{
“User-Agent”:“Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36”,
“Accept”:“text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8”,
“Accept-Language”:“en-us,en;q=0.5”,
“Sec-Fetch-Mode”:“navigate”
}
},
{
“format_id”:“sb1”,
“format_note”:“storyboard”,
“ext”:“mhtml”,
“protocol”:“mhtml”,
“acodec”:“none”,
“vcodec”:“none”,
“url”:“”,
“width”:120,
“height”:90,
“fps”:0.20170109356014582,
“rows”:5,
“columns”:5,
“fragments”:[
{
“url”:“,
“duration”:123.94578313253012
},
{
“url”:”“,
“duration”:123.94578313253012
},
{
“url”:”“,
“duration”:123.94578313253012
},
{
“url”:”“,
“duration”:123.94578313253012
},
{
“url”:”“,
“duration”:123.94578313253012
},
{
“url”:”“,
“duration”:123.94578313253012
},
{
“url”:”“,
“duration”:79.3253012048192
}
],
“audio_ext”:“none”,
“video_ext”:“none”,
“format”:“sb1 - 120x90 (storyboard)”,
“resolution”:“120x90”,
“http_headers”:{
“User-Agent”:“Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36”,
“Accept”:“text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8”,
“Accept-Language”:“en-us,en;q=0.5”,
“Sec-Fetch-Mode”:“navigate”
}
},
{
“format_id”:“sb0”,
“format_note”:“storyboard”,
“ext”:“mhtml”,
“protocol”:“mhtml”,
“acodec”:“none”,
“vcodec”:“none”,
“url”:”,
“width”:240,
“height”:180,
“fps”:0.20170109356014582,
“rows”:3,
“columns”:3,
“fragments”:[
{
“url”:“”,
“duration”:44.62048192771085
},
{
“url”:“”,
“duration”:44.62048192771085
},
{
“url”:“”,
“duration”:44.62048192771085
},
{
“url”:“,
“duration”:44.62048192771085
},
{
“url”:”“,
“duration”:44.62048192771085
},
{
“url”:”“,
“duration”:44.62048192771085
},
{
“url”:”“,
“duration”:44.62048192771085
},
{
“url”:”“,
“duration”:44.62048192771085
},
{
“url”:”“,
“duration”:44.62048192771085
},
{
“url”:”“,
“duration”:44.62048192771085
},
{
“url”:”",
“duration”:44.62048192771085
},"duration":19.831325301204743 } ], "audio_ext":"none", "video_ext":"none", "format":"sb0 - 240x180 (storyboard)", "resolution":"240x180", "http_headers":{ "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36", "Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Language":"en-us,en;q=0.5", "Sec-Fetch-Mode":"navigate" }
},
those code are generate all formats in 1 videos.
using another python code (Python.py code) like this :
def extract_video_data_from_url(url):
command = f'youtube-dl "{url}" -j --no-playlist' output = os.popen(command).read() video_data = json.loads(output) title = video_data["title"] formats = video_data["formats"] for element in formats: if "251 -" in element['format']: element['format'] = "1" elif "18 -" in element['format']: element['format'] = "2" elif "22 -" in element['format']: element['format'] = "2" else: element['format'] = "Broken Link" thumbnail = video_data["thumbnail"] formats = [extract_format_data(format_data) for format_data in formats] return { "title": title, "formats": formats, "thumbnail": thumbnail }
and it show pictures like this :
how i can filter the button in Python.py code so that shows only 1 and 2 in the buttons? the “broken link” should gone or cannot in the loop.
Thanks