gotrakt

package module
v0.0.0-...-9727a29 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2014 License: MIT Imports: 14 Imported by: 0

README

gotrakt

Golang API for Trakt.tv

Usage

Get a Show's information:

show, err := t.GetShow("battlestar-galactica-2003)

show, err := t.GetShow(TvdbID)

Get information about particular seasons of a show:

seasons, err := t.ShowSeasons("battlestar-galactica-2003", []int{0,1})

Search for a show matching a particular string:

shows, err := t.ShowSearch("query")

ToDo

Authentication support More API coverage

Documentation

Index

Constants

View Source
const TraktTVBaseURL = "https://api.trakt.tv"

Base URL for TraktTV api

Variables

View Source
var MovieSearchTmpl = template.Must(
	template.New("MovieSearch").Parse("{{.Host}}/search/movies.json/{{.APIKey|urlquery}}?query={{.Query | urlquery}}"),
)

https://trakt.tv/api-docs/search-movies

View Source
var MovieSummaryTmpl = template.Must(
	template.New("MovieSummary").Parse("{{.Host}}/movie/summary.json/{{.APIKey|urlquery}}/query={{.Query | urlquery}}"),
)

https://trakt.tv/api-docs/movie-summary

View Source
var ShowSearchTempl = template.Must(
	template.New("ShowSearch").Parse("{{.Host}}/search/shows.json/{{.APIKey|urlquery}}?query={{.Query | urlquery}}&seasons=true"),
)

https://trakt.tv/api-docs/search-shows

View Source
var ShowSeasonTmpl = template.Must(
	template.New("ShowSeason").Parse("{{.Host}}/show/season.json/{{.APIKey|urlquery}}/{{.Query | urlquery}}/{{.Season | urlquery}}"),
)

https://trakt.tv/api-docs/show-season

View Source
var ShowSummaryTmpl = template.Must(
	template.New("ShowSummary").Parse("{{.Host}}/show/summary.json/{{.APIKey|urlquery}}/{{.Query | urlquery}}/extended"),
)

http://trakt.tv/api-docs/show-summary

Functions

func HighlightBytePosition

func HighlightBytePosition(f io.Reader, pos int64) (line, col int, highlight string)

HighlightBytePosition takes a reader and the location in bytes of a parse error (for instance, from json.SyntaxError.Offset) and returns the line, column, and pretty-printed context around the error with an arrow indicating the exact position of the syntax error.

Taken from the Camlistore source

func Host

func Host(host string) option

Host sets the host to use for talking to TraktTV This includes the protocol, hostname, port: i.e. https://api.trakt.tv:443

func Session

func Session(sess *napping.Session) option

Session sets the session to use for talking to TraktTV

func Userinfo

func Userinfo(username, password string) option

Userinfo configures the user and password information for API calls

Types

type APIError

type APIError struct {
	Status    string `json:"status"`
	ErrorDesc string `json:"error"`
}

APIError represents errors that the Trakt.tv api may return

func (APIError) Error

func (e APIError) Error() string

type Episode

type Episode struct {
	Season        int               `json:"season"`
	Episode       int               `json:"episode"`
	Number        int               `json:"number"`
	TvdbID        int               `json:"tvdb_id"`
	Title         string            `json:"title"`
	Overview      string            `json:"overview"`
	FirstAired    int               `json:"first_aired"`
	FirstAiredIso string            `json:"first_aired_iso"`
	FirstAiredUtc int               `json:"first_aired_utc"`
	URL           string            `json:"url"`
	Screen        string            `json:"screen"`
	Images        map[string]string `json:"images"`
	Ratings       Ratings           `json:"ratings"`
	//Not filled out as we don't do auth with the api
	Watched        bool `json:"watched"`
	InCollection   bool `json:"in_collection"`
	InWatchlist    bool `json:"in_watchlist"`
	Rating         bool `json:"rating"`
	RatingAdvanced int  `json:"rating_advanced"`
}

Episode contains the information for a given Show Episode

type Movie

type Movie struct {
	Title         string `json:"title"`
	Year          int    `json:"year"`
	Released      int    `json:"released"`
	URL           string `json:"url"`
	Trailer       string `json:"trailer"`
	Runtime       int    `json:"runtime"`
	Tagline       string `json:"tagline"`
	Overview      string `json:"overview"`
	Certification string `json:"certification"`
	ImdbID        string `json:"imdb_id"`
	TmdbID        int    `json:"tmdb_id"`
	RtID          int    `json:"rt_id"`
	LastUpdated   int    `json:"last_updated"`
	Images        struct {
		Poster string `json:"poster"`
		Fanart string `json:"fanart"`
	} `json:"images"`
	Genres []string `json:"genres"`
	// It seems like if Age is unset it returns an empty string "" rather than 0,
	// setting these to interface{} values lets the decoder work properly.
	TopWatchers []struct {
		Plays     interface{} `json:"plays"`
		Username  string      `json:"username"`
		Protected bool        `json:"protected"`
		FullName  string      `json:"full_name"`
		Gender    string      `json:"gender"`
		Age       interface{} `json:"age"`
		Location  string      `json:"location"`
		About     string      `json:"about"`
		Joined    interface{} `json:"joined"`
		Avatar    string      `json:"avatar"`
		URL       string      `json:"url"`
	} `json:"top_watchers"`
	Ratings struct {
		Percentage int `json:"percentage"`
		Votes      int `json:"votes"`
		Loved      int `json:"loved"`
		Hated      int `json:"hated"`
	} `json:"ratings"`
	Stats struct {
		Watchers   int `json:"watchers"`
		Plays      int `json:"plays"`
		Scrobbles  int `json:"scrobbles"`
		Checkins   int `json:"checkins"`
		Collection int `json:"collection"`
	} `json:"stats"`
	People struct {
		Directors []struct {
			Name   string `json:"name"`
			Images struct {
				Headshot string `json:"headshot"`
			} `json:"images"`
		} `json:"directors"`
		Writers []struct {
			Name   string `json:"name"`
			Job    string `json:"job"`
			Images struct {
				Headshot string `json:"headshot"`
			} `json:"images"`
		} `json:"writers"`
		Producers []struct {
			Name      string `json:"name"`
			Executive bool   `json:"executive"`
			Images    struct {
				Headshot string `json:"headshot"`
			} `json:"images"`
		} `json:"producers"`
		Actors []struct {
			Name      string `json:"name"`
			Character string `json:"character"`
			Images    struct {
				Headshot string `json:"headshot"`
			} `json:"images"`
		} `json:"actors"`
	} `json:"people"`
	Watched        bool   `json:"watched"`
	Plays          int    `json:"plays"`
	Rating         string `json:"rating"`
	RatingAdvanced int    `json:"rating_advanced"`
	InWatchlist    bool   `json:"in_watchlist"`
	InCollection   bool   `json:"in_collection"`
}

Movie holds the result of a Movie search from Trakt

type Ratings

type Ratings struct {
	Percentage int `json:"percentage"`
	Votes      int `json:"votes"`
	Loved      int `json:"loved"`
	Hated      int `json:"hated"`
}

Ratings represents the how the thing was rated by Trakt users

type Season

type Season struct {
	Season   int       `json:"season"`
	URL      string    `json:"url"`
	Poster   string    `json:"poster"`
	Episodes []Episode `json:"episodes"`
}

Season is a containter for tv episodes

type Show

type Show struct {
	Title         string            `json:"title"`
	Year          int               `json:"year"`
	URL           string            `json:"url"`
	FirstAired    int               `json:"first_aired"`
	Country       string            `json:"country"`
	Overview      string            `json:"overview"`
	Runtime       int               `json:"runtime"`
	Network       string            `json:"network"`
	AirDay        string            `json:"air_day"`
	AirTime       string            `json:"air_time"`
	Certification string            `json:"certification"`
	ImdbID        string            `json:"imdb_id"`
	TvdbID        int               `json:"tvdb_id"`
	TvrageID      int               `json:"tvrage_id"`
	Ended         bool              `json:"ended"`
	Images        map[string]string `json:"images"`
	Genres        []string          `json:"genres"`
	Seasons       []Season          `json:"seasons"`
}

Show is the show result from Trakt

type TraktTV

type TraktTV struct {
	APIKey   string
	BaseURL  string
	Session  *napping.Session
	Userinfo *url.Userinfo
}

TraktTV is the main struct used to query Trakt.tv. Use NewTraktTV to create new instances.

func New

func New(api string, options ...option) (*TraktTV, error)

New initializes and returns a new TraktTV struct

func (*TraktTV) GetMovie

func (t *TraktTV) GetMovie(slugOrImdbID string) (*Movie, error)

GetMovie searches Trakt.tv for movies matching the query

func (*TraktTV) GetShow

func (t *TraktTV) GetShow(slugOrTvdbID string) (*Show, error)

GetShow returns a show and all of it's Seasons and Episodes

func (*TraktTV) MovieSearch

func (t *TraktTV) MovieSearch(query string) ([]Movie, error)

MovieSearch searches Trakt.tv for movies matching the query

func (*TraktTV) ShowSearch

func (t *TraktTV) ShowSearch(name string) ([]Show, error)

ShowSearch searches tv shows

func (*TraktTV) ShowSeasons

func (t *TraktTV) ShowSeasons(slugOrTvdbID string, seasons []int) ([]Season, error)

ShowSeasons searches for a shows episode summaries by season. You can optionally limit the query to just a given set of seasons.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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