swaglyrics_go

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2021 License: MIT Imports: 13 Imported by: 4

README

swaglyrics-go

Look ma, I copied that code! Go lang rewrite of swaglyrics

From Swaglyrics/Swaglyrics-for-Spotify's README:

Fetches the currently playing song from Spotify on Windows, Linux and macOS and displays the lyrics in the command-line, browser tab or in a desktop application. Refreshes automatically when song changes. The lyrics are fetched from Genius. Turns out Deezer already has this feature in-built but with swaglyrics, you can have it in Spotify as well.

This rewrite doesn't do all that, but, you can get the lyrics for a song from your terminal: just do

sl --track 'bad guy' --artist 'Billie Eilish'

and you get the lyrics!

I'm mainly trying to build this project as far as I can, for practice and to learn and work with more technologies and platforms because I had to use it in a Go project, and didn't want to add python dependencies to it.

Initially developed copied this for personal use, and still is. Pretty much This is not functionality oriented, It Just Werkz™ -- I usually develop something that I can see helping me and other users in the same situation. Packaged so I can first hand handle production-ready code to an extent and to make distribution and usage easier. Used Go lang, because it makes package distribution very easy. Finally, I don't need to worry about a million pip packages, version conflicts, etc...

Installation

sudo wget https://github.com/srevinsaju/swaglyrics-go/releases/download/continuous/sl -O /usr/local/bin/sl
sudo chmod +x /usr/local/bin/sl
sl --help

Usage

usage: sl --track 'Foo' --artist 'Bar'

NAME:
   swaglyrics-go - Get the lyrics for a song

USAGE:
   sl [global options] command [command options] [arguments...]

COMMANDS:
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --track value   Song title
   --artist value  Song artist
   --help, -h      show help (default: false)

Before using, you should check USING.txt to comply with the Genius ToS. There's a copy included inside the package as well.

API

A simple broiler plate to use swaglyrics in your golang project:

package main

import (
	"fmt"
	"log"

	sl "github.com/srevinsaju/swaglyrics-go"
	"github.com/srevinsaju/swaglyrics-go/types"
)

func main() {
	lyrics, err := sl.GetLyrics(types.Song{Track: "Butter", Artist: "BTS"})
	if err != nil {
		log.Fatalln(err)
	}
	fmt.Println(lyrics)
}

Building

git clone https://github.com/srevinsaju/swaglyrics-go
cd swaglyrics-go/cmd/sl
go build .
./sl --help

References

License

Since swaglyrics-go is a port of swaglyrics from python, respect its license.

See LICENSE

Documentation

Index

Constants

View Source
const ApiTimeout = 20
View Source
const BackendUrl = "https://api.swaglyrics.dev"

Variables

View Source
var Aln = regexp.MustCompile(`[^ \-a-zA-Z0-9]+`) // matches non space or - or alphanumeric characters
View Source
var Brc = regexp.MustCompile(`([(\[](feat|ft|From|Feat|from "[^"]*")[^)\]]*[)\]]|- .*)`)
View Source
var FetchLyricsError = errors.New("couldn't fetch lyrics from genius")
View Source
var InvalidSongError = errors.New("invalid song")
View Source
var Nlt = regexp.MustCompile(`[^\x00-\x7F\x80-\xFF\p{Latin}]`) // match only latin characters,
View Source
var Spc = regexp.MustCompile(` *- *| +`) // matches one or more spaces
View Source
var Wth = regexp.MustCompile(` *\(with ([^)]+)\)`) // capture text after with

Functions

func GetLyrics

func GetLyrics(song types.Song) (string, error)

GetLyrics fetches a song from the genius api

func NormalizeArtist

func NormalizeArtist(artist string) string

func Stripper

func Stripper(song types.Song) string

Stripper Generate the url path given the song and artist to format the Genius URL with. Strips the song and artist of special characters and unresolved text such as 'feat.' or text within braces. Then concatenates both with hyphens replacing the blank spaces.

Types

This section is empty.

Directories

Path Synopsis
cmd
sl

Jump to

Keyboard shortcuts

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