Skip to content

Commit 3f9f202

Browse files
author
Martin Panter
committed
Fix reading from separate bootstrap URL
1 parent 7ad8193 commit 3f9f202

File tree

1 file changed

+59
-59
lines changed

1 file changed

+59
-59
lines changed

iview/hds.py

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -116,70 +116,70 @@ def get_bootstrap(media, *, session, url, player=""):
116116
if bsurl is not None:
117117
bsurl = urljoin(url, bsurl)
118118
bsurl = urljoin(bsurl, player)
119-
with http_get(session, bsurl, ("video/abst",)) as response:
120-
bootstrap = response.read()
119+
bootstrap = http_get(session, bsurl, ("video/abst",))
121120
else:
122121
bootstrap = io.BytesIO(bootstrap["data"])
123122

124-
(type, _) = read_box_header(bootstrap)
125-
assert type == b"abst"
126-
127-
result = dict()
128-
129-
fastforward(bootstrap, 1 + 3 + 4) # Version, flags, bootstrap version
130-
131-
flags = read_int(bootstrap, 1)
132-
flags >> 6 # Profile
133-
bool(flags & 0x20) # Live flag
134-
bool(flags & 0x10) # Update flag
135-
136-
result["timescale"] = read_int(bootstrap, 4) # Time scale
137-
result["time"] = read_int(bootstrap, 8) # Media time at end of bootstrap
138-
fastforward(bootstrap, 8) # SMPTE timecode offset
139-
140-
result["movie_identifier"] = read_string(bootstrap).decode("utf-8")
141-
142-
count = read_int(bootstrap, 1) # Server table
143-
for _ in range(count):
144-
entry = read_string(bootstrap)
145-
if "server_base_url" not in result:
146-
result["server_base_url"] = entry.decode("utf-8")
147-
148-
count = read_int(bootstrap, 1) # Quality table
149-
for _ in range(count):
150-
quality = read_string(bootstrap)
151-
if "highest_quality" not in result:
152-
result["highest_quality"] = quality.decode("utf-8")
153-
154-
read_string(bootstrap) # DRM data
155-
read_string(bootstrap) # Metadata
156-
157-
# Read segment and fragment run tables. Read the first table of each type
158-
# that is understood, and skip any subsequent ones.
159-
count = read_int(bootstrap, 1)
160-
for _ in range(count):
123+
with bootstrap:
124+
(type, _) = read_box_header(bootstrap)
125+
assert type == b"abst"
126+
127+
result = dict()
128+
129+
fastforward(bootstrap, 1 + 3 + 4) # Version, flags, bootstrap version
130+
131+
flags = read_int(bootstrap, 1)
132+
flags >> 6 # Profile
133+
bool(flags & 0x20) # Live flag
134+
bool(flags & 0x10) # Update flag
135+
136+
result["timescale"] = read_int(bootstrap, 4) # Time scale
137+
result["time"] = read_int(bootstrap, 8) # Media time at end of bootstrap
138+
fastforward(bootstrap, 8) # SMPTE timecode offset
139+
140+
result["movie_identifier"] = read_string(bootstrap).decode("utf-8")
141+
142+
count = read_int(bootstrap, 1) # Server table
143+
for _ in range(count):
144+
entry = read_string(bootstrap)
145+
if "server_base_url" not in result:
146+
result["server_base_url"] = entry.decode("utf-8")
147+
148+
count = read_int(bootstrap, 1) # Quality table
149+
for _ in range(count):
150+
quality = read_string(bootstrap)
151+
if "highest_quality" not in result:
152+
result["highest_quality"] = quality.decode("utf-8")
153+
154+
read_string(bootstrap) # DRM data
155+
read_string(bootstrap) # Metadata
156+
157+
# Read segment and fragment run tables. Read the first table of each type
158+
# that is understood, and skip any subsequent ones.
159+
count = read_int(bootstrap, 1)
160+
for _ in range(count):
161+
if "seg_runs" not in result:
162+
(qualities, runs) = read_asrt(bootstrap)
163+
if not qualities or result.get("highest_quality") in qualities:
164+
result["seg_runs"] = runs
165+
else:
166+
skip_box(bootstrap)
161167
if "seg_runs" not in result:
162-
(qualities, runs) = read_asrt(bootstrap)
163-
if not qualities or result.get("highest_quality") in qualities:
164-
result["seg_runs"] = runs
165-
else:
166-
skip_box(bootstrap)
167-
if "seg_runs" not in result:
168-
fmt = "Segment run table not found (quality = {!r})"
169-
raise LookupError(fmt.format(result.get("highest_quality")))
170-
171-
count = read_int(bootstrap, 1)
172-
for _ in range(count):
168+
fmt = "Segment run table not found (quality = {!r})"
169+
raise LookupError(fmt.format(result.get("highest_quality")))
170+
171+
count = read_int(bootstrap, 1)
172+
for _ in range(count):
173+
if "frag_runs" not in result:
174+
(qualities, runs, timescale) = read_afrt(bootstrap)
175+
if not qualities or result.get("highest_quality") in qualities:
176+
result["frag_runs"] = runs
177+
result["frag_timescale"] = timescale
178+
else:
179+
skip_box(bootstrap)
173180
if "frag_runs" not in result:
174-
(qualities, runs, timescale) = read_afrt(bootstrap)
175-
if not qualities or result.get("highest_quality") in qualities:
176-
result["frag_runs"] = runs
177-
result["frag_timescale"] = timescale
178-
else:
179-
skip_box(bootstrap)
180-
if "frag_runs" not in result:
181-
fmt = "Fragment run table not found (quality = {!r})"
182-
raise LookupError(fmt.format(result.get("highest_quality")))
181+
fmt = "Fragment run table not found (quality = {!r})"
182+
raise LookupError(fmt.format(result.get("highest_quality")))
183183

184184
return result
185185

0 commit comments

Comments
 (0)