lyrics

package module
v0.1.44 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2022 License: MIT Imports: 7 Imported by: 0

README

lyrics-api-go-extended

This is a fork of known lyrics-api-go providing extended functionality.

Status

Work in progress...

Table of contents

  • Why
  • Extended Functionality
  • Examples

Why

Due to lack of response for issue, I forked repo to extend it for my needs

Extended functionality

  • Pass your own http.Client (example case: proxy, change timeout, ...)
  • Custom parse rules (e.g. line by line returned as a list of strings, split by regex, split by dot, ...)
  • Custom http header (=> custom UserAgent, Proxy auth, ...)
  • If possible, more providers

Examples

import (
	"fmt"
	
	"github.com/hashicorp/go-retryablehttp"
	"git.itmodulo.eu/Forks/lyrics-api-go-extended"
)

// Create http.Client using lib or by yourself, here you can specify proxy settings
myClient := retryablehttp.NewClient().StandardClient() // External

// Set UserAgent
lyrics.DefaultHeaderUserAgent() // Default
lyrics.AddToheaderMap("User-Agent", "Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:94.0) Gecko/20100101 Firefox/94.0") // or custom

// Set other Header Settings if needed (e.g. proxy auth goes here)
// ...

// Create lyrics object
l := lyrics.New(*myClient) // To use all providers

// Using Only a Certain Provider (here Genius)
l :=  lyrics.New(*myClient, lyrics.WithoutProviders(), lyrics.WithGeniusLyrics("your_access_token_here"))

// Specify artist and songTitle
artist := "..."
songTitle := "..."

// Actual search
lyric, err := l.Search(artist, songTitle)

if err != nil {
    fmt.Printf("%v: Lyrics for %v-%v were not found", err, artist, songTitle)
}

//Print in console
fmt.Println(lyric)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddToheaderMap

func AddToheaderMap(k string, v string)

func DefaultHeaderUserAgent

func DefaultHeaderUserAgent()

func RmHeaderMap

func RmHeaderMap(k string)

Types

type Lyric

type Lyric struct {
	// contains filtered or unexported fields
}

Lyric API.

func New

func New(client http.Client, o ...Option) Lyric

New creates a new Lyric API, which can be used to Search for Lyrics using various providers. The default behaviour is to use all providers available, although it can be explicitly set to the same using, eg.

lyrics.New(WithAllProviders())

In case your usecase requires using only specific providers, you can provide New() with WithoutProviders() followed by the specific WithXXXXProvider() as an optional parameter.

Note: The providers are processed one by one so custom providers, can also be used to set the priority for your usecase.

Eg. to attempt only with Lyrics Wikia:

lyrics.New(WithoutProviders(), WithLyricsWikia())

Eg. to attempt with both Lyrics Wikia and Song Lyrics:

lyrics.New(WithoutProviders(), WithLyricsWikia(), WithSongLyrics())

func (*Lyric) Search

func (l *Lyric) Search(artist, song string) (string, error)

Search attempts to search for lyrics using artist and song by trying various lyrics providers one by one.

type Option

type Option func(Lyric) Lyric

Option type describes Option Configuration Decorator return type.

func WithAllProviders

func WithAllProviders() Option

WithAllProviders is an Option Configuration Decorator that sets Lyric to attempt fetching lyrics using all providers that do not require setup.

func WithGeniusLyrics

func WithGeniusLyrics(accessToken string) Option

WithGeniusLyrics is an Option Configuration Decorator that adds Genius Provider to the list of providers to attempt fetching lyrics from. It requires an additional access token which can be obtained using the developer portal (https://genius.com/developers)

func WithLyricsWikia

func WithLyricsWikia() Option

WithLyricsWikia is an Option Configuration Decorator that adds Lyrics Wikia Provider to the list of providers to attempt fetching lyrics from.

func WithMusixMatch

func WithMusixMatch() Option

WithMusixMatch is an Option Configuration Decorator that adds Musixmatch Provider to the list of providers to attempt fetching lyrics from.

func WithSongLyrics

func WithSongLyrics() Option

WithSongLyrics is an Option Configuration Decorator that adds Song Lyrics Provider to the list of providers to attempt fetching lyrics from.

func WithoutProviders

func WithoutProviders() Option

WithoutProviders is an Option Configuration Decorator that removes all providers from the list of providers to attempt fetching lyrics from. It can be used to remove the default providers and set a custom provider list.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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