rattlehead

package module
v0.0.0-...-5749874 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2024 License: MIT Imports: 41 Imported by: 1

README

Rattlehead

Rattlehead is an application that can publish information about new metal releases to Mastodon.

It aggregates data from the available information found on Wikipedia, MusicBrainz and the MetalArchives.

Documentation

Index

Constants

View Source
const (
	ResolutionDay      = 24 * time.Hour
	ResolutionWeek     = 7 * ResolutionDay
	ResolutionMonthish = 31 * ResolutionDay
	ResolutionYearish  = 365 * ResolutionDay
)
View Source
const (
	TypeMastodon = "mastodon"
	TypeFedBOX   = "fedbox"
	TypeONI      = "oni"
)
View Source
const ExecOpenCmd = "xdg-open"
View Source
const SourceMetalArchives = "metal-archives"
View Source
const SourceMusicBrainz = "musicbrainz"
View Source
const SourceWikipedia = "wikipedia"

Variables

View Source
var (
	Info  logFn = emptyLogFn
	Error logFn = emptyLogFn

	AppVersion = "HEAD"
	AppName    = "rattlehead"
	AppWebsite = "https://git.sr.ht/~mariusor/rattlehead"
	// NOTE(marius): instead of using separate values for each scope value,
	// we mash them together, because the API client doesn't encode them properly
	AppScopes = []string{"read+write+follow"}

	DefaultInstance = "metalhead.club"
)
View Source
var AccountDetails embed.FS
View Source
var Sources = []string{
	"https://en.wikipedia.org/wiki/2022_in_heavy_metal_music",
	"https://www.metal-archives.com/release/upcoming",
	"https://time-for-metal.eu/metal-releases-kalender/",
	"https://www.metalunderground.com/upcoming_metal_releases/",
}
View Source
var (
	UserAgent = fmt.Sprintf("%s/%s (%s)", AppName, AppVersion, AppWebsite)
)

Functions

func CachePath

func CachePath() string

func CheckMastodonCredentialsFile

func CheckMastodonCredentialsFile(key, secret, token, instance string, dryRun bool, getAccessTokenFn func() (string, error)) (*madon.Client, error)

func DataPath

func DataPath() string

func FormatDuration

func FormatDuration(d time.Duration) string

func GetHTTPClient

func GetHTTPClient() *http.Client

func InstanceName

func InstanceName(inst string) string

func Levenshtein

func Levenshtein(s1, s2 []rune) int

Levenshtein This implementation translated from the optimized C code at https://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Levenshtein_distance#C Original at https://github.com/dgryski/trifles/blob/master/leven/leven.go

func LoadCredentials

func LoadCredentials() (map[string]any, error)
func LoadLinks(c LoadLinksConfig) error

func LoadLinksWithBandCamp

func LoadLinksWithBandCamp(rel map[int]release) (map[int]release, error)

func LoadLinksWithDDG

func LoadLinksWithDDG(rel map[int]release, useCache bool) (map[int]release, error)

func LoadReleases

func LoadReleases(loadFn func() (map[int]release, error)) (map[time.Time][]release, error)

func LoadSources

func LoadSources(c FetchConfig) error

func MkDirIfNotExists

func MkDirIfNotExists(p string) error

func NewStorage

func NewStorage(dir string, logFn, errFn logFn) *repo

NewStorage returns a new repository

func Post

func Post(c PostConfig) error

func PostToStdout

func PostToStdout(groupped map[time.Time][]release) error

func UpdateAPAccount

func UpdateAPAccount(app *APClient, dryRun bool) error

func UpdateMastodonAccount

func UpdateMastodonAccount(app *madon.Client, dryRun bool) error

func ValidMastodonApp

func ValidMastodonApp(c *madon.Client) bool

func ValidMastodonAuth

func ValidMastodonAuth(c *madon.Client) bool

Types

type APClient

type APClient struct {
	ID   vocab.IRI
	Type string
	Conf oauth2.Config
	Tok  *oauth2.Token
}

func CheckFedBOXCredentialsFile

func CheckFedBOXCredentialsFile(instance, key, secret, token string, dryRun bool) (*APClient, error)

func CheckONICredentialsFile

func CheckONICredentialsFile(instance string, cl *http.Client, secret, token string, dryRun bool) (*APClient, error)

type AdditionalProperty

type AdditionalProperty struct {
	Type  string `json:"@type"`
	Name  string `json:"name"`
	Value any    `json:"value"`
}

type Author

type Author struct {
	Type               string               `json:"-" jsonld:"@type"`
	URL                string               `json:"url"`
	Image              string               `json:"image"`
	Name               string               `json:"name"`
	AdditionalProperty []AdditionalProperty `json:"additionalProperty,omitempty"`
}

type BandCamp

type BandCamp struct {
	URL    string
	Album  string
	Artist string
	ItemId int
}

func (BandCamp) String

func (b BandCamp) String() string

type ByArtist

type ByArtist struct {
	ID   string `json:"@id"`
	Type string `json:"-" jsonld:"@type"`
	Name string `json:"name"`
}

type Comment

type Comment struct {
	Type   string   `json:"-" jsonld:"@type"`
	Author Author   `json:"author"`
	Text   []string `json:"text"`
}

type DuckDuckGo

type DuckDuckGo string

func DDGSearch

func DDGSearch(rel release) DuckDuckGo

type FetchConfig

type FetchConfig struct {
	DryRun     bool
	NoCache    bool
	Sources    []SourceFn
	Dates      []time.Time
	Resolution time.Duration
}

type FoundingLocation

type FoundingLocation struct {
	Type string `json:"-" jsonld:"@type"`
	Name string `json:"name"`
}

type Item

type Item struct {
	ID                 string               `json:"@id"`
	Type               string               `json:"-" jsonld:"@type"`
	Name               string               `json:"name"`
	Duration           string               `json:"duration"`
	CopyrightNotice    string               `json:"copyrightNotice"`
	MainEntityOfPage   string               `json:"mainEntityOfPage"`
	AdditionalProperty []AdditionalProperty `json:"additionalProperty,omitempty"`
}

type ItemElement

type ItemElement struct {
	Type     string `json:"-" jsonld:"@type"`
	Position int    `json:"position"`
	Item     Item   `json:"item"`
}

type LoadLinksConfig

type LoadLinksConfig struct {
	DryRun     bool
	NoCache    bool
	Sources    []string
	Date       time.Time
	Resolution time.Duration
}

type MetalArchives

type MetalArchives struct {
	Start    time.Time     `json:"start"`
	Duration time.Duration `json:"duration"`
}

func (MetalArchives) Load

func (m MetalArchives) Load(saveFn StorageSaveFn) error

func (MetalArchives) String

func (m MetalArchives) String() string

type MusicAlbum

type MusicAlbum struct {
	ID                 string               `json:"@id"`
	Context            string               `json:"@context"`
	Type               string               `json:"-" jsonld:"@type"`
	AlbumReleaseType   string               `json:"albumReleaseType"`
	MainEntityOfPage   string               `json:"mainEntityOfPage"`
	Name               string               `json:"name"`
	DateModified       string               `json:"dateModified"`
	AlbumRelease       []MusicRelease       `json:"albumRelease"`
	ByArtist           ByArtist             `json:"byArtist"`
	Publisher          Publisher            `json:"publisher"`
	NumTracks          int                  `json:"numTracks"`
	Track              TrackInfo            `json:"track"`
	Image              string               `json:"image"`
	Keywords           []string             `json:"keywords"`
	DatePublished      string               `json:"datePublished"`
	CopyrightNotice    string               `json:"copyrightNotice"`
	Comment            []Comment            `json:"comment"`
	Sponsor            []Sponsor            `json:"sponsor"`
	AdditionalProperty []AdditionalProperty `json:"additionalProperty,omitempty"`
}

type MusicBrainz

type MusicBrainz struct {
	Search
}

func (MusicBrainz) Load

func (m MusicBrainz) Load(saveFn StorageSaveFn) error

func (MusicBrainz) String

func (m MusicBrainz) String() string

type MusicRelease

