lyrics

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2018 License: MIT Imports: 5 Imported by: 0

README

Lyric API written in Golang

GoDoc

This library provides an API to search for lyrics from various providers.

Supported Providers

  • Genius (Requires Setup)
  • MusixMatch (Default)
  • LyricsWikia (Default)
  • SongLyrics (Default)

Please refer to the test files, examples, and GoDoc for more details on using the providers.

Installing

using go get
go get github.com/rhnvrm/lyric-api-go

Usage Example

More examples can be found in the examples directory.

Basic Usage
package main

import (
    "fmt"

    "github.com/rhnvrm/lyric-api-go"
)

func main() {
    var (
        artist = "John Lennon"
        song   = "Imagine"
    )

    l := lyrics.New()
    lyric, err := l.Search(artist, song)

    if err != nil {
        fmt.Printf("Lyrics for %v-%v were not found", artist, song)
    }
    fmt.Println(lyric)
}
Using Only a Certain Provider
package main

import (
    "fmt"

    "github.com/rhnvrm/lyric-api-go"
)

func main() {
    var (
        artist = "John Lennon"
        song   = "Imagine"
    )

    l := lyrics.New(lyrics.WithoutProviders(), lyrics.WithGeniusLyrics("your_access_token_here"))
    // Use the following if you wish to just add Genius as a fallback
    // l := lyrics.New(lyrics.WithGeniusLyrics("your_access_token_here"))
    lyric, err := l.Search(artist, song)

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

Contributing

You are more than welcome to contribute to this project. Fork and make a Pull Request, or create an Issue if you see any problem or want to propose a feature.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lyric

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

Lyric API.

func New

func New(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 added in v0.1.1

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 added in v0.1.1

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