jesseward / jellyfin-plugin-lastfm

LastFM plugin for the Jellyfin media system. Fork of the Emby Last.FM plug-in
182 stars 12 forks source link

Scrobbling failing with "Invalid parameters - Your request is missing a required parameter" #12

Closed r0bbie closed 5 years ago

r0bbie commented 5 years ago

Updated plugin version to head (9c804771386ef59c05979d508149d5a9408baf69) in order to get it working with latest version of Jellyfin again (10.3.7) with #10 now resolved.

Unfortunately scrobbling is still failing. Checked Jellyfin logs, related error pasted here:

[2019-08-25 01:41:01.581 +01:00] [INF] Setting range response values for "/mnt/sdc/music/[song here].flac". RangeRequest: "bytes=0-" Content-Length: "21645529", Content-Range: "bytes 0-21645528/21645529"
[2019-08-25 01:41:02.056 +01:00] [ERR] HTTP request failed with message: "{\"error\":6,\"message\":\"Invalid parameters - Your request is missing a required parameter\"}"
[2019-08-25 01:41:02.058 +01:00] [ERR] Failed to send now playing for track: ex="MediaBrowser.Model.Net.HttpException: Bad Request
   at Emby.Server.Implementations.HttpClientManager.HttpClientManager.EnsureSuccessStatusCode(HttpResponseMessage response, HttpRequestOptions options)
   at Emby.Server.Implementations.HttpClientManager.HttpClientManager.SendAsyncInternal(HttpRequestOptions options, HttpMethod httpMethod)
   at Emby.Server.Implementations.HttpClientManager.HttpClientManager.SendAsync(HttpRequestOptions options, HttpMethod httpMethod)
   at Jellyfin.Plugin.Lastfm.Api.BaseLastfmApiClient.Post[TRequest,TResponse](TRequest request)
   at Jellyfin.Plugin.Lastfm.Api.LastfmApiClient.NowPlaying(Audio item, LastfmUser user)", name="[song here]", track="[song here]", artist="[artist here]", album="[album here], mbid=null
jesseward commented 5 years ago

hey @r0bbie , thanks for reporting.

The problem appears to be in the JSON serialization (https://github.com/jesseward/jellyfin-plugin-lastfm/pull/11/files#diff-9c919f330ccd65f1e36800913392211dR53). The last.fm mobile auth handshake is specific in how it can receive its payload (https://www.last.fm/api/mobileauth).

The following change to Jellyfin.Plugin.Lastfm/Api/BaseLastfmApiClient.cs should fix. I will get this merged soon.

$ git diff Jellyfin.Plugin.Lastfm/Api/BaseLastfmApiClient.cs
diff --git a/Jellyfin.Plugin.Lastfm/Api/BaseLastfmApiClient.cs b/Jellyfin.Plugin.Lastfm/Api/BaseLastfmApiClient.cs
index 08f0dfb..90cd6e6 100644
--- a/Jellyfin.Plugin.Lastfm/Api/BaseLastfmApiClient.cs
+++ b/Jellyfin.Plugin.Lastfm/Api/BaseLastfmApiClient.cs
@@ -48,9 +48,13 @@
                 Url = BuildPostUrl(request.Secure),
                 CancellationToken = CancellationToken.None,
                 DecompressionMethod = CompressionMethod.None,
+                LogRequest = true,
+                LogErrors = true,
+                LogRequestAsDebug = false,
             };

-            options.RequestContent = _jsonSerializer.SerializeToString(EscapeDictionary(data));
+            options.RequestContentType = "application/x-www-form-urlencoded";
+            options.RequestContent = SetPostData(data);
             using (var response = await _httpClient.Post(options))
             {
                 using (var stream = response.Content)
@@ -127,10 +131,13 @@
                                 );
         }

-        private Dictionary<string, string> EscapeDictionary(Dictionary<string, string> dic)
+        private static string SetPostData(Dictionary<string, string> dic)
         {
-            return dic.ToDictionary(item => item.Key, item => Uri.EscapeDataString(item.Value));
+            var strings = dic.Keys.Select(key => string.Format("{0}={1}", key, Uri.EscapeDataString(dic[key])));
+            return string.Join("&", strings.ToArray());
+
         }
         #endregion
     }
 }
+

With the above, I am able to again submit tracks.

[17:24:42] [INF] Setting range response values for /media/Nightmares on Wax - Smokers Delight/01-damn.mp3. RangeRequest: bytes=0- Content-Length: 764176, Content-Range: bytes 0-764175/764176
[17:24:43] [INF] jw76 is now playing artist=Nightmares on Wax, track=Damn, album=Smokers Delight
[17:25:10] [INF] Playback stopped reported by app Jellyfin Web 10.3.7 playing Damn. Stopped at 27252 ms
[17:25:10] [INF] jw76 played artist=Nightmares on Wax, track=Damn, album=Smokers Delight
jesseward commented 5 years ago

Created 2.0.0 release (https://github.com/jesseward/jellyfin-plugin-lastfm/releases/tag/v2.0.0), which should address this

r0bbie commented 5 years ago

Just to confirm, all now running smoothly for me!