mirror of
https://git.sr.ht/~cadence/NewLeaf
synced 2024-11-22 07:37:29 +00:00
Support true dash manifests
This commit is contained in:
parent
18b383386f
commit
0493e5a236
30
index.py
30
index.py
@ -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,13 +235,18 @@ 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"]:
|
||||||
itagDict[str(f["itag"])] = {
|
if "indexRange" in f:
|
||||||
"initRange": f["initRange"],
|
itagDict[str(f["itag"])] = {
|
||||||
"indexRange": f["indexRange"],
|
"initRange": f["initRange"],
|
||||||
"audioChannels": f["audioChannels"] if "audioChannels" in f else None
|
"indexRange": f["indexRange"],
|
||||||
}
|
"audioChannels": f["audioChannels"] if "audioChannels" in f else None
|
||||||
|
}
|
||||||
for f in result["adaptiveFormats"]:
|
for f in result["adaptiveFormats"]:
|
||||||
if f["itag"] in itagDict:
|
if f["itag"] in itagDict:
|
||||||
i = itagDict[f["itag"]]
|
i = itagDict[f["itag"]]
|
||||||
@ -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"]
|
||||||
|
Loading…
Reference in New Issue
Block a user