mirror of
https://git.sr.ht/~phw/scotty
synced 2025-06-30 23:41:54 +02:00
Introduced Backend.Close method
This allows Backend implementations to free used resources. Currently used for musicbrainzws2.Client
This commit is contained in:
parent
c1a480a1a6
commit
499786cab9
14 changed files with 45 additions and 8 deletions
|
@ -38,6 +38,8 @@ type DeezerApiBackend struct {
|
|||
|
||||
func (b *DeezerApiBackend) Name() string { return "deezer" }
|
||||
|
||||
func (b *DeezerApiBackend) Close() {}
|
||||
|
||||
func (b *DeezerApiBackend) Options() []models.BackendOption {
|
||||
return []models.BackendOption{{
|
||||
Name: "client-id",
|
||||
|
|
|
@ -43,6 +43,8 @@ type DeezerHistoryBackend struct {
|
|||
|
||||
func (b *DeezerHistoryBackend) Name() string { return "deezer-history" }
|
||||
|
||||
func (b *DeezerHistoryBackend) Close() {}
|
||||
|
||||
func (b *DeezerHistoryBackend) Options() []models.BackendOption {
|
||||
return []models.BackendOption{{
|
||||
Name: "file-path",
|
||||
|
|
|
@ -36,6 +36,8 @@ type DumpBackend struct {
|
|||
|
||||
func (b *DumpBackend) Name() string { return "dump" }
|
||||
|
||||
func (b *DumpBackend) Close() {}
|
||||
|
||||
func (b *DumpBackend) Options() []models.BackendOption {
|
||||
return []models.BackendOption{{
|
||||
Name: "file-path",
|
||||
|
|
|
@ -36,6 +36,8 @@ type FunkwhaleApiBackend struct {
|
|||
|
||||
func (b *FunkwhaleApiBackend) Name() string { return "funkwhale" }
|
||||
|
||||
func (b *FunkwhaleApiBackend) Close() {}
|
||||
|
||||
func (b *FunkwhaleApiBackend) Options() []models.BackendOption {
|
||||
return []models.BackendOption{{
|
||||
Name: "server-url",
|
||||
|
|
|
@ -46,6 +46,8 @@ type JSPFBackend struct {
|
|||
|
||||
func (b *JSPFBackend) Name() string { return "jspf" }
|
||||
|
||||
func (b *JSPFBackend) Close() {}
|
||||
|
||||
func (b *JSPFBackend) Options() []models.BackendOption {
|
||||
return []models.BackendOption{{
|
||||
Name: "file-path",
|
||||
|
|
|
@ -46,6 +46,8 @@ type LastfmApiBackend struct {
|
|||
|
||||
func (b *LastfmApiBackend) Name() string { return "lastfm" }
|
||||
|
||||
func (b *LastfmApiBackend) Close() {}
|
||||
|
||||
func (b *LastfmApiBackend) Options() []models.BackendOption {
|
||||
return []models.BackendOption{{
|
||||
Name: "username",
|
||||
|
|
|
@ -42,11 +42,17 @@ const (
|
|||
type ListenBrainzArchiveBackend struct {
|
||||
filePath string
|
||||
lbClient listenbrainz.Client
|
||||
mbClient musicbrainzws2.Client
|
||||
mbClient *musicbrainzws2.Client
|
||||
}
|
||||
|
||||
func (b *ListenBrainzArchiveBackend) Name() string { return "listenbrainz-archive" }
|
||||
|
||||
func (b *ListenBrainzArchiveBackend) Close() {
|
||||
if b.mbClient != nil {
|
||||
b.mbClient.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func (b *ListenBrainzArchiveBackend) Options() []models.BackendOption {
|
||||
return []models.BackendOption{{
|
||||
Name: "archive-path",
|
||||
|
@ -58,7 +64,7 @@ func (b *ListenBrainzArchiveBackend) Options() []models.BackendOption {
|
|||
func (b *ListenBrainzArchiveBackend) InitConfig(config *config.ServiceConfig) error {
|
||||
b.filePath = config.GetString("archive-path")
|
||||
b.lbClient = listenbrainz.NewClient("", version.UserAgent())
|
||||
b.mbClient = *musicbrainzws2.NewClient(musicbrainzws2.AppInfo{
|
||||
b.mbClient = musicbrainzws2.NewClient(musicbrainzws2.AppInfo{
|
||||
Name: version.AppName,
|
||||
Version: version.AppVersion,
|
||||
URL: version.AppURL,
|
||||
|
@ -191,7 +197,7 @@ func (b *ListenBrainzArchiveBackend) ExportLoves(
|
|||
if len(batch) >= lovesBatchSize {
|
||||
// The dump does not contain track metadata. Extend it with additional
|
||||
// lookups
|
||||
loves, err := lbapi.ExtendTrackMetadata(ctx, &b.lbClient, &b.mbClient, &batch)
|
||||
loves, err := lbapi.ExtendTrackMetadata(ctx, &b.lbClient, b.mbClient, &batch)
|
||||
if err != nil {
|
||||
p.Export.Abort()
|
||||
progress <- p
|
||||
|
@ -205,7 +211,7 @@ func (b *ListenBrainzArchiveBackend) ExportLoves(
|
|||
}
|
||||
}
|
||||
|
||||
loves, err := lbapi.ExtendTrackMetadata(ctx, &b.lbClient, &b.mbClient, &batch)
|
||||
loves, err := lbapi.ExtendTrackMetadata(ctx, &b.lbClient, b.mbClient, &batch)
|
||||
if err != nil {
|
||||
p.Export.Abort()
|
||||
progress <- p
|
||||
|
|
|
@ -36,12 +36,18 @@ const lovesBatchSize = listenbrainz.MaxItemsPerGet
|
|||
|
||||
type ListenBrainzApiBackend struct {
|
||||
client listenbrainz.Client
|
||||
mbClient musicbrainzws2.Client
|
||||
mbClient *musicbrainzws2.Client
|
||||
username string
|
||||
checkDuplicates bool
|
||||
existingMBIDs map[mbtypes.MBID]bool
|
||||
}
|
||||
|
||||
func (b *ListenBrainzApiBackend) Close() {
|
||||
if b.mbClient != nil {
|
||||
b.mbClient.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func (b *ListenBrainzApiBackend) Name() string { return "listenbrainz" }
|
||||
|
||||
func (b *ListenBrainzApiBackend) Options() []models.BackendOption {
|
||||
|
@ -62,7 +68,7 @@ func (b *ListenBrainzApiBackend) Options() []models.BackendOption {
|
|||
|
||||
func (b *ListenBrainzApiBackend) InitConfig(config *config.ServiceConfig) error {
|
||||
b.client = listenbrainz.NewClient(config.GetString("token"), version.UserAgent())
|
||||
b.mbClient = *musicbrainzws2.NewClient(musicbrainzws2.AppInfo{
|
||||
b.mbClient = musicbrainzws2.NewClient(musicbrainzws2.AppInfo{
|
||||
Name: version.AppName,
|
||||
Version: version.AppVersion,
|
||||
URL: version.AppURL,
|
||||
|
@ -261,7 +267,7 @@ out:
|
|||
// Missing track metadata indicates that the recording MBID is no
|
||||
// longer available and might have been merged. Try fetching details
|
||||
// from MusicBrainz.
|
||||
lovesBatch, err := ExtendTrackMetadata(ctx, &b.client, &b.mbClient, &batch)
|
||||
lovesBatch, err := ExtendTrackMetadata(ctx, &b.client, b.mbClient, &batch)
|
||||
if err != nil {
|
||||
results <- models.LovesResult{Error: err}
|
||||
return
|
||||
|
@ -276,7 +282,7 @@ out:
|
|||
offset += listenbrainz.MaxItemsPerGet
|
||||
}
|
||||
|
||||
lovesBatch, err := ExtendTrackMetadata(ctx, &b.client, &b.mbClient, &batch)
|
||||
lovesBatch, err := ExtendTrackMetadata(ctx, &b.client, b.mbClient, &batch)
|
||||
if err != nil {
|
||||
results <- models.LovesResult{Error: err}
|
||||
return
|
||||
|
|
|
@ -35,6 +35,8 @@ type MalojaApiBackend struct {
|
|||
|
||||
func (b *MalojaApiBackend) Name() string { return "maloja" }
|
||||
|
||||
func (b *MalojaApiBackend) Close() {}
|
||||
|
||||
func (b *MalojaApiBackend) Options() []models.BackendOption {
|
||||
return []models.BackendOption{{
|
||||
Name: "server-url",
|
||||
|
|
|
@ -41,6 +41,8 @@ type ScrobblerLogBackend struct {
|
|||
|
||||
func (b *ScrobblerLogBackend) Name() string { return "scrobbler-log" }
|
||||
|
||||
func (b *ScrobblerLogBackend) Close() {}
|
||||
|
||||
func (b *ScrobblerLogBackend) Options() []models.BackendOption {
|
||||
return []models.BackendOption{{
|
||||
Name: "file-path",
|
||||
|
|
|
@ -41,6 +41,8 @@ type SpotifyApiBackend struct {
|
|||
|
||||
func (b *SpotifyApiBackend) Name() string { return "spotify" }
|
||||
|
||||
func (b *SpotifyApiBackend) Close() {}
|
||||
|
||||
func (b *SpotifyApiBackend) Options() []models.BackendOption {
|
||||
return []models.BackendOption{{
|
||||
Name: "client-id",
|
||||
|
|
|
@ -36,6 +36,8 @@ type SpotifyHistoryBackend struct {
|
|||
|
||||
func (b *SpotifyHistoryBackend) Name() string { return "spotify-history" }
|
||||
|
||||
func (b *SpotifyHistoryBackend) Close() {}
|
||||
|
||||
func (b *SpotifyHistoryBackend) Options() []models.BackendOption {
|
||||
return []models.BackendOption{{
|
||||
Name: "archive-path",
|
||||
|
|
|
@ -37,6 +37,8 @@ type SubsonicApiBackend struct {
|
|||
|
||||
func (b *SubsonicApiBackend) Name() string { return "subsonic" }
|
||||
|
||||
func (b *SubsonicApiBackend) Close() {}
|
||||
|
||||
func (b *SubsonicApiBackend) Options() []models.BackendOption {
|
||||
return []models.BackendOption{{
|
||||
Name: "server-url",
|
||||
|
|
|
@ -35,6 +35,9 @@ type Backend interface {
|
|||
|
||||
// Return configuration options
|
||||
Options() []BackendOption
|
||||
|
||||
// Free all resources of the backend
|
||||
Close()
|
||||
}
|
||||
|
||||
type ImportBackend interface {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue