From 19b041a90bf31e45d49119a787de743c7efbd092 Mon Sep 17 00:00:00 2001 From: NEETzsche Date: Wed, 15 Nov 2023 00:43:58 -0700 Subject: [PATCH] Add optional URL value for scrobbles --- changelog.d/scrobble-url.add | 1 + .../web/api_spec/operations/pleroma_scrobble_operation.ex | 6 +++++- lib/pleroma/web/common_api/activity_draft.ex | 2 +- lib/pleroma/web/pleroma_api/views/scrobble_view.ex | 1 + 4 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 changelog.d/scrobble-url.add diff --git a/changelog.d/scrobble-url.add b/changelog.d/scrobble-url.add new file mode 100644 index 0000000000..24bdeed89c --- /dev/null +++ b/changelog.d/scrobble-url.add @@ -0,0 +1 @@ +Adds the capability to add a URL to a scrobble (optional field) diff --git a/lib/pleroma/web/api_spec/operations/pleroma_scrobble_operation.ex b/lib/pleroma/web/api_spec/operations/pleroma_scrobble_operation.ex index b6273bfcfd..1facc96bd7 100644 --- a/lib/pleroma/web/api_spec/operations/pleroma_scrobble_operation.ex +++ b/lib/pleroma/web/api_spec/operations/pleroma_scrobble_operation.ex @@ -57,6 +57,7 @@ defp create_request do album: %Schema{type: :string, description: "The album of the media playing"}, artist: %Schema{type: :string, description: "The artist of the media playing"}, length: %Schema{type: :integer, description: "The length of the media playing"}, + url: %Schema{type: :string, description: "A URL referencing the media playing"}, visibility: %Schema{ allOf: [VisibilityScope], default: "public", @@ -67,7 +68,8 @@ defp create_request do "title" => "Some Title", "artist" => "Some Artist", "album" => "Some Album", - "length" => 180_000 + "length" => 180_000, + "url" => "https://www.last.fm/music/Some+Artist/_/Some+Title" } } end @@ -81,6 +83,7 @@ defp scrobble do title: %Schema{type: :string, description: "The title of the media playing"}, album: %Schema{type: :string, description: "The album of the media playing"}, artist: %Schema{type: :string, description: "The artist of the media playing"}, + url: %Schema{type: :string, description: "A URL referencing the media playing"}, length: %Schema{ type: :integer, description: "The length of the media playing", @@ -95,6 +98,7 @@ defp scrobble do "artist" => "Some Artist", "album" => "Some Album", "length" => 180_000, + "url" => "https://www.last.fm/music/Some+Artist/_/Some+Title", "created_at" => "2019-09-28T12:40:45.000Z" } } diff --git a/lib/pleroma/web/common_api/activity_draft.ex b/lib/pleroma/web/common_api/activity_draft.ex index a531c61ff5..4e09fee070 100644 --- a/lib/pleroma/web/common_api/activity_draft.ex +++ b/lib/pleroma/web/common_api/activity_draft.ex @@ -92,7 +92,7 @@ def listen(user, params) do defp listen_object(draft) do object = draft.params - |> Map.take([:album, :artist, :title, :length]) + |> Map.take([:album, :artist, :title, :length, :url]) |> Map.new(fn {key, value} -> {to_string(key), value} end) |> Map.put("type", "Audio") |> Map.put("to", draft.to) diff --git a/lib/pleroma/web/pleroma_api/views/scrobble_view.ex b/lib/pleroma/web/pleroma_api/views/scrobble_view.ex index a5985fb2a0..7a983f8b5d 100644 --- a/lib/pleroma/web/pleroma_api/views/scrobble_view.ex +++ b/lib/pleroma/web/pleroma_api/views/scrobble_view.ex @@ -27,6 +27,7 @@ def render("show.json", %{activity: %Activity{data: %{"type" => "Listen"}} = act title: object.data["title"] |> HTML.strip_tags(), artist: object.data["artist"] |> HTML.strip_tags(), album: object.data["album"] |> HTML.strip_tags(), + url: object.data["url"], length: object.data["length"] } end