-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathread-api.sh
executable file
·76 lines (50 loc) · 2.22 KB
/
read-api.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
# Get stuff from RadioCult API
# Source and export the API key ($API_KEY) from the .env file
source .env
export API_KEY
STATION_ID="eist-radio"
URL="https://api.radiocult.fm/api/station/${STATION_ID}/schedule/live"
ARTISTS_URL="https://api.radiocult.fm/api/station/${STATION_ID}/artists"
TIMEZONE=$(timedatectl | awk '/Time zone/ {print $3}')
SCHEDULE_URL="https://api.radiocult.fm/api/station/${STATION_ID}/schedule?startDate=$(date -I)T00:00:00Z&endDate=$(date -I -d '+7 days')T23:59:59Z&timezone=${TIMEZONE}"
SCHEDULE=$(curl -s -X GET "$SCHEDULE_URL" \
-H "Content-Type: application/json" | jq '[.schedules[] | {title, startDateUtc}]')
# Make the API request and extract the first element of artistIds using jq
ARTIST_ID=$(curl -s -X GET "$URL" \
-H "x-api-key: $API_KEY" \
-H "Content-Type: application/json" | jq -r '.result.content.artistIds[0]')
ARTIST_URL="https://api.radiocult.fm/api/station/${STATION_ID}/artists/${ARTIST_ID}"
ARTISTS_ARRAY=$(curl -s -X GET "$ARTISTS_URL" \
-H "x-api-key: $API_KEY" \
-H "Content-Type: application/json" | jq)
SHOW_DESC=$(curl -s -X GET "$URL" \
-H "x-api-key: $API_KEY" \
-H "Content-Type: application/json" | jq -r '.result.content.description.content[0].content[0].text')
BROADCAST_STATUS=$(curl -s -X GET "$URL" \
-H "x-api-key: $API_KEY" \
-H "Content-Type: application/json" | jq -r '.result.status')
SHOW_TITLE=$(curl -s -X GET "$URL" \
-H "x-api-key: $API_KEY" \
-H "Content-Type: application/json" | jq -r '.result.content.title')
# Return the artist name
ARTIST_NAME=$(curl -s -X GET "$ARTIST_URL" \
-H "x-api-key: $API_KEY" \
-H "Content-Type: application/json" | jq -r '.artist.name')
# Return the artist bio
ARTIST_BIO=$(curl -s -X GET "$ARTIST_URL" \
-H "x-api-key: $API_KEY" \
-H "Content-Type: application/json" | jq -r '.artist.description.content[0].content[0].text')
# Return the artist image
ARTIST_LOGO_URL=$(curl -s -X GET "$ARTIST_URL" \
-H "x-api-key: $API_KEY" \
-H "Content-Type: application/json" | jq -r '.artist.logo["256x256"]')
echo "${ARTIST_ID}"
echo "${BROADCAST_STATUS}"
echo "${SHOW_DESC}"
echo "${SHOW_TITLE}"
echo "${ARTIST_NAME}"
echo "${ARTIST_BIO}"
echo "${ARTIST_LOGO_URL}"
echo "${ARTISTS_ARRAY}"
echo "${SCHEDULE}"