Skip to content

Commit 9185502

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

File tree

4 files changed

+4415
-2471
lines changed

4 files changed

+4415
-2471
lines changed

README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -280,14 +280,13 @@ this generator as a stream source. The data can be provided in ``array`` type o
280280
the audio data has, and the sample with in bytes.
281281

282282

283-
*function* ``stream_with_callbacks (sample_stream: Generator[Union[bytes, array.array], int, NoneType], progress_callback: Optional[Callable[[int], NoneType]] = None, frame_process_method: Union[Callable[[array.array], array.array], None] = None, end_callback: Optional[Callable] = None) -> Generator[Union[bytes, array.array], int, NoneType]``
284-
> Convenience generator function to add callback and processing functionality to another stream. You can specify:
285-
A callback function that gets called during play and takes an ``int``
286-
for the number of frames played.
287-
A function that can be used to process raw data frames before they are yielded back
288-
(takes an ``array.array`` and returns an ``array.array``)
289-
*Note: if the processing method is slow it will result in audio glitchiness*
290-
A callback function that gets called when the stream ends playing.
283+
*function* ``stream_with_callbacks (sample_stream: Generator[Union[bytes, array.array], int, NoneType], progress_callback: Optional[Callable[[int], NoneType]] = None, frame_process_method: Optional[Callable[[Union[bytes, array.array]], Union[bytes, array.array]]] = None, end_callback: Optional[Callable] = None) -> Generator[Union[bytes, array.array], int, NoneType]``
284+
> Convenience generator function to add callback and processing functionality to another stream. You
285+
can specify : > A callback function that gets called during play and takes an int for the number of
286+
frames played. > A function that can be used to process raw data frames before they are yielded
287+
back (takes an array.array or bytes, returns an array.array or bytes) *Note: if the processing
288+
method is slow it will result in audio glitchiness > A callback function that gets called when the
289+
stream ends playing.
291290

292291

293292
*function* ``vorbis_get_file_info (filename: str) -> miniaudio.SoundFileInfo``
@@ -419,12 +418,14 @@ already be started before passing it in)
419418

420419
*class* ``IceCastClient``
421420

422-
``IceCastClient (self, url: str, update_stream_title: Callable[[ForwardRef('IceCastClient'), str], NoneType] = None) ``
421+
``IceCastClient (self, url: str, update_stream_title: Callable[[ForwardRef('IceCastClient'), str], NoneType] = None, ssl_context: 'ssl.SSLContext' = None) ``
423422
> A simple client for IceCast audio streams as miniaudio streamable source. If the stream has Icy
424-
Meta Data, the stream_title attribute will be updated with the actual title taken from the meta
425-
data. You can also provide a callback to be called when a new stream title is available. The
426-
downloading of the data from the internet is done in a background thread and it tries to keep a
427-
(small) buffer filled with available data to read.
423+
MetaData, the stream_title attribute will be updated with the actual title taken from the metadata.
424+
You can also provide a callback to be called when a new stream title is available. The downloading
425+
of the data from the internet is done in a background thread and it tries to keep a (small) buffer
426+
filled with available data to read. You can optionally provide a custom ssl.SSLContext in the
427+
ssl_context parameter, if you need to change the way SSL connections are configured (certificates,
428+
checks, etc).
428429

429430
> *method* ``close (self) ``
430431
> > Stop the stream, aborting the background downloading.
@@ -464,7 +465,7 @@ The generator should already be started before passing it in.
464465

465466
*class* ``SoundFileInfo``
466467

467-
``SoundFileInfo (self, name: str, file_format: miniaudio.FileFormat, nchannels: int, sample_rate: int, sample_format: miniaudio.SampleFormat, duration: float, num_frames: int) ``
468+
``SoundFileInfo (self, name: str, file_format: miniaudio.FileFormat, nchannels: int, sample_rate: int, sample_format: miniaudio.SampleFormat, duration: float, num_frames: int, sub_format: int = None) ``
468469
> Contains various properties of an audio file.
469470
470471

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: 8 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,17 +1130,20 @@ 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.
1138+
You can optionally provide a custom ssl.SSLContext in the ssl_context parameter,
1139+
if you need to change the way SSL connections are configured (certificates, checks, etc).
11381140
"""
11391141

11401142
BLOCK_SIZE = 8*1024
11411143
BUFFER_SIZE = 64*1024
11421144

1143-
def __init__(self, url: str, update_stream_title: Callable[['IceCastClient', str], None] = None) -> None:
1145+
def __init__(self, url: str, update_stream_title: Callable[['IceCastClient', str], None] = None,
1146+
ssl_context: "ssl.SSLContext" = None) -> None:
11441147
self.url = url
11451148
self.stream_title = "???"
11461149
self.station_genre = "???"
@@ -1152,7 +1155,7 @@ def __init__(self, url: str, update_stream_title: Callable[['IceCastClient', str
11521155
self._buffer_lock = threading.Lock()
11531156
self._update_title = update_stream_title
11541157
req = urllib.request.Request(url, headers={"icy-metadata": "1"})
1155-
with urllib.request.urlopen(req) as result:
1158+
with urllib.request.urlopen(req, context=ssl_context) as result:
11561159
self.station_genre = result.headers["icy-genre"]
11571160
self.station_name = result.headers["icy-name"]
11581161
stream_format = result.headers["Content-Type"]

0 commit comments

Comments
 (0)