gonius

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2025 License: GPL-3.0 Imports: 10 Imported by: 0

README

gonius

gonius is a Go client to access the Genius API.

Go Report Card GoDoc

Contributing

IDK, it would be really nice of you to contribute, check the poorly written CONTRIBUTING.md for more info.

Roadmap

  • Search
  • Get artist
  • Get artist's songs
  • Get annotation
  • Get song
  • Lyrics
  • Pagination
  • Account
  • Find missing shit using genius-lyrics as a reference
  • Lyrics timing?

Usage

package main

import (
	"encoding/json"
	"fmt"

	"github.com/mbaraa/gonius"
)

func main() {
	client := gonius.NewClient("top-secret-token-woo-scary")
	results, err := client.Search.Get("lana del rey jealous girl")
	if err != nil {
		panic(err)
	}

	for _, result := range results {
		jsonn, _ := json.MarshalIndent(result, "", "\t")
		fmt.Println("search result", string(jsonn))
	}
}

Support :)

Give a ⭐️ if this project helped you!


Made with 🧉 by Baraa Al-Masri

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidToken = errors.New("invalid access token")
	ErrNotFound     = errors.New("not found")
	ErrApiError     = errors.New("api error")
)

Functions

This section is empty.

Types

type AccountService

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

type Album

type Album struct {
	Id int `json:"id,omitempty"`

	ApiPath     string `json:"api_path,omitempty"`
	CoverArtURL string `json:"cover_art_url,omitempty"`
	FullTitle   string `json:"full_title,omitempty"`
	Name        string `json:"name,omitempty"`
	URL         string `json:"url,omitempty"`

	Artist *Artist `json:"artist,omitempty"`
}

type Annotation

type Annotation struct {
	ApiPath             string `json:"api_path,omitempty"`
	Body                any    `json:"body,omitempty"`
	CommentCount        int    `json:"comment_count,omitempty"`
	Community           bool   `json:"community,omitempty"`
	CustomPreview       bool   `json:"custom_preview,omitempty"`
	HasVoters           bool   `json:"has_voters,omitempty"`
	Id                  int    `json:"id,omitempty"`
	Pinned              bool   `json:"pinned,omitempty"`
	ShareURL            string `json:"share_url,omitempty"`
	Source              string `json:"source,omitempty"`
	State               string `json:"state,omitempty"`
	URL                 string `json:"url,omitempty"`
	Verified            bool   `json:"verified,omitempty"`
	VotesTotal          int    `json:"votes_total,omitempty"`
	CurrentUserMetadata *struct {
		Permissions         []string `json:"permissions,omitempty"`
		ExcludedPermissions []string `json:"excluded_permissions,omitempty"`
		Interactions        *struct {
			Following bool `json:"following,omitempty"`
		} `json:"interactions,omitempty"`
	} `json:"current_user_metadata,omitempty"`
	Authors          []Author `json:"authors,omitempty"`
	CosignedBy       []any    `json:"cosigned_by,omitempty"`
	RejectionComment string   `json:"rejection_comment,omitempty"`
	VerifiedBy       *User    `json:"verified_by,omitempty"`
}

type AnnotationsService

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

func (*AnnotationsService) Get

func (s *AnnotationsService) Get(id string) (Annotation, error)

type ApiResponse

type ApiResponse struct {
	Meta *struct {
		Status int `json:"status,omitempty"`
	} `json:"meta,omitempty"`
	Response *struct {
		Annotation *Annotation `json:"annotation,omitempty"`
		Song       *Song       `json:"song,omitempty"`
		Songs      []Song      `json:"songs,omitempty"`
		Artist     *Artist     `json:"artist,omitempty"`
		Hits       []Hit       `json:"hits,omitempty"`
	} `json:"response,omitempty"`
}

ApiResponse is the general response structure that is received from different api calls from api.genius.com

type Artist

type Artist struct {
	IsMemeVerified    bool `json:"is_meme_verified,omitempty"`
	IsVerified        bool `json:"is_verified,omitempty"`
	TranslationArtist bool `json:"translation_artist,omitempty"`

	FollowersCount int `json:"followers_count,omitempty"`
	Id             int `json:"id,omitempty"`
	IQ             int `json:"iq,omitempty"`

	ApiPath        string `json:"api_path,omitempty"`
	HeaderImageURL string `json:"header_image_url,omitempty"`
	ImageURL       string `json:"image_url,omitempty"`
	InstagramName  string `json:"instagram_name,omitempty"`
	Name           string `json:"name,omitempty"`
	TwitterName    string `json:"twitter_name,omitempty"`
	URL            string `json:"url,omitempty"`

	AlternateNames []string `json:"alternate_names,omitempty"`
	User           *User    `json:"user,omitempty"`
}

type ArtistSongsSort

type ArtistSongsSort string
const (
	ArtistSongsSortTitle      ArtistSongsSort = "title"
	ArtistSongsSortPopularity ArtistSongsSort = "popularity"
)

type ArtistsService

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

func (*ArtistsService) Get

func (s *ArtistsService) Get(id string) (Artist, error)

func (*ArtistsService) GetSongs

func (s *ArtistsService) GetSongs(artistId string, sort ArtistSongsSort) ([]Song, error)

type Author

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

type Client

type Client struct {
	Account     *AccountService
	Annotations *AnnotationsService
	Artists     *ArtistsService
	Lyrics      *LyricsService
	Search      *SearchService
	Songs       *SongsService
}

Client is the Genius client that handles all the different API calls to api.genius.com

func NewClient

func NewClient(accessToken string) *Client

NewClient initializes the genius Client with the given access token to interact with different api.genius.com calls.

func (*Client) SetPageSize

func (c *Client) SetPageSize()

type Hit

type Hit struct {
	HighLights any    `json:"highlights,omitempty"`
	Index      string `json:"string,omitempty"`
	Type       string `json:"type,omitempty"`
	Result     *struct {
		AnnotationCount          int    `json:"annotation_count,omitempty"`
		ApiPath                  string `json:"api_path,omitempty"`
		FullTitle                string `json:"full_title,omitempty"`
		HeaderImageThumbnailURL  string `json:"header_image_thumbnail_url,omitempty"`
		Id                       int    `json:"id,omitempty"`
		LyricsOwnerId            int    `json:"lyrics_owner_id,omitempty"`
		LyricsState              string `json:"lyrics_state,omitempty"`
		Path                     string `json:"path,omitempty"`
		PyongsCount              int    `json:"pyongs_count,omitempty"`
		SongArtImageThumbnailURL string `json:"song_art_image_thumbnail_url,omitempty"`
		SongArtImageURL          string `json:"song_art_image_url,omitempty"`
		Stats                    *struct {
			UnreviewedAnnotations int  `json:"unreviewed_annotations,omitempty"`
			Concurrents           int  `json:"concurrents,omitempty"`
			Hot                   bool `json:"hot,omitempty"`
			PageViews             int  `json:"page_views,omitempty"`
		} `json:"stats,omitempty"`
		Title             string  `json:"title,omitempty"`
		TitleWithFeatured string  `json:"title_with_featured,omitempty"`
		URL               string  `json:"url,omitempty"`
		PrimaryArtist     *Artist `json:"primary_artist,omitempty"`
	} `json:"result,omitempty"`
}

type Lyrics

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

Lyrics holds the actual plain text value of the lyrics.

func (*Lyrics) Parts

func (l *Lyrics) Parts() []string

func (*Lyrics) String

func (l *Lyrics) String() string

type LyricsService

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

LyricsService fetches lyrics of a song.

func (*LyricsService) FindForSong

func (l *LyricsService) FindForSong(songUrl string) (Lyrics, error)

type Media

type Media struct {
	Start int `json:"start,omitempty"`

	NativeURI   string `json:"native_uri,omitempty"`
	Provider    string `json:"provider,omitempty"`
	Type        string `json:"type,omitempty"`
	URL         string `json:"url,omitempty"`
	Attribution string `json:"attribution,omitempty"`
}

type SearchService

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

func (*SearchService) Get

func (s *SearchService) Get(q string) ([]Hit, error)

type Song

