trakt

package module
v0.0.0-...-79c6f1f Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: MIT Imports: 10 Imported by: 0

README

Golang client for Trakt.tv

Inspired by: https://github.com/42minutes/go-trakt

TODO

Documentation

Index

Constants

View Source
const Version = "0.1.0"

Version of go-trakt.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseEpisode

type BaseEpisode struct {
	Season uint16  `json:"season"`
	Number uint16  `json:"number"`
	Title  string  `json:"title"`
	IDs    ItemIDs `json:"ids"`
}

BaseEpisode represents the base set of fields for an episode.

type Client

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

Client wraps connection parameters for the Trakt.tv API.

func NewClient

func NewClient(options ClientConfig) *Client

NewClient returns new Trakt.tv client.

func (*Client) OAuth

func (c *Client) OAuth(redirectURI string) *OAuthService

OAuth creates a new OAuthService.

func (*Client) Scrobble

func (c *Client) Scrobble() *ScrobbleService

Scrobble creates a new ScrobbleService.

func (*Client) Search

func (c *Client) Search() *SearchService

Search creates a new SearchService.

func (*Client) Show

func (c *Client) Show(showID uint64) *ShowService

Show creates a new ShowService.

func (*Client) Sync

func (c *Client) Sync() *SyncService

Sync creates a new SyncService.

func (*Client) User

func (c *Client) User(userID string) *UserService

User creates a new UserService.

func (*Client) Users

func (c *Client) Users() *UsersService

Users creates a new UsersService.

type ClientConfig

type ClientConfig struct {
	ClientID     string
	ClientSecret string
	AccessToken  string
}

ClientConfig contains auth and connection details for the Trakt.tv API.

type Episode

type Episode struct {
	BaseEpisode
	FirstAired time.Time `json:"first_aired"`
}

Episode represents an episode.

type Error

type Error struct {
	Message           string
	Method            string
	URL               string
	ResponseCode      int
	RateLimitExceeded bool
	Parent            error
}

func (*Error) Error

func (e *Error) Error() string

type GetAccessTokenResponse

type GetAccessTokenResponse struct {
	Error            string `json:"error"`
	ErrorDescription string `json:"error_description"`
	AccessToken      string `json:"access_token"`
	TokenType        string `json:"token_type"`
	ExpiresIn        uint64 `json:"expires_in"`
	RefreshToken     string `json:"refresh_token"`
	Scope            string `json:"scope"`
	CreatedAt        uint64 `json:"created_at"`
}

GetAccessTokenResponse response for a access token request.

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPClient is a subset of the http.Client interface defining only the methods required.

type HistoryItem

type HistoryItem struct {
	Item

	ID        uint64    `json:"id"`
	WatchedAt time.Time `json:"watched_at"`
	Action    string    `json:"action"`
}

HistoryItem a movie, show, season or episode from watch histroy.

type Item

type Item struct {
	Type    ItemType `json:"type"`
	Movie   Movie    `json:"movie"`
	Show    Show     `json:"show"`
	Season  Season   `json:"season"`
	Episode Episode  `json:"episode"`
}

Item a movie, show, episode, person or list.

func (*Item) String

func (i *Item) String() string

func (*Item) TraktID

func (i *Item) TraktID() uint64

TraktID returns the Trakt.tv id of an item.

func (*Item) TraktKey

func (i *Item) TraktKey() *Key

TraktKey Trakt.tv key (type and id).

type ItemIDs

type ItemIDs struct {
	Slug  string `json:"slug"`
	Trakt uint64 `json:"trakt"`
	TvDB  uint64 `json:"tvdb"`
	Tmdb  uint64 `json:"tmdb"`
	Imdb  string `json:"imdb"`
}

type ItemType

type ItemType string

ItemType type of item.

const (
	ItemTypeAll     ItemType = ""
	ItemTypeMovie   ItemType = "movie"
	ItemTypeShow    ItemType = "show"
	ItemTypeSeason  ItemType = "season"
	ItemTypeEpisode ItemType = "episode"
)

Item types.

type Key

type Key struct {
	Type ItemType `json:"type"`
	ID   uint64   `json:"id"`
}

Key identifies an item by type and id.

func (*Key) Equal

func (k *Key) Equal(k2 *Key) bool

Equal compares two keys for equality.

