From e06fca346922ed54253f3a1b080fc92ae563f85c Mon Sep 17 00:00:00 2001 From: NoPlagiarism <37241775+NoPlagiarism@users.noreply.github.com> Date: Wed, 4 Sep 2024 12:48:33 +0500 Subject: [PATCH 1/2] fix: recognize works with files now --- shaq/_cli.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/shaq/_cli.py b/shaq/_cli.py index 19b816c..6153d4b 100644 --- a/shaq/_cli.py +++ b/shaq/_cli.py @@ -96,11 +96,11 @@ def _listen(console: Console, args: argparse.Namespace) -> bytearray: def _from_file(console: Console, args: argparse.Namespace) -> AudioSegment: with Status(f"Extracting from {args.input}", console=console): - input = AudioSegment.from_file(args.input) - - # pydub measures things in milliseconds - duration = args.duration * 1000 - return input[:duration] + data = AudioSegment.from_file(args.input, duration=args.duration) + + buffer = data.export(format="wav") + audio_data = buffer.read() + return audio_data async def _shaq(console: Console, args: argparse.Namespace) -> dict[str, Any]: @@ -112,7 +112,7 @@ async def _shaq(console: Console, args: argparse.Namespace) -> dict[str, Any]: shazam = Shazam(language="en-US", endpoint_country="US") - return await shazam.recognize_song(input, proxy=args.proxy) # type: ignore + return await shazam.recognize(input, proxy=args.proxy) # type: ignore def _parser() -> argparse.ArgumentParser: @@ -178,7 +178,8 @@ def main() -> None: sys.exit(1) try: - raw = asyncio.run(_shaq(console, args)) + loop = asyncio.get_event_loop() + raw = loop.run_until_complete(_shaq(console, args)) track = Serialize.full_track(raw) except KeyboardInterrupt: console.print("[red]Interrupted.[/red]") From d307f0c3318eb4a602e6d9d4f5b5bcc7d2984164 Mon Sep 17 00:00:00 2001 From: NoPlagiarism <37241775+NoPlagiarism@users.noreply.github.com> Date: Sun, 8 Sep 2024 15:17:07 +0500 Subject: [PATCH 2/2] fix: force SelectorEventLoop on Windows --- shaq/_cli.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/shaq/_cli.py b/shaq/_cli.py index 6153d4b..610c9b5 100644 --- a/shaq/_cli.py +++ b/shaq/_cli.py @@ -178,8 +178,9 @@ def main() -> None: sys.exit(1) try: - loop = asyncio.get_event_loop() - raw = loop.run_until_complete(_shaq(console, args)) + if os.name == "nt": + asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) + raw = asyncio.run(_shaq(console, args)) track = Serialize.full_track(raw) except KeyboardInterrupt: console.print("[red]Interrupted.[/red]")