From 06511f89dbb1a2c54c7362db75982a8d5a0eee8b Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Fri, 30 May 2025 16:52:07 +0100 Subject: [PATCH] Cache Last.fm tracks raw data when parsing api response --- lib/last_fm/track.ex | 12 +- test/last_fm/feed_test.exs | 6 +- test/last_fm/track_test.exs | 799 +++++++++++++++++- .../live/stats_live/index_test.exs | 12 +- 4 files changed, 797 insertions(+), 32 deletions(-) diff --git a/lib/last_fm/track.ex b/lib/last_fm/track.ex index 20cf3df3..2e9460a5 100644 --- a/lib/last_fm/track.ex +++ b/lib/last_fm/track.ex @@ -14,7 +14,8 @@ defmodule LastFm.Track do :album, :cover_url, :scrobbled_at_uts, - :scrobbled_at_label + :scrobbled_at_label, + :last_fm_data ] defstruct [ :musicbrainz_id, @@ -23,7 +24,8 @@ defmodule LastFm.Track do :album, :cover_url, :scrobbled_at_uts, - :scrobbled_at_label + :scrobbled_at_label, + :last_fm_data ] @type t :: %__MODULE__{ @@ -33,7 +35,8 @@ defmodule LastFm.Track do album: Album.t(), cover_url: String.t(), scrobbled_at_uts: integer(), - scrobbled_at_label: String.t() + scrobbled_at_label: String.t(), + last_fm_data: map() } def from_api_response(raw_tracks) do @@ -55,7 +58,8 @@ defmodule LastFm.Track do album: album, cover_url: parse_cover_url(t), scrobbled_at_uts: parse_scrobble_at_uts(t), - scrobbled_at_label: t["date"]["#text"] + scrobbled_at_label: t["date"]["#text"], + last_fm_data: t } end) end diff --git a/test/last_fm/feed_test.exs b/test/last_fm/feed_test.exs index 819df384..5c26dc98 100644 --- a/test/last_fm/feed_test.exs +++ b/test/last_fm/feed_test.exs @@ -16,7 +16,8 @@ defmodule LastFm.FeedTest do }, cover_url: "https://lastfm.freetls.fastly.net/i/u/64s/9741e297b9884a4294624f0f90e14749.jpg", scrobbled_at_uts: 1_731_318_211, - scrobbled_at_label: "11 Nov 2024, 09:43" + scrobbled_at_label: "11 Nov 2024, 09:43", + last_fm_data: %{} } @track_two %Track{ musicbrainz_id: "619cb295-b155-3e35-b65a-396a7cd1fc47", @@ -31,7 +32,8 @@ defmodule LastFm.FeedTest do }, cover_url: "https://lastfm.freetls.fastly.net/i/u/64s/9741e297b9884a4294624f0f90e14749.jpg", scrobbled_at_uts: 1_731_318_945, - scrobbled_at_label: "11 Nov 2024, 09:55" + scrobbled_at_label: "11 Nov 2024, 09:55", + last_fm_data: %{} } describe "update and broadcast" do diff --git a/test/last_fm/track_test.exs b/test/last_fm/track_test.exs index 01bbb9d2..c258c60c 100644 --- a/test/last_fm/track_test.exs +++ b/test/last_fm/track_test.exs @@ -26,7 +26,45 @@ defmodule LastFm.TrackTest do cover_url: "https://lastfm.freetls.fastly.net/i/u/64s/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", scrobbled_at_uts: 1_730_678_348, - scrobbled_at_label: "03 Nov 2024, 23:59" + scrobbled_at_label: "03 Nov 2024, 23:59", + last_fm_data: %{ + "album" => %{ + "#text" => "Machinarium Soundtrack", + "mbid" => "4bad26f6-1b27-4554-93bd-40b91ed7866c" + }, + "artist" => %{ + "#text" => "Tomáš Dvořák", + "mbid" => "35ac1700-84f1-4bd9-924b-3792b742e618" + }, + "date" => %{"#text" => "03 Nov 2024, 23:59", "uts" => "1730678348"}, + "image" => [ + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/34s/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", + "size" => "small" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/64s/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", + "size" => "medium" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/174s/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", + "size" => "large" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/300x300/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", + "size" => "extralarge" + } + ], + "mbid" => "190567f8-900e-44ce-a574-69adc10cf93a", + "name" => "Gameboy Tune", + "streamable" => "0", + "url" => + "https://www.last.fm/music/Tom%C3%A1%C5%A1+Dvo%C5%99%C3%A1k/_/Gameboy+Tune" + } }, %LastFm.Track{ musicbrainz_id: "21829902-c427-4eb5-b777-86d252d8591f", @@ -42,7 +80,45 @@ defmodule LastFm.TrackTest do cover_url: "https://lastfm.freetls.fastly.net/i/u/64s/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", scrobbled_at_uts: 1_730_592_942, - scrobbled_at_label: "03 Nov 2024, 00:15" + scrobbled_at_label: "03 Nov 2024, 00:15", + last_fm_data: %{ + "album" => %{ + "#text" => "Machinarium Soundtrack", + "mbid" => "4bad26f6-1b27-4554-93bd-40b91ed7866c" + }, + "artist" => %{ + "#text" => "Tomáš Dvořák", + "mbid" => "35ac1700-84f1-4bd9-924b-3792b742e618" + }, + "date" => %{"#text" => "03 Nov 2024, 00:15", "uts" => "1730592942"}, + "image" => [ + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/34s/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", + "size" => "small" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/64s/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", + "size" => "medium" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/174s/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", + "size" => "large" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/300x300/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", + "size" => "extralarge" + } + ], + "mbid" => "21829902-c427-4eb5-b777-86d252d8591f", + "name" => "Mr. Handagote", + "streamable" => "0", + "url" => + "https://www.last.fm/music/Tom%C3%A1%C5%A1+Dvo%C5%99%C3%A1k/_/Mr.+Handagote" + } }, %LastFm.Track{ musicbrainz_id: "07efe704-e3d3-450f-b64d-906448101aa5", @@ -58,7 +134,45 @@ defmodule LastFm.TrackTest do cover_url: "https://lastfm.freetls.fastly.net/i/u/64s/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", scrobbled_at_uts: 1_730_592_775, - scrobbled_at_label: "03 Nov 2024, 00:12" + scrobbled_at_label: "03 Nov 2024, 00:12", + last_fm_data: %{ + "album" => %{ + "#text" => "Machinarium Soundtrack", + "mbid" => "4bad26f6-1b27-4554-93bd-40b91ed7866c" + }, + "artist" => %{ + "#text" => "Tomáš Dvořák", + "mbid" => "35ac1700-84f1-4bd9-924b-3792b742e618" + }, + "date" => %{"#text" => "03 Nov 2024, 00:12", "uts" => "1730592775"}, + "image" => [ + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/34s/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", + "size" => "small" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/64s/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", + "size" => "medium" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/174s/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", + "size" => "large" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/300x300/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", + "size" => "extralarge" + } + ], + "mbid" => "07efe704-e3d3-450f-b64d-906448101aa5", + "name" => "The Mezzanine", + "streamable" => "0", + "url" => + "https://www.last.fm/music/Tom%C3%A1%C5%A1+Dvo%C5%99%C3%A1k/_/The+Mezzanine" + } }, %LastFm.Track{ musicbrainz_id: "09dc71fd-cf8a-4ad7-a3ed-5fd3dd2da143", @@ -74,7 +188,45 @@ defmodule LastFm.TrackTest do cover_url: "https://lastfm.freetls.fastly.net/i/u/64s/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", scrobbled_at_uts: 1_730_587_431, - scrobbled_at_label: "02 Nov 2024, 22:43" + scrobbled_at_label: "02 Nov 2024, 22:43", + last_fm_data: %{ + "album" => %{ + "#text" => "Machinarium Soundtrack", + "mbid" => "4bad26f6-1b27-4554-93bd-40b91ed7866c" + }, + "artist" => %{ + "#text" => "Tomáš Dvořák", + "mbid" => "35ac1700-84f1-4bd9-924b-3792b742e618" + }, + "date" => %{"#text" => "02 Nov 2024, 22:43", "uts" => "1730587431"}, + "image" => [ + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/34s/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", + "size" => "small" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/64s/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", + "size" => "medium" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/174s/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", + "size" => "large" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/300x300/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", + "size" => "extralarge" + } + ], + "mbid" => "09dc71fd-cf8a-4ad7-a3ed-5fd3dd2da143", + "name" => "Nanorobot Tune", + "streamable" => "0", + "url" => + "https://www.last.fm/music/Tom%C3%A1%C5%A1+Dvo%C5%99%C3%A1k/_/Nanorobot+Tune" + } }, %LastFm.Track{ musicbrainz_id: "03a99f77-9da7-314b-8fdb-bfe1f3e9f6e6", @@ -90,7 +242,45 @@ defmodule LastFm.TrackTest do cover_url: "https://lastfm.freetls.fastly.net/i/u/64s/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", scrobbled_at_uts: 1_730_587_213, - scrobbled_at_label: "02 Nov 2024, 22:40" + scrobbled_at_label: "02 Nov 2024, 22:40", + last_fm_data: %{ + "album" => %{ + "#text" => "Machinarium Soundtrack", + "mbid" => "4bad26f6-1b27-4554-93bd-40b91ed7866c" + }, + "artist" => %{ + "#text" => "Tomáš Dvořák", + "mbid" => "35ac1700-84f1-4bd9-924b-3792b742e618" + }, + "date" => %{"#text" => "02 Nov 2024, 22:40", "uts" => "1730587213"}, + "image" => [ + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/34s/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", + "size" => "small" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/64s/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", + "size" => "medium" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/174s/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", + "size" => "large" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/300x300/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", + "size" => "extralarge" + } + ], + "mbid" => "03a99f77-9da7-314b-8fdb-bfe1f3e9f6e6", + "name" => "Clockwise Operetta", + "streamable" => "0", + "url" => + "https://www.last.fm/music/Tom%C3%A1%C5%A1+Dvo%C5%99%C3%A1k/_/Clockwise+Operetta" + } }, %LastFm.Track{ musicbrainz_id: "3525dfb3-fe86-4295-a1ad-332f00d7239a", @@ -106,7 +296,44 @@ defmodule LastFm.TrackTest do cover_url: "https://lastfm.freetls.fastly.net/i/u/64s/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", scrobbled_at_uts: 1_730_586_978, - scrobbled_at_label: "02 Nov 2024, 22:36" + scrobbled_at_label: "02 Nov 2024, 22:36", + last_fm_data: %{ + "album" => %{ + "#text" => "Machinarium Soundtrack", + "mbid" => "4bad26f6-1b27-4554-93bd-40b91ed7866c" + }, + "artist" => %{ + "#text" => "Tomáš Dvořák", + "mbid" => "35ac1700-84f1-4bd9-924b-3792b742e618" + }, + "date" => %{"#text" => "02 Nov 2024, 22:36", "uts" => "1730586978"}, + "image" => [ + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/34s/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", + "size" => "small" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/64s/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", + "size" => "medium" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/174s/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", + "size" => "large" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/300x300/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", + "size" => "extralarge" + } + ], + "mbid" => "3525dfb3-fe86-4295-a1ad-332f00d7239a", + "name" => "The Sea", + "streamable" => "0", + "url" => "https://www.last.fm/music/Tom%C3%A1%C5%A1+Dvo%C5%99%C3%A1k/_/The+Sea" + } }, %LastFm.Track{ musicbrainz_id: "2e468dc8-8734-42af-a820-201ab92835a7", @@ -122,7 +349,45 @@ defmodule LastFm.TrackTest do cover_url: "https://lastfm.freetls.fastly.net/i/u/64s/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", scrobbled_at_uts: 1_730_586_696, - scrobbled_at_label: "02 Nov 2024, 22:31" + scrobbled_at_label: "02 Nov 2024, 22:31", + last_fm_data: %{ + "album" => %{ + "#text" => "Machinarium Soundtrack", + "mbid" => "4bad26f6-1b27-4554-93bd-40b91ed7866c" + }, + "artist" => %{ + "#text" => "Tomáš Dvořák", + "mbid" => "35ac1700-84f1-4bd9-924b-3792b742e618" + }, + "date" => %{"#text" => "02 Nov 2024, 22:31", "uts" => "1730586696"}, + "image" => [ + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/34s/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", + "size" => "small" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/64s/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", + "size" => "medium" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/174s/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", + "size" => "large" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/300x300/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", + "size" => "extralarge" + } + ], + "mbid" => "2e468dc8-8734-42af-a820-201ab92835a7", + "name" => "The Bottom", + "streamable" => "0", + "url" => + "https://www.last.fm/music/Tom%C3%A1%C5%A1+Dvo%C5%99%C3%A1k/_/The+Bottom" + } }, %LastFm.Track{ musicbrainz_id: "", @@ -138,7 +403,45 @@ defmodule LastFm.TrackTest do cover_url: "https://lastfm.freetls.fastly.net/i/u/64s/7272b50a02fb3e35c59376d2f96cad97.jpg", scrobbled_at_uts: 1_730_583_124, - scrobbled_at_label: "02 Nov 2024, 21:32" + scrobbled_at_label: "02 Nov 2024, 21:32", + last_fm_data: %{ + "album" => %{ + "#text" => "The Last Flight", + "mbid" => "2157367e-bf73-48bb-8185-41023a54fa08" + }, + "artist" => %{ + "#text" => "Public Service Broadcasting feat. This Is The Kit", + "mbid" => "" + }, + "date" => %{"#text" => "02 Nov 2024, 21:32", "uts" => "1730583124"}, + "image" => [ + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/34s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "small" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/64s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "medium" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/174s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "large" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/300x300/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "extralarge" + } + ], + "mbid" => "", + "name" => "The South Atlantic", + "streamable" => "0", + "url" => + "https://www.last.fm/music/Public+Service+Broadcasting+feat.+This+Is+The+Kit/_/The+South+Atlantic" + } }, %LastFm.Track{ musicbrainz_id: "", @@ -154,7 +457,45 @@ defmodule LastFm.TrackTest do cover_url: "https://lastfm.freetls.fastly.net/i/u/64s/7272b50a02fb3e35c59376d2f96cad97.jpg", scrobbled_at_uts: 1_730_582_915, - scrobbled_at_label: "02 Nov 2024, 21:28" + scrobbled_at_label: "02 Nov 2024, 21:28", + last_fm_data: %{ + "album" => %{ + "#text" => "The Last Flight", + "mbid" => "2157367e-bf73-48bb-8185-41023a54fa08" + }, + "artist" => %{ + "#text" => "Public Service Broadcasting feat. Andreya Casablanca", + "mbid" => "" + }, + "date" => %{"#text" => "02 Nov 2024, 21:28", "uts" => "1730582915"}, + "image" => [ + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/34s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "small" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/64s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "medium" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/174s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "large" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/300x300/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "extralarge" + } + ], + "mbid" => "", + "name" => "The Fun Of It", + "streamable" => "0", + "url" => + "https://www.last.fm/music/Public+Service+Broadcasting+feat.+Andreya+Casablanca/_/The+Fun+Of+It" + } }, %LastFm.Track{ musicbrainz_id: "77719694-4c4a-4bb6-a20e-5852b3166b34", @@ -170,7 +511,45 @@ defmodule LastFm.TrackTest do cover_url: "https://lastfm.freetls.fastly.net/i/u/64s/7272b50a02fb3e35c59376d2f96cad97.jpg", scrobbled_at_uts: 1_730_582_721, - scrobbled_at_label: "02 Nov 2024, 21:25" + scrobbled_at_label: "02 Nov 2024, 21:25", + last_fm_data: %{ + "album" => %{ + "#text" => "The Last Flight", + "mbid" => "2157367e-bf73-48bb-8185-41023a54fa08" + }, + "artist" => %{ + "#text" => "Public Service Broadcasting", + "mbid" => "93834e82-3a0b-4ec2-a2e4-6eca0a497e6d" + }, + "date" => %{"#text" => "02 Nov 2024, 21:25", "uts" => "1730582721"}, + "image" => [ + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/34s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "small" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/64s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "medium" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/174s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "large" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/300x300/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "extralarge" + } + ], + "mbid" => "77719694-4c4a-4bb6-a20e-5852b3166b34", + "name" => "Towards The Dawn", + "streamable" => "0", + "url" => + "https://www.last.fm/music/Public+Service+Broadcasting/_/Towards+The+Dawn" + } }, %LastFm.Track{ musicbrainz_id: "", @@ -186,7 +565,45 @@ defmodule LastFm.TrackTest do cover_url: "https://lastfm.freetls.fastly.net/i/u/64s/7272b50a02fb3e35c59376d2f96cad97.jpg", scrobbled_at_uts: 1_730_582_531, - scrobbled_at_label: "02 Nov 2024, 21:22" + scrobbled_at_label: "02 Nov 2024, 21:22", + last_fm_data: %{ + "album" => %{ + "#text" => "The Last Flight", + "mbid" => "2157367e-bf73-48bb-8185-41023a54fa08" + }, + "artist" => %{ + "#text" => "Public Service Broadcasting", + "mbid" => "93834e82-3a0b-4ec2-a2e4-6eca0a497e6d" + }, + "date" => %{"#text" => "02 Nov 2024, 21:22", "uts" => "1730582531"}, + "image" => [ + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/34s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "small" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/64s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "medium" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/174s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "large" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/300x300/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "extralarge" + } + ], + "mbid" => "", + "name" => "I Was Always Dreaming", + "streamable" => "0", + "url" => + "https://www.last.fm/music/Public+Service+Broadcasting/_/I+Was+Always+Dreaming" + } }, %LastFm.Track{ musicbrainz_id: "", @@ -202,7 +619,44 @@ defmodule LastFm.TrackTest do cover_url: "https://lastfm.freetls.fastly.net/i/u/64s/7272b50a02fb3e35c59376d2f96cad97.jpg", scrobbled_at_uts: 1_730_582_162, - scrobbled_at_label: "02 Nov 2024, 21:16" + scrobbled_at_label: "02 Nov 2024, 21:16", + last_fm_data: %{ + "album" => %{ + "#text" => "The Last Flight", + "mbid" => "2157367e-bf73-48bb-8185-41023a54fa08" + }, + "artist" => %{ + "#text" => "Public Service Broadcasting", + "mbid" => "93834e82-3a0b-4ec2-a2e4-6eca0a497e6d" + }, + "date" => %{"#text" => "02 Nov 2024, 21:16", "uts" => "1730582162"}, + "image" => [ + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/34s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "small" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/64s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "medium" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/174s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "large" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/300x300/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "extralarge" + } + ], + "mbid" => "", + "name" => "Howland", + "streamable" => "0", + "url" => "https://www.last.fm/music/Public+Service+Broadcasting/_/Howland" + } }, %LastFm.Track{ musicbrainz_id: "", @@ -218,7 +672,45 @@ defmodule LastFm.TrackTest do cover_url: "https://lastfm.freetls.fastly.net/i/u/64s/7272b50a02fb3e35c59376d2f96cad97.jpg", scrobbled_at_uts: 1_730_581_791, - scrobbled_at_label: "02 Nov 2024, 21:09" + scrobbled_at_label: "02 Nov 2024, 21:09", + last_fm_data: %{ + "album" => %{ + "#text" => "The Last Flight", + "mbid" => "2157367e-bf73-48bb-8185-41023a54fa08" + }, + "artist" => %{ + "#text" => "Public Service Broadcasting Feat. EERA", + "mbid" => "" + }, + "date" => %{"#text" => "02 Nov 2024, 21:09", "uts" => "1730581791"}, + "image" => [ + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/34s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "small" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/64s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "medium" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/174s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "large" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/300x300/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "extralarge" + } + ], + "mbid" => "", + "name" => "A Different Kind Of Love", + "streamable" => "0", + "url" => + "https://www.last.fm/music/Public+Service+Broadcasting+Feat.+EERA/_/A+Different+Kind+Of+Love" + } }, %LastFm.Track{ musicbrainz_id: "", @@ -234,7 +726,44 @@ defmodule LastFm.TrackTest do cover_url: "https://lastfm.freetls.fastly.net/i/u/64s/7272b50a02fb3e35c59376d2f96cad97.jpg", scrobbled_at_uts: 1_730_581_574, - scrobbled_at_label: "02 Nov 2024, 21:06" + scrobbled_at_label: "02 Nov 2024, 21:06", + last_fm_data: %{ + "album" => %{ + "#text" => "The Last Flight", + "mbid" => "2157367e-bf73-48bb-8185-41023a54fa08" + }, + "artist" => %{ + "#text" => "Public Service Broadcasting", + "mbid" => "93834e82-3a0b-4ec2-a2e4-6eca0a497e6d" + }, + "date" => %{"#text" => "02 Nov 2024, 21:06", "uts" => "1730581574"}, + "image" => [ + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/34s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "small" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/64s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "medium" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/174s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "large" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/300x300/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "extralarge" + } + ], + "mbid" => "", + "name" => "Monsoons", + "streamable" => "0", + "url" => "https://www.last.fm/music/Public+Service+Broadcasting/_/Monsoons" + } }, %LastFm.Track{ musicbrainz_id: "", @@ -250,7 +779,45 @@ defmodule LastFm.TrackTest do cover_url: "https://lastfm.freetls.fastly.net/i/u/64s/7272b50a02fb3e35c59376d2f96cad97.jpg", scrobbled_at_uts: 1_730_581_335, - scrobbled_at_label: "02 Nov 2024, 21:02" + scrobbled_at_label: "02 Nov 2024, 21:02", + last_fm_data: %{ + "album" => %{ + "#text" => "The Last Flight", + "mbid" => "2157367e-bf73-48bb-8185-41023a54fa08" + }, + "artist" => %{ + "#text" => "Public Service Broadcasting", + "mbid" => "93834e82-3a0b-4ec2-a2e4-6eca0a497e6d" + }, + "date" => %{"#text" => "02 Nov 2024, 21:02", "uts" => "1730581335"}, + "image" => [ + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/34s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "small" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/64s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "medium" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/174s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "large" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/300x300/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "extralarge" + } + ], + "mbid" => "", + "name" => "Arabian Flight", + "streamable" => "0", + "url" => + "https://www.last.fm/music/Public+Service+Broadcasting/_/Arabian+Flight" + } }, %LastFm.Track{ musicbrainz_id: "6b61f1d9-0323-43f3-a85e-b57e5094bbaf", @@ -266,7 +833,44 @@ defmodule LastFm.TrackTest do cover_url: "https://lastfm.freetls.fastly.net/i/u/64s/7272b50a02fb3e35c59376d2f96cad97.jpg", scrobbled_at_uts: 1_730_581_095, - scrobbled_at_label: "02 Nov 2024, 20:58" + scrobbled_at_label: "02 Nov 2024, 20:58", + last_fm_data: %{ + "album" => %{ + "#text" => "The Last Flight", + "mbid" => "2157367e-bf73-48bb-8185-41023a54fa08" + }, + "artist" => %{ + "#text" => "Public Service Broadcasting", + "mbid" => "93834e82-3a0b-4ec2-a2e4-6eca0a497e6d" + }, + "date" => %{"#text" => "02 Nov 2024, 20:58", "uts" => "1730581095"}, + "image" => [ + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/34s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "small" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/64s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "medium" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/174s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "large" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/300x300/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "extralarge" + } + ], + "mbid" => "6b61f1d9-0323-43f3-a85e-b57e5094bbaf", + "name" => "Electra", + "streamable" => "0", + "url" => "https://www.last.fm/music/Public+Service+Broadcasting/_/Electra" + } }, %LastFm.Track{ musicbrainz_id: "", @@ -282,7 +886,45 @@ defmodule LastFm.TrackTest do cover_url: "https://lastfm.freetls.fastly.net/i/u/64s/7272b50a02fb3e35c59376d2f96cad97.jpg", scrobbled_at_uts: 1_730_580_883, - scrobbled_at_label: "02 Nov 2024, 20:54" + scrobbled_at_label: "02 Nov 2024, 20:54", + last_fm_data: %{ + "album" => %{ + "#text" => "The Last Flight", + "mbid" => "2157367e-bf73-48bb-8185-41023a54fa08" + }, + "artist" => %{ + "#text" => "Public Service Broadcasting feat. This Is The Kit", + "mbid" => "" + }, + "date" => %{"#text" => "02 Nov 2024, 20:54", "uts" => "1730580883"}, + "image" => [ + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/34s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "small" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/64s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "medium" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/174s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "large" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/300x300/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "extralarge" + } + ], + "mbid" => "", + "name" => "The South Atlantic", + "streamable" => "0", + "url" => + "https://www.last.fm/music/Public+Service+Broadcasting+feat.+This+Is+The+Kit/_/The+South+Atlantic" + } }, %LastFm.Track{ musicbrainz_id: "", @@ -298,7 +940,45 @@ defmodule LastFm.TrackTest do cover_url: "https://lastfm.freetls.fastly.net/i/u/64s/7272b50a02fb3e35c59376d2f96cad97.jpg", scrobbled_at_uts: 1_730_580_673, - scrobbled_at_label: "02 Nov 2024, 20:51" + scrobbled_at_label: "02 Nov 2024, 20:51", + last_fm_data: %{ + "album" => %{ + "#text" => "The Last Flight", + "mbid" => "2157367e-bf73-48bb-8185-41023a54fa08" + }, + "artist" => %{ + "#text" => "Public Service Broadcasting feat. Andreya Casablanca", + "mbid" => "" + }, + "date" => %{"#text" => "02 Nov 2024, 20:51", "uts" => "1730580673"}, + "image" => [ + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/34s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "small" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/64s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "medium" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/174s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "large" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/300x300/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "extralarge" + } + ], + "mbid" => "", + "name" => "The Fun Of It", + "streamable" => "0", + "url" => + "https://www.last.fm/music/Public+Service+Broadcasting+feat.+Andreya+Casablanca/_/The+Fun+Of+It" + } }, %LastFm.Track{ musicbrainz_id: "77719694-4c4a-4bb6-a20e-5852b3166b34", @@ -314,7 +994,45 @@ defmodule LastFm.TrackTest do cover_url: "https://lastfm.freetls.fastly.net/i/u/64s/7272b50a02fb3e35c59376d2f96cad97.jpg", scrobbled_at_uts: 1_730_580_481, - scrobbled_at_label: "02 Nov 2024, 20:48" + scrobbled_at_label: "02 Nov 2024, 20:48", + last_fm_data: %{ + "album" => %{ + "#text" => "The Last Flight", + "mbid" => "2157367e-bf73-48bb-8185-41023a54fa08" + }, + "artist" => %{ + "#text" => "Public Service Broadcasting", + "mbid" => "93834e82-3a0b-4ec2-a2e4-6eca0a497e6d" + }, + "date" => %{"#text" => "02 Nov 2024, 20:48", "uts" => "1730580481"}, + "image" => [ + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/34s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "small" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/64s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "medium" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/174s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "large" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/300x300/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "extralarge" + } + ], + "mbid" => "77719694-4c4a-4bb6-a20e-5852b3166b34", + "name" => "Towards The Dawn", + "streamable" => "0", + "url" => + "https://www.last.fm/music/Public+Service+Broadcasting/_/Towards+The+Dawn" + } }, %LastFm.Track{ musicbrainz_id: "", @@ -330,10 +1048,47 @@ defmodule LastFm.TrackTest do cover_url: "https://lastfm.freetls.fastly.net/i/u/64s/7272b50a02fb3e35c59376d2f96cad97.jpg", scrobbled_at_uts: 1_730_580_290, - scrobbled_at_label: "02 Nov 2024, 20:44" + scrobbled_at_label: "02 Nov 2024, 20:44", + last_fm_data: %{ + "album" => %{ + "#text" => "The Last Flight", + "mbid" => "2157367e-bf73-48bb-8185-41023a54fa08" + }, + "artist" => %{ + "#text" => "Public Service Broadcasting", + "mbid" => "93834e82-3a0b-4ec2-a2e4-6eca0a497e6d" + }, + "date" => %{"#text" => "02 Nov 2024, 20:44", "uts" => "1730580290"}, + "image" => [ + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/34s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "small" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/64s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "medium" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/174s/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "large" + }, + %{ + "#text" => + "https://lastfm.freetls.fastly.net/i/u/300x300/7272b50a02fb3e35c59376d2f96cad97.jpg", + "size" => "extralarge" + } + ], + "mbid" => "", + "name" => "I Was Always Dreaming", + "streamable" => "0", + "url" => + "https://www.last.fm/music/Public+Service+Broadcasting/_/I+Was+Always+Dreaming" + } } - ] == - LastFm.Track.from_api_response(api_response) + ] == LastFm.Track.from_api_response(api_response) end end end diff --git a/test/music_library_web/live/stats_live/index_test.exs b/test/music_library_web/live/stats_live/index_test.exs index 5d4bf03f..40650496 100644 --- a/test/music_library_web/live/stats_live/index_test.exs +++ b/test/music_library_web/live/stats_live/index_test.exs @@ -92,7 +92,8 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do cover_url: "https://lastfm.freetls.fastly.net/i/u/64s/b301ac9a72f14eb4ce3ddd785eb562b2.jpg", scrobbled_at_uts: 1_730_678_348, - scrobbled_at_label: "03 Nov 2024, 23:59" + scrobbled_at_label: "03 Nov 2024, 23:59", + last_fm_data: %{} } the_last_flight_track = %LastFm.Track{ @@ -109,7 +110,8 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do cover_url: "https://lastfm.freetls.fastly.net/i/u/64s/7272b50a02fb3e35c59376d2f96cad97.jpg", scrobbled_at_uts: 1_730_582_531, - scrobbled_at_label: "02 Nov 2024, 21:22" + scrobbled_at_label: "02 Nov 2024, 21:22", + last_fm_data: %{} } the_mystery_of_time_track = %LastFm.Track{ @@ -126,7 +128,8 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do cover_url: "https://lastfm.freetls.fastly.net/i/u/64s/104b3f466df84b67cbbe8eadf503fba4.jpg", scrobbled_at_uts: 1_732_103_695, - scrobbled_at_label: "20 Nov 2024, 11:54" + scrobbled_at_label: "20 Nov 2024, 11:54", + last_fm_data: %{} } in_murmuration_track = %LastFm.Track{ @@ -143,7 +146,8 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do cover_url: "https://lastfm.freetls.fastly.net/i/u/64s/f4923850113a5d365b1fd2d04cb4c1c3.jpg", scrobbled_at_uts: 1_732_399_832, - scrobbled_at_label: "23 Nov 2024, 22:10" + scrobbled_at_label: "23 Nov 2024, 22:10", + last_fm_data: %{} } LastFm.Feed.update([