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
|
|
|
|
2020-09-28 18:31:57 +02:00
|
|
|
from parser import BaseFetcher
|
2018-02-13 22:31:30 +01:00
|
|
|
from utils import *
|
|
|
|
|
2021-11-23 21:32:02 +01:00
|
|
|
URL = "wss://www.arabella.at/api/_socket/"
|
2018-02-13 22:31:30 +01:00
|
|
|
|
|
|
|
|
2020-09-28 18:31:57 +02:00
|
|
|
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
|