-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsomafm.py
37 lines (26 loc) · 1.02 KB
/
somafm.py
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
import requests # https://requests.readthedocs.io
from requests.exceptions import HTTPError
url = "https://somafm.com/channels.json"
def get_channels(url): # Get list of SomaFM channels (json object)
try:
response = requests.get(url)
response.raise_for_status()
except HTTPError as http_err:
print(f'HTTP error occured:\n {http_err}')
except Exception as err:
print(f'Other error occured: {err}')
return response
def get_playlists(response):
channels = [] # Store channel playlists
for channel in response['channels']:
#print(f"{channel['title']} : {channel['description']}")
for playlist in channel['playlists']:
if playlist['quality'] == 'highest' and playlist['format'] == 'aac':
channels.append(f"{playlist['url']}")
return (channels)
def print_playlists(playlist):
for url in playlist:
print(url)
response = get_channels(url)
somafm_playlist = get_playlists(response.json())
print_playlists(somafm_playlist)