mirror of
https://git.sr.ht/~cadence/NewLeaf
synced 2024-11-14 20:17:29 +00:00
Experimental: filter specific itags for dash video
This commit is contained in:
parent
4a4f48e9d9
commit
c2a7bb907b
@ -61,25 +61,6 @@ def extract_video(id):
|
|||||||
day = int(info["upload_date"][6:8])
|
day = int(info["upload_date"][6:8])
|
||||||
published = int(datetime.datetime(year, month, day).timestamp())
|
published = int(datetime.datetime(year, month, day).timestamp())
|
||||||
|
|
||||||
# Adaptive formats have either audio or video, format streams have both
|
|
||||||
def format_is_adaptive(format):
|
|
||||||
return format["acodec"] == "none" or format["vcodec"] == "none"
|
|
||||||
|
|
||||||
def format_mime(format):
|
|
||||||
sense = "video" if format["vcodec"] != "none" else "audio"
|
|
||||||
return "{}/{}".format(sense, format["ext"])
|
|
||||||
|
|
||||||
def format_codecs(format):
|
|
||||||
codecs = []
|
|
||||||
if format["vcodec"] != "none":
|
|
||||||
codecs.append(format["vcodec"])
|
|
||||||
if format["acodec"] != "none":
|
|
||||||
codecs.append(format["acodec"])
|
|
||||||
return codecs
|
|
||||||
|
|
||||||
def format_type(format):
|
|
||||||
return '{}; codecs="{}"'.format(format_mime(format), ", ".join(format_codecs(format)))
|
|
||||||
|
|
||||||
result = {
|
result = {
|
||||||
"type": "video",
|
"type": "video",
|
||||||
"title": info["title"],
|
"title": info["title"],
|
||||||
@ -117,15 +98,43 @@ def extract_video(id):
|
|||||||
"isUpcoming": None,
|
"isUpcoming": None,
|
||||||
"dashUrl": "{}/api/manifest/dash/id/{}".format(configuration.website_origin, info["id"]),
|
"dashUrl": "{}/api/manifest/dash/id/{}".format(configuration.website_origin, info["id"]),
|
||||||
"second__providedDashUrl": None,
|
"second__providedDashUrl": None,
|
||||||
"adaptiveFormats": [{
|
"adaptiveFormats": [],
|
||||||
|
"formatStreams": [],
|
||||||
|
"captions": [],
|
||||||
|
"recommendedVideos": []
|
||||||
|
}
|
||||||
|
|
||||||
|
for format in info["formats"]:
|
||||||
|
# Adaptive formats have either audio or video, format streams have both
|
||||||
|
is_adaptive = format["acodec"] == "none" or format["vcodec"] == "none"
|
||||||
|
sense = "video" if format["vcodec"] != "none" else "audio"
|
||||||
|
mime = sense + "/" + format["ext"]
|
||||||
|
codecs = []
|
||||||
|
if format["vcodec"] != "none":
|
||||||
|
codecs.append(format["vcodec"])
|
||||||
|
if format["acodec"] != "none":
|
||||||
|
codecs.append(format["acodec"])
|
||||||
|
result_type = '{}; codecs="{}"'.format(mime, ", ".join(codecs))
|
||||||
|
|
||||||
|
if is_adaptive:
|
||||||
|
url = ""
|
||||||
|
if format["protocol"] == "http_dash_segments":
|
||||||
|
# this is http dash, which is annoying and doesn't work in <video>.
|
||||||
|
# we have a fragment_base_url, which seems to be playable for all audio, but only with certain video itags??? very confused
|
||||||
|
if format["acodec"] == "none" and format["format_id"] not in ["134", "136"]:
|
||||||
|
continue
|
||||||
|
url = format["fragment_base_url"]
|
||||||
|
else: # just a normal media file
|
||||||
|
url = format["url"]
|
||||||
|
result["adaptiveFormats"].append({
|
||||||
"index": None,
|
"index": None,
|
||||||
"bitrate": str(int(format["tbr"]*1000)),
|
"bitrate": str(int(format["tbr"]*1000)),
|
||||||
"init": None,
|
"init": None,
|
||||||
"url": format["fragment_base_url"] if format["protocol"] == "http_dash_segments" else format["url"],
|
"url": url,
|
||||||
"itag": format["format_id"],
|
"itag": format["format_id"],
|
||||||
"type": format_type(format),
|
"type": result_type,
|
||||||
"second__mime": format_mime(format),
|
"second__mime": mime,
|
||||||
"second__codecs": format_codecs(format),
|
"second__codecs": codecs,
|
||||||
"clen": str(format["filesize"]) if format["filesize"] else None,
|
"clen": str(format["filesize"]) if format["filesize"] else None,
|
||||||
"lmt": None,
|
"lmt": None,
|
||||||
"projectionType": None,
|
"projectionType": None,
|
||||||
@ -138,25 +147,23 @@ def extract_video(id):
|
|||||||
"second__height": format["height"],
|
"second__height": format["height"],
|
||||||
"second__audioChannels": None,
|
"second__audioChannels": None,
|
||||||
"second__order": 0
|
"second__order": 0
|
||||||
} for format in info["formats"] if format_is_adaptive(format)],
|
})
|
||||||
"formatStreams": [{
|
else: # format is not adaptive
|
||||||
|
result["formatStreams"].append({
|
||||||
"url": format["url"],
|
"url": format["url"],
|
||||||
"itag": format["format_id"],
|
"itag": format["format_id"],
|
||||||
"type": format_type(format),
|
"type": result_type,
|
||||||
"second__mime": format_mime(format),
|
"second__mime": mime,
|
||||||
"quality": None,
|
"quality": None,
|
||||||
"fps": format["fps"],
|
"fps": format["fps"],
|
||||||
"container": format["ext"],
|
"container": format["ext"],
|
||||||
"encoding": None,
|
"encoding": None,
|
||||||
"resolution": format["format_note"],
|
"resolution": format["format_note"],
|
||||||
"qualityLabel": format["format_note"],
|
"qualityLabel": format["format_note"],
|
||||||
"size": "{}x{}".format(format["width"], format["height"]),
|
"size": str(format["width"]) + "x" + str(format["height"]),
|
||||||
"second__width": format["width"],
|
"second__width": format["width"],
|
||||||
"second__height": format["height"]
|
"second__height": format["height"]
|
||||||
} for format in info["formats"] if not format_is_adaptive(format)],
|
})
|
||||||
"captions": [],
|
|
||||||
"recommendedVideos": []
|
|
||||||
}
|
|
||||||
|
|
||||||
result = get_more_stuff_from_file(info["id"], result)
|
result = get_more_stuff_from_file(info["id"], result)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user