From 5b515be34bd0c282a38886c4fca1991141d01c72 Mon Sep 17 00:00:00 2001 From: DevilXD <4180725+DevilXD@users.noreply.github.com> Date: Sun, 30 Jun 2024 12:37:15 +0200 Subject: [PATCH] Account for end-of-stream tag when sending watch requests --- channel.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/channel.py b/channel.py index 3ecce8b..b93c8a7 100644 --- a/channel.py +++ b/channel.py @@ -363,8 +363,13 @@ class Channel: ) as chunks_response: available_chunks: str = await chunks_response.text() # the list contains ~10-13 chunks of the stream at 2s intervals, - # let's pick the last chunk URL available - stream_chunk_url: URLType = URLType(available_chunks.strip().split("\n")[-1]) + # pick the last chunk URL available. Ensure it's not the end-of-stream tag, + # otherwise use the 2nd to last line. + chunks_list: list[str] = available_chunks.strip().split("\n") + selected_chunk: str = chunks_list[-1] + if selected_chunk == "#EXT-X-ENDLIST": + selected_chunk = chunks_list[-2] + stream_chunk_url: URLType = URLType(selected_chunk) # sending a HEAD request is enough to advance the drops, # without downloading the actual stream data async with self._twitch.request("HEAD", stream_chunk_url) as head_response: