1
0
mirror of https://git.pleroma.social/sjw/pleroma.git synced 2024-11-12 09:39:08 +01:00

Add optional URL value for scrobbles

This commit is contained in:
NEETzsche 2023-11-15 00:43:58 -07:00
parent 6d708664b5
commit 510a7b64f1
5 changed files with 16 additions and 6 deletions

View File

@ -0,0 +1 @@
Adds the capability to add a URL to a scrobble (optional field)

View File

@ -59,6 +59,7 @@ defmodule Pleroma.Web.ApiSpec.PleromaScrobbleOperation do
album: %Schema{type: :string, description: "The album 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"}, artist: %Schema{type: :string, description: "The artist of the media playing"},
length: %Schema{type: :integer, description: "The length 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{ visibility: %Schema{
allOf: [VisibilityScope], allOf: [VisibilityScope],
default: "public", default: "public",
@ -69,7 +70,8 @@ defmodule Pleroma.Web.ApiSpec.PleromaScrobbleOperation do
"title" => "Some Title", "title" => "Some Title",
"artist" => "Some Artist", "artist" => "Some Artist",
"album" => "Some Album", "album" => "Some Album",
"length" => 180_000 "length" => 180_000,
"url" => "https://www.last.fm/music/Some+Artist/_/Some+Title"
} }
} }
end end
@ -83,6 +85,7 @@ defmodule Pleroma.Web.ApiSpec.PleromaScrobbleOperation do
title: %Schema{type: :string, description: "The title of the media playing"}, title: %Schema{type: :string, description: "The title of the media playing"},
album: %Schema{type: :string, description: "The album 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"}, artist: %Schema{type: :string, description: "The artist of the media playing"},
url: %Schema{type: :string, description: "A URL referencing the media playing"},
length: %Schema{ length: %Schema{
type: :integer, type: :integer,
description: "The length of the media playing", description: "The length of the media playing",
@ -97,6 +100,7 @@ defmodule Pleroma.Web.ApiSpec.PleromaScrobbleOperation do
"artist" => "Some Artist", "artist" => "Some Artist",
"album" => "Some Album", "album" => "Some Album",
"length" => 180_000, "length" => 180_000,
"url" => "https://www.last.fm/music/Some+Artist/_/Some+Title",
"created_at" => "2019-09-28T12:40:45.000Z" "created_at" => "2019-09-28T12:40:45.000Z"
} }
} }

View File

@ -83,7 +83,7 @@ defmodule Pleroma.Web.CommonAPI.ActivityDraft do
defp listen_object(draft) do defp listen_object(draft) do
object = object =
draft.params 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.new(fn {key, value} -> {to_string(key), value} end)
|> Map.put("type", "Audio") |> Map.put("type", "Audio")
|> Map.put("to", draft.to) |> Map.put("to", draft.to)

View File

@ -27,6 +27,7 @@ defmodule Pleroma.Web.PleromaAPI.ScrobbleView do
title: object.data["title"] |> HTML.strip_tags(), title: object.data["title"] |> HTML.strip_tags(),
artist: object.data["artist"] |> HTML.strip_tags(), artist: object.data["artist"] |> HTML.strip_tags(),
album: object.data["album"] |> HTML.strip_tags(), album: object.data["album"] |> HTML.strip_tags(),
url: object.data["url"],
length: object.data["length"] length: object.data["length"]
} }
end end

View File

@ -18,7 +18,8 @@ defmodule Pleroma.Web.PleromaAPI.ScrobbleControllerTest do
"title" => "lain radio episode 1", "title" => "lain radio episode 1",
"artist" => "lain", "artist" => "lain",
"album" => "lain radio", "album" => "lain radio",
"length" => "180000" "length" => "180000",
"url" => "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+1"
}) })
assert %{"title" => "lain radio episode 1"} = json_response_and_validate_schema(conn, 200) assert %{"title" => "lain radio episode 1"} = json_response_and_validate_schema(conn, 200)
@ -33,21 +34,24 @@ defmodule Pleroma.Web.PleromaAPI.ScrobbleControllerTest do
CommonAPI.listen(user, %{ CommonAPI.listen(user, %{
title: "lain radio episode 1", title: "lain radio episode 1",
artist: "lain", artist: "lain",
album: "lain radio" album: "lain radio",
url: "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+1"
}) })
{:ok, _activity} = {:ok, _activity} =
CommonAPI.listen(user, %{ CommonAPI.listen(user, %{
title: "lain radio episode 2", title: "lain radio episode 2",
artist: "lain", artist: "lain",
album: "lain radio" album: "lain radio",
url: "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+2"
}) })
{:ok, _activity} = {:ok, _activity} =
CommonAPI.listen(user, %{ CommonAPI.listen(user, %{
title: "lain radio episode 3", title: "lain radio episode 3",
artist: "lain", artist: "lain",
album: "lain radio" album: "lain radio",
url: "https://www.last.fm/music/lain/lain+radio/lain+radio+episode+3"
}) })
conn = get(conn, "/api/v1/pleroma/accounts/#{user.id}/scrobbles") conn = get(conn, "/api/v1/pleroma/accounts/#{user.id}/scrobbles")