1
0
mirror of https://git.sr.ht/~cadence/NewLeaf synced 2024-11-26 01:17:29 +00:00

Support true dash manifests

This commit is contained in:
Cadence Ember 2020-08-09 22:31:54 +12:00
parent 18b383386f
commit 0493e5a236
No known key found for this signature in database
GPG Key ID: 128B99B1B74A6412

View File

@ -116,7 +116,8 @@ class Second(object):
"isListed": None, "isListed": None,
"liveNow": None, "liveNow": None,
"isUpcoming": None, "isUpcoming": None,
"dashUrl": None, "dashUrl": "/api/manifest/dash/id/{}".format(info["id"]),
"second__providedDashUrl": None,
"adaptiveFormats": list({ "adaptiveFormats": list({
"index": None, "index": None,
"bitrate": str(int(format["tbr"]*1000)), "bitrate": str(int(format["tbr"]*1000)),
@ -159,7 +160,8 @@ class Second(object):
# Now try to get more stuff by manually examining the saved file # Now try to get more stuff by manually examining the saved file
# Figure out what the name of the saved file was # Figure out what the name of the saved file was
recommendations = [] recommendations = []
possible_files = [f for f in os.listdir() if f.startswith("{}_".format(info["id"]))] created_files = [f for f in os.listdir() if f.startswith("{}_".format(info["id"]))]
possible_files = [f for f in created_files if f.startswith("{}_https_-_www.youtube.com".format(info["id"]))]
try: try:
if len(possible_files) == 1: if len(possible_files) == 1:
filename = possible_files[0] filename = possible_files[0]
@ -233,8 +235,13 @@ class Second(object):
if m_yt_player_config: if m_yt_player_config:
yt_player_config = json.loads(m_yt_player_config.group(1)) yt_player_config = json.loads(m_yt_player_config.group(1))
player_response = json.loads(yt_player_config["args"]["player_response"]) player_response = json.loads(yt_player_config["args"]["player_response"])
if "dashManifestUrl" in player_response["streamingData"]:
result["second__providedDashUrl"] = player_response["streamingData"]["dashManifestUrl"]
# result = player_response
# return result
itagDict = {} itagDict = {}
for f in player_response["streamingData"]["adaptiveFormats"]: for f in player_response["streamingData"]["adaptiveFormats"]:
if "indexRange" in f:
itagDict[str(f["itag"])] = { itagDict[str(f["itag"])] = {
"initRange": f["initRange"], "initRange": f["initRange"],
"indexRange": f["indexRange"], "indexRange": f["indexRange"],
@ -248,10 +255,11 @@ class Second(object):
f["second__audioChannels"] = i["audioChannels"] f["second__audioChannels"] = i["audioChannels"]
except Exception: except Exception:
print("messed up extracting recommendations.")
traceback.print_exc() traceback.print_exc()
finally: finally:
for file in possible_files: for file in created_files:
os.unlink(file) os.unlink(file)
self.video_cache[id] = result self.video_cache[id] = result
@ -272,6 +280,12 @@ class Second(object):
if "error" in video: if "error" in video:
return video return video
if video["second__providedDashUrl"]:
with requests.get(video["second__providedDashUrl"]) as r:
r.raise_for_status()
cherrypy.response.headers["content-type"] = r.headers["content-type"]
return r
adaptation_sets_dict = {} adaptation_sets_dict = {}
for f in video["adaptiveFormats"]: for f in video["adaptiveFormats"]:
mime = f["second__mime"] mime = f["second__mime"]