From 2b7f5f9e7a25ef704254b259fda96cd4eadaf359 Mon Sep 17 00:00:00 2001 From: me Date: Sat, 12 Oct 2024 16:40:52 +0000 Subject: [PATCH] who up scrobbling --- src/api.vala | 12 ++++++++++++ src/window.vala | 1 + 2 files changed, 13 insertions(+) diff --git a/src/api.vala b/src/api.vala index a8c0642..fbfe0c7 100644 --- a/src/api.vala +++ b/src/api.vala @@ -204,6 +204,18 @@ public class Wavelet.Subsonic : Object { this.unwrap_response (reader); } + public async void scrobble (string id) throws Error { + var msg = new Soup.Message ("GET", @"$(this.url)/rest/scrobble?id=$(Uri.escape_string (id))&f=json&$(this.parameters)"); + var bytes = yield this.session.send_and_read_async (msg, Priority.DEFAULT, null); + assert (msg.get_status () == Soup.Status.OK); + + var parser = new Json.Parser (); + parser.load_from_data ((string) bytes.get_data ()); + + var reader = new Json.Reader (parser.get_root ()); + this.unwrap_response (reader); + } + public async void get_random_songs (string? parameters, SongCallback callback) throws Error { string str_parameters; if (parameters == null) { diff --git a/src/window.vala b/src/window.vala index cdc2786..a3f91ed 100644 --- a/src/window.vala +++ b/src/window.vala @@ -102,6 +102,7 @@ class Wavelet.Window : Adw.ApplicationWindow { this.play_queue.now_playing.connect ((song) => { this.playing = true; this.song = song; + api.scrobble.begin (song.id); }); this.play_queue.play_now.connect ((song) => {