marin-m / SongRec

An open-source Shazam client for Linux, written in Rust.
GNU General Public License v3.0
1.39k stars 103 forks source link

Error: Network unreachable #154

Open stuckintraffic0 opened 9 months ago

stuckintraffic0 commented 9 months ago

Hello. I don't know why, but the library stopped working. It says: Error: Network unreachable, the command I used: songrec recognize mysong.mp3

Bile1970 commented 9 months ago

I have the same problem. Error: Network unreachable.

I have multiple services running on my linux ubuntu,songrec became unstable in last 2-3 days.in some scripts songrec working fine,but in a more than half it doesnt work,the same error.

marin-m commented 9 months ago

Hello

Can you please paste the output of the curl -I https://amp.shazam.com/ and host amp.shazam.com commands (it may priorly require to install the curl and bind9-host packages on Ubuntu)?

Thank you,

Bile1970 commented 9 months ago

Here is the output for commands:

`root@playlister:~# curl -I https://amp.shazam.com/ HTTP/2 200 date: Thu, 01 Feb 2024 12:37:44 GMT content-length: 0 x-shazam-location: ew4 x-forensic-id: a6d2452d-e9ca-4008-b6de-47c0e8036979 via: 1.1 google alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000

root@playlister:~# host amp.shazam.com amp.shazam.com is an alias for kong-k8s-prod.shz-amp-prod.shazamcloud.com. kong-k8s-prod.shz-amp-prod.shazamcloud.com has address 34.149.250.49`

Thank you,

stuckintraffic0 commented 9 months ago

Hello @marin-m curl output:

HTTP/2 200 
date: Thu, 01 Feb 2024 12:57:35 GMT
content-length: 0
x-shazam-location: ew4
x-forensic-id: bb9daf9c-10c9-4624-9282-ef75c0f2ec0c
via: 1.1 google
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000

host output:

amp.shazam.com is an alias for kong-k8s-prod.shz-amp-prod.shazamcloud.com.
kong-k8s-prod.shz-amp-prod.shazamcloud.com has address 34.149.250.49
marin-m commented 9 months ago

Thank you,

Does the issue occur both with the GUI and the command line/permanently?

Are you using the distribution from the PPA/the rust source or Flatpak? (The CLI is not guaranteed to work witk Flatpak)

Are you using a container or firewall system of any kind?

It may be required to use a network capture analysis tool such as Wireshark (or a system debugging tool such as strace) to understand the issue if there is persistent difference of functionment between songrec and curl.

stuckintraffic0 commented 9 months ago

Does the issue occur both with the GUI and the command line/permanently?

didn't test GUI, only CLI

Are you using the distribution from the PPA/the rust source or Flatpak? (The CLI is not guaranteed to work witk Flatpak)

using cargo install command, PPA doesn't seem to work

Are you using a container or firewall system of any kind?

I am using this library in docker container, and also behind firewall

stuckintraffic0 commented 9 months ago

It may be required to use a network capture analysis tool such as Wireshark (or a system debugging tool such as strace) to understand the issue if there is persistent difference of functionment between songrec and curl.

you think it's firewall issue? But it was working just fine

marin-m commented 9 months ago

I am using this library in docker container, and also behind firewall

In any case I think you should check the configuration of your container/firewall to ensure that the access to amp.shazam.com on port 443 + resolving the domain is authorized. (Also this is infrastructure controlled by Apple, if you are doing bulk recognition of any kind you don't have guarantee that the tool keeps working)

stuckintraffic0 commented 9 months ago

Thank you. Appreciate your help. Let me test it

stuckintraffic0 commented 9 months ago

okay, disabling firewall (ufw) didn't make any difference so far

stuckintraffic0 commented 9 months ago

Also this is infrastructure controlled by Apple, if you are doing bulk recognition of any kind you don't have guarantee that the tool keeps working

How can we use proxies?

stuckintraffic0 commented 9 months ago

proxychains works

stuckintraffic0 commented 9 months ago

okay, now it doesn't work. Says the same thing

simon816 commented 9 months ago

I started getting this too.

The audio-file-to-recognised-song commands worked:

$ songrec audio-file-to-recognized-song Better\ Off\ Alone.opus 
...
    "subtitle": "Alice Deejay",
    "title": "Better Off Alone",
...

while recognize didn't:

$ songrec recognize Better\ Off\ Alone.opus 
Error: Network unreachable

I then started poking around the code, I ended up compiling it with one crucial change:

diff --git a/src/core/http_thread.rs b/src/core/http_thread.rs
index fe8910b..557174a 100644
--- a/src/core/http_thread.rs
+++ b/src/core/http_thread.rs
@@ -91,6 +91,7 @@ pub fn http_thread(http_rx: mpsc::Receiver<HTTPMessage>, gui_tx: glib::Sender<GU
                                 gui_tx.send(GUIMessage::NetworkStatus(true)).unwrap();
                             }
                             _ => {
+                                gui_tx.send(GUIMessage::ErrorMessage(error.to_string())).unwrap();
                                 gui_tx.send(GUIMessage::NetworkStatus(false)).unwrap();
                             }
                         }

Now we can see what the error is:

$ target/release/songrec recognize Better\ Off\ Alone.opus 
Error: error sending request for url (https://is1-ssl.mzstatic.com/image/thumb/Music112/v4/e4/fe/72/e4fe72dc-453e-0ec4-ddfa-f797375c1bd2/22UMGIM63672.rgb.jpg/400x400cc.jpg): error trying to connect: tcp connect error: Connection refused (os error 111)

Ah! It had been pi-hole'd

$ host is1-ssl.mzstatic.com
is1-ssl.mzstatic.com has address 0.0.0.0
is1-ssl.mzstatic.com has IPv6 address ::

Indeed this was a mistaken block https://github.com/AdguardTeam/AdguardFilters/commit/3892bd6f66a0a11f2f14b7cd662324c8ce435a11

So perhaps two takeaways:

randomscumbag commented 9 months ago

has there been a fix or a work around? I get connections for a few minutes then a disconnect for a long while then it'll reconnect back for a little bit. Not entirely sure if its Just me or a common problem maybe with the servers. It says Shazam servers are not reachable, are you connected? and I am definitely connected.

2024-02-12_23-06

dotX12 commented 9 months ago

Shazam has introduced a limit on the number of requests, and then sends a 429 error. We also encountered this problem. https://github.com/dotX12/ShazamIO/issues/81