func (*Key) String

func (k *Key) String() string

type LastActivities

type LastActivities struct {
	All    time.Time `json:"all"`
	Movies struct {
		WatchedAt         time.Time `json:"watched_at"`
		CollectedAt       time.Time `json:"collected_at"`
		RatedAt           time.Time `json:"rated_at"`
		WatchlistedAt     time.Time `json:"watchlisted_at"`
		RecommendationsAt time.Time `json:"recommendations_at"`
		CommentedAt       time.Time `json:"commented_at"`
		PausedAt          time.Time `json:"paused_at"`
		HiddenAt          time.Time `json:"hidden_at"`
	} `json:"movies"`
	Episodes struct {
		WatchedAt     time.Time `json:"watched_at"`
		CollectedAt   time.Time `json:"collected_at"`
		RatedAt       time.Time `json:"rated_at"`
		WatchlistedAt time.Time `json:"watchlisted_at"`
		CommentedAt   time.Time `json:"commented_at"`
		PausedAt      time.Time `json:"paused_at"`
	} `json:"episodes"`
	Shows struct {
		RatedAt           time.Time `json:"rated_at"`
		WatchlistedAt     time.Time `json:"watchlisted_at"`
		RecommendationsAt time.Time `json:"recommendations_at"`
		CommentedAt       time.Time `json:"commented_at"`
		HiddenAt          time.Time `json:"hidden_at"`
	} `json:"shows"`
	Seasons struct {
		RatedAt       time.Time `json:"rated_at"`
		WatchlistedAt time.Time `json:"watchlisted_at"`
		CommentedAt   time.Time `json:"commented_at"`
		HiddenAt      time.Time `json:"hidden_at"`
	} `json:"seasons"`
	Comments struct {
		LikedAt   time.Time `json:"liked_at"`
		BlockedAt time.Time `json:"blocked_at"`
	} `json:"comments"`
	Lists struct {
		LikedAt     time.Time `json:"liked_at"`
		UpdatedAt   time.Time `json:"updated_at"`
		CommentedAt time.Time `json:"commented_at"`
	} `json:"lists"`
	Watchlist struct {
		UpdatedAt time.Time `json:"updated_at"`
	} `json:"watchlist"`
	Recommendations struct {
		UpdatedAt time.Time `json:"updated_at"`
	} `json:"recommendations"`
	Account struct {
		SettingsAt  time.Time `json:"settings_at"`
		FollowedAt  time.Time `json:"followed_at"`
		FollowingAt time.Time `json:"following_at"`
		PendingAt   time.Time `json:"pending_at"`
		RequestedAt time.Time `json:"requested_at"`
	} `json:"account"`
	SavedFilters struct {
		UpdatedAt time.Time `json:"updated_at"`
	} `json:"saved_filters"`
}

LastActivities represents the last activity of a user.

type Movie

type Movie struct {
	Title string  `json:"title"`
	Year  uint16  `json:"year"`
	IDs   ItemIDs `json:"ids"`
}

Movie represents a movie.

type OAuthService

type OAuthService struct {
	Client      *Client
	RedirectURI string
}

OAuthService services wrapping the OAuth scope.

func (*OAuthService) GetAccessToken

func (s *OAuthService) GetAccessToken(ctx context.Context, code string) (*GetAccessTokenResponse, error)

GetAccessToken exchange code for access_token.

func (*OAuthService) RefreshToken

func (s *OAuthService) RefreshToken(ctx context.Context, refreshToken string) (*RefreshTokenResponse, error)

RefreshToken exchange refresh_token for access_token.

type RefreshTokenResponse

type RefreshTokenResponse struct {
	Error            string `json:"error"`
	ErrorDescription string `json:"error_description"`
	AccessToken      string `json:"access_token"`
	TokenType        string `json:"token_type"`
	ExpiresIn        uint64 `json:"expires_in"`
	RefreshToken     string `json:"refresh_token"`
	Scope            string `json:"scope"`
	CreatedAt        uint64 `json:"created_at"`
}

RefreshTokenResponse response for a refresh token request.

type ScrobbleItem

type ScrobbleItem struct {
	Item

	ID       uint64  `json:"id"`
	Action   string  `json:"action"`
	Progress float64 `json:"progress"`
}

