refactor scrobblers (#383)

- no need to explicitly pass api key
- move packages up a level
- catch more errors by extended scrobbler interface with IsUserAuthenticated
- move interface to server
- delete scrobbber package, clients implicitly satisfy Scrobble

this also helps with gonic-lastfm-sync
This commit is contained in:
Senan Kelly
2023-09-27 01:13:00 +01:00
committed by GitHub
parent 32064d0279
commit f119659acf
27 changed files with 1100 additions and 1144 deletions

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<lfm status="ok">
<artist>
<name>Artist 1</name>
<mbid>366c1119-ec4f-4312-b729-a5637d148e3e</mbid>
<url>https://www.last.fm/music/Artist+1</url>
<image size="small">https://last.fm/artist-1-small.png</image>
<streamable>0</streamable>
<ontour>0</ontour>
<stats>
<listeners>1</listeners>
<playcount>2</playcount>
</stats>
<similar>
<artist>
<name>Similar Artist 1</name>
<url>https://www.last.fm/music/Similar+Artist+1</url>
<image size="small">https://last.fm/similar-artist-1-small.png</image>
</artist>
</similar>
<tags>
<tag>
<name>tag1</name>
<url>https://www.last.fm/tag/tag1</url>
</tag>
</tags>
<bio>
<links>
<link rel="original" href="https://last.fm/music/Artist+1/+wiki"></link>
</links>
<published>13 May 2023, 00:24</published>
<summary>Summary</summary>
<content>Content</content>
</bio>
</artist>
</lfm>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8" ?>
<lfm status="ok">
<similarartists artist="Artist 1">
<artist>
<name>Artist 2</name>
<mbid>d2addad9-3fc4-4ce8-9cd4-63f2a19bb922</mbid>
<match>1</match>
<url>https://www.last.fm/music/Artist+2</url>
<image size="small">https://last.fm/artist-2-small.png</image>
<image size="large">https://last.fm/artist-2-large.png</image>
<streamable>0</streamable>
</artist>
<artist>
<name>Artist 3</name>
<mbid>dc95d067-df3e-4b83-a5fe-5ec773b1883f</mbid>
<match>0.790991</match>
<url>https://www.last.fm/music/Artist+3</url>
<image size="small">https://last.fm/artist-3-small.png</image>
<image size="large">https://last.fm/artist-3-large.png</image>
<streamable>0</streamable>
</artist>
</similarartists>
</lfm>

View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<lfm status="ok">
<toptracks artist="Artist 1" page="1" perPage="50" totalPages="5" total="225">
<track rank="1">
<name>Track 1</name>
<playcount>1</playcount>
<listeners>2</listeners>
<mbid>fdfc47cb-69d3-4318-ba71-d54fbc20169a</mbid>
<url>https://www.last.fm/music/Artist+1/_/Track+1</url>
<streamable>0</streamable>
<artist>
<name>Artist 1</name>
<mbid>366c1119-ec4f-4312-b729-a5637d148e3e</mbid>
<url>https://www.last.fm/music/Artist+1</url>
</artist>
<image size="small">https://last.fm/track-1-small.png</image>
<image size="large">https://last.fm/track-1-large.png</image>
</track>
<track rank="2">
<name>Track 2</name>
<playcount>2</playcount>
<listeners>3</listeners>
<mbid>cf32e694-1ea6-4ba0-9e8b-d5f1950da9c8</mbid>
<url>https://www.last.fm/music/Artist+1/_/Track+2</url>
<streamable>0</streamable>
<artist>
<name>Artist 1</name>
<mbid>366c1119-ec4f-4312-b729-a5637d148e3e</mbid>
<url>https://www.last.fm/music/Artist+1</url>
</artist>
<image size="small">https://last.fm/track-2-small.png</image>
<image size="large">https://last.fm/track-2-large.png</image>
</track>
</toptracks>
</lfm>

View File

@@ -0,0 +1,7 @@
<lfm status="ok">
<session>
<name>username1</name>
<key>sessionKey1</key>
<subscriber>0</subscriber>
</session>
</lfm>

View File

@@ -0,0 +1,44 @@
package mockclient
import (
"context"
"crypto/tls"
_ "embed"
"net"
"net/http"
"net/http/httptest"
"testing"
)
func New(tb testing.TB, handler http.HandlerFunc) *http.Client {
tb.Helper()
server := httptest.NewTLSServer(handler)
tb.Cleanup(server.Close)
return &http.Client{
Transport: &http.Transport{
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
return net.Dial(network, server.Listener.Addr().String())
},
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true, //nolint:gosec
},
},
}
}
//go:embed artist_get_info_response.xml
var ArtistGetInfoResponse []byte
//go:embed artist_get_top_tracks_response.xml
var ArtistGetTopTracksResponse []byte
//go:embed artist_get_similar_response.xml
var ArtistGetSimilarResponse []byte
//go:embed track_get_similar_response.xml
var TrackGetSimilarResponse []byte
//go:embed get_session_response.xml
var GetSessionResponse []byte

View File

@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<lfm status="ok">
<similartracks artist="Artist 1" track="Track 1">
<track>
<name>Track 1</name>
<playcount>1</playcount>
<mbid>7096931c-bf82-4896-b1e7-42b60a0e16ea</mbid>
<match>1.000</match>
<url>https://www.last.fm/music/Artist+1/_/Track+1</url>
<streamable fulltrack="0">0</streamable>
<duration>80</duration>
<artist>
<name>Artist+1</name>
<mbid>366c1119-ec4f-4312-b729-a5637d148e3e</mbid>
<url>https://www.last.fm/music/Artist+1</url>
</artist>
<image size="small">https://last.fm/track-1-small.png</image>
<image size="large">https://last.fm/track-1-large.png</image>
</track>
<track>
<name>Track 2</name>
<playcount>2</playcount>
<mbid>2aff1321-149f-4000-8762-3468c917600c</mbid>
<match>0.422</match>
<url>https://www.last.fm/music/Artist+2/_/Track+2</url>
<streamable fulltrack="0">0</streamable>
<duration>80</duration>
<artist>
<name>Artist+2</name>
<mbid>9842b07f-956b-4c36-8ce1-884b4b96254d</mbid>
<url>https://www.last.fm/music/Artist+1</url>
</artist>
<image size="small">https://last.fm/track-2-small.png</image>
<image size="large">https://last.fm/track-2-large.png</image>
</track>
</similartracks>
</lfm>