Skip to content

Commit fc1766c

Browse files
committed
update to miniaudio 0.11.14 , added ssl_context to IceCastClient
1 parent 9851563 commit fc1766c

File tree

3 files changed

+4398
-2457
lines changed

3 files changed

+4398
-2457
lines changed

examples/internetradio.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@
1111
def title_printer(client: miniaudio.IceCastClient, new_title: str) -> None:
1212
print("Stream title: ", new_title)
1313

14-
source = miniaudio.IceCastClient(url, update_stream_title=title_printer)
14+
# you can optionally pass a SSL context in the 'ssl_context' keyword argument,
15+
# to configure the SSL connection.
16+
# For instance, to disable the SSL certificate check:
17+
# import ssl
18+
# ctx = ssl.create_default_context()
19+
# ctx.check_hostname = False
20+
# ctx.verify_mode = ssl.CERT_NONE
21+
# and then create the IceCastClient with ssl_context=ctx
22+
source = miniaudio.IceCastClient(url, update_stream_title=title_printer, ssl_context=None)
1523
print("Connected to internet stream, audio format:", source.audio_format.name)
1624
print("Station name: ", source.station_name)
1725
print("Station genre: ", source.station_genre)

miniaudio.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Software license: "MIT software license". See http://opensource.org/licenses/MIT
66
"""
77

8-
__version__ = "1.55"
8+
__version__ = "1.56"
99

1010

1111
import abc
@@ -1130,8 +1130,8 @@ def __exit__(self, exc_type, exc_val, exc_tb) -> None:
11301130
class IceCastClient(StreamableSource):
11311131
"""
11321132
A simple client for IceCast audio streams as miniaudio streamable source.
1133-
If the stream has Icy Meta Data, the stream_title attribute will be updated
1134-
with the actual title taken from the meta data.
1133+
If the stream has Icy MetaData, the stream_title attribute will be updated
1134+
with the actual title taken from the metadata.
11351135
You can also provide a callback to be called when a new stream title is available.
11361136
The downloading of the data from the internet is done in a background thread
11371137
and it tries to keep a (small) buffer filled with available data to read.
@@ -1140,7 +1140,8 @@ class IceCastClient(StreamableSource):
11401140
BLOCK_SIZE = 8*1024
11411141
BUFFER_SIZE = 64*1024
11421142

1143-
def __init__(self, url: str, update_stream_title: Callable[['IceCastClient', str], None] = None) -> None:
1143+
def __init__(self, url: str, update_stream_title: Callable[['IceCastClient', str], None] = None,
1144+
ssl_context: "ssl.SSLContext" = None) -> None:
11441145
self.url = url
11451146
self.stream_title = "???"
11461147
self.station_genre = "???"
@@ -1152,7 +1153,7 @@ def __init__(self, url: str, update_stream_title: Callable[['IceCastClient', str
11521153
self._buffer_lock = threading.Lock()
11531154
self._update_title = update_stream_title
11541155
req = urllib.request.Request(url, headers={"icy-metadata": "1"})
1155-
with urllib.request.urlopen(req) as result:
1156+
with urllib.request.urlopen(req, context=ssl_context) as result:
11561157
self.station_genre = result.headers["icy-genre"]
11571158
self.station_name = result.headers["icy-name"]
11581159
stream_format = result.headers["Content-Type"]

0 commit comments

Comments
 (0)