type Song struct {
	FeaturedVideo bool `json:"featured_video,omitempty"`

	AnnotationCount int `json:"annotation_count,omitempty"`
	Id              int `json:"id,omitempty"`
	LyricsOwnerId   int `json:"lyrics_owner_id,omitempty"`
	PyongsCount     int `json:"pyongs_count,omitempty"`

	ApiPath                  string `json:"api_path,omitempty"`
	AppleMusicId             string `json:"apple_music_id,omitempty"`
	AppleMusicPlayerURL      string `json:"apple_music_player_url,omitempty"`
	EmbedContent             string `json:"embed_content,omitempty"`
	FullTitle                string `json:"full_title,omitempty"`
	HeaderImageThumbnailURL  string `json:"header_image_thumbnail_url,omitempty"`
	HeaderImageURL           string `json:"header_image_url,omitempty"`
	LyricsState              string `json:"lyrics_state,omitempty"`
	Path                     string `json:"path,omitempty"`
	SongArtImageThumbnailURL string `json:"song_art_image_thumbnail_url,omitempty"`
	SongArtImageURL          string `json:"song_art_image_url,omitempty"`
	Title                    string `json:"title,omitempty"`
	TitleFeatured            string `json:"title_features,omitempty"`
	URL                      string `json:"url,omitempty"`

	Album             *Album             `json:"album,omitempty"`
	FeaturedArtists   []Artist           `json:"featured_artists,omitempty"`
	Media             []Media            `json:"media,omitempty"`
	PrimaryArtist     *Artist            `json:"primary_artist,omitempty"`
	ProducerArtists   []Artist           `json:"producer_artists,omitempty"`
	SongRelationships []SongRelationship `json:"song_relationships,omitempty"`
	WriterArtists     []Artist           `json:"writer_artists,omitempty"`

	Description struct {
		Plain string `json:"plain,omitempty"`
	} `json:"description,omitempty"`
}

type SongRelationship

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

type SongsService

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

func (*SongsService) FetchLyrics

func (s *SongsService) FetchLyrics(song Song) (Lyrics, error)

func (*SongsService) Get

func (s *SongsService) Get(id string) (Song, error)

type User

type User struct {
	ApiPath string `json:"api_path,omitempty"`
	Avatar  *struct {
		Tiny *struct {
			URL         string `json:"url,omitempty"`
			BoundingBox *struct {
				Width  int `json:"width,omitempty"`
				Height int `json:"height,omitempty"`
			} `json:"bounding_box,omitempty"`
		} `json:"tiny,omitempty"`
		Thumb *struct {
			URL         string `json:"url,omitempty"`
			BoundingBox *struct {
				Width  int `json:"width,omitempty"`
				Height int `json:"height,omitempty"`
			} `json:"bounding_box,omitempty"`
		} `json:"thumb,omitempty"`
		Small *struct {
			URL         string `json:"url,omitempty"`
			BoundingBox *struct {
				Width  int `json:"width,omitempty"`
				Height int `json:"height,omitempty"`
			} `json:"bounding_box,omitempty"`
		} `json:"small,omitempty"`
		Medium *struct {
			URL         string `json:"url,omitempty"`
			BoundingBox *struct {
				Width  int `json:"width,omitempty"`
				Height int `json:"height,omitempty"`
			} `json:"bounding_box,omitempty"`
		} `json:"medium,omitempty"`
	} `json:"avatar,omitempty"`
	HeaderImageURL              string `json:"header_image_url,omitempty"`
	HumanReadableRoleForDisplay string `json:"human_readable_role_for_display,omitempty"`
	Id                          int    `json:"id,omitempty"`
	IQ                          int    `json:"iq,omitempty"`
	Login                       string `json:"login,omitempty"`
	Name                        string `json:"string,omitempty"`
	RoleForDisplay              string `json:"role_for_display,omitempty"`
	URL                         string `json:"url,omitempty"`
	CurrentUserMetadata         *struct {
		Permissions         []string `json:"permissions,omitempty"`
		ExcludedPermissions []string `json:"excluded_permissions,omitempty"`
		Interactions        *struct {
			Following bool `json:"following,omitempty"`
		} `json:"interactions,omitempty"`
	} `json:"current_user_metadata,omitempty"`
}

Jump to

Keyboard shortcuts

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