Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: recognize works with files now #31

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions shaq/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand All @@ -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:
Expand Down Expand Up @@ -178,6 +178,8 @@ def main() -> None:
sys.exit(1)

try:
if os.name == "nt":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
raw = asyncio.run(_shaq(console, args))
track = Serialize.full_track(raw)
except KeyboardInterrupt:
Expand Down