rattlehead

package module
v0.0.0-...-28f0487 Latest Latest
Warning

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

Go to latest
Published: May 22, 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 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 BandCamp

type BandCamp string

func (BandCamp) String

func (b BandCamp) String() string

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 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 MusicBrainz

type MusicBrainz struct {
	Search
}

func (MusicBrainz) Load

func (m MusicBrainz) Load(saveFn StorageSaveFn) error

func (MusicBrainz) String

func (m MusicBrainz) String() string

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 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 Spotify

type Spotify string

func (Spotify) String

func (s Spotify) String() string

type StorageSaveFn

type StorageSaveFn func(rel ...release) error

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