shazamio / ShazamIO

🎵 Is a free asynchronous library from reverse engineered Shazam API written in Python 3.8+ with asyncio and aiohttp.
MIT License
521 stars 76 forks source link

Song recognition giving error #6

Closed YashMakan closed 3 years ago

YashMakan commented 3 years ago

When I tried to recognize the song, it is giving me the following error. How to fix it? Code:

import asyncio
from shazamio import Shazam

async def main():
  shazam = Shazam()
  out = await shazam.recognize_song('sample.mp3')
  print(out)

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Error:

Traceback (most recent call last):
  File "D:\programs\shazamio_shazam_t.py", line 11, in <module>
    loop.run_until_complete(main())
  File "D:\Python\lib\asyncio\base_events.py", line 616, in run_until_complete
    return future.result()
  File "D:\programs\shazamio_shazam_t.py", line 7, in main
    out = await shazam.recognize_song('sample.mp3')
  File "D:\Python\lib\site-packages\shazamio\api.py", line 220, in recognize_song
    audio = self.normalize_audio_data(file)
  File "D:\Python\lib\site-packages\shazamio\converter.py", line 45, in normalize_audio_data
    audio = AudioSegment.from_file(BytesIO(song_data))
  File "D:\Python\lib\site-packages\pydub\audio_segment.py", line 728, in from_file
    info = mediainfo_json(orig_file, read_ahead_limit=read_ahead_limit)
  File "D:\Python\lib\site-packages\pydub\utils.py", line 279, in mediainfo_json
    info = json.loads(output)
  File "D:\Python\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "D:\Python\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "D:\Python\lib\json\decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
dotX12 commented 3 years ago

@YashMakan Hello, At first I thought that the problem was that the mp3 format could not be recognized, but I just checked - everything works.

Do you have it installed ffmpeg?

image

YashMakan commented 3 years ago

Yes and when I entered ffmpeg -version. It returns version 4.2. I am unable to figure out the problem.

dotX12 commented 3 years ago

@YashMakan give your test mp3 file, i check it

YashMakan commented 3 years ago

@dotX12 https://easyupload.io/rgcukg

dotX12 commented 3 years ago

@dotX12 https://easyupload.io/rgcukg

Hmm, everything works for me stably with your file, you probably have problems with pydub or ffmpeg

https://transfer.sh/1dE2aJk/KWHmwkbzT9.png

My requirements:

image

ffmpeg -version

ffmpeg version 2021-02-07-git-a52b9464e4-full_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers built with gcc 10.2.0 (Rev6, Built by MSYS2 project) configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-libsnappy --enable-zlib --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libglslang --enable-vulkan --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint libavutil 56. 64.100 / 56. 64.100 libavcodec 58.121.100 / 58.121.100 libavformat 58. 67.100 / 58. 67.100 libavdevice 58. 11.103 / 58. 11.103 libavfilter 7.102.100 / 7.102.100 libswscale 5. 8.100 / 5. 8.100 libswresample 3. 8.100 / 3. 8.100 libpostproc 55. 8.100 / 55. 8.100

YashMakan commented 3 years ago

Yes, I think that my ffmpeg version is old. I am reinstalling it. Thanks for the help.

YashMakan commented 3 years ago

I reinstalled the new version from the official website i.e ffmpeg version 4.4-essentials_build-www.gyan.dev and now when I run the below code it works

>>> sound = AudioSegment.from_mp3("sample.mp3")
>>>

but...

sound = pydub.AudioSegment.from_file(BytesIO(open("sample.mp3",'rb').read()))

giving the same error i.e json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0). What should I do now?

dotX12 commented 3 years ago

@YashMakan, hmmmm. I seem to have found a solution. https://github.com/jiaaro/pydub/issues/450

YashMakan commented 3 years ago

@dotX12 Thanks I will follow the issue jiaaro/pydub#450 for updates. Also, are you using FFmpeg in windows? if so, if possible can you send the FFmpeg... So that I can install the same working version of ffmpeg.

dotX12 commented 3 years ago

@YashMakan, in windows i use very old version... https://transfer.sh/jeoDp/ffmpeg-2021-02-07-git-a52b9464e4-full_build.7z I think you need to read what is in issue and try to do it, because I have a very old version on Windows. On ubuntu, I use the most current version and everything works well for me.

dotX12 commented 9 months ago

Fixed in 0.5.0.