letterboxd

package module
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2023 License: MIT Imports: 20 Imported by: 3

README

go-letterboxd

codecov Go Reference Go Report Card

Overview

Go client for reading Letterboxd data. This project provides a client that can be used to programatically access letterboxd public data.

Usage

Projects Using go-letterboxd

  • letterboxdctl - A command line interface for interacting with letterboxd.

Documentation

Overview

Package letterboxd is the client for interacting with the http api

Index

Constants

This section is empty.

Variables

View Source
var Professions = []string{"actor", "director", "producer", "writer"}

Professions is a string array of all the professions this module cares about

Functions

func BindDiaryFilterWithCobra added in v0.1.25

func BindDiaryFilterWithCobra(cmd *cobra.Command, opts DiaryCobraOpts)

BindDiaryFilterWithCobra inits all the pieces in a given Cmd to allow for diary filters

func DiaryFilterDateSpecified added in v0.1.24

func DiaryFilterDateSpecified(e DiaryEntry, f DiaryFilterOpts) bool

DiaryFilterDateSpecified only returns items that actually list the date they were watched

func DiaryFilterEarliest added in v0.1.24

func DiaryFilterEarliest(e DiaryEntry, f DiaryFilterOpts) bool

DiaryFilterEarliest filters based on the earliest date

func DiaryFilterLatest added in v0.1.24

func DiaryFilterLatest(e DiaryEntry, f DiaryFilterOpts) bool

DiaryFilterLatest filters based on the latest date

func DiaryFilterMaxRating added in v0.2.0

func DiaryFilterMaxRating(e DiaryEntry, f DiaryFilterOpts) bool

DiaryFilterMaxRating filters based on maximum rating

func DiaryFilterMinRating added in v0.2.0

func DiaryFilterMinRating(e DiaryEntry, f DiaryFilterOpts) bool

DiaryFilterMinRating filters based on minimum rating

func DiaryFilterRewatch added in v0.1.24

func DiaryFilterRewatch(e DiaryEntry, f DiaryFilterOpts) bool

DiaryFilterRewatch only show entries that are re-watches

func GetFilmographyProfessions

func GetFilmographyProfessions() []string

GetFilmographyProfessions is just a hard coded list of professions. Should this be a constant instead?

func WithBaseURL added in v0.2.2

func WithBaseURL(u string) func(*Client)

WithBaseURL sets the url (Example: https://letterboxd.com) to use for scraping

func WithCache added in v0.2.2

func WithCache(cc *cache.Cache) func(*Client)

WithCache applies a given cache.Cache to the letterboxd library

func WithNoCache added in v0.2.2

func WithNoCache() func(*Client)

WithNoCache removes the default cache

Types

type Client

type Client struct {
	UserAgent string

	// Options
	MaxConcurrentPages int
	Cache              *cache.Cache

	User UserService
	Film FilmService
	List ListService
	URL  URLService
	// contains filtered or unexported fields
}

Client represents the thing containing services and methods for interacting with Letterboxd

func New added in v0.2.2

func New(options ...func(*Client)) *Client

New returns a new client using functional options

type ClientConfig added in v0.1.7

type ClientConfig struct {
	HTTPClient         *http.Client
	BaseURL            string
	MaxConcurrentPages int
	DisableCache       bool
	RedisHost          string
	RedisPassword      string
	RedisDB            int
	Cache              *cache.Cache
	CacheTime          *time.Duration
	// Maybe favor this instead of cache.Cache?
	RedisClient *redis.Client
}

ClientConfig is the configuration strcut for the client

type DiaryCobraOpts added in v0.2.0

type DiaryCobraOpts struct {
	Prefix string
}

DiaryCobraOpts allows customization of the options passed in to Cobra Cmd

type DiaryEntries added in v0.1.24

type DiaryEntries []*DiaryEntry

DiaryEntries is multiple DiaryEntry items

func ApplyDiaryFilters added in v0.1.24

func ApplyDiaryFilters(records DiaryEntries, opts DiaryFilterOpts, filters ...DiaryFilter) DiaryEntries

ApplyDiaryFilters applies all of the given filters to a given diary

func SlurpDiary added in v0.1.21

func SlurpDiary(itemC chan *DiaryEntry, doneC chan error) (DiaryEntries, error)

SlurpDiary is just a helper to quickly read in all Diary streams

type DiaryEntry added in v0.1.21

type DiaryEntry struct {
	Watched       *time.Time
	Rating        *int
	Rewatch       bool
	SpecifiedDate bool
	Film          *Film
	Slug          *string
}

DiaryEntry is a specific film from a users Diary

func NewDiaryEntry added in v0.2.2

func NewDiaryEntry(s *goquery.Selection) *DiaryEntry

NewDiaryEntry returns a new DiaryEntry with attributes for a goquery.Selection

type DiaryFilter added in v0.1.24

type DiaryFilter func(DiaryEntry, DiaryFilterOpts) bool

DiaryFilter is a generic function to filter diary entries

type DiaryFilterBulk added in v0.1.24

type DiaryFilterBulk func(DiaryEntries, DiaryFilterOpts) DiaryEntries

DiaryFilterBulk is a generic function to filter diary entries in bulk

type DiaryFilterOpts added in v0.1.24

type DiaryFilterOpts struct {
	Earliest      *time.Time
	Latest        *time.Time
	MinRating     *int
	MaxRating     *int
	Rewatch       *bool
	SpecifiedDate *bool
}

DiaryFilterOpts provides options for filtering a user diary

func DiaryFilterWithCobra added in v0.1.25

func DiaryFilterWithCobra(cmd *cobra.Command, dopts DiaryCobraOpts) (*DiaryFilterOpts, error)

DiaryFilterWithCobra returns a diary filter from a Cobra Cmd

type ErrorResponse

type ErrorResponse struct {
	Message string `json:"errors"`
}

ErrorResponse just contains the errors of a response

type ExternalFilmIDs

type ExternalFilmIDs struct {
	IMDB string `json:"imdb"`
	TMDB string `json:"tmdb"`
}

ExternalFilmIDs references 3rd party IDs for a given film

type Film

type Film struct {
	ID          string           `json:"id"`
	Title       string           `json:"title"`
	Slug        string           `json:"slug"`
	Target      string           `json:"target"`
	Year        int              `json:"year"`
	ExternalIDs *ExternalFilmIDs `json:"external_ids,omitempty"`
}

Film represents a Letterboxd Film

func NewFilm added in v0.2.2

func NewFilm() *Film

NewFilm initializes a new Film pointer

type FilmBatchOpts

type FilmBatchOpts struct {
	Watched   []string  `json:"watched"`
	List      []*ListID `json:"list"`
	WatchList []string  `json:"watchlist"`
}

FilmBatchOpts provides options for retrieving a batch of films

type FilmListOpts added in v0.1.23

type FilmListOpts struct {
	SortBy       string
	ShufflePages bool
	PageCount    int
}

FilmListOpts options for listing films

type FilmService

type FilmService interface {
	EnhanceFilm(context.Context, *Film) error
	EnhanceFilmList(context.Context, *FilmSet) error
	Filmography(context.Context, *FilmographyOpt) (FilmSet, error)
	Get(context.Context, string) (*Film, error)
	GetWatchedIMDBIDs(context.Context, string) ([]string, error)
	ExtractFilmsWithPath(context.Context, string) (FilmSet, *Pagination, error)
	ExtractEnhancedFilmsWithPath(context.Context, string) (FilmSet, *Pagination, error)
	StreamBatch(context.Context, *FilmBatchOpts, chan *Film, chan error)
	List(context.Context, *FilmListOpts) (FilmSet, error)
}

FilmService defines a service to handle methods against Letterboxd films

type FilmServiceOp

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

FilmServiceOp is the operator for a FilmService

func (*FilmServiceOp) EnhanceFilm

func (f *FilmServiceOp) EnhanceFilm(ctx context.Context, film *Film) error

EnhanceFilm Given a film, with some minimal information (like the slug), get as much data as you can

func (*FilmServiceOp) EnhanceFilmList

func (f *FilmServiceOp) EnhanceFilmList(ctx context.Context, films *FilmSet) error

EnhanceFilmList takes a list of films, and returns the enhanced version

func (*FilmServiceOp) ExtractEnhancedFilmsWithPath

func (f *FilmServiceOp) ExtractEnhancedFilmsWithPath(ctx context.Context, path string) (FilmSet, *Pagination, error)

ExtractEnhancedFilmsWithPath returns a list of data enriched films from a URL path

func (*FilmServiceOp) ExtractFilmsWithPath

func (f *FilmServiceOp) ExtractFilmsWithPath(ctx context.Context, path string) (FilmSet, *Pagination, error)

ExtractFilmsWithPath Given a url path, return a list of films it contains

func (*FilmServiceOp) Filmography

func (f *FilmServiceOp) Filmography(ctx context.Context, opt *FilmographyOpt) (FilmSet, error)

Filmography returns the Filmography based on certain options

func (*FilmServiceOp) Get

func (f *FilmServiceOp) Get(ctx context.Context, slug string) (*Film, error)

Get returns a single film from the slug

func (*FilmServiceOp) GetWatchedIMDBIDs added in v0.1.17

func (f *FilmServiceOp) GetWatchedIMDBIDs(ctx context.Context, username string) ([]string, error)

GetWatchedIMDBIDs returns a list of imdb ids that have been watched by a given user

func (*FilmServiceOp) List added in v0.1.23

func (f *FilmServiceOp) List(ctx context.Context, opts *FilmListOpts) (FilmSet, error)

List lists out all films using the given options

func (*FilmServiceOp) StreamBatch

func (f *FilmServiceOp) StreamBatch(ctx context.Context, batchOpts *FilmBatchOpts, filmsC chan *Film, done chan error)

StreamBatch Get a bunch of different films at once and stream them back to the user

type FilmSet added in v0.1.23

type FilmSet []*Film

FilmSet is just a list of pointers to Film items

func SlurpFilms added in v0.1.9

func SlurpFilms(filmC chan *Film, errorC chan error) (FilmSet, error)

SlurpFilms Helper blocking function to slurp a batch of films from the streaming calls. This negates the whole 'Streaming' thing, so use sparingly

func (*FilmSet) IMDBIDs added in v0.1.23

func (fs *FilmSet) IMDBIDs() []string

IMDBIDs returns a list of IMDB IDs from a FilmSet

func (*FilmSet) TMDBIDs added in v0.1.23

func (fs *FilmSet) TMDBIDs() []string

TMDBIDs returns a list of TMDB IDs from a FilmSet

type FilmographyOpt

type FilmographyOpt struct {
	Person     string // Person whos filmography is to be fetched
	Profession string // Profession of the person (actor, writer, director)
}

FilmographyOpt is the options for a filmography

func (*FilmographyOpt) Validate

func (f *FilmographyOpt) Validate() error

Validate ensures that filmography options contains the appropriate fields

type ListFilmsOpt

type ListFilmsOpt struct {
	User      string // Username of the user for the list. Example: 'dave'
	Slug      string // Slug of the list: Example: 'official-top-250-narrative-feature-films'
	FirstPage int    // First page to fetch. Defaults to 1
	LastPage  int    // Last page to fetch. Defaults to FirstPage. Use -1 to fetch all pages
}

ListFilmsOpt is the options for the ListFilms method

type ListID

type ListID struct {
	User string
	Slug string
}

ListID is the base amount of info we need to find a list

func ParseListArgs

func ParseListArgs(args []string) ([]*ListID, error)

ParseListArgs Given a slice of strings, return a slice of ListIDs

type ListService

type ListService interface {
	GetOfficialMap(context.Context) map[string]string
	GetOfficial(context.Context) []*ListID
}

ListService is the interface defining which methods we can use for List items

type ListServiceOp

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

ListServiceOp is the Operator for the ListService

func (*ListServiceOp) GetOfficial added in v0.1.20

func (l *ListServiceOp) GetOfficial(ctx context.Context) []*ListID

GetOfficial returns the official lists as a slice

func (*ListServiceOp) GetOfficialMap added in v0.1.20

func (l *ListServiceOp) GetOfficialMap(ctx context.Context) map[string]string

GetOfficialMap returns the official letterboxd lists using the slug as the key

type PageData

type PageData struct {
	Data       interface{}
	Pagination Pagination
}

PageData just provides Pagination info and 'Data'

type Pagination

type Pagination struct {
	CurrentPage  int  `json:"current_page"`
	NextPage     int  `json:"next_page"`
	TotalPages   int  `json:"total_pages"`
	TotalItems   int  `json:"total_items"`
	ItemsPerPage int  `json:"items_per_page"`
	IsLast       bool `json:"is_last"`
}

Pagination contains all the information about a pages pagination

func ExtractPagination added in v0.2.3

func ExtractPagination(r io.Reader) (*Pagination, error)

ExtractPagination pulls the pagination from an io.Reader

func ExtractPaginationWithDoc

func ExtractPaginationWithDoc(doc *goquery.Document) (*Pagination, error)

ExtractPaginationWithDoc returns a pagination object from a goquery Doc

func ExtractPeople added in v0.2.0

func ExtractPeople(r io.Reader) (interface{}, *Pagination, error)

ExtractPeople returns people from a given io.Reader

func ExtractPeopleWithBytes added in v0.2.0

func ExtractPeopleWithBytes(b []byte) (interface{}, *Pagination, error)

ExtractPeopleWithBytes returns people from a given byte array

func ExtractUser

func ExtractUser(r io.Reader) (interface{}, *Pagination, error)

ExtractUser returns a user from a given io.Reader

func ExtractUserFilms

func ExtractUserFilms(r io.Reader) (interface{}, *Pagination, error)

ExtractUserFilms returns a list of films from an io.Reader

func (*Pagination) SetTotalItems added in v0.2.1

func (p *Pagination) SetTotalItems(i int)

SetTotalItems will set the TotalItems count, along with anything else that needs an update based on the TotalItems

type Response

type Response struct {
	*http.Response
	FromCache bool
}

Response holds the http response and metadata arounda given request

type URLService

type URLService interface {
	Items(ctx context.Context, url string) (interface{}, error)
}

URLService is an interface for defining methods on a URL

type URLServiceOp

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

URLServiceOp is the operator for an URLService

func (*URLServiceOp) Items

func (u *URLServiceOp) Items(ctx context.Context, lurl string) (interface{}, error)

Items returns items from an URLService

type User

type User struct {
	Username         string   `json:"username"`
	Bio              string   `json:"bio,omitempty"`
	WatchedFilmCount int      `json:"watched_film_count"`
	Following        []string `json:"following"`
	Followers        []string `json:"followers"`
}

User represents a Letterboxd user

type UserService

type UserService interface {
	Exists(context.Context, string) (bool, error)
	Profile(context.Context, string) (*User, *Response, error)
	Following(context.Context, string) ([]string, *Response, error)
	Followers(context.Context, string) ([]string, *Response, error)
	// Interact with Diary
	StreamDiary(context.Context, string, chan *DiaryEntry, chan error)
	Diary(context.Context, string) (DiaryEntries, error)
	MustDiary(context.Context, string) DiaryEntries

	StreamList(context.Context, string, string, chan *Film, chan error)
	StreamWatched(context.Context, string, chan *Film, chan error)
	StreamWatchList(context.Context, string, chan *Film, chan error)
	WatchList(context.Context, string) (FilmSet, *Response, error)
	ExtractDiaryEntries(io.Reader) (interface{}, *Pagination, error)
}

UserService provides an interface to user methods

type UserServiceOp

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

UserServiceOp is the operator for the UserService

func (*UserServiceOp) Diary added in v0.1.24

func (u *UserServiceOp) Diary(ctx context.Context, username string) (DiaryEntries, error)

Diary returns all diary entries for a given order, sorted by watched date, with the most recent watches first

func (*UserServiceOp) Exists

func (u *UserServiceOp) Exists(ctx context.Context, userID string) (bool, error)

Exists returns a boolion on if a user exists

func (*UserServiceOp) ExtractDiaryEntries added in v0.1.21

func (u *UserServiceOp) ExtractDiaryEntries(r io.Reader) (interface{}, *Pagination, error)

ExtractDiaryEntries returns a list of DiaryEntries

func (*UserServiceOp) Followers added in v0.2.1

func (u *UserServiceOp) Followers(ctx context.Context, userID string) ([]string, *Response, error)

Followers returns a list of users a given id is following

func (*UserServiceOp) Following added in v0.2.0

func (u *UserServiceOp) Following(ctx context.Context, userID string) ([]string, *Response, error)

Following returns a list of users following a given user

func (*UserServiceOp) MustDiary added in v0.1.24

func (u *UserServiceOp) MustDiary(ctx context.Context, username string) DiaryEntries

MustDiary See GetDiary, but will panic instead of returning an error

func (*UserServiceOp) Profile

func (u *UserServiceOp) Profile(ctx context.Context, userID string) (*User, *Response, error)

Profile returns a bunch of information about a given user

func (*UserServiceOp) StreamDiary added in v0.1.21

func (u *UserServiceOp) StreamDiary(ctx context.Context, username string, dec chan *DiaryEntry, done chan error)

StreamDiary streams a users diary in to the given channels

func (*UserServiceOp) StreamList added in v0.1.3

func (u *UserServiceOp) StreamList(
	ctx context.Context,
	username string,
	slug string,
	rchan chan *Film,
	done chan error,
)

StreamList streams a list back through channels

func (*UserServiceOp) StreamWatchList added in v0.1.2

func (u *UserServiceOp) StreamWatchList(
	ctx context.Context,
	username string,
	rchan chan *Film,
	done chan error,
)

StreamWatchList streams a WatchList back to channels

func (*UserServiceOp) StreamWatched

func (u *UserServiceOp) StreamWatched(ctx context.Context, userID string, rchan chan *Film, done chan error)

StreamWatched streams a given list of Watched films

func (*UserServiceOp) WatchList

func (u *UserServiceOp) WatchList(ctx context.Context, userID string) (FilmSet, *Response, error)

WatchList returns a given users watchlist

Jump to

Keyboard shortcuts

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