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

33 lines
964 B
Python
Raw 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 *
2021-11-23 21:32:02 +01:00
URL = "wss://www.arabella.at/api/_socket/"
class ArabellaFetcher(BaseFetcher):
def get(self, channel):
2022-03-29 00:01:09 +02:00
ws: WebSocket = create_connection(
URL,
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"]]
tracks.extend(data["previousTracks"])
tracks.extend(data["futureTracks"])
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