fix time variable for kexp.
This commit is contained in:
parent
323d6c0499
commit
cd7f93100b
|
@ -28,6 +28,8 @@ def _stream(stream, t: Optional[datetime]):
|
||||||
|
|
||||||
if t is not None:
|
if t is not None:
|
||||||
time = t.astimezone(tz=timezone.utc)
|
time = t.astimezone(tz=timezone.utc)
|
||||||
|
else:
|
||||||
|
time = None
|
||||||
play(stream, time)
|
play(stream, time)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,23 +15,33 @@ class Stream(str, Enum):
|
||||||
CLIS = "clis"
|
CLIS = "clis"
|
||||||
|
|
||||||
|
|
||||||
|
def url_for_time(t) -> str:
|
||||||
|
default = "https://kexp-mp3-128.streamguys1.com/kexp128.mp3"
|
||||||
|
tz = t.strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||||
|
print(f"getting archive: {t}")
|
||||||
|
check_url = (
|
||||||
|
f"https://api.kexp.org/get_streaming_url/?bitrate=128×tamp={tz}&location=1"
|
||||||
|
)
|
||||||
|
response = requests.get(check_url)
|
||||||
|
if response.status_code == 200:
|
||||||
|
found = response.json().get("sg-url")
|
||||||
|
if found is None:
|
||||||
|
print(f"error getting archive: {t}")
|
||||||
|
return default
|
||||||
|
else:
|
||||||
|
print(f"error getting archive: {t}")
|
||||||
|
return default
|
||||||
|
|
||||||
|
return found
|
||||||
|
|
||||||
|
|
||||||
def play(stream, t=None):
|
def play(stream, t=None):
|
||||||
"""Play streams using mpv."""
|
"""Play streams using mpv."""
|
||||||
match stream:
|
match stream:
|
||||||
case Stream.KEXP:
|
case Stream.KEXP:
|
||||||
default = "https://kexp-mp3-128.streamguys1.com/kexp128.mp3"
|
url = "https://kexp-mp3-128.streamguys1.com/kexp128.mp3"
|
||||||
if t:
|
if t:
|
||||||
tz = t.strftime("%Y-%m-%dT%H:%M:%SZ")
|
url = url_for_time(t)
|
||||||
print(f"getting archive: {t}")
|
|
||||||
check_url = f"https://api.kexp.org/get_streaming_url/?bitrate=128×tamp={tz}&location=1"
|
|
||||||
response = requests.get(check_url)
|
|
||||||
if response.status_code == 200:
|
|
||||||
url = response.json().get("sg-url")
|
|
||||||
if url is None:
|
|
||||||
print(f"error getting archive: {t}")
|
|
||||||
url = default
|
|
||||||
else:
|
|
||||||
url = default
|
|
||||||
case Stream.KUGS:
|
case Stream.KUGS:
|
||||||
url = "https://peridot.streamguys1.com:7175/kugs-mp3"
|
url = "https://peridot.streamguys1.com:7175/kugs-mp3"
|
||||||
case Stream.CLIS:
|
case Stream.CLIS:
|
||||||
|
|
Loading…
Reference in New Issue