Audacious listenbrainz access

I’m sure this has been asked before and I might not have searched hard enough yet.

Anyway, this tutorial Last.FM Compatible API for ListenBrainz — ListenBrainz 0.1.0 documentation includes recompiling, which I did but still can’t get my listens to show up on my listenbrainz profile.

I’s not entirely clear to me if the tutorial is still up to date and which steps are actually required. One thing is that I think the scrobbler plugin does not have that much configuration options (any more?) There is exactly these buttons:

image

At the end of the day I would like to mention: Is there any “normal” way of making a rather standard app like audacious compatible with listenbrainz rather than “spoofing” last.fm - I seem to have a problem with the complexity of getting listenbrainz to run with my favorite desktop music player… Rhythmbox and otthers (which I do not prefer) have native listenbrainz plugins already. Anyone know if audacious makes efforts, how I can help (not a gui programmer though) or at least how to find the feature requrest that might be existing already.

In the meantime: Dear listenbrainz users and devs: Please clarify on this tutorial, which steps do I have to do and which not: Last.FM Compatible API for ListenBrainz — ListenBrainz 0.1.0 documentation

Thanks in advance
Jojo

2 Likes

That tutorial is pretty bad, yeah.

If you are on linux, an easy way to get working Listenbrainz scrobbling with audacious without needing to recompile is to use the MPRIS API through rescrobbled instead.

2 Likes

Hi!

I am not sure what the issue, if you could get Audacious to print debug logs and share those it might help. Regarding the normal way, one would need to add another module like audacious-plugins/src/scrobbler2 at master · audacious-media-player/audacious-plugins · GitHub. A lot of the code there could probably be copied/reused I assume. I would happy to contribute a patch for that but given that its C/C++, it will take a while…

1 Like

I don’t know about audacious and its last.fm plugin. But in your screenshot it seems like it is registered. So did the login to ListenBrainz work?

Awesome feedback! I’ll give rescrobbled a try! Thanks!

1 Like

The login to listenbrainz did not work. I’m getting this error message when pressing “Check Perm…”:

And this is on the console:

I’m not sure if I did everything right because the tuturial did confuse me / is not written well enough for me to understand. Could be user error though ;-)))

I’m not a C programmer, but my go to move now would be to put print statements to see where actually it is trying to authenticate to… Any hints on roughly where in the plugin’s code and how a console statement can be put woudl be appreciated!

This is the change I did to the audacious-plugin before compiling:

git diff
diff --git a/src/scrobbler2/scrobbler.h b/src/scrobbler2/scrobbler.h
index 9236a3159..4dae9d4e9 100644
--- a/src/scrobbler2/scrobbler.h
+++ b/src/scrobbler2/scrobbler.h
@@ -24,7 +24,7 @@
 
 #define SCROBBLER_API_KEY "4b4f73bda181868353f9b438604adf52"
 #define SCROBBLER_SHARED_SECRET "716cc0a784bb62835de5bd674e65eb57"
-#define SCROBBLER_URL "https://ws.audioscrobbler.com/2.0/"
+#define SCROBBLER_URL "http://ws.audioscrobbler.com/2.0/"
 
 
 extern const PluginPreferences configuration;

1 Like

Does Audacious report any more info about the server connection if you run it in verbose mode?

audacious -V

I’m using Audacious 4.0.4 (latest version doesn’t want to build on my system) and it seems to be working.

Here’s how I patched it. These patches are for 4.0.4 but should hopefully be adaptable to newer versions. (It looks like this forum software is putting them in scrolling boxes so you might have to scroll to see the whole patches.)

Disclaimer: I’m not a C++ programmer so this is probably buggy!

1st the new URL…

diff --git a/src/scrobbler2/scrobbler.h b/src/scrobbler2/scrobbler.h
index 9236a3159..07c96a27f 100644
--- a/src/scrobbler2/scrobbler.h
+++ b/src/scrobbler2/scrobbler.h
@@ -24,7 +24,7 @@
 
 #define SCROBBLER_API_KEY "4b4f73bda181868353f9b438604adf52"
 #define SCROBBLER_SHARED_SECRET "716cc0a784bb62835de5bd674e65eb57"
-#define SCROBBLER_URL "https://ws.audioscrobbler.com/2.0/"
+#define SCROBBLER_URL "https://listenbrainz.org/2.0/"
 
 
 extern const PluginPreferences configuration;

Work around authorization check not working… (not sure if you may still have to click the button to check the login anyway, I don’t recall)

