crunchyroll

package module
v3.0.8 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2023 License: LGPL-3.0 Imports: 21 Imported by: 0

README ΒΆ

crunchyroll-go

A Go library & cli for the undocumented crunchyroll api. To use it, you need a crunchyroll premium account to for full (api) access.

If you're searching for the command line client, head over to crunchy-cli. This repo only contains the golang crunchyroll library!

Code size License Go version Release Discord CI

Beginning with version v3, this project is set to maintenance mode (only small fixes, no new features) in favor of rewriting it completely in Rust. Go bindings for the finished rust rewrite will be provided.

πŸ“₯ Download

Download the library via go get

$ go get github.com/ottdump/crunchyroll-go/v3

πŸ“š Documentation

The documentation is available on pkg.go.dev.

β˜‚οΈ Coverage

As of 19.10.2022 Crunchyroll rolled out a breaking change for their website which makes some of this library function unusable

Around 90% - 95% of the crunchyroll api (at state of writing) are implemented. Only some endpoints on the home / index screen are missing. Since the library will be rewritten in Rust, I don't see any further use cases of implementing the missing endpoints in this project. They would be useless for 99% of the library usage anyway, unless you want to rebuild crunchyroll on top of it (or for whatever reason you want to implement home screen endpoints).

βš– License

This project is licensed under the GNU Lesser General Public License v3.0 (LGPL-3.0) - see the LICENSE file for more details.

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

View Source
const (
	JP  LOCALE = "ja-JP"
	US         = "en-US"
	LA         = "es-419"
	LA2        = "es-LA"
	ES         = "es-ES"
	FR         = "fr-FR"
	PT         = "pt-PT"
	BR         = "pt-BR"
	IT         = "it-IT"
	DE         = "de-DE"
	RU         = "ru-RU"
	AR         = "ar-SA"
	ME         = "ar-ME"
	CN         = "zh-CN"
	IN         = "hi-IN"
	IN2        = "en-IN"
)
View Source
const (
	WatchlistEntryEpisode = "episode"
	WatchlistEntrySeries  = "series"
)
View Source
const (
	OneStar    ReviewRating = "s1"
	TwoStars                = "s2"
	ThreeStars              = "s3"
	FourStars               = "s4"
	FiveStars               = "s5"
)
View Source
const (
	BrowseSortPopularity   BrowseSortType = "popularity"
	BrowseSortNewlyAdded                  = "newly_added"
	BrowseSortAlphabetical                = "alphabetical"
)
View Source
const (
	ReviewSortNewest  ReviewSortType = "newest"
	ReviewSortOldest                 = "oldest"
	ReviewSortHelpful                = "helpful"
)
View Source
const (
	WatchlistOrderAsc  = "asc"
	WatchlistOrderDesc = "desc"
)

Variables ΒΆ

This section is empty.

Functions ΒΆ

func ParseEpisodeURL ΒΆ

func ParseEpisodeURL(url string) (episodeId string, ok bool)

ParseEpisodeURL tries to extract the episode id of the given crunchyroll url, pointing to an episode.

func ParseSeriesURL ΒΆ

func ParseSeriesURL(url string) (seasonId string, ok bool)

ParseSeriesURL tries to extract the season id of the given crunchyroll url, pointing to a season.

Types ΒΆ

type Account ΒΆ

type Account struct {
	AccountID     string    `json:"account_id"`
	ExternalID    string    `json:"external_id"`
	EmailVerified bool      `json:"email_verified"`
	Created       time.Time `json:"created"`

	Avatar                           string `json:"avatar"`
	CrBetaOptIn                      bool   `json:"cr_beta_opt_in"`
	Email                            string `json:"email"`
	MatureContentFlagManga           string `json:"mature_content_flag_manga"`
	MaturityRating                   string `json:"maturity_rating"`
	OptOutAndroidInAppMarketing      bool   `json:"opt_out_android_in_app_marketing"`
	OptOutFreeTrials                 bool   `json:"opt_out_free_trials"`
	OptOutNewMediaQueueUpdates       bool   `json:"opt_out_new_media_queue_updates"`
	OptOutNewsletters                bool   `json:"opt_out_newsletters"`
	OptOutPmUpdates                  bool   `json:"opt_out_pm_updates"`
	OptOutPromotionalUpdates         bool   `json:"opt_out_promotional_updates"`
	OptOutQueueUpdates               bool   `json:"opt_out_queue_updates"`
	OptOutStoreDeals                 bool   `json:"opt_out_store_deals"`
	PreferredCommunicationLanguage   LOCALE `json:"preferred_communication_language"`
	PreferredContentSubtitleLanguage LOCALE `json:"preferred_content_subtitle_language"`
	QaUser                           bool   `json:"qa_user"`

	Username  string     `json:"username"`
	Wallpaper *Wallpaper `json:"wallpaper"`
	// contains filtered or unexported fields
}

Account contains information about a crunchyroll account.

func (*Account) AvailableWallpapers ΒΆ

func (a *Account) AvailableWallpapers() (w []*Wallpaper, err error)

AvailableWallpapers returns all available wallpapers which can be set as profile wallpaper.

func (*Account) ChangeEmail ΒΆ

func (a *Account) ChangeEmail(currentPassword, newEmail string) error

ChangeEmail changes the email address for the current account.

func (*Account) ChangePassword ΒΆ

func (a *Account) ChangePassword(currentPassword, newPassword string) error

ChangePassword changes the password for the current account.

func (*Account) ChangeWallpaper ΒΆ

func (a *Account) ChangeWallpaper(wallpaper *Wallpaper) error

ChangeWallpaper changes the profile wallpaper of the current user. Use AvailableWallpapers to get all available ones.

func (*Account) UpdateMatureMangaContent ΒΆ

func (a *Account) UpdateMatureMangaContent(enabled bool) error

UpdateMatureMangaContent sets if mature manga content / 18+ content should be shown

func (*Account) UpdateMatureVideoContent ΒΆ

func (a *Account) UpdateMatureVideoContent(enabled bool) error

UpdateMatureVideoContent sets if mature video content / 18+ content should be shown

func (*Account) UpdatePreferredEmailLanguage ΒΆ

func (a *Account) UpdatePreferredEmailLanguage(language LOCALE) error

UpdatePreferredEmailLanguage sets in which language emails should be received.

func (*Account) UpdatePreferredVideoSubtitleLanguage ΒΆ

func (a *Account) UpdatePreferredVideoSubtitleLanguage(language LOCALE) error

UpdatePreferredVideoSubtitleLanguage sets in which language default subtitles should be shown

type BrowseOptions ΒΆ

type BrowseOptions struct {
	// Categories specifies the categories of the entries.
	Categories []string `param:"categories"`

	// IsDubbed specifies whether the entries should be dubbed.
	IsDubbed bool `param:"is_dubbed"`

	// IsSubbed specifies whether the entries should be subbed.
	IsSubbed bool `param:"is_subbed"`

	// Simulcast specifies a particular simulcast season by id in which the entries have been aired.
	Simulcast string `param:"season_tag"`

	// Sort specifies how the entries should be sorted.
	Sort BrowseSortType `param:"sort_by"`

	// Start specifies the index from which the entries should be returned.
	Start uint `param:"start"`

	// Type specifies the media type of the entries.
	Type MediaType `param:"type"`
}

BrowseOptions represents options for browsing the crunchyroll catalog.

type BrowseSortType ΒΆ

type BrowseSortType string

BrowseSortType represents a sort type to sort Crunchyroll.Browse items after.

type BulkResult ΒΆ

type BulkResult[T any] struct {
	Items []T `json:"items"`
	Total int `json:"total"`
}

type Category ΒΆ

type Category struct {
	Category string `json:"tenant_category"`

	SubCategories []struct {
		Category       string `json:"tenant_category"`
		ParentCategory string `json:"parent_category"`

		Localization struct {
			Title       string `json:"title"`
			Description string `json:"description"`
			Locale      LOCALE `json:"locale"`
		} `json:"localization"`

		Slug string `json:"slug"`
	} `json:"sub_categories"`

	Images struct {
		Background []Image `json:"background"`
		Low        []Image `json:"low"`
	} `json:"images"`

	Localization struct {
		Title       string `json:"title"`
		Description string `json:"description"`
		Locale      LOCALE `json:"locale"`
	} `json:"localization"`

	Slug string `json:"slug"`
}

Category contains all information about a category.

type Comment ΒΆ

type Comment struct {
	EpisodeID string `json:"episode_id"`

	CommentID string `json:"comment_id"`
	DomainID  string `json:"domain_id"`

	GuestbookKey string `json:"guestbook_key"`

	User struct {
		UserKey        string `json:"user_key"`
		UserAttributes struct {
			Username string `json:"username"`
			Avatar   struct {
				Locked   []Image `json:"locked"`
				Unlocked []Image `json:"unlocked"`
			} `json:"avatar"`
		} `json:"user_attributes"`
		UserFlags []any `json:"user_flags"`
	} `json:"user"`

	Message         string `json:"message"`
	ParentCommentID int    `json:"parent_comment_id"`

	Locale LOCALE `json:"locale"`

	UserVotes []string `json:"user_votes"`
	Flags     []string `json:"flags"`
	Votes     struct {
		Inappropriate int `json:"inappropriate"`
		Like          int `json:"like"`
		Spoiler       int `json:"spoiler"`
	} `json:"votes"`

	DeleteReason any `json:"delete_reason"`

	Created  time.Time `json:"created"`
	Modified time.Time `json:"modified"`

	IsOwner      bool `json:"is_owner"`
	RepliesCount int  `json:"replies_count"`
	// contains filtered or unexported fields
}

Comment contains all information about a comment.

func (*Comment) Delete ΒΆ

func (c *Comment) Delete() error

Delete deleted the current comment. Works only if the user has written the comment.

func (*Comment) FlagAsSpoiler ΒΆ

func (c *Comment) FlagAsSpoiler() error

FlagAsSpoiler sends a request to the user (and / or crunchyroll?) to mark the comment as spoiler. Only works if the comment hasn't been flagged as spoiler yet.

func (*Comment) IsFlaggedAsSpoiler ΒΆ

func (c *Comment) IsFlaggedAsSpoiler() bool

func (*Comment) IsReported ΒΆ

func (c *Comment) IsReported() bool

func (*Comment) IsSpoiler ΒΆ

func (c *Comment) IsSpoiler() bool

IsSpoiler returns if the comment is marked as spoiler or not.

func (*Comment) Like ΒΆ

func (c *Comment) Like() error

Like likes the comment. Works only if the user hasn't already liked it.

func (*Comment) Liked ΒΆ

func (c *Comment) Liked() bool

Liked returns if the user has liked the comment.

func (*Comment) MarkAsSpoiler ΒΆ

func (c *Comment) MarkAsSpoiler() error

MarkAsSpoiler marks the current comment as spoiler. Works only if the user has written the comment, and it isn't already marked as spoiler.

func (*Comment) RemoveLike ΒΆ

func (c *Comment) RemoveLike() error

RemoveLike removes the like from the comment. Works only if the user has liked it.

func (*Comment) RemoveReport ΒΆ

func (c *Comment) RemoveReport() error

RemoveReport removes the report request from the comment. Only works if the user has reported the comment.

func (*Comment) Replies ΒΆ

func (c *Comment) Replies(page uint, size uint) ([]*Comment, error)

Replies shows all replies to the current comment.

func (*Comment) Reply ΒΆ

func (c *Comment) Reply(message string, spoiler bool) (*Comment, error)

Reply replies to the current comment.

func (*Comment) Report ΒΆ

func (c *Comment) Report() error

Report reports the comment. Only works if the comment hasn't been reported yet.

func (*Comment) UnflagAsSpoiler ΒΆ

func (c *Comment) UnflagAsSpoiler() error

UnflagAsSpoiler rewokes the request to the user (and / or crunchyroll?) to mark the comment as spoiler. Only works if the user has flagged the comment as spoiler.

func (*Comment) UnmarkAsSpoiler ΒΆ

func (c *Comment) UnmarkAsSpoiler() error

UnmarkAsSpoiler unmarks the current comment as spoiler. Works only if the user has written the comment, and it is already marked as spoiler.

type CommentsOptions ΒΆ

type CommentsOptions struct {
	// Order specified the order how the comments should be returned.
	Order CommentsOrderType `json:"order"`

	// Sort specified after which key the comments should be sorted.
	Sort CommentsSortType `json:"sort"`
}

type CommentsOrderType ΒΆ

type CommentsOrderType string

CommentsOrderType represents a sort type to sort Episode.Comments after.

const (
	CommentsOrderAsc  CommentsOrderType = "asc"
	CommentsOrderDesc                   = "desc"
)

type CommentsSortType ΒΆ

type CommentsSortType string

CommentsSortType specified after which factor Episode.Comments should be sorted.

const (
	CommentsSortPopular CommentsSortType = "popular"
	CommentsSortDate                     = "date"
)

type Crunchylist ΒΆ

type Crunchylist struct {
	ID string `json:"id"`

	Max        int                `json:"max"`
	Total      int                `json:"total"`
	Title      string             `json:"title"`
	IsPublic   bool               `json:"is_public"`
	ModifiedAt time.Time          `json:"modified_at"`
	Items      []*CrunchylistItem `json:"items"`
	// contains filtered or unexported fields
}

Crunchylist contains information about a crunchylist.

func (*Crunchylist) AddSeries ΒΆ

func (cl *Crunchylist) AddSeries(series *Series) error

AddSeries adds a series.

func (*Crunchylist) AddSeriesFromID ΒΆ

func (cl *Crunchylist) AddSeriesFromID(id string) error

AddSeriesFromID adds a series from its id

func (*Crunchylist) Delete ΒΆ

func (cl *Crunchylist) Delete() error

Delete deleted the current crunchylist.

func (*Crunchylist) RemoveSeries ΒΆ

func (cl *Crunchylist) RemoveSeries(series *Series) error

RemoveSeries removes a series

func (*Crunchylist) RemoveSeriesFromID ΒΆ

func (cl *Crunchylist) RemoveSeriesFromID(id string) error

RemoveSeriesFromID removes a series by its id

func (*Crunchylist) Rename ΒΆ

func (cl *Crunchylist) Rename(name string) error

Rename renames the current crunchylist.

type CrunchylistItem ΒΆ

type CrunchylistItem struct {
	ListID     string    `json:"list_id"`
	ID         string    `json:"id"`
	ModifiedAt time.Time `json:"modified_at"`
	Panel      Panel     `json:"panel"`
	// contains filtered or unexported fields
}

CrunchylistItem represents a series, saved in Crunchylist.

func (*CrunchylistItem) Remove ΒΆ

func (cli *CrunchylistItem) Remove() error

Remove removes the current item from its crunchylist.

type CrunchylistPreview ΒΆ

type CrunchylistPreview struct {
	ListID     string    `json:"list_id"`
	IsPublic   bool      `json:"is_public"`
	Total      int       `json:"total"`
	ModifiedAt time.Time `json:"modified_at"`
	Title      string    `json:"title"`
	// contains filtered or unexported fields
}

CrunchylistPreview is a preview to Crunchylist.

func (*CrunchylistPreview) Crunchylist ΒΆ

func (clp *CrunchylistPreview) Crunchylist() (*Crunchylist, error)

Crunchylist returns the belonging Crunchylist struct.

type Crunchylists ΒΆ

type Crunchylists struct {
	Items        []*CrunchylistPreview `json:"items"`
	TotalPublic  int                   `json:"total_public"`
	TotalPrivate int                   `json:"total_private"`
	MaxPrivate   int                   `json:"max_private"`
	// contains filtered or unexported fields
}

Crunchylists contains all information about a crunchylists

func (*Crunchylists) Create ΒΆ

func (cl *Crunchylists) Create(name string) (*Crunchylist, error)

Create creates a new crunchylist with the given name. Duplicate names for lists are allowed.

type Crunchyroll ΒΆ

type Crunchyroll struct {
	// Client is the http.Client to perform all requests over.
	Client *http.Client
	// Context can be used to stop requests with Client and is context.Background by default.
	Context context.Context
	// Locale specifies in which language all results should be returned / requested.
	Locale LOCALE
	// RefreshToken is the crunchyroll beta equivalent to a session id (prior SessionID field in
	// this struct in v2 and below).
	RefreshToken string

	// Config stores parameters which are needed by some api calls.
	Config struct {
		TokenType   string
		AccessToken string

		Bucket string

		CountryCode    string
		Premium        bool
		Channel        string
		Policy         string
		Signature      string
		KeyPairID      string
		AccountID      string
		ExternalID     string
		MaturityRating string
	}
	// contains filtered or unexported fields
}

Crunchyroll is the base struct which is needed for every request and contains the most important information. Use LoginWithCredentials, LoginWithRefreshToken or LoginWithSessionID to create a new instance.

func LoginWithCredentials ΒΆ

func LoginWithCredentials(user string, password string, locale LOCALE, client *http.Client) (*Crunchyroll, error)

LoginWithCredentials logs in via crunchyroll username or email and password.

func LoginWithRefreshToken ΒΆ

func LoginWithRefreshToken(refreshToken string, locale LOCALE, client *http.Client) (*Crunchyroll, error)

LoginWithRefreshToken logs in via the crunchyroll refresh token. It can be obtained by copying the etp_rt cookie from beta.crunchyroll.com. The etp_rt cookie is automatically set when visiting https://www.crunchyroll.com. Note that you need a crunchyroll account to access it.

func LoginWithSessionID deprecated

func LoginWithSessionID(sessionID string, locale LOCALE, client *http.Client) (*Crunchyroll, error)

LoginWithSessionID logs in via a crunchyroll session id. Session ids are automatically generated as a cookie when visiting https://www.crunchyroll.com.

Deprecated: Login via session id caused some trouble in the past (e.g. #15 or #30) which resulted in login not working. Use LoginWithRefreshToken instead. The method will stay in the library until session id login is removed completely or login with it does not work for a longer period of time.

func (*Crunchyroll) Account ΒΆ

func (c *Crunchyroll) Account() (*Account, error)

Account returns information about the currently logged in crunchyroll account.

func (*Crunchyroll) Browse ΒΆ

func (c *Crunchyroll) Browse(options BrowseOptions, limit uint) (s []*Series, m []*Movie, err error)

Browse browses the crunchyroll catalog filtered by the specified options and returns all found series and movies within the given limit.

func (*Crunchyroll) Categories ΒΆ

func (c *Crunchyroll) Categories(includeSubcategories bool) (ca []*Category, err error)

Categories returns all available categories and possible subcategories.

func (*Crunchyroll) Crunchylists ΒΆ

func (c *Crunchyroll) Crunchylists() (*Crunchylists, error)

Crunchylists returns a struct to control crunchylists.

func (*Crunchyroll) ExtractEpisodesFromUrl ΒΆ

func (c *Crunchyroll) ExtractEpisodesFromUrl(url string, audio ...LOCALE) ([]*Episode, error)

ExtractEpisodesFromUrl extracts all episodes from an url. If audio is not empty, the episodes gets filtered after the given locale.

func (*Crunchyroll) FindEpisodeByName ΒΆ

func (c *Crunchyroll) FindEpisodeByName(seriesName, episodeTitle string) ([]*Episode, error)

FindEpisodeByName finds an episode by its crunchyroll series name and episode title. Use this in combination with ParseEpisodeURL and hand over the corresponding results to this function.

func (*Crunchyroll) FindVideoByName deprecated

func (c *Crunchyroll) FindVideoByName(seriesName string) (Video, error)

FindVideoByName finds a Video (Season or Movie) by its name. Use this in combination with ParseVideoURL and hand over the corresponding results to this function.

Deprecated: Use Search instead. The first result sometimes isn't the correct one so this function is inaccurate in some cases. See https://github.com/ByteDream/crunchyroll-go/issues/22 for more information.

func (*Crunchyroll) InvalidateSession ΒΆ

func (c *Crunchyroll) InvalidateSession() error

InvalidateSession logs the user out which invalidates the current session. You have to call a login method again and create a new Crunchyroll instance if you want to perform any further actions since this instance is not usable anymore after calling this.

func (*Crunchyroll) IsCaching ΒΆ

func (c *Crunchyroll) IsCaching() bool

IsCaching returns if data gets cached or not. See SetCaching for more information.

func (*Crunchyroll) News ΒΆ

func (c *Crunchyroll) News(topLimit uint, latestLimit uint) (t []*News, l []*News, err error)

News returns the top and latest news from crunchyroll for the current locale within the given limits.

func (*Crunchyroll) ParseUrl ΒΆ

func (c *Crunchyroll) ParseUrl(url string) (*Series, []*Episode, error)

ParseUrl parses the given url into a series or episode. The returning episode is a slice because non-beta urls have the same episode with different languages.

func (*Crunchyroll) Recommendations ΒΆ

func (c *Crunchyroll) Recommendations(limit uint) (s []*Series, m []*Movie, err error)

Recommendations returns series and movie recommendations from crunchyroll based on the currently logged in account within the given limit.

func (*Crunchyroll) Search ΒΆ

func (c *Crunchyroll) Search(query string, limit uint) (s []*Series, m []*Movie, err error)

Search searches a query and returns all found series and movies within the given limit.

func (*Crunchyroll) SetCaching ΒΆ

func (c *Crunchyroll) SetCaching(caching bool)

SetCaching enables or disables internal caching of requests made. Caching is enabled by default. If it is disabled the already cached data still gets called. The best way to prevent this is to create a complete new Crunchyroll struct.

func (*Crunchyroll) Simulcasts ΒΆ

func (c *Crunchyroll) Simulcasts() (s []*Simulcast, err error)

Simulcasts returns all available simulcast seasons for the current locale.

func (*Crunchyroll) UpNext ΒΆ

func (c *Crunchyroll) UpNext(limit uint) (e []*Episode, err error)

UpNext returns the episodes that are up next based on the currently logged in account within the given limit.

func (*Crunchyroll) WatchHistory ΒΆ

func (c *Crunchyroll) WatchHistory(page uint, size uint) (e []*HistoryEpisode, err error)

WatchHistory returns the history of watched episodes based on the currently logged in account from the given page with the given size.

func (*Crunchyroll) Watchlist ΒΆ

func (c *Crunchyroll) Watchlist(options WatchlistOptions, limit uint) ([]*WatchlistEntry, error)

Watchlist returns the watchlist entries for the currently logged in user.

type Downloader ΒΆ

type Downloader struct {
	// The output is all written to Writer.
	Writer io.Writer

	// TempDir is the directory where the temporary segment files should be stored.
	// The files will be placed directly into the root of the directory.
	// If empty a random temporary directory on the system's default tempdir
	// will be created.
	// If the directory does not exist, it will be created.
	TempDir string
	// If DeleteTempAfter is true, the temp directory gets deleted afterwards.
	// Note that in case of a hard signal exit (os.Interrupt, ...) the directory
	// will NOT be deleted. In such situations try to catch the signal and
	// cancel Context.
	DeleteTempAfter bool

	// Context to control the download process with.
	// There is a tiny delay when canceling the context and the actual stop of the
	// process. So it is not recommend stopping the program immediately after calling
	// the cancel function. It's better when canceling it and then exit the program
	// when Format.Download throws an error. See the signal handling section in
	// cmd/crunchyroll-go/cmd/download.go for an example.
	Context context.Context

	// Goroutines is the number of goroutines to download segments with.
	Goroutines int

	// A method to call when a segment was downloaded.
	// Note that the segments are downloaded asynchronously (depending on the count of
	// Goroutines) and the function gets called asynchronously too, so for example it is
	// first called on segment 1, then segment 254, then segment 3 and so on.
	OnSegmentDownload func(segment *m3u8.MediaSegment, current, total int, file *os.File) error
	// If LockOnSegmentDownload is true, only one OnSegmentDownload function can be called at
	// once. Normally (because of the use of goroutines while downloading) multiple could get
	// called simultaneously.
	LockOnSegmentDownload bool

	// If FFmpegOpts is not nil, ffmpeg will be used to merge and convert files.
	// The given opts will be used as ffmpeg parameters while merging.
	//
	// If Writer is *os.File and -f (which sets the output format) is not specified, the output
	// format will be retrieved by its file ending. If this is not the case and -f is not given,
	// the output format will be mpegts / mpeg transport stream.
	// Execute 'ffmpeg -muxers' to see all available output formats.
	FFmpegOpts []string
}

Downloader is used to download Format's

func NewDownloader ΒΆ

func NewDownloader(context context.Context, writer io.Writer, goroutines int, onSegmentDownload func(segment *m3u8.MediaSegment, current, total int, file *os.File) error) Downloader

NewDownloader creates a downloader with default settings which should fit the most needs.

type Episode ΒΆ

type Episode struct {
	ID        string `json:"id"`
	ChannelID string `json:"channel_id"`

	SeriesID        string `json:"series_id"`
	SeriesTitle     string `json:"series_title"`
	SeriesSlugTitle string `json:"series_slug_title"`

	SeasonID        string `json:"season_id"`
	SeasonTitle     string `json:"season_title"`
	SeasonSlugTitle string `json:"season_slug_title"`
	SeasonNumber    int    `json:"season_number"`

	Episode             string  `json:"episode"`
	EpisodeNumber       int     `json:"episode_number"`
	SequenceNumber      float64 `json:"sequence_number"`
	ProductionEpisodeID string  `json:"production_episode_id"`

	Title            string `json:"title"`
	SlugTitle        string `json:"slug_title"`
	Description      string `json:"description"`
	NextEpisodeID    string `json:"next_episode_id"`
	NextEpisodeTitle string `json:"next_episode_title"`

	HDFlag          bool     `json:"hd_flag"`
	MaturityRatings []string `json:"maturity_ratings"`
	IsMature        bool     `json:"is_mature"`
	MatureBlocked   bool     `json:"mature_blocked"`

	EpisodeAirDate       time.Time `json:"episode_air_date"`
	FreeAvailableDate    time.Time `json:"free_available_date"`
	PremiumAvailableDate time.Time `json:"premium_available_date"`

	IsSubbed       bool     `json:"is_subbed"`
	IsDubbed       bool     `json:"is_dubbed"`
	IsClip         bool     `json:"is_clip"`
	SeoTitle       string   `json:"seo_title"`
	SeoDescription string   `json:"seo_description"`
	SeasonTags     []string `json:"season_tags"`

	AvailableOffline bool      `json:"available_offline"`
	MediaType        MediaType `json:"media_type"`
	Slug             string    `json:"slug"`

	Images struct {
		Thumbnail [][]Image `json:"thumbnail"`
	} `json:"images"`

	DurationMS    int    `json:"duration_ms"`
	IsPremiumOnly bool   `json:"is_premium_only"`
	ListingID     string `json:"listing_id"`

	SubtitleLocales []LOCALE `json:"subtitle_locales"`
	Playback        string   `json:"playback"`

	AvailabilityNotes string `json:"availability_notes"`

	StreamID string
	// contains filtered or unexported fields
}

Episode contains all information about an episode.

func EpisodeFromID ΒΆ

func EpisodeFromID(crunchy *Crunchyroll, id string) (*Episode, error)

EpisodeFromID returns an episode by its api id.

func (*Episode) AddToWatchlist ΒΆ

func (e *Episode) AddToWatchlist() error

AddToWatchlist adds the current episode to the watchlist. Will return an RequestError with the response status code of 409 if the series was already on the watchlist before. There is currently a bug, or as I like to say in context of the crunchyroll api, feature, that only series and not individual episode can be added to the watchlist. Even though I somehow got an episode to my watchlist on the crunchyroll website, it never worked with the api here. So this function actually adds the whole series to the watchlist.

func (*Episode) AudioLocale ΒΆ

func (e *Episode) AudioLocale() (LOCALE, error)

AudioLocale returns the audio locale of the episode. Every episode in a season (should) have the same audio locale, so if you want to get the audio locale of a season, just call this method on the first episode of the season. Will fail if no streams are available, thus use Episode.Available to prevent any misleading errors.

func (*Episode) Available ΒΆ

func (e *Episode) Available() bool

Available returns if downloadable streams for this episodes are available.

func (*Episode) Comment ΒΆ

func (e *Episode) Comment(message string, spoiler bool) (*Comment, error)

Comment creates a new comment under the episode.

func (*Episode) Comments ΒΆ

func (e *Episode) Comments(options CommentsOptions, page uint, size uint) (c []*Comment, err error)

Comments returns comments under the given episode.

func (*Episode) GetFormat ΒΆ

func (e *Episode) GetFormat(resolution string, subtitle LOCALE, hardsub bool) (*Format, error)

GetFormat returns the format which matches the given resolution and subtitle locale.

func (*Episode) RemoveFromWatchlist ΒΆ

func (e *Episode) RemoveFromWatchlist() error

RemoveFromWatchlist removes the current episode from the watchlist. Will return an RequestError with the response status code of 404 if the series was not on the watchlist before.

func (*Episode) Streams ΒΆ

func (e *Episode) Streams() ([]*Stream, error)

Streams returns all streams which are available for the episode.

type Format ΒΆ

type Format struct {
	ID string
	// FormatType represents if the format parent is an episode or a movie.
	FormatType  FormatType
	Video       *m3u8.Variant
	AudioLocale LOCALE
	Hardsub     LOCALE
	Subtitles   []*Subtitle
	// contains filtered or unexported fields
}

Format contains detailed information about an episode video stream.

func (*Format) Download ΒΆ

func (f *Format) Download(downloader Downloader) error

Download downloads the Format with the via Downloader specified options.

func (*Format) InitVideo ΒΆ

func (f *Format) InitVideo() error

InitVideo initializes the Format.Video completely. The Format.Video.Chunklist pointer is, by default, nil because an additional request must be made to receive its content. The request is not made when initializing a Format struct because it would probably cause an intense overhead since Format.Video.Chunklist is only used sometimes.

type FormatType ΒΆ

type FormatType string

FormatType represents if Format is an episode or a movie.

const (
	EPISODE FormatType = "episodes"
	MOVIE              = "movies"
)

type HistoryEpisode ΒΆ

type HistoryEpisode struct {
	*Episode

	DatePlayed   time.Time `json:"date_played"`
	ParentID     string    `json:"parent_id"`
	ParentType   MediaType `json:"parent_type"`
	Playhead     uint      `json:"playhead"`
	FullyWatched bool      `json:"fully_watched"`
}

HistoryEpisode contains additional information about an episode if the account has watched or started to watch the episode.

type Image ΒΆ

type Image struct {
	Height int    `json:"height"`
	Source string `json:"source"`
	Type   string `json:"type"`
	Width  int    `json:"width"`
}

type LOCALE ΒΆ

type LOCALE string

LOCALE represents a locale / language.

type MediaType ΒΆ

type MediaType string

MediaType represents a media type.

const (
	MediaTypeSeries MediaType = "series"
	MediaTypeMovie            = "movie_listing"
)

type Movie ΒΆ

type Movie struct {
	Video

	// not generated when calling MovieFromID.
	MovieListingMetadata struct {
		AvailabilityNotes   string   `json:"availability_notes"`
		AvailableOffline    bool     `json:"available_offline"`
		DurationMS          int      `json:"duration_ms"`
		ExtendedDescription string   `json:"extended_description"`
		FirstMovieID        string   `json:"first_movie_id"`
		IsDubbed            bool     `json:"is_dubbed"`
		IsMature            bool     `json:"is_mature"`
		IsPremiumOnly       bool     `json:"is_premium_only"`
		IsSubbed            bool     `json:"is_subbed"`
		MatureRatings       []string `json:"mature_ratings"`
		MovieReleaseYear    int      `json:"movie_release_year"`
		SubtitleLocales     []LOCALE `json:"subtitle_locales"`
	} `json:"movie_listing_metadata"`

	Playback string `json:"playback"`

	PromoDescription string `json:"promo_description"`
	PromoTitle       string `json:"promo_title"`
	SearchMetadata   struct {
		Score float64 `json:"score"`
	}
	// contains filtered or unexported fields
}

Movie contains information about a movie.

func MovieFromID ΒΆ

func MovieFromID(crunchy *Crunchyroll, id string) (*Movie, error)

MovieFromID returns a movie by its api id.

func (*Movie) MovieListing ΒΆ

func (m *Movie) MovieListing() (movieListings []*MovieListing, err error)

MovieListing returns all videos corresponding with the movie.

type MovieListing ΒΆ

type MovieListing struct {
	ID string `json:"id"`

	Title       string `json:"title"`
	Slug        string `json:"slug"`
	SlugTitle   string `json:"slug_title"`
	Description string `json:"description"`

	Images struct {
		Thumbnail [][]Image `json:"thumbnail"`
	} `json:"images"`

	DurationMS       int    `json:"duration_ms"`
	IsPremiumOnly    bool   `json:"is_premium_only"`
	ListeningID      string `json:"listening_id"`
	IsMature         bool   `json:"is_mature"`
	AvailableOffline bool   `json:"available_offline"`
	IsSubbed         bool   `json:"is_subbed"`
	IsDubbed         bool   `json:"is_dubbed"`

	Playback          string `json:"playback"`
	AvailabilityNotes string `json:"availability_notes"`
	// contains filtered or unexported fields
}

MovieListing contains information about something which is called movie listing. I don't know what this means thb.

func MovieListingFromID ΒΆ

func MovieListingFromID(crunchy *Crunchyroll, id string) (*MovieListing, error)

MovieListingFromID returns a movie listing by its api id.

func (*MovieListing) AudioLocale ΒΆ

func (ml *MovieListing) AudioLocale() (LOCALE, error)

AudioLocale is same as Episode.AudioLocale.

func (*MovieListing) Streams ΒΆ

func (ml *MovieListing) Streams() ([]*Stream, error)

Streams returns all streams which are available for the movie listing.

type News ΒΆ

type News struct {
	Title       string `json:"title"`
	Link        string `json:"link"`
	Image       string `json:"image"`
	Creator     string `json:"creator"`
	PublishDate string `json:"publish_date"`
	Description string `json:"description"`
}

News contains all information about news.

type OwnerReview ΒΆ

type OwnerReview struct {
	Review
	// contains filtered or unexported fields
}

OwnerReview is a series review which has been written from the current logged-in user.

func (*OwnerReview) Delete ΒΆ

func (or *OwnerReview) Delete() error

Delete deletes the review from the logged in account.

func (*OwnerReview) Edit ΒΆ

func (or *OwnerReview) Edit(title, content string, spoiler bool) error

Edit edits the review from the logged in account.

type Panel ΒΆ

type Panel struct {
	Title            string `json:"title"`
	PromoTitle       string `json:"promo_title"`
	Slug             string `json:"slug"`
	Playback         string `json:"playback"`
	PromoDescription string `json:"promo_description"`
	Images           struct {
		Thumbnail  [][]Image `json:"thumbnail"`
		PosterTall [][]Image `json:"poster_tall"`
		PosterWide [][]Image `json:"poster_wide"`
	} `json:"images"`
	ID          string             `json:"id"`
	Description string             `json:"description"`
	ChannelID   string             `json:"channel_id"`
	Type        WatchlistEntryType `json:"type"`
	ExternalID  string             `json:"external_id"`
	SlugTitle   string             `json:"slug_title"`
	// not null if Type is WATCHLISTENTRYEPISODE
	EpisodeMetadata *Episode `json:"episode_metadata"`
	// not null if Type is WATCHLISTENTRYSERIES
	SeriesMetadata *Series `json:"series_metadata"`
}

type Rating ΒΆ

type Rating struct {
	OneStar    ratingStar `json:"1s"`
	TwoStars   ratingStar `json:"2s"`
	ThreeStars ratingStar `json:"3s"`
	FourStars  ratingStar `json:"4s"`
	FiveStars  ratingStar `json:"5s"`
	Average    string     `json:"average"`
	Total      int        `json:"total"`
	Rating     string     `json:"rating"`
}

Rating represents the overall rating of a series.

type RequestError ΒΆ

type RequestError struct {
	Response *http.Response
	Message  string
	// contains filtered or unexported fields
}

RequestError is an error interface which gets used whenever a crunchyroll delivers an error response.

func (*RequestError) Error ΒΆ

func (re *RequestError) Error() string

type Review ΒΆ

type Review interface{}

Review is the interface which gets implemented by OwnerReview and UserReview.

type ReviewOptions ΒΆ

type ReviewOptions struct {
	// Sort specifies how the items should be sorted.
	Sort ReviewSortType `json:"sort"`
	// Filter specified after which the returning items should be filtered.
	Filter ReviewRating `json:"filter"`
}

ReviewOptions represents options for fetching series reviews.

type ReviewRating ΒΆ

type ReviewRating string

ReviewRating represents stars for a series rating from one to five.

type ReviewSortType ΒΆ

type ReviewSortType string

ReviewSortType represents a sort type to sort Series.Reviews items after.

type Season ΒΆ

type Season struct {
	ID        string `json:"id"`
	ChannelID string `json:"channel_id"`

	Title     string `json:"title"`
	SlugTitle string `json:"slug_title"`

	SeriesID     string `json:"series_id"`
	SeasonNumber int    `json:"season_number"`

	IsComplete bool `json:"is_complete"`

	Description   string   `json:"description"`
	Keywords      []string `json:"keywords"`
	SeasonTags    []string `json:"season_tags"`
	IsMature      bool     `json:"is_mature"`
	MatureBlocked bool     `json:"mature_blocked"`
	IsSubbed      bool     `json:"is_subbed"`
	IsDubbed      bool     `json:"is_dubbed"`
	IsSimulcast   bool     `json:"is_simulcast"`

	SeoTitle       string `json:"seo_title"`
	SeoDescription string `json:"seo_description"`

	AvailabilityNotes string `json:"availability_notes"`

	// the locales are always empty, idk why, this may change in the future
	AudioLocales    []LOCALE
	SubtitleLocales []LOCALE
	// contains filtered or unexported fields
}

Season contains information about an anime season.

func SeasonFromID ΒΆ

func SeasonFromID(crunchy *Crunchyroll, id string) (*Season, error)

SeasonFromID returns a season by its api id.

func (*Season) AudioLocale ΒΆ

func (s *Season) AudioLocale() (LOCALE, error)

AudioLocale returns the audio locale of the season. Will fail if no streams are available, thus use Season.Available to prevent any misleading errors.

func (*Season) Available ΒΆ

func (s *Season) Available() (bool, error)

Available returns if downloadable streams for this season are available.

func (*Season) Episodes ΒΆ

func (s *Season) Episodes() (episodes []*Episode, err error)

Episodes returns all episodes which are available for the season.

type Series ΒΆ

type Series struct {
	Video

	PromoDescription string `json:"promo_description"`
	PromoTitle       string `json:"promo_title"`

	AvailabilityNotes   string   `json:"availability_notes"`
	EpisodeCount        int      `json:"episode_count"`
	ExtendedDescription string   `json:"extended_description"`
	IsDubbed            bool     `json:"is_dubbed"`
	IsMature            bool     `json:"is_mature"`
	IsSimulcast         bool     `json:"is_simulcast"`
	IsSubbed            bool     `json:"is_subbed"`
	MatureBlocked       bool     `json:"mature_blocked"`
	MatureRatings       []string `json:"mature_ratings"`
	SeasonCount         int      `json:"season_count"`

	// not generated when calling SeriesFromID.
	SearchMetadata struct {
		Score float64 `json:"score"`
	}
	// contains filtered or unexported fields
}

Series contains information about an anime series.

func SeriesFromID ΒΆ

func SeriesFromID(crunchy *Crunchyroll, id string) (*Series, error)

SeriesFromID returns a series by its api id.

func (*Series) AddToWatchlist ΒΆ

func (s *Series) AddToWatchlist() error

AddToWatchlist adds the current episode to the watchlist. Will return an RequestError with the response status code of 409 if the series was already on the watchlist before.

func (*Series) CreateReview ΒΆ

func (s *Series) CreateReview(title, content string, spoiler bool) (*OwnerReview, error)

CreateReview creates a review for the current series with the logged-in account. Will fail if a review is already present. Check Series.HasOwnerReview if the account has already written a review. If this is the case, use Series.GetOwnerReview and user OwnerReview.Edit to edit the review.

func (*Series) GetOwnerReview ΒΆ

func (s *Series) GetOwnerReview() (*OwnerReview, error)

GetOwnerReview returns the series review, written by the current logged-in account. Returns an error if no review was written yet.

func (*Series) HasOwnerReview ΒΆ

func (s *Series) HasOwnerReview() bool

HasOwnerReview returns if the logged-in account has written a review for the series.

func (*Series) Rate ΒΆ

func (s *Series) Rate(rating ReviewRating) error

Rate rates the current series.

func (*Series) Rating ΒΆ

func (s *Series) Rating() (*Rating, error)

Rating returns the series rating.

func (*Series) RemoveFromWatchlist ΒΆ

func (s *Series) RemoveFromWatchlist() error

RemoveFromWatchlist removes the current episode from the watchlist. Will return an RequestError with the response status code of 404 if the series was not on the watchlist before.

func (*Series) Reviews ΒΆ

func (s *Series) Reviews(options ReviewOptions, page uint, size uint) (BulkResult[*UserReview], error)

Reviews returns user reviews for the series.

func (*Series) Seasons ΒΆ

func (s *Series) Seasons() (seasons []*Season, err error)

Seasons returns all seasons of a series.

func (*Series) Similar ΒΆ

func (s *Series) Similar(limit uint) (ss []*Series, m []*Movie, err error)

Similar returns similar series and movies to the current series within the given limit.

type Simulcast ΒΆ

type Simulcast struct {
	ID string `json:"id"`

	Localization struct {
		Title string `json:"title"`

		// appears to be always an empty string.
		Description string `json:"description"`
	} `json:"localization"`
}

Simulcast contains all information about a simulcast season.

type Stream ΒΆ

type Stream struct {
	HardsubLocale LOCALE
	AudioLocale   LOCALE
	Subtitles     []*Subtitle
	// contains filtered or unexported fields
}

Stream contains information about all available video stream of an episode.

func StreamsFromID ΒΆ

func StreamsFromID(crunchy *Crunchyroll, id string) ([]*Stream, error)

StreamsFromID returns a stream by its api id.

func (*Stream) Formats ΒΆ

func (s *Stream) Formats() ([]*Format, error)

Formats returns all formats which are available for the stream.

type Subtitle ΒΆ

type Subtitle struct {
	Locale LOCALE `json:"locale"`
	URL    string `json:"url"`
	Format string `json:"format"`
	// contains filtered or unexported fields
}

Subtitle contains the information about a video subtitle.

func (Subtitle) Save ΒΆ

func (s Subtitle) Save(writer io.Writer) error

Save writes the subtitle to the given io.Writer.

type UserReview ΒΆ

type UserReview struct {
	Review
	// contains filtered or unexported fields
}

UserReview is a series review written from other crunchyroll users.

func (*UserReview) RateHelpful ΒΆ

func (ur *UserReview) RateHelpful() error

RateHelpful rates the review as helpful. A review can only be rated once as helpful (or not helpful) and this cannot be undone, so be careful. Use Rated to see if the review was already rated.

func (*UserReview) RateNotHelpful ΒΆ

func (ur *UserReview) RateNotHelpful() error

RateNotHelpful rates the review as not helpful. A review can only be rated once as helpful (or not helpful) and this cannot be undone, so be careful. Use Rated to see if the review was already rated.

func (*UserReview) Rated ΒΆ

func (ur *UserReview) Rated() bool

Rated returns if the user already rated the review (with RateHelpful or RateNotHelpful).

func (*UserReview) RemoveReport ΒΆ

func (ur *UserReview) RemoveReport() error

RemoveReport removes the report request from the review. Only works if the user has reported the review. See UserReview.Ratings.Reported if it is already reported.

func (*UserReview) Report ΒΆ

func (ur *UserReview) Report() error

Report reports the review. Only works if the review hasn't been reported yet. See UserReview.Ratings.Reported if it is already reported.

type Video ΒΆ

type Video interface{}

Video is the base for Movie and Season.

type Wallpaper ΒΆ

type Wallpaper string

Wallpaper contains a wallpaper name which can be set via Account.ChangeWallpaper.

func (*Wallpaper) BigUrl ΒΆ

func (w *Wallpaper) BigUrl() string

BigUrl returns the url to the wallpaper in high resolution.

func (*Wallpaper) TinyUrl ΒΆ

func (w *Wallpaper) TinyUrl() string

TinyUrl returns the url to the wallpaper in low resolution.

type WatchlistEntry ΒΆ

type WatchlistEntry struct {
	Panel Panel `json:"panel"`

	New            bool `json:"new"`
	NewContent     bool `json:"new_content"`
	IsFavorite     bool `json:"is_favorite"`
	NeverWatched   bool `json:"never_watched"`
	CompleteStatus bool `json:"complete_status"`
	Playahead      uint `json:"playahead"`
}

WatchlistEntry contains information about an entry on the watchlist.

type WatchlistEntryType ΒΆ

type WatchlistEntryType string

WatchlistEntryType specifies which type a watchlist entry has.

type WatchlistLanguageType ΒΆ

type WatchlistLanguageType int

WatchlistLanguageType represents a filter type to filter Crunchyroll.Watchlist entries after sub or dub.

const (
	WatchlistLanguageSubbed WatchlistLanguageType = iota + 1
	WatchlistLanguageDubbed
)

type WatchlistOptions ΒΆ

type WatchlistOptions struct {
	// Order specified whether the results should be order ascending or descending.
	Order WatchlistOrderType

	// OnlyFavorites specifies whether only episodes which are marked as favorite should be returned.
	OnlyFavorites bool

	// LanguageType specifies whether returning episodes should be only subbed or dubbed.
	LanguageType WatchlistLanguageType

	// ContentType specified whether returning videos should only be series episodes or movies.
	// But tbh all movies I've searched on crunchy were flagged as series too, so this
	// parameter is kinda useless.
	ContentType MediaType
}

WatchlistOptions represents options for receiving the user watchlist.

type WatchlistOrderType ΒΆ

type WatchlistOrderType string

WatchlistOrderType represents how Crunchyroll.Watchlist entries should be ordered.

Directories ΒΆ

Path Synopsis

Jump to

Keyboard shortcuts

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