Untitled
unknown
plain_text
a year ago
3.5 kB
11
Indexable
# Assuming this code is within a class and is part of a larger process
# --- Start of the corrected code ---
if 'vod-cf' in playback['content_url']:
mpd_url = playback['content_url'].split('?')[0]
datax = self.session.get(playback['content_url'])
data = datax.text
# FIX: Get the cookies as a dictionary directly.
# We will pass this dictionary to the download function later.
cookies = datax.cookies.get_dict()
# We don't need to create the 'cookie' header string manually anymore.
# self.session.headers.update({'cookie': cookies_}) is no longer needed.
# Prepare the headers for the downloader.
# This dictionary should NOT contain the 'cookie' header.
# Assuming self.session.headers already has other headers like 'User-Agent'.
# If not, you might need to build it here.
download_headers = self.session.headers.copy()
if 'cookie' in download_headers:
del download_headers['cookie']
else:
mpd_url = playback['content_url']
r = Request(playback["content_url"])
# It's good practice to set headers on the Request object itself.
r.add_header(
"user-agent",
"Disney+;in.startv.hotstar.dplus.tv/23.08.14.4.2915 (Android/13)",
)
r1 = urlopen(r)
# FIX: Get the cookies as a dictionary instead of a single string.
# This is the format required by the aria2c downloader.
download_cookies = {}
cookies_list = r1.info().get_all("Set-Cookie")
if cookies_list is not None:
for cookie_str in cookies_list:
# Parse each cookie string and add it to the dictionary
key_value_pair = cookie_str.split(";")[0].split("=", 1)
if len(key_value_pair) == 2:
download_cookies[key_value_pair[0]] = key_value_pair[1]
data = r1.read()
if isinstance(data, bytes):
data = data.decode("utf-8", errors="replace")
if ".m3u8" in mpd_url:
data = data.decode("utf-8")
# Prepare the headers for the downloader.
# This dictionary should NOT contain the 'cookie' header.
download_headers = {
"user-agent": "Disney+;in.startv.hotstar.dplus.tv/23.08.14.4.2915 (Android/13)",
}
if ".mpd" in mpd_url:
self.log.debug(f"Video MPD : {mpd_url}")
tracks = DASH.from_text(data, mpd_url).to_tracks(title.language)
# FIX: This is where you would call the download function.
# The crucial change is passing 'download_cookies' to a 'cookies' parameter.
# You need to replace 'your_download_function' with the actual function name.
# The 'headers' parameter should only contain non-cookie headers.
# your_downloader_class.your_download_function(
# url=mpd_url,
# headers=download_headers,
# cookies=download_cookies, # Pass the cookies separately
# tracks=tracks
# )
else:
self.log.debug(f"M3U8 : {mpd_url}")
tracks = HLS.from_text(self.session.get(mpd_url).text, url=mpd_url).to_tracks(title.language)
# FIX: Same as above, call the download function with the separated cookies.
# your_downloader_class.your_download_function(
# url=mpd_url,
# headers=download_headers,
# cookies=download_cookies, # Pass the cookies separately
# tracks=tracks
# ) Editor is loading...
Leave a Comment