1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-28 06:04:17 +01:00

simplify m3u media_segment by adding tag 'URI'

This commit is contained in:
dalgr 2018-01-06 00:08:29 +01:00 committed by Johan Andersson
parent c28e35b1cb
commit 786fc6a027

View File

@ -86,19 +86,17 @@ class HLS(VideoRetriever):
if self.options.live and not self.options.force: if self.options.live and not self.options.force:
raise LiveHLSException(self.url) raise LiveHLSException(self.url)
cookies = self.kwargs["cookies"] if self.audio:
data_m3u = self.http.request("get", self.url, cookies=cookies).text cookies = self.kwargs["cookies"]
m3u8 = M3U8(data_m3u)
# TODO: fix me
if ("avc1" in m3u8.media_segment[0][0].lower()) and self.audio:
audio_data_m3u = self.http.request("get", self.audio, cookies=cookies).text audio_data_m3u = self.http.request("get", self.audio, cookies=cookies).text
audio_m3u8 = M3U8(audio_data_m3u) audio_m3u8 = M3U8(audio_data_m3u)
total_size = audio_m3u8.media_segment[-1][1]["EXT-X-BYTERANGE"]["n"] + audio_m3u8.media_segment[-1][1]["EXT-X-BYTERANGE"]["o"] total_size = audio_m3u8.media_segment[-1]["EXT-X-BYTERANGE"]["n"] + audio_m3u8.media_segment[-1]["EXT-X-BYTERANGE"]["o"]
self._download_url(audio_m3u8.media_segment[0][0], audio=True, total_size=total_size) self._download_url(audio_m3u8.media_segment[0]["URI"], audio=True, total_size=total_size)
total_size = m3u8.media_segment[-1][1]["EXT-X-BYTERANGE"]["n"] + m3u8.media_segment[-1][1]["EXT-X-BYTERANGE"]["o"] data_m3u = self.http.request("get", self.url, cookies=cookies).text
self._download_url(m3u8.media_segment[0][0], total_size=total_size) m3u8 = M3U8(data_m3u)
total_size = m3u8.media_segment[-1]["EXT-X-BYTERANGE"]["n"] + m3u8.media_segment[-1]["EXT-X-BYTERANGE"]["o"]
self._download_url(m3u8.media_segment[0]["URI"], total_size=total_size)
else: else:
self._download(self.url) self._download(self.url)
@ -119,21 +117,14 @@ class HLS(VideoRetriever):
if file_d is None: if file_d is None:
return return
all_urls = [x[0] for x in m3u8.media_segment]
# duplicate_urls
if all_urls[1:][::][0] == all_urls[:-1][::][0]:
dl_urls = [m3u8.media_segment[0]]
else:
dl_urls = m3u8.media_segment
decryptor = None decryptor = None
eta = ETA(len(dl_urls)) eta = ETA(len(m3u8.media_segment))
for index, i in enumerate(dl_urls): for index, i in enumerate(m3u8.media_segment):
item = _get_full_url(i[0], url) item = _get_full_url(i["URI"], url)
if not self.options.silent: if not self.options.silent:
eta.increment() eta.increment()
progressbar(len(dl_urls), index+1, ''.join(['ETA: ', str(eta)])) progressbar(len(m3u8.media_segment), index+1, ''.join(['ETA: ', str(eta)]))
data = self.http.request("get", item, cookies=cookies) data = self.http.request("get", item, cookies=cookies)
if data.status_code == 404: if data.status_code == 404:
@ -146,10 +137,11 @@ class HLS(VideoRetriever):
keycookies = cookies keycookies = cookies
# Update key/decryptor # Update key/decryptor
if "EXT-X-KEY" in i[1]: if "EXT-X-KEY" in i:
keyurl = _get_full_url(i[1]["EXT-X-KEY"]["URI"], self.url) keyurl = _get_full_url(i["EXT-X-KEY"]["URI"], self.url)
key = self.http.request("get", keyurl, cookies=keycookies).content key = self.http.request("get", keyurl, cookies=keycookies).content
decryptor = AES.new(key, AES.MODE_CBC, os.urandom(16)) decryptor = AES.new(key, AES.MODE_CBC, os.urandom(16))
if decryptor: if decryptor:
data = decryptor.decrypt(data) data = decryptor.decrypt(data)
else: else:
@ -235,6 +227,7 @@ class M3U8():
info["n"], info["o"] = (int(n), int(o)) info["n"], info["o"] = (int(n), int(o))
else: else:
info["n"] = int(attr) info["n"] = int(attr)
info["o"] = 0
# 4.3.2.3. EXT-X-DISCONTINUITY # 4.3.2.3. EXT-X-DISCONTINUITY
elif tag == "EXT-X-DISCONTINUITY": elif tag == "EXT-X-DISCONTINUITY":
@ -345,7 +338,8 @@ class M3U8():
tag_type = None tag_type = None
if last_tag_type is M3U8.TAG_TYPES["MEDIA_SEGMENT"]: if last_tag_type is M3U8.TAG_TYPES["MEDIA_SEGMENT"]:
self.media_segment.append((l, media_segment_info)) media_segment_info["URI"] = l
self.media_segment.append(media_segment_info)
media_segment_info = {} media_segment_info = {}
last_tag_type = tag_type last_tag_type = tag_type