genius

package module
v0.0.0-...-78673da Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: MIT Imports: 13 Imported by: 0

README

genius-api

GoDoc

Golang bindings for Genius API.

To get token visit https://genius.com/developers

Usage

import (
	"fmt"
	"github.com/broxgit/genius"
)

func main() {
	accessToken := "token"
	client := genius.NewClient(nil, accessToken)

	response, err := client.GetArtistHTML(16775)
	if err != nil {
		panic(err)
	}

	fmt.Println(response.Response.Artist)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Album

type Album struct {
	APIPath              string `json:"api_path"`
	CommentCount         int    `json:"comment_count"`
	CoverArtURL          string `json:"cover_art_url"`
	CustomHeaderImageURL string `json:"custom_header_image_url"`
	FullTitle            string `json:"full_title"`
	HeaderImageURL       string `json:"header_image_url"`
	ID                   int    `json:"id"`
	LockState            string `json:"lock_state"`
	Name                 string `json:"name"`
	PyongsCount          int    `json:"pyongs_count"`
	ReleaseDate          string `json:"release_date"`
	//ReleaseDateComponents DateComponents     `json:"release_date_components"`
	ReleaseDateForDisplay string              `json:"release_date_for_display"`
	URL                   string              `json:"url"`
	CurrentUserMetadata   *UserMetadata       `json:"current_user_metadata"`
	SongPageviews         int                 `json:"song_pageviews"`
	Artist                *Artist             `json:"artist"`
	CoverArts             []*CoverArt         `json:"cover_arts"`
	DescriptionAnnotation *Annotation         `json:"description_annotation"`
	PerformanceGroups     []*PerformanceGroup `json:"performance_groups"`
	SongPerformances      []*Performance      `json:"song_performances"`
	Tracks                []*AlbumTrack       `json:"tracks"`
}

type AlbumTrack

type AlbumTrack struct {
	Number int  `json:"number"`
	Song   Song `json:"song"`
}

type Annotatable

type Annotatable struct {
	APIPath   string `json:"api_path"`
	Context   string `json:"context"`
	ID        int    `json:"id"`
	ImageURL  string `json:"image_url"`
	LinkTitle string `json:"link_title"`
	Title     string `json:"title"`
	Type      string `json:"type"`
	URL       string `json:"url"`

	ClientTimestamps struct {
		UpdatedByHumanAt int `json:"updated_by_human_at"`
		LyricsUpdatedAt  int `json:"lyrics_updated_at"`
	} `json:"client_timestamps"`
}

type Annotation

type Annotation struct {
	WithBody
	APIPath             string        `json:"api_path"`
	CommentCount        int           `json:"comment_count"`
	Community           bool          `json:"community"`
	CustomPreview       string        `json:"custom_preview"`
	HasVoters           bool          `json:"has_voters"`
	ID                  int           `json:"id"`
	Pinned              bool          `json:"pinned"`
	ShareURL            string        `json:"share_url"`
	Source              string        `json:"source"`
	State               string        `json:"state"`
	URL                 string        `json:"url"`
	Verified            bool          `json:"verified"`
	VotesTotal          int           `json:"voters_total"`
	CurrentUserMetadata *UserMetadata `json:"current_user_metadata"`
	Authors             []*Author     `json:"authors"`
	CosignedBy          []*Artist     `json:"cosigned_by"`
	VerifiedBy          *User         `json:"verified_by"`
}

Annotation is annotation on Genius API.

type Artist

type Artist struct {
	AlternateNames        []string               `json:"alternate_names"`
	APIPath               string                 `json:"api_path"`
	Description           *interface{}           `json:"description"`
	FacebookName          string                 `json:"facebook_name"`
	FollowersCount        int                    `json:"followers_count"`
	HeaderImageURL        string                 `json:"header_image_url"`
	ID                    int                    `json:"id"`
	ImageURL              string                 `json:"image_url"`
	InstagramName         string                 `json:"instagram_name"`
	IsMemeVerified        bool                   `json:"is_meme_verified"`
	IsVerified            bool                   `json:"is_verified"`
	Name                  string                 `json:"name"`
	TwitterName           string                 `json:"twitter_name"`
	URL                   string                 `json:"url"`
	CurrentUserMetadata   *UserMetadata          `json:"current_user_metadata"`
	IQ                    int                    `json:"iq"`
	DescriptionAnnotation *DescriptionAnnotation `json:"description_annotation"`
	User                  *User                  `json:"user"`
}

Artist is artist on Genius API.

type Author

type Author struct {
	Attribution float64 `json:"attribution"`
	PinnedRole  string  `json:"pinned_role"`
	User        *User   `json:"user"`
}

type Avatar

type Avatar struct {
	Tiny   *Image `json:"tiny"`
	Thumb  *Image `json:"thumb"`
	Small  *Image `json:"small"`
	Medium *Image `json:"medium"`
}

type Client

type Client struct {
	AccessToken string
	// contains filtered or unexported fields
}

Client is a client for Genius API.

func NewClient

func NewClient(httpClient *http.Client, token string, opts ...ClientOption) *Client

NewClient creates Client to work with Genius API You can pass http.Client or it will use http.DefaultClient by default

It requires a token for accessing Genius API.

func (*Client) GetAccount

func (c *Client) GetAccount() (*GeniusResponse, error)

GetAccount returns current user account data.

func (*Client) GetAlbum

func (c *Client) GetAlbum(id int, getTracks bool) (*Album, error)

GetAlbum returns Album object in response

func (*Client) GetAlbumTracks

func (c *Client) GetAlbumTracks(id int) ([]*AlbumTrack, error)

func (*Client) GetAnnotation

func (c *Client) GetAnnotation(id string, textFormat string) (*GeniusResponse, error)

GetAnnotation gets annotation object in response.

func (*Client) GetArtist

func (c *Client) GetArtist(id int) (*GeniusResponse, error)

GetArtist returns Artist object in response Uses "dom" as textFormat by default.

func (*Client) GetArtistAlbums

func (c *Client) GetArtistAlbums(id int) ([]*Album, error)

func (*Client) GetArtistDom

func (c *Client) GetArtistDom(id int) (*GeniusResponse, error)

GetArtistDom returns Artist object in response With "dom" as textFormat.

func (*Client) GetArtistHTML

func (c *Client) GetArtistHTML(id int) (*GeniusResponse, error)

GetArtistHTML returns Artist object in response With "html" as textFormat.

func (*Client) GetArtistPlain

func (c *Client) GetArtistPlain(id int) (*GeniusResponse, error)

GetArtistPlain returns Artist object in response With "plain" as textFormat.

func (*Client) GetArtistSongs

func (c *Client) GetArtistSongs(id int, sort string, total int) ([]*Song, error)

func (*Client) GetLyrics

func (c *Client) GetLyrics(uri string) (string, error)

func (*Client) GetSong

func (c *Client) GetSong(id int) (*Song, error)

GetSong returns Song object in response

Uses "dom" as textFormat by default.

func (*Client) GetSongDom

func (c *Client) GetSongDom(id int) (*Song, error)

GetSongDom returns Song object in response With "dom" as textFormat.

func (*Client) GetSongHTML

func (c *Client) GetSongHTML(id int) (*Song, error)

GetSongHTML returns Song object in response With "html" as textFormat.

func (*Client) GetSongPlain

func (c *Client) GetSongPlain(id int) (*Song, error)

GetSongPlain returns Song object in response With "plain" as textFormat.

func (*Client) GetSongWithLyrics

func (c *Client) GetSongWithLyrics(id int) (*Song, error)

func (*Client) Search

func (c *Client) Search(q string) (*GeniusResponse, error)

Search returns array of Hit objects in response

Currently only songs are searchable by this handler.

func (*Client) WebSearch

func (c *Client) WebSearch(perPage int, searchTerm string) (*GeniusResponse, error)

type ClientOption

type ClientOption func(client *Client)

func WithBaseURL

func WithBaseURL(url string) ClientOption

WithBaseURL provides an alternative base url to use for requests to the Spotify API. This can be used to connect to a staging or other alternative environment.

type Contributor

type Contributor struct {
	Contributions []string `json:"contributions"`
	Artist        *Artist  `json:"artist"`
	User          *User    `json:"user"`
}

type CoverArt

type CoverArt struct {
	Annotated         bool   `json:"annotated"`
	APIPath           string `json:"api_path"`
	ID                int    `json:"id"`
	ImageURL          string `json:"image_url"`
	ThumbnailImageURL string `json:"thumbnail_image_url"`
	URL               string `json:"url"`
}

type CustomPerformance

type CustomPerformance struct {
	Label   string    `json:"label"`
	Artists []*Artist `json:"artists"`
}

type Description

type Description struct {
	Plain string `json:"plain"`
	Dom   *Dom   `json:"dom"`
}

type DescriptionAnnotation

type DescriptionAnnotation struct {
	Type                 string        `json:"_type"`
	AnnotatorID          int           `json:"annotator_id"`
	AnnotatorLogin       string        `json:"annotator_login"`
	APIPath              string        `json:"api_path"`
	Classification       string        `json:"classification"`
	Fragment             string        `json:"fragment"`
	ID                   int           `json:"id"`
	IsDescription        bool          `json:"is_description"`
	Path                 string        `json:"path"`
	SongID               int           `json:"song_id"`
	URL                  string        `json:"url"`
	VerifiedAnnotatorIDs []int         `json:"verified_annotator_ids"`
	Annotatable          *Annotatable  `json:"annotatable"`
	Annotations          []*Annotation `json:"annotations"`

	Range struct {
		Content string `json:"content"`
	} `json:"range"`
}

type Dom

type Dom struct {
	Tag      string        `json:"tag"`
	Children []interface{} `json:"children"`
}

type Extractor

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

func NewExtractor

func NewExtractor(reader io.Reader) *Extractor

func (*Extractor) Extract

func (e *Extractor) Extract() (string, error)

type FactTrack

type FactTrack struct {
	Provider     string `json:"provider"`
	ExternalURL  string `json:"external_url"`
	ButtonText   string `json:"button_text"`
	HelpLinkText string `json:"help_link_text"`
	HelpLinkURL  string `json:"help_link_url"`
}

type GeniusResponse

type GeniusResponse struct {
	Meta     *Meta     `json:"meta"`
	Response *Response `json:"response"`
}

GeniusResponse is an actual response object from Genius API Consist links to possible retrievable objects: Artist, Song, etc.

type Hit

type Hit struct {
	Highlights []interface{} `json:"highlights"`
	Index      string        `json:"index"`
	Type       string        `json:"type"`
	Result     *Song         `json:"result"`
}

Hit is a hit on Genius API Used in /search handler Includes song results only.

type IQByAction

type IQByAction struct {
	Accept struct {
		Primary *Primary `json:"primary"`
	} `json:"accept"`
	Reject struct {
		Primary *Primary `json:"primary"`
	} `json:"reject"`
	Delete struct {
		Primary *Primary `json:"primary"`
	} `json:"delete"`
	EditMetadata struct {
		Primary *Primary `json:"primary"`
	} `json:"edit_metadata"`
}

type Image

type Image struct {
	URL         string `json:"url"`
	BoundingBox struct {
		Width  int `json:"width"`
		Height int `json:"height"`
	} `json:"bounding_box"`
}

type Media

type Media struct {
	Provider   string `json:"provider"`
	ProviderID string `json:"provider_id"`
	NativeURI  string `json:"native_uri"`
	Start      int    `json:"start"`
	Type       string `json:"type"`
	URL        string `json:"url"`
}

type Meta

type Meta struct {
	Status  int    `json:"status"`
	Message string `json:"message"`
}

type Performance

type Performance struct {
	Label   string    `json:"label"`
	Artists []*Artist `json:"artists"`
}

type PerformanceGroup

type PerformanceGroup struct {
	Label   string    `json:"label"`
	Artists []*Artist `json:"artists"`
}

type Primary

type Primary struct {
	Multiplier int     `json:"multiplier"`
	Base       float64 `json:"base"`
	Applicable bool    `json:"applicable"`
}

type ReleaseDateComponents

type ReleaseDateComponents struct {
	Year  int `json:"year"`
	Month int `json:"month"`
	Day   int `json:"day"`
}

type Response

type Response struct {
	Artist      *Artist       `json:"artist"`
	Album       *Album        `json:"album"`
	AlbumTracks []*AlbumTrack `json:"tracks"`
	Albums      []*Album      `json:"albums"`
	Song        *Song         `json:"song"`
	Songs       []*Song       `json:"songs"`
	Annotation  *Annotation   `json:"annotation"`
	User        *User         `json:"user"`
	NextPage    int           `json:"next_page"`
	Hits        []*Hit        `json:"hits"`
	WebPage     *WebPage      `json:"web_page"`
	Sections    []Sections    `json:"sections"`
}

type Sections

type Sections struct {
	Type string `json:"type"`
	Hits []Hit  `json:"hits"`
}

type Song

type Song struct {
	Type                                      string                 `json:"_type"`
	AnnotationCount                           int                    `json:"annotation_count"`
	APIPath                                   string                 `json:"api_path"`
	ArtistNames                               string                 `json:"artist_names"`
	Description                               *interface{}           `json:"description"`
	EmbedContent                              string                 `json:"embed_content"`
	FactTrack                                 *FactTrack             `json:"fact_track"`
	FeaturedVideo                             bool                   `json:"features_video"`
	FullTitle                                 string                 `json:"full_title"`
	HeaderImageThumbnailURL                   string                 `json:"header_image_thumbnail_url"`
	HeaderImageURL                            string                 `json:"header_image_url"`
	ID                                        int                    `json:"id"`
	Instrumental                              bool                   `json:"instrumental"`
	Language                                  string                 `json:"language"`
	Lyrics                                    string                 `json:"lyrics"`
	LyricsOwnerID                             int                    `json:"lyrics_owner_id"`
	LyricsState                               string                 `json:"lyrics_state"`
	LyricsUpdatedAt                           int                    `json:"lyrics_updated_at"`
	Name                                      string                 `json:"name"`
	Path                                      string                 `json:"path"`
	PyongsCount                               int                    `json:"pyong_count"`
	RecordingLocation                         string                 `json:"recording_location"`
	ReleaseDate                               string                 `json:"release_date"`
	RelationshipsIndexURL                     string                 `json:"relationships_index_url"`
	ReleaseDateComponents                     *ReleaseDateComponents `json:"release_date_components"`
	ReleaseDateForDisplay                     string                 `json:"release_date_for_display"`
	ReleaseDateWithAbbreviatedMonthForDisplay string                 `json:"release_date_with_abbreviated_month_for_display"`
	SongArtImageThumbnailURL                  string                 `json:"song_art_image_thumbnail_url"`
	SongArtImageURL                           string                 `json:"song_art_image_url"`
	Stats                                     *Stats                 `json:"stats"`
	Title                                     string                 `json:"title"`
	TitleWithFeatured                         string                 `json:"title_with_featured"`
	URL                                       string                 `json:"url"`
	CurrentUserMetadata                       *UserMetadata          `json:"current_user_metadata"`
	Album                                     *Album                 `json:"album"`
	CustomPerformances                        []*CustomPerformance   `json:"custom_performances"`
	DescriptionAnnotation                     *DescriptionAnnotation `json:"description_annotation"`
	FeaturedArtists                           []*Artist              `json:"featured_artists"`
	Media                                     []*Media               `json:"media"`
	PrimaryArtist                             *Artist                `json:"primary_artist"`
	ProducerArtists                           []*Artist              `json:"producer_artists"`
	SongRelationships                         []*SongRelationship    `json:"song_relationships"`
	VerifiedAnnotationsBy                     []*User                `json:"verified_annotations_by"`
	VerifiedContributors                      []*Contributor         `json:"verified_contributors"`
	VerifiedLyricsBy                          []*User                `json:"verified_lyrics_by"`
	WriterArtists                             []*Artist              `json:"writer_artists"`
}

Song is song on Genius API.

func GetArtistFromSearchResponse

func GetArtistFromSearchResponse(response *GeniusResponse, searchTerm string) (*Song, error)

func GetSongFromSearchResponse

func GetSongFromSearchResponse(response *GeniusResponse, searchTerm string) (*Song, error)

type SongRelationship

type SongRelationship struct {
	Type  string  `json:"type"`
	Songs []*Song `json:"songs"`
}

type Stats

type Stats struct {
	AcceptedAnnotations   int  `json:"accepted_annotations"`
	Contributors          int  `json:"contributors"`
	Hot                   bool `json:"hot"`
	IQEarners             int  `json:"iq_earners"`
	Transcribers          int  `json:"transcribers"`
	UnreviewedAnnotations int  `json:"unreviewed_annotations"`
	VerifiedAnnotations   int  `json:"verified_annotations"`
	Concurrents           int  `json:"concurrents"`
	Pageviews             int  `json:"pageviews"`
}

type User

type User struct {
	APIPath                     string        `json:"api_path"`
	Avatar                      *Avatar       `json:"avatar"`
	HeaderImageURL              string        `json:"header_image_url"`
	HumanReadableRoleForDisplay string        `json:"human_readable_role_for_display"`
	ID                          int           `json:"id"`
	IQ                          int           `json:"iq"`
	Login                       string        `json:"login"`
	Name                        string        `json:"name"`
	RoleForDisplay              string        `json:"role_for_display"`
	URL                         string        `json:"url"`
	CurrentUserMetadata         *UserMetadata `json:"current_user_metadata"`
}

User is user on Genius API.

type UserMetadata

type UserMetadata struct {
	Permissions          []string    `json:"permissions"`
	ExcludedPersmissions []string    `json:"excluded_permissions"`
	Features             []string    `json:"features"`
	IQByAction           *IQByAction `json:"iq_by_action"`

	Interactions struct {
		Following bool `json:"following"`
		Cosign    bool `json:"cosign"`
		Pyong     bool `json:"pyong"`
		Vote      bool `json:"vote"`
	} `json:"interactions"`

	Relationships struct {
		PinnedRole string `json:"pinned_role"`
	} `json:"relationships"`
}

type WebPage

type WebPage struct {
	APIPath         string `json:"api_path"`
	Domain          string `json:"domain"`
	ID              int    `json:"id"`
	NormalizedURL   string `json:"normalized_url"`
	ShareURL        string `json:"share_url"`
	Title           string `json:"title"`
	URL             string `json:"url"`
	AnnotationCount int    `json:"annotation_count"`
}

WebPage is web_page on Genius API.

type WithBody

type WithBody struct {
	Body    string                 `json:"-"`
	RawBody map[string]interface{} `json:"body"`
}

WithBody is a struct to take care of different formats of field "body" If "textFormat" was either "html" or "plain" Process method will put result string in Body field In case of "dom" use RawBody.

func (*WithBody) Process

func (b *WithBody) Process(textFormat string)

Process will check the textFormat and put result string in Body field if textFormat was "html" or "plain".

Jump to

Keyboard shortcuts

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