type MusicRelease struct {
	Type               string               `json:"-" jsonld:"@type"`
	ID                 string               `json:"@id"`
	Name               string               `json:"name,omitempty"`
	AdditionalProperty []AdditionalProperty `json:"additionalProperty,omitempty"`
	Description        string               `json:"description,omitempty"`
	Identifier         string               `json:"identifier,omitempty"`
	Offers             Offers               `json:"offers,omitempty"`
	MusicReleaseFormat string               `json:"musicReleaseFormat,omitempty"`
	Image              []string             `json:"image,omitempty"`
	RecordLabel        RecordLabel          `json:"recordLabel,omitempty"`
}

type Offers

type Offers struct {
	Type               string    `json:"-" jsonld:"@type"`
	URL                string    `json:"url"`
	PriceCurrency      string    `json:"priceCurrency"`
	Price              float64   `json:"price"`
	PriceSpecification PriceSpec `json:"priceSpecification"`
	Availability       string    `json:"availability"`
}

type PostConfig

type PostConfig struct {
	DryRun     bool
	Date       time.Time
	Resolution time.Duration
	PostFns    []PosterFn
}

type PosterFn

type PosterFn func(releases map[time.Time][]release) error

func PostToActivityPub

func PostToActivityPub(cl *APClient) PosterFn

func PostToMastodon

func PostToMastodon(client *madon.Client, withLinks bool) PosterFn

type PriceSpec

type PriceSpec struct {
	MinPrice float64 `json:"minPrice"`
}

type Publisher

type Publisher struct {
	ID                 string               `json:"@id"`
	Type               string               `json:"-" jsonld:"@type"`
	Name               string               `json:"name"`
	Image              string               `json:"image"`
	Genre              string               `json:"genre"`
	SubjectOf          []SubjectOf          `json:"subjectOf"`
	FoundingLocation   FoundingLocation     `json:"foundingLocation"`
	AdditionalProperty []AdditionalProperty `json:"additionalProperty,omitempty"`
}

type RecordLabel

type RecordLabel struct {
	ID                 string               `json:"@id"`
	Type               string               `json:"-" jsonld:"@type"`
	Name               string               `json:"name"`
	AdditionalProperty []AdditionalProperty `json:"additionalProperty,omitempty"`
}
type Search struct {
	Tags       []string      `json:"tags"`
	Type       []string      `json:"type"`
	Date       time.Time     `json:"date"`
	Resolution time.Duration `json:"resolution"`
}

type SoundCloud

type SoundCloud string

func (SoundCloud) String

func (s SoundCloud) String() string

type Source

type Source interface {
	Load(StorageSaveFn) error
}

func MetalArchivesRelease

func MetalArchivesRelease(date time.Time, resolution time.Duration) Source

func MusicBrainzRelease

func MusicBrainzRelease(date time.Time, resolution time.Duration) Source

func WikiRelease

func WikiRelease(year time.Time, resolution time.Duration) Source

type SourceFn

type SourceFn func(date time.Time, resolution time.Duration) Source
type Sponsor struct {
	Type               string               `json:"-" jsonld:"@type"`
	URL                string               `json:"url"`
	Image              string               `json:"image"`
	Name               string               `json:"name"`
	AdditionalProperty []AdditionalProperty `json:"additionalProperty,omitempty"`
}

type Spotify

type Spotify string

func (Spotify) String

func (s Spotify) String() string

type StorageSaveFn

type StorageSaveFn func(rel ...release) error

type SubjectOf

type SubjectOf struct {
	Type               string               `json:"-" jsonld:"@type"`
	URL                string               `json:"url"`
	Name               string               `json:"name"`
	AdditionalProperty []AdditionalProperty `json:"additionalProperty,omitempty"`
}

type TrackInfo

type TrackInfo struct {
	Type            string        `json:"-" jsonld:"@type"`
	NumberOfItems   int           `json:"numberOfItems"`
	ItemListElement []ItemElement `json:"itemListElement"`
}

type Wikipedia

type Wikipedia string

func (Wikipedia) Load

func (w Wikipedia) Load(saveFn StorageSaveFn) error

func (Wikipedia) String

func (w Wikipedia) String() string

type Youtube

type Youtube string

func (Youtube) String

func (y Youtube) String() string

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