models

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2024 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Copyright © 2023 Philipp Wolfer <phw@uploadedlobster.com>

This file is part of Scotty.

Scotty is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Scotty is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Scotty. If not, see <https://www.gnu.org/licenses/>.

Copyright © 2023 Philipp Wolfer <phw@uploadedlobster.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AdditionalInfo

type AdditionalInfo map[string]any

type Backend

type Backend interface {
	// Return the name of the interface
	Name() string

	// Initialize the backend from a config.
	FromConfig(config *config.ServiceConfig) Backend

	// Return configuration options
	Options() []BackendOption
}

A listen service backend. All listen services must implement this interface.

type BackendOption added in v0.3.0

type BackendOption struct {
	Name     string
	Label    string
	Type     OptionType
	Default  string
	Validate func(string) error
}

type Entity added in v0.4.0

type Entity string
const (
	Listens Entity = "listens"
	Loves   Entity = "loves"
)

type ExportResult added in v0.3.0

type ExportResult[T LovesList | ListensList] struct {
	Items           T
	Total           int
	OldestTimestamp time.Time
	Error           error
}

type ImportBackend

type ImportBackend interface {
	Backend

	// If the backend needs to setup resources before starting to import,
	// this can be done here.
	StartImport() error

	// The implementation can perform all steps here to finalize the
	// export/import and free used resources.
	FinishImport() error
}

type ImportResult

type ImportResult struct {
	TotalCount    int
	ImportCount   int
	LastTimestamp time.Time
	ImportLog     []LogEntry

	// Error is only set if an unrecoverable import error occurred
	Error error
}

func (*ImportResult) Log added in v0.4.0

func (i *ImportResult) Log(t LogEntryType, msg string)

func (*ImportResult) Update

func (i *ImportResult) Update(from ImportResult)

func (*ImportResult) UpdateTimestamp

func (i *ImportResult) UpdateTimestamp(newTime time.Time)

Sets LastTimestamp to newTime, if newTime is newer than LastTimestamp

type Listen

type Listen struct {
	Track
	ListenedAt       time.Time
	PlaybackDuration time.Duration
	UserName         string
}

type ListensExport

type ListensExport interface {
	Backend

	// Returns a list of all listens newer then oldestTimestamp.
	// The returned list of listens is supposed to be ordered by the
	// Listen.ListenedAt timestamp, with the oldest entry first.
	ExportListens(oldestTimestamp time.Time, results chan ListensResult, progress chan Progress)
}

Must be implemented by services supporting the export of listens.

type ListensImport

type ListensImport interface {
	ImportBackend

	// Imports the given list of listens.
	ImportListens(export ListensResult, importResult ImportResult, progress chan Progress) (ImportResult, error)
}

Must be implemented by services supporting the import of listens.

type ListensList

type ListensList []Listen

func (ListensList) Len

func (l ListensList) Len() int

func (ListensList) Less

func (l ListensList) Less(i, j int) bool

func (ListensList) NewerThan

func (l ListensList) NewerThan(t time.Time) ListensList

Returns a new ListensList with only elements that are newer than t.

func (ListensList) Swap

func (l ListensList) Swap(i, j int)

type ListensResult

type ListensResult ExportResult[ListensList]

type LogEntry added in v0.4.0

type LogEntry struct {
	Type    LogEntryType
	Message string
}

type LogEntryType added in v0.4.0

type LogEntryType string
const (
	Info    LogEntryType = "Info"
	Warning LogEntryType = "Warning"
	Error   LogEntryType = "Error"
)

type Love

type Love struct {
	Track
	Created       time.Time
	UserName      string
	RecordingMbid MBID
	RecordingMsid MBID
}

type LovesExport

type LovesExport interface {
	Backend

	// Returns a list of all loves newer then oldestTimestamp.
	// The returned list of listens is supposed to be ordered by the
	// Love.Created timestamp, with the oldest entry first.
	ExportLoves(oldestTimestamp time.Time, results chan LovesResult, progress chan Progress)
}

Must be implemented by services supporting the export of loves.

type LovesImport

type LovesImport interface {
	ImportBackend

	// Imports the given list of loves.
	ImportLoves(export LovesResult, importResult ImportResult, progress chan Progress) (ImportResult, error)
}

Must be implemented by services supporting the import of loves.

type LovesList

type LovesList []Love

func (LovesList) Len

func (l LovesList) Len() int

func (LovesList) Less

func (l LovesList) Less(i, j int) bool

func (LovesList) Swap

func (l LovesList) Swap(i, j int)

type LovesResult

type LovesResult ExportResult[LovesList]

type MBID

type MBID string

type OptionType added in v0.3.0

type OptionType string
const (
	Bool   OptionType = "bool"
	Secret OptionType = "secret"
	String OptionType = "string"
	Int    OptionType = "int"
)

type Progress

type Progress struct {
	Total     int64
	Elapsed   int64
	Completed bool
}

func (Progress) Complete

func (p Progress) Complete() Progress

func (Progress) FromImportResult

func (p Progress) FromImportResult(result ImportResult) Progress

type Track

type Track struct {
	TrackName        string
	ReleaseName      string
	ArtistNames      []string
	TrackNumber      int
	DiscNumber       int
	Duration         time.Duration
	ISRC             string
	RecordingMbid    MBID
	ReleaseMbid      MBID
	ReleaseGroupMbid MBID
	ArtistMbids      []MBID
	WorkMbids        []MBID
	Tags             []string
	AdditionalInfo   AdditionalInfo
}

func (Track) ArtistName

func (t Track) ArtistName() string

func (*Track) FillAdditionalInfo

func (t *Track) FillAdditionalInfo()

Updates AdditionalInfo to have standard fields as defined by ListenBrainz

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL