1
0
Fork 0
mirror of https://github.com/Findus23/RadioStats.git synced 2024-09-19 16:03:48 +02:00
RadioStats/parser/ara.py

35 lines
1 KiB
Python
Raw Permalink Normal View History

2021-11-23 21:32:02 +01:00
import json
2021-11-23 21:33:19 +01:00
from websocket import create_connection, WebSocket
2021-11-23 21:32:02 +01:00
from parser import BaseFetcher
from utils import *
class ArabellaFetcher(BaseFetcher):
2022-12-16 00:02:33 +01:00
URL = "wss://www.arabella.at/api/_socket/"
def get(self, channel):
2022-03-29 00:01:09 +02:00
ws: WebSocket = create_connection(
2022-12-16 00:02:33 +01:00
self.URL,
2022-03-29 00:01:09 +02:00
suppress_origin=True,
header=["User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:98.0) Gecko/20100101 Firefox/98.0"]
)
2021-11-23 21:32:02 +01:00
init = ws.recv()
ws.send(json.dumps({"type": "select_channels", "channelIds": [1]}))
result = ws.recv()
2021-11-23 21:33:19 +01:00
ws.close()
2021-11-23 21:32:02 +01:00
data = json.loads(result)
tracks = [data["currentTrack"]]
2022-12-16 00:02:33 +01:00
if "previousTracks" in data:
tracks.extend(data["previousTracks"])
if "futureTracks" in data:
tracks.extend(data["futureTracks"])
2021-11-23 21:32:02 +01:00
for track in tracks:
artist = track["artist"]
title = track["title"]
time = time_to_date(string_to_time(track["time"], seconds=False))
yield time, artist, title