Martin
Martin

Reputation: 155

How to get meta data from a webradio stream in CircuitPython?

I have the following working code to stream audio from a webradio station: (Raspberry Pi Pico on a Pimoroni Pico Demo Base. CircuitPython 9.2.1)

import time, os
import adafruit_connection_manager
import adafruit_requests
import audiobusio
import audiomp3
import board
import wifi


ssid = os.getenv("CIRCUITPY_WIFI_SSID")
password = os.getenv("CIRCUITPY_WIFI_PASSWORD")

mp3_buffer = bytearray(16384)
mp3_decoder = audiomp3.MP3Decoder("slow.mp3", mp3_buffer)

pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio)
ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio)
requests = adafruit_requests.Session(pool, ssl_context)

STREAMING_URL = "http://www.radioeins.de/livemp3_s"

i2s = audiobusio.I2SOut(bit_clock = board.GP27, word_select = board.GP28, data = board.GP26)


try:
    # Connect to the Wi-Fi network
    wifi.radio.connect(ssid, password)
except OSError as e:
    print(f"OSError: {e}")


with requests.get(STREAMING_URL, headers = {"connection": "close"}, stream = True) as response:
    mp3_decoder.file = response.socket
    i2s.play(mp3_decoder)
    while i2s.playing:
        time.sleep(0.1)

Now I would like to get the meta data from that stream but couldn't find a solution online. Can anyone please help me with this? I know how to use json decode but in this case it's not a json file but just meta data.

Thank's Martin

Upvotes: 0

Views: 9

Answers (0)

Related Questions