ScrobbleItem a movie, show, season or episode from a scrobble response.

type ScrobbleService

type ScrobbleService struct {
	Client *Client
}

ScrobbleService services wrapping the scrobble scope.

func (*ScrobbleService) Pause

func (s *ScrobbleService) Pause(ctx context.Context, item *Item, progress float64) (*ScrobbleItem, error)

Pause watching in a media center.

func (*ScrobbleService) Start

func (s *ScrobbleService) Start(ctx context.Context, item *Item, progress float64) (*ScrobbleItem, error)

Start watching in a media center.

func (*ScrobbleService) Stop

func (s *ScrobbleService) Stop(ctx context.Context, item *Item, progress float64) (*ScrobbleItem, error)

Stop watching in a media center.

type SearchService

type SearchService struct {
	Client *Client
}

SearchService services wrapping the search scope.

func (*SearchService) IDLookup

func (s *SearchService) IDLookup(
	ctx context.Context,
	serviceType ServiceType,
	itemID string,
	itemType ItemType,
) ([]*Item, error)

IDLookup find items by service id and optional type.

func (*SearchService) TextQuery

func (s *SearchService) TextQuery(
	ctx context.Context,
	itemType ItemType,
	query string,
) ([]*Item, error)

TextQuery find items by type and query string.

type Season

type Season struct {
	Number   uint16    `json:"number"`
	Episodes []Episode `json:"episodes"`
	IDs      ItemIDs   `json:"ids"`
}

Season represents a season.

type ServiceType

type ServiceType string

ServiceType type of service.

const (
	ServiceTypeTrakt ServiceType = "trakt"
	ServiceTypeIMDB  ServiceType = "imdb"
	ServiceTypeTMDB  ServiceType = "tmdb"
	ServiceTypeTVDB  ServiceType = "tvdb"
)

Service types.

type Show

type Show struct {
	Title string  `json:"title"`
	Year  uint16  `json:"year"`
	IDs   ItemIDs `json:"ids"`
}

Show represents a show.

type ShowSeasonEpisodeService

type ShowSeasonEpisodeService struct {
	Client        *Client
	ShowID        uint64
	SeasonNumber  uint16
	EpisodeNumber uint16
}

ShowSeasonEpisodeService services wrapping the episodes scope for a single episode within the seasons scope for a single season within the shows scope for a single show.

func (*ShowSeasonEpisodeService) Summary

Summary summary of an episode.

type ShowSeasonService

type ShowSeasonService struct {
	Client       *Client
	ShowID       uint64
	SeasonNumber uint16
}

ShowSeasonService services wrapping the seasons scope for a single season within the shows scope for a single show.

func (*ShowSeasonService) Episode

func (s *ShowSeasonService) Episode(episodeNumber uint16) *ShowSeasonEpisodeService

Episode creates a new ShowSeasonEpisodeService.

type ShowSeasonsService

type ShowSeasonsService struct {
	Client *Client
	ShowID uint64
}

ShowSeasonsService services wrapping the seasons scope within the shows scope for a single show.

func (*ShowSeasonsService) Summary

func (s *ShowSeasonsService) Summary(ctx context.Context) ([]*Season, error)

Summary of all seasons of a show.

type ShowService

type ShowService struct {
	Client *Client
	ShowID uint64
}

ShowService services wrapping the shows scope for a single show.

func (*ShowService) LastEpisode

func (s *ShowService) LastEpisode(ctx context.Context) (*BaseEpisode, error)

LastEpisode gets the most recently aired episode for a show.

func (*ShowService) Season

func (s *ShowService) Season(seasonNumber uint16) *ShowSeasonService

Season creates a new ShowSeasonService.

func (*ShowService) Seasons

func (s *ShowService) Seasons() *ShowSeasonsService

Seasons creates a new ShowSeasonsService.

type SyncService

type SyncService struct {
	Client *Client
}

SyncService services wrapping the sync scope.

func (*SyncService) AddHistory

func (s *SyncService) AddHistory(ctx context.Context, item *Item, watchedAt time.Time) (bool, error)

AddHistory remove watched item from history.

func (*SyncService) GetHistory

func (s *SyncService) GetHistory(ctx context.Context, itemType ItemType, itemID uint64) ([]*HistoryItem, error)

GetHistory get watches of movie, show, season or episode by type and id.

