Skip to content

Commit

Permalink
Refactor download function to handle HTTP errors and return appropria…
Browse files Browse the repository at this point in the history
…te messages
  • Loading branch information
mdrxy committed Oct 23, 2024
1 parent 9e6a2fe commit 7ebcff4
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions spinget.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import os
import subprocess
import sys
from urllib.error import HTTPError

import concurrent.futures

Expand Down Expand Up @@ -172,9 +173,16 @@ def loadsegs(stamp, duration_hours):
while accum < required:
showtime = curts.strftime("%Y%m%dT%H%M00Z")
print(f"Fetching index for {showtime}")
playlist = m3u8.load(INDEXURL.format(STATION_SHORTCODE, showtime))
if len(playlist.segments) == 0:
print("No playlist data found!")
try:
playlist = m3u8.load(INDEXURL.format(STATION_SHORTCODE, showtime))
if len(playlist.segments) == 0:
print("No playlist data found!")
return []
except HTTPError as e:
if e.code == 404:
print(f"404 Error: Playlist for {showtime} not found. Try waiting an hour...")
return []
print(f"HTTPError occurred: {e}")
return []
total_secs = 0
for seg in playlist.segments:
Expand Down

0 comments on commit 7ebcff4

Please sign in to comment.