diff --git a/src/scrobbler2/scrobbler_communication.cc b/src/scrobbler2/scrobbler_communication.cc
index 29dfbcf96..ee5db8d3d 100644
--- a/src/scrobbler2/scrobbler_communication.cc
+++ b/src/scrobbler2/scrobbler_communication.cc
@@ -217,11 +217,11 @@ static gboolean scrobbler_test_connection() {
 
     if (success == false) {
         AUDDBG("Network problems. Will not scrobble any tracks.\n");
-        scrobbling_enabled = false;
+        scrobbling_enabled = true;
         if (permission_check_requested) {
-            perm_result = PERMISSION_NONET;
+            perm_result = PERMISSION_ALLOWED;
         }
-        return false;
+        return true;
     }
 
     String error_code;
@@ -236,12 +236,12 @@ static gboolean scrobbler_test_connection() {
             )) {
             session_key = String();
             aud_set_str("scrobbler", "session_key", "");
-            scrobbling_enabled = false;
+            scrobbling_enabled = true;
         } else {
             //network problem.
-            scrobbling_enabled = false;
+            scrobbling_enabled = true;
             AUDDBG("Connection NOT OK. Scrobbling disabled\n");
-            success = false;
+            success = true;
         }
     } else {
         //THIS IS THE ONLY PLACE WHERE SCROBBLING IS SET TO ENABLED IN RUN-TIME

Disable now playing feature, and clean up titles with SoundCloud IDs in them

diff --git a/src/scrobbler2/scrobbler.cc b/src/scrobbler2/scrobbler.cc
index 9c44b9465..74fc3aebd 100644
--- a/src/scrobbler2/scrobbler.cc
+++ b/src/scrobbler2/scrobbler.cc
@@ -7,6 +7,8 @@
  * It is licensed under the GNU General Public License, version 3.
  */
 
+#include <regex>
+#include <string>
 #include <glib/gstdio.h>
 
 //audacious includes
@@ -91,8 +93,10 @@ static gboolean queue_track_to_scrobble (void * data) {
 
     char *queuepath = g_strconcat(aud_get_path(AudPath::UserDir),"/scrobbler.log", nullptr);
 
+    std::regex filter ("(-(([-\\w]{11})|(\\d{9,10})))$");
+
     StringBuf artist = clean_string (playing_track.get_str (Tuple::Artist));
-    StringBuf title  = clean_string (playing_track.get_str (Tuple::Title));
+    StringBuf title = clean_string (std::regex_replace(std::string (playing_track.get_str (Tuple::Title)), filter, "").c_str());
     StringBuf album  = clean_string (playing_track.get_str (Tuple::Album));
 
     int track  = playing_track.get_int (Tuple::Track);
diff --git a/src/scrobbler2/scrobbler_communication.cc b/src/scrobbler2/scrobbler_communication.cc
index b3d343c37..3e03d1c4b 100644
--- a/src/scrobbler2/scrobbler_communication.cc
+++ b/src/scrobbler2/scrobbler_communication.cc
@@ -3,6 +3,7 @@
 #include <stdarg.h>
 #include <stdlib.h>
 #include <sys/time.h>
+#include <regex>
 #include <curl/curl.h>
 
 #include <glib.h>
@@ -500,8 +501,12 @@ static void send_now_playing() {
    */
   Tuple curr_track = now_playing_track.ref ();
 
+  std::regex filter ("-(([-\\w]{11})|(\\d{9,10}))$");
+
   StringBuf artist = clean_string (curr_track.get_str (Tuple::Artist));
-  StringBuf title = clean_string (curr_track.get_str (Tuple::Title));
+  StringBuf titletemp = clean_string (curr_track.get_str (Tuple::Title));
+  const char * titletempb =  std::regex_replace((const char *)titletemp, filter, "").c_str();
+  StringBuf title = str_copy(titletempb);
   StringBuf album = clean_string (curr_track.get_str (Tuple::Album));
 
   int track  = curr_track.get_int (Tuple::Track);
@@ -517,7 +522,8 @@ static void send_now_playing() {
      "duration", (const char *) length_str, "api_key", SCROBBLER_API_KEY,
      "sk", (const char *) session_key);
 
-    gboolean success = send_message_to_lastfm(playingmsg);
+    // gboolean success = send_message_to_lastfm(playingmsg);
+    gboolean success = true;
 
     if (success == false) {
       AUDDBG("Network problems. Could not send \"now playing\" to last.fm\n");

Probably don’t need this, but I did anyway…

diff --git a/src/scrobbler2/config_window.cc b/src/scrobbler2/config_window.cc
index 374c04b73..3663cdb1d 100644
--- a/src/scrobbler2/config_window.cc
+++ b/src/scrobbler2/config_window.cc
@@ -37,7 +37,7 @@ static gboolean permission_checker_thread (void *) {
             auto msg1 = _("Permission denied.  Open the following "
              "URL in a browser, allow Audacious access to your account, and "
              "then click 'Check Permission' again:");
-            auto url = str_printf("http://www.last.fm/api/auth/?api_key=%s"
+            auto url = str_printf("https://listenbrainz.org/api/auth/?api_key=%s"
              "&token=%s", SCROBBLER_API_KEY, (const char *)request_token);
 
             hook_call("ui show error", (void *)(const char *)str_concat

Prevent empty album tag getting rejected by LB… ([LB-1283] Suggestion - Treat empty release name as omitted? - MetaBrainz JIRA)

diff --git a/audacious-plugins-4.0.4/src/scrobbler2/scrobbler_communication.cc b/audacious-plugins-4.0.4/src/scrobbler2/scrobbler_communication.cc
index 40c9d1b..29dfbcf 100644
--- a/src/scrobbler2/scrobbler_communication.cc
+++ b/src/scrobbler2/scrobbler_communication.cc
@@ -398,7 +397,7 @@ static void scrobble_cached_queue() {
             if (line[0] && line[2] && (strcmp(line[5], "L") == 0) && line[6] && (line[7] == nullptr))
             {
                 String scrobblemsg = create_message_to_lastfm ("track.scrobble",
-                 8, "artist", line[0], "album", line[1], "track", line[2],
+                 8, "artist", line[0], "album", (line[1] != nullptr && (bool)strlen(line[1])) ? line[1] : "UnknownAlbum", "track", line[2],
                  "trackNumber", line[3], "duration", line[4],
                  "timestamp", line[6], "api_key", SCROBBLER_API_KEY,
                  "sk", (const char *) session_key);

I hope this helps!

3 Likes

Unfortunately not any more details about the server connection in verbose mode:

INFO probe-buffer.cc:30 [ProbeBuffer]: <0x562d82b7ea00> buffering enabled for /home/jojo/.config/audacious/playlists/order
INFO vfs.cc:105 [VFSFile]: <0x562d82b7ea00> open (mode r) /home/jojo/.config/audacious/playlists/order
INFO probe-buffer.cc:30 [ProbeBuffer]: <0x562d82cac300> buffering enabled for /home/jojo/.config/audacious/playlists/order
INFO vfs.cc:105 [VFSFile]: <0x562d82cac300> open (mode r) /home/jojo/.config/audacious/playlists/order

ERROR scrobbler_communication.cc:124 [send_message_to_lastfm]: Could not communicate with last.fm: Couldn't connect to server.

INFO probe-buffer.cc:30 [ProbeBuffer]: <0x562d82f588d0> buffering enabled for /home/jojo/.config/audacious/playlists/order
INFO vfs.cc:105 [VFSFile]: <0x562d82f588d0> open (mode r) /home/jojo/.config/audacious/playlists/order
INFO vfs.cc:105 [VFSFile]: <0x562d82bc6600> open (mode w) /home/jojo/.config/audacious/config
INFO probe-buffer.cc:30 [ProbeBuffer]: <0x562d82bc6600> buffering enabled for /home/jojo/.config/audacious/playlists/order

Wow, that’s quite some more than is stated in the official article…

You don’t happen to have this in a branch in your fork somehwere online? I’d love to just cherry-pick those commits into my fork :slight_smile:

I don’t off hand, sorry! But you can apply the patches (assuming Linux or similar OS) like:

  • Copy each patch to a new text file, then saving it as whatever-patch.diff
  • Then in a terminal cd into the source code folder like cd audacious-plugins-4.0.4 or wherever you have it
  • Then apply the patch with patch -p1 < /path/to/whatever-patch.diff

Then assuming you’re in a git clone of the repository you can git add .; git commit to make git commits from them, which you could cherry pick onto a newer branch of the player than the 4.0.4 these patches are for (may run into conflicts if they need updates, in particular I think the patch for empty album tag will need to be lightly tweaked for latest Audacious).

Hope this helps!

1 Like

+1 for Rescrobbled. I used to use it a lot for Spotify on Linux before I linked my Spotify account again. Work with basically any player that supports MPRIS - plugin or otherwise.

If you’re a bit obessive with your data, there is the downside of having to rely on the automated mapping system, but if you do have issues with that, there’s a ticket on the JIRA and you can also link the listen to the correct recording.

1 Like