|
39 | 39 | import warnings |
40 | 40 | from math import floor |
41 | 41 | from typing import IO, TYPE_CHECKING, Any, Callable, Generic, Literal, TypeVar, overload |
42 | | - |
| 42 | +from collections.abc import Set |
43 | 43 | from .enums import SpeakingState |
44 | 44 | from .errors import ClientException |
45 | 45 | from .oggparse import OggStream |
|
52 | 52 |
|
53 | 53 | from .voice import VoiceClient |
54 | 54 |
|
55 | | - |
56 | 55 | AT = TypeVar("AT", bound="AudioSource") |
57 | 56 | FT = TypeVar("FT", bound="FFmpegOpusAudio") |
58 | 57 |
|
@@ -152,12 +151,12 @@ class FFmpegAudio(AudioSource): |
152 | 151 | BLOCKSIZE: int = io.DEFAULT_BUFFER_SIZE |
153 | 152 |
|
154 | 153 | def __init__( |
155 | | - self, |
156 | | - source: str | io.BufferedIOBase, |
157 | | - *, |
158 | | - executable: str = "ffmpeg", |
159 | | - args: Any, |
160 | | - **subprocess_kwargs: Any, |
| 154 | + self, |
| 155 | + source: str | io.BufferedIOBase, |
| 156 | + *, |
| 157 | + executable: str = "ffmpeg", |
| 158 | + args: Any, |
| 159 | + **subprocess_kwargs: Any, |
161 | 160 | ): |
162 | 161 | piping_stdin = subprocess_kwargs.get("stdin") == subprocess.PIPE |
163 | 162 | if piping_stdin and isinstance(source, str): |
@@ -309,7 +308,7 @@ def cleanup(self) -> None: |
309 | 308 | self._process = self._stdout = self._stdin = self._stderr = MISSING |
310 | 309 |
|
311 | 310 |
|
312 | | -DEFAULT_PROTOCOL_WHITELIST: set[str] = frozenset( |
| 311 | +DEFAULT_PROTOCOL_WHITELIST: Set[str] = frozenset( |
313 | 312 | {"file", "http", "https", "tcp", "tls", "crypto", "pipe", "fd", "cache"} |
314 | 313 | ) |
315 | 314 |
|
@@ -372,40 +371,42 @@ class FFmpegPCMAudio(FFmpegAudio): |
372 | 371 |
|
373 | 372 | @overload |
374 | 373 | def __init__( |
375 | | - self, |
376 | | - source: io.BufferedIOBase, |
377 | | - *, |
378 | | - executable: str = ..., |
379 | | - pipe: Literal[True] = ..., |
380 | | - stderr: IO[bytes] | None = ..., |
381 | | - before_options: str | None = ..., |
382 | | - options: str | None = ..., |
383 | | - protocol_whitelist: set[str] | None = ..., |
384 | | - ) -> None: ... |
| 374 | + self, |
| 375 | + source: io.BufferedIOBase, |
| 376 | + *, |
| 377 | + executable: str = ..., |
| 378 | + pipe: Literal[True] = ..., |
| 379 | + stderr: IO[bytes] | None = ..., |
| 380 | + before_options: str | None = ..., |
| 381 | + options: str | None = ..., |
| 382 | + protocol_whitelist: Set[str] | None = ..., |
| 383 | + ) -> None: |
| 384 | + ... |
385 | 385 |
|
386 | 386 | @overload |
387 | 387 | def __init__( |
388 | | - self, |
389 | | - source: str, |
390 | | - *, |
391 | | - executable: str = ..., |
392 | | - pipe: Literal[False] = ..., |
393 | | - stderr: IO[bytes] | None = ..., |
394 | | - before_options: str | None = ..., |
395 | | - options: str | None = ..., |
396 | | - protocol_whitelist: set[str] | None = ..., |
397 | | - ) -> None: ... |
| 388 | + self, |
| 389 | + source: str, |
| 390 | + *, |
| 391 | + executable: str = ..., |
| 392 | + pipe: Literal[False] = ..., |
| 393 | + stderr: IO[bytes] | None = ..., |
| 394 | + before_options: str | None = ..., |
| 395 | + options: str | None = ..., |
| 396 | + protocol_whitelist: Set[str] | None = ..., |
| 397 | + ) -> None: |
| 398 | + ... |
398 | 399 |
|
399 | 400 | def __init__( |
400 | | - self, |
401 | | - source: str | io.BufferedIOBase, |
402 | | - *, |
403 | | - executable: str = "ffmpeg", |
404 | | - pipe: bool = False, |
405 | | - stderr: IO[bytes] | None = None, |
406 | | - before_options: str | None = None, |
407 | | - options: str | None = None, |
408 | | - protocol_whitelist: set[str] | None = DEFAULT_PROTOCOL_WHITELIST, |
| 401 | + self, |
| 402 | + source: str | io.BufferedIOBase, |
| 403 | + *, |
| 404 | + executable: str = "ffmpeg", |
| 405 | + pipe: bool = False, |
| 406 | + stderr: IO[bytes] | None = None, |
| 407 | + before_options: str | None = None, |
| 408 | + options: str | None = None, |
| 409 | + protocol_whitelist: Set[str] | None = DEFAULT_PROTOCOL_WHITELIST, |
409 | 410 | ) -> None: |
410 | 411 | args = [] |
411 | 412 | subprocess_kwargs = { |
@@ -532,46 +533,48 @@ class FFmpegOpusAudio(FFmpegAudio): |
532 | 533 |
|
533 | 534 | @overload |
534 | 535 | def __init__( |
535 | | - self, |
536 | | - source: io.BufferedIOBase, |
537 | | - *, |
538 | | - bitrate: int | None = None, |
539 | | - codec: str | None = None, |
540 | | - executable: str = ..., |
541 | | - pipe: Literal[True] = ..., |
542 | | - stderr: IO[bytes] | None = ..., |
543 | | - before_options: str | None = ..., |
544 | | - options: str | None = ..., |
545 | | - protocol_whitelist: set[str] | None = ..., |
546 | | - ) -> None: ... |
| 536 | + self, |
| 537 | + source: io.BufferedIOBase, |
| 538 | + *, |
| 539 | + bitrate: int | None = None, |
| 540 | + codec: str | None = None, |
| 541 | + executable: str = ..., |
| 542 | + pipe: Literal[True] = ..., |
| 543 | + stderr: IO[bytes] | None = ..., |
| 544 | + before_options: str | None = ..., |
| 545 | + options: str | None = ..., |
| 546 | + protocol_whitelist: Set[str] | None = ..., |
| 547 | + ) -> None: |
| 548 | + ... |
547 | 549 |
|
548 | 550 | @overload |
549 | 551 | def __init__( |
550 | | - self, |
551 | | - source: str, |
552 | | - *, |
553 | | - bitrate: int | None = None, |
554 | | - codec: str | None = None, |
555 | | - executable: str = ..., |
556 | | - pipe: Literal[False] = ..., |
557 | | - stderr: IO[bytes] | None = ..., |
558 | | - before_options: str | None = ..., |
559 | | - options: str | None = ..., |
560 | | - protocol_whitelist: set[str] | None = ..., |
561 | | - ) -> None: ... |
| 552 | + self, |
| 553 | + source: str, |
| 554 | + *, |
| 555 | + bitrate: int | None = None, |
| 556 | + codec: str | None = None, |
| 557 | + executable: str = ..., |
| 558 | + pipe: Literal[False] = ..., |
| 559 | + stderr: IO[bytes] | None = ..., |
| 560 | + before_options: str | None = ..., |
| 561 | + options: str | None = ..., |
| 562 | + protocol_whitelist: Set[str] | None = ..., |
| 563 | + ) -> None: |
| 564 | + ... |
562 | 565 |
|
563 | 566 | def __init__( |
564 | | - self, |
565 | | - source: str | io.BufferedIOBase, |
566 | | - *, |
567 | | - bitrate: int | None = None, |
568 | | - codec: str | None = None, |
569 | | - executable: str = "ffmpeg", |
570 | | - pipe: bool = False, |
571 | | - stderr: IO[bytes] | None = None, |
572 | | - before_options: str | None = None, |
573 | | - options: str | None = None, |
574 | | - protocol_whitelist: set[str] | None = DEFAULT_PROTOCOL_WHITELIST, |
| 567 | + self, |
| 568 | + source: str | io.BufferedIOBase, |
| 569 | + *, |
| 570 | + bitrate: int | None = None, |
| 571 | + codec: str | None = None, |
| 572 | + executable: str = "ffmpeg", |
| 573 | + pipe: bool = False, |
| 574 | + stderr: IO[bytes] | None = None, |
| 575 | + before_options: str | None = None, |
| 576 | + options: str | None = None, |
| 577 | + protocol_whitelist: Set[str] | None = DEFAULT_PROTOCOL_WHITELIST, |
575 | 578 | ) -> None: |
576 | 579 | args = [] |
577 | 580 | subprocess_kwargs = { |
@@ -626,11 +629,11 @@ def __init__( |
626 | 629 |
|
627 | 630 | @classmethod |
628 | 631 | async def from_probe( |
629 | | - cls, |
630 | | - source: str, |
631 | | - *, |
632 | | - method: str | Callable[[str, str], tuple[str | None, int | None]] | None = None, |
633 | | - **kwargs: Any, |
| 632 | + cls, |
| 633 | + source: str, |
| 634 | + *, |
| 635 | + method: str | Callable[[str, str], tuple[str | None, int | None]] | None = None, |
| 636 | + **kwargs: Any, |
634 | 637 | ) -> Self: |
635 | 638 | r"""|coro| |
636 | 639 |
|
@@ -693,11 +696,11 @@ def custom_probe(source, executable): |
693 | 696 |
|
694 | 697 | @classmethod |
695 | 698 | async def probe( |
696 | | - cls, |
697 | | - source: str, |
698 | | - *, |
699 | | - method: str | Callable[[str, str], tuple[str | None, int | None]] | None = None, |
700 | | - executable: str | None = None, |
| 699 | + cls, |
| 700 | + source: str, |
| 701 | + *, |
| 702 | + method: str | Callable[[str, str], tuple[str | None, int | None]] | None = None, |
| 703 | + executable: str | None = None, |
701 | 704 | ) -> tuple[str | None, int | None]: |
702 | 705 | """|coro| |
703 | 706 |
|
@@ -779,7 +782,7 @@ async def probe( |
779 | 782 |
|
780 | 783 | @staticmethod |
781 | 784 | def _probe_codec_native( |
782 | | - source, executable: str = "ffmpeg" |
| 785 | + source, executable: str = "ffmpeg" |
783 | 786 | ) -> tuple[str | None, int | None]: |
784 | 787 | exe = ( |
785 | 788 | executable[:2] + "probe" |
@@ -812,7 +815,7 @@ def _probe_codec_native( |
812 | 815 |
|
813 | 816 | @staticmethod |
814 | 817 | def _probe_codec_fallback( |
815 | | - source, executable: str = "ffmpeg" |
| 818 | + source, executable: str = "ffmpeg" |
816 | 819 | ) -> tuple[str | None, int | None]: |
817 | 820 | args = [executable, "-hide_banner", "-i", source] |
818 | 821 | proc = subprocess.Popen( |
@@ -904,11 +907,11 @@ class AudioPlayer(threading.Thread): |
904 | 907 | DELAY: float = OpusEncoder.FRAME_LENGTH / 1000.0 |
905 | 908 |
|
906 | 909 | def __init__( |
907 | | - self, |
908 | | - source: AudioSource, |
909 | | - client: VoiceClient, |
910 | | - *, |
911 | | - after: Callable[[Exception | None], Any] | None = None, |
| 910 | + self, |
| 911 | + source: AudioSource, |
| 912 | + client: VoiceClient, |
| 913 | + *, |
| 914 | + after: Callable[[Exception | None], Any] | None = None, |
912 | 915 | ) -> None: |
913 | 916 | super().__init__(daemon=True, name=f"audio-player:{id(self):#x}") |
914 | 917 | self.source: AudioSource = source |
|
0 commit comments