func (*SyncService) GetHistoryAll

func (s *SyncService) GetHistoryAll(ctx context.Context, itemType ItemType) ([]*HistoryItem, error)

GetHistoryAll get all watched movies, shows, seasons and episodes.

func (*SyncService) GetLastActivities

func (s *SyncService) GetLastActivities(ctx context.Context) (*LastActivities, error)

GetLastActivities gets information about the most recent activity for a user.

func (*SyncService) GetWatched

func (s *SyncService) GetWatched(ctx context.Context, itemType ItemType, seasons bool) ([]*Watched, error)

GetWatched gets watched information for the provided type.

func (*SyncService) GetWatchlist

func (s *SyncService) GetWatchlist(
	ctx context.Context,
	itemType ItemType,
	sort WatchlistSortBy,
) ([]*WatchlistItem, error)

GetWatchlist gets watchlist information for the provided item type and sorted by sort method. Default sort method is rank. Provided sort value is only used if itemType is not ItemTypeAll.

func (*SyncService) RemoveHistory

func (s *SyncService) RemoveHistory(ctx context.Context, historyID uint64) (bool, error)

RemoveHistory remove watched item from history.

type UserListService

type UserListService struct {
	Client   *Client
	UserID   string
	ListName string
}

UserListService services wrapping the list scope for a single list within the users scope for a single user.

func (*UserListService) Items

func (s *UserListService) Items(ctx context.Context) ([]*Item, error)

Items items on a list.

func (*UserListService) RemoveItems

func (s *UserListService) RemoveItems(ctx context.Context, traktKeys []*Key) (bool, error)

RemoveItems removes items from a list.

type UserService

type UserService struct {
	Client *Client
	UserID string
}

UserService services wrapping the users scope for a single user.

func (*UserService) List

func (s *UserService) List(name string) *UserListService

List creates a new UserListService.

type UserSettings

type UserSettings struct {
	User struct {
		Username             string `json:"username"`
		Name                 string `json:"name"`
		Private              bool   `json:"private"`
		VIP                  bool   `json:"vip"`
		VIPExecutiveProducer bool   `json:"vip_ep"`
		IDs                  struct {
			Slug string `json:"slug"`
		} `json:"ids"`
	} `json:"user"`
}

UserSettings response for a settings request.

type UsersService

type UsersService struct {
	Client *Client
}

UsersService services wrapping the users scope.

func (*UsersService) Settings

func (s *UsersService) Settings(ctx context.Context) (*UserSettings, error)

Settings get user settings.

type Watched

type Watched struct {
	Plays         uint16    `json:"plays"`
	LastWatchedAt time.Time `json:"last_watched_at"`
	LastUpdatedAt time.Time `json:"last_updated_at"`
	ResetAt       any       `json:"reset_at,omitempty"`
	Show          struct {
		Title string  `json:"title"`
		Year  uint16  `json:"year"`
		IDs   ItemIDs `json:"ids"`
	} `json:"show"`
	Seasons []struct {
		Number   uint16 `json:"number"`
		Episodes []struct {
			Number        uint16    `json:"number"`
			Plays         uint16    `json:"plays"`
			LastWatchedAt time.Time `json:"last_watched_at"`
		} `json:"episodes"`
	} `json:"seasons"`
	Movie struct {
		Title string  `json:"title"`
		Year  uint16  `json:"year"`
		IDs   ItemIDs `json:"ids"`
	} `json:"movie"`
}

Watched represents a watched movie, show, season or episode.

type WatchlistItem

type WatchlistItem struct {
	Rank     uint16    `json:"rank"`
	ID       uint64    `json:"id"`
	ListedAt time.Time `json:"listed_at"`
	Notes    string    `json:"notes"`
	Item
}

WatchlistItem a movie, show, season or episode from a watchlist response.

type WatchlistSortBy

type WatchlistSortBy string

WatchlistSortBy attribute to sort by.

const (
	WatchlistSortByRank     WatchlistSortBy = "rank"
	WatchlistSortByAdded    WatchlistSortBy = "added"
	WatchlistSortByReleased WatchlistSortBy = "released"
	WatchlistSortByTitle    WatchlistSortBy = "title"
)

WatchlistSortBy attributes.

Jump to

Keyboard shortcuts

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