polochon

package
v0.0.0-...-2b5c1d7 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCalendarNotFound       = errors.New("polochon: calendar not found")
	ErrCalendarModuleNotFound = errors.New("polochon: calendar module not found")
)

Calendar error

View Source
var (
	ErrGuessingVideo    = errors.New("polochon: failed to guess video")
	ErrGuessingMetadata = errors.New("polochon: failed to guess metadata")
)

Guess errors

View Source
var (
	ErrMissingSubtitleLang = errors.New("polochon: no subtitle lang")
	ErrMissingSubtitlePath = errors.New("polochon: no subtitle path")
	ErrMissingSubtitleData = errors.New("polochon: no subtitle data")
)

Subtitle errors

View Source
var (
	// ErrDuplicateTorrent returned when the torrent is already added
	ErrDuplicateTorrent = errors.New("Torrent already added")
)
View Source
var ErrGettingDetails = errors.New("polochon: failed to get details")

ErrGettingDetails is returned if polochon failed to get details of the video

View Source
var ErrNoSubtitleFound = errors.New("polochon: no subtitle found")

ErrNoSubtitleFound trigger when no subtitle found

View Source
var (
	ErrNotAvailable = errors.New("modules: function not available")
)

Modules error

View Source
var (
	ErrTorrentNotFound = errors.New("torrenter: failed to find torrent")
)

Torrenter error

Functions

func ClearRegisteredModules

func ClearRegisteredModules()

ClearRegisteredModules clears the registered modules from polochon. This function exists for test purposes only. Do not use this unless you know what you're doing.

func GetDetails

func GetDetails(v Detailable, log *logrus.Entry) error

GetDetails helps getting infos for a Detailable object If there is an error, it will be of type *errors.Collector

func GetTorrents

func GetTorrents(v Torrentable, log *logrus.Entry) error

GetTorrents helps getting the torrent files for a movie

func RegisterModule

func RegisterModule(m Module)

RegisterModule is a function used by the module to register themselves

Types

type BaseVideo

type BaseVideo struct {
	File
	VideoMetadata
	Subtitles []*Subtitle `json:"subtitles"`
	Torrents  []*Torrent  `json:"torrents"`
}

BaseVideo holds common characteristics of videos

func (*BaseVideo) GetFile

func (bv *BaseVideo) GetFile() *File

GetFile implements the Video interface

func (*BaseVideo) GetSubtitles

func (bv *BaseVideo) GetSubtitles() []*Subtitle

GetSubtitles implements the Video interface

func (*BaseVideo) GetTorrents

func (bv *BaseVideo) GetTorrents() []*Torrent

GetTorrents implements the Video interface

func (*BaseVideo) SetFile

func (bv *BaseVideo) SetFile(f File)

SetFile implements the Video interface

func (*BaseVideo) SetMetadata

func (bv *BaseVideo) SetMetadata(metadata *VideoMetadata)

SetMetadata implements the Video interface

func (*BaseVideo) SetSubtitles

func (bv *BaseVideo) SetSubtitles(subtitles []*Subtitle)

SetSubtitles implements the Video interface

func (*BaseVideo) SetTorrents

func (bv *BaseVideo) SetTorrents(torrents []*Torrent)

SetTorrents implements the Video interface

type Calendar

type Calendar interface {
	Module
	GetShowCalendar(*Show, *logrus.Entry) (*ShowCalendar, error)
}

Calendar is an interface to get the calendar for movies and shows

type Detailable

type Detailable interface {
	GetDetailers() []Detailer
}

Detailable represents a ressource which can be detailed

type Detailer

type Detailer interface {
	Module
	GetDetails(i interface{}, log *logrus.Entry) error
}

Detailer is the interface to get details on a video or a show

type Downloader

type Downloader interface {
	Module
	Download(*Torrent) error
	Remove(*Torrent) error
	List() ([]*Torrent, error)
}

Downloader represent a interface for any downloader

type Explorer

type Explorer interface {
	Module
	AvailableMovieOptions() []string
	GetMovieList(option string, log *logrus.Entry) ([]*Movie, error)
	AvailableShowOptions() []string
	GetShowList(option string, log *logrus.Entry) ([]*Show, error)
}

Explorer is the interface explore new videos from different sources

type File

type File struct {
	FileConfig `json:"-"`
	Path       string `json:"-"`
	Size       int64  `json:"size"`
}

File handles polochon files

func NewFile

func NewFile(path string) *File

NewFile returns a new file from a path

func NewFileWithConfig

func NewFileWithConfig(path string, conf FileConfig) *File

NewFileWithConfig returns a new file from a path

func (*File) Exists

func (f *File) Exists() bool

Exists returns true is the file exists

func (*File) Ext

func (f *File) Ext() string

Ext returns the file extension

func (*File) Filename

func (f *File) Filename() string

Filename returns the file name

func (*File) Guess

func (f *File) Guess(movieConf MovieConfig, showConf ShowConfig, log *logrus.Entry) (Video, error)

Guess video information from file

func (*File) GuessMetadata

func (f *File) GuessMetadata(log *logrus.Entry) (*VideoMetadata, error)

GuessMetadata guesses the metadata of a file

func (*File) Ignore

func (f *File) Ignore() error

Ignore create a ".ignore" file next to the file to indicate that it is ignored

func (*File) IgnorePath

func (f *File) IgnorePath() string

IgnorePath is an helper to get the ignore file path

func (*File) IsExcluded

func (f *File) IsExcluded() bool

IsExcluded returns true if the file contains an excluded word

func (*File) IsIgnored

func (f *File) IsIgnored() bool

IsIgnored returns true if the file has a ".ignore" file with the same name

func (f *File) IsSymlink() bool

IsSymlink returns true if the file is a symlink

func (*File) IsVideo

func (f *File) IsVideo() bool

IsVideo returns true is the file is considered to be a video

func (*File) MovieFanartPath

func (f *File) MovieFanartPath() string

MovieFanartPath returns the movie fanart path

func (*File) MovieThumbPath

func (f *File) MovieThumbPath() string

MovieThumbPath returns the movie thumb path

func (*File) NfoPath

func (f *File) NfoPath() string

NfoPath is an helper to get the nfo filename from the video filename

func (*File) PathWithoutExt

func (f *File) PathWithoutExt() string

PathWithoutExt returns the file path without the file extension

func (*File) SubtitlePath

func (f *File) SubtitlePath(lang Language) string

SubtitlePath is an helper to get the subtitle path from the filename

type FileConfig

type FileConfig struct {
	ExcludeFileContaining     []string
	VideoExtensions           []string
	AllowedExtensionsToDelete []string
	Guessers                  []Guesser
	// contains filtered or unexported fields
}

FileConfig represents the configuration for a file

func (*FileConfig) IsVideo

func (fc *FileConfig) IsVideo(filename string) bool

IsVideo returns true if the file is considered a video based on the extension of the file

type FsNotifier

type FsNotifier interface {
	Module
	Watch(watchPath string, ctx FsNotifierCtx, log *logrus.Entry) error
}

FsNotifier is an interface to notify on filesystem change

type FsNotifierCtx

type FsNotifierCtx struct {
	Event chan string
	Done  <-chan struct{}
	Wg    *sync.WaitGroup
}

FsNotifierCtx is the context of the notifier

type Guesser

type Guesser interface {
	Module
	Guess(File, MovieConfig, ShowConfig, *logrus.Entry) (Video, error)
	GuessMetadata(*File, *logrus.Entry) (*VideoMetadata, error)
}

Guesser is an interface which allows to get informations to create a video from a file

type LangInfo

type LangInfo struct {
	ShortForm string
}

LangInfo represents differents infos of a Lang

type Language

type Language string

Language type

const (
	EN Language = "en_US"
	FR Language = "fr_FR"
)

Based on unix locale

func (Language) ShortForm

func (l Language) ShortForm() string

ShortForm returns the short form of a lang

type Module

type Module interface {
	Init(params []byte) error
	Name() string
	Status() (ModuleStatus, error)
}

Module type, all modules must implement it

func GetModule

func GetModule(name string, t ModuleType) (Module, error)

GetModule returns a module ensuring it implements the type linked to the ModuleType

type ModuleStatus

type ModuleStatus string

ModuleStatus holds modules status

const (
	StatusOK             ModuleStatus = "ok"
	StatusNotImplemented ModuleStatus = "not_implemented"
	StatusFail           ModuleStatus = "fail"
)

Available modules statuses

type ModuleType

type ModuleType string

ModuleType holds modules type

const (
	TypeTorrenter  ModuleType = "torrenter"
	TypeDetailer   ModuleType = "detailer"
	TypeGuesser    ModuleType = "guesser"
	TypeFsNotifier ModuleType = "fsnotifier"
	TypeNotifier   ModuleType = "notifier"
	TypeSubtitler  ModuleType = "subtitler"
	TypeWishlister ModuleType = "wishlister"
	TypeDownloader ModuleType = "downloader"
	TypeCalendar   ModuleType = "calendar"
	TypeExplorer   ModuleType = "explorer"
	TypeSearcher   ModuleType = "searcher"
)

Available modules types

type Movie

type Movie struct {
	MovieConfig `json:"-"`

	BaseVideo
	ImdbID        string   `json:"imdb_id"`
	OriginalTitle string   `json:"original_title"`
	Plot          string   `json:"plot"`
	Rating        float32  `json:"rating"`
	Runtime       int      `json:"runtime"`
	SortTitle     string   `json:"sort_title"`
	Tagline       string   `json:"tag_line"`
	Thumb         string   `json:"thumb"`
	Fanart        string   `json:"fanart"`
	Title         string   `json:"title"`
	TmdbID        int      `json:"tmdb_id"`
	Votes         int      `json:"votes"`
	Year          int      `json:"year"`
	Genres        []string `json:"genres"`
}

Movie represents a movie

func NewMovie

func NewMovie(movieConfig MovieConfig) *Movie

NewMovie returns a new movie

func NewMovieFromFile

func NewMovieFromFile(movieConfig MovieConfig, file File) *Movie

NewMovieFromFile returns a new movie from a file

type MovieConfig

type MovieConfig struct {
	Torrenters []Torrenter
	Detailers  []Detailer
	Subtitlers []Subtitler
	Explorers  []Explorer
	Searchers  []Searcher
}

MovieConfig represents the configuration for a movie

func (*MovieConfig) GetDetailers

func (m *MovieConfig) GetDetailers() []Detailer

GetDetailers implements the Detailable interface

func (*MovieConfig) GetExplorers

func (m *MovieConfig) GetExplorers() []Explorer

GetExplorers implements the Explorer interface

func (*MovieConfig) GetSearchers

func (m *MovieConfig) GetSearchers() []Searcher

GetSearchers implements the Searcher interface

func (*MovieConfig) GetSubtitlers

func (m *MovieConfig) GetSubtitlers() []Subtitler

GetSubtitlers implements the Subtitlable interface

func (*MovieConfig) GetTorrenters

func (m *MovieConfig) GetTorrenters() []Torrenter

GetTorrenters implements the Torrentable interface

type Notifier

type Notifier interface {
	Module
	Notify(interface{}, *logrus.Entry) error
}

Notifier is an interface to notify when a video is added

type Quality

type Quality string

Quality represents the qualities of a video

const (
	Quality480p  Quality = "480p"
	Quality720p  Quality = "720p"
	Quality1080p Quality = "1080p"
	Quality2160p Quality = "2160p"
	Quality3D    Quality = "3D"
)

Possible qualities

func StringToQuality

func StringToQuality(q string) (*Quality, error)

StringToQuality returns a Quality from a string

func (*Quality) IsAllowed

func (q *Quality) IsAllowed() bool

IsAllowed checks if the quality is allowed

type Searcher

type Searcher interface {
	Module
	SearchMovie(key string, log *logrus.Entry) ([]*Movie, error)
	SearchShow(key string, log *logrus.Entry) ([]*Show, error)
}

Searcher is the interface to search shows or movies from different sources

type Show

type Show struct {
	ShowConfig `json:"-"`
	Title      string         `json:"title"`
	Rating     float32        `json:"rating"`
	Plot       string         `json:"plot"`
	URL        string         `json:"-"`
	TvdbID     int            `json:"tvdb_id"`
	ImdbID     string         `json:"imdb_id"`
	Year       int            `json:"year"`
	FirstAired *time.Time     `json:"first_aired"`
	Banner     string         `json:"-"`
	Fanart     string         `json:"-"`
	Poster     string         `json:"-"`
	Episodes   []*ShowEpisode `json:"-"`
}

Show represents a tv show

func NewShow

func NewShow(showConf ShowConfig) *Show

NewShow returns a new show

func NewShowFromEpisode

func NewShowFromEpisode(e *ShowEpisode) *Show

NewShowFromEpisode will return a show from an episode

func (*Show) GetCalendar

func (s *Show) GetCalendar(log *logrus.Entry) (*ShowCalendar, error)

GetCalendar gets the calendar for the show If there is an error, it will be of type *errors.Error

type ShowCalendar

type ShowCalendar struct {
	ImdbID   string
	Episodes []*ShowCalendarEpisode
}

ShowCalendar holds the calendar for a show

func NewShowCalendar

func NewShowCalendar(imdbID string) *ShowCalendar

NewShowCalendar returns a new show calendar

type ShowCalendarEpisode

type ShowCalendarEpisode struct {
	Season    int
	Episode   int
	AiredDate *time.Time
}

ShowCalendarEpisode holds the episode calendar infos

func (*ShowCalendarEpisode) IsAvailable

func (sc *ShowCalendarEpisode) IsAvailable() bool

IsAvailable tells if the episode is currently available

func (*ShowCalendarEpisode) IsOlder

func (sc *ShowCalendarEpisode) IsOlder(ws *WishedShow) bool

IsOlder returns true if the given show is older than the calendar episode

type ShowConfig

type ShowConfig struct {
	Calendar   Calendar
	Detailers  []Detailer
	Subtitlers []Subtitler
	Torrenters []Torrenter
	Explorers  []Explorer
	Searchers  []Searcher
}

ShowConfig represents the configuration for a show and its show episodes

func (*ShowConfig) GetDetailers

func (s *ShowConfig) GetDetailers() []Detailer

GetDetailers implements the Detailable interface

func (*ShowConfig) GetExplorers

func (s *ShowConfig) GetExplorers() []Explorer

GetExplorers implements the Explorer interface

func (*ShowConfig) GetSearchers

func (s *ShowConfig) GetSearchers() []Searcher

GetSearchers implements the Searcher interface

func (*ShowConfig) GetSubtitlers

func (s *ShowConfig) GetSubtitlers() []Subtitler

GetSubtitlers implements the Subtitlable interface

func (*ShowConfig) GetTorrenters

func (s *ShowConfig) GetTorrenters() []Torrenter

GetTorrenters implements the Torrentable interface

type ShowEpisode

type ShowEpisode struct {
	ShowConfig `json:"-"`
	BaseVideo

	Title         string  `json:"title"`
	ShowTitle     string  `json:"show_title"`
	Season        int     `json:"season"`
	Episode       int     `json:"episode"`
	TvdbID        int     `json:"tvdb_id"`
	Aired         string  `json:"aired"`
	Plot          string  `json:"plot"`
	Runtime       int     `json:"runtime"`
	Thumb         string  `json:"thumb"`
	Rating        float32 `json:"rating"`
	ShowImdbID    string  `json:"show_imdb_id"`
	ShowTvdbID    int     `json:"show_tvdb_id"`
	EpisodeImdbID string  `json:"imdb_id"`
	Show          *Show   `json:"-"`
}

ShowEpisode represents a tvshow episode

func NewShowEpisode

func NewShowEpisode(showConf ShowConfig) *ShowEpisode

NewShowEpisode returns a new show episode

func NewShowEpisodeFromFile

func NewShowEpisodeFromFile(showConf ShowConfig, file File) *ShowEpisode

NewShowEpisodeFromFile returns a new show episode from a file

type ShowSeason

type ShowSeason struct {
	ShowConfig `json:"-"`
	ShowImdbID string `json:"show_imdb_id"`
	Season     int    `json:"season"`
	Banner     string `json:"-"`
	Fanart     string `json:"-"`
	Poster     string `json:"-"`
}

ShowSeason represents a show season

func NewShowSeason

func NewShowSeason(conf ShowConfig) *ShowSeason

NewShowSeason returns a new show season

type Subtitlable

type Subtitlable interface {
	SubtitlePath(Language) string
	GetSubtitlers() []Subtitler
}

Subtitlable represents a ressource which can be subtitled

type Subtitle

type Subtitle struct {
	File

	// Embedded is true if the subtitle is embedded in the video file
	Embedded bool   `json:"embedded"`
	Data     []byte `json:"-"`

	Lang  Language `json:"lang"`
	Video Video    `json:"-"`
}

Subtitle represents a subtitle

func GetSubtitle

func GetSubtitle(video Video, lang Language, log *logrus.Entry) (*Subtitle, error)

GetSubtitle gets the subtitles of a video in the given languages

func NewSubtitleFromVideo

func NewSubtitleFromVideo(v Video, l Language) *Subtitle

NewSubtitleFromVideo returns a subtitle from a video

func (*Subtitle) Save

func (s *Subtitle) Save() error

Save saves the subtitle to its path

type Subtitler

type Subtitler interface {
	Module
	GetSubtitle(interface{}, Language, *logrus.Entry) (*Subtitle, error)
}

Subtitler all subtitler must implement it

type Torrent

type Torrent struct {
	ImdbID  string    `json:"imdb_id"`
	Type    VideoType `json:"type"`
	Season  int       `json:"season"`
	Episode int       `json:"episode"`
	Quality Quality   `json:"quality"`

	Result *TorrentResult `json:"result"`
	Status *TorrentStatus `json:"status"`
}

Torrent represents a torrent file

func ChooseTorrentFromQualities

func ChooseTorrentFromQualities(torrents []*Torrent, qualities []Quality) *Torrent

ChooseTorrentFromQualities chooses the best torrent matching the given qualities

func FilterTorrents

func FilterTorrents(torrents []*Torrent) []*Torrent

FilterTorrents filters the torrents to keep only the best ones

func (*Torrent) HasVideo

func (t *Torrent) HasVideo() bool

HasVideo returns true if the torrent has enough information to return a video

func (*Torrent) RatioReached

func (t *Torrent) RatioReached(ratio float32) bool

RatioReached tells if the given ratio has been reached

func (*Torrent) Video

func (t *Torrent) Video() Video

Video returns a new video based on the torrent informations

type TorrentResult

type TorrentResult struct {
	Name       string `json:"name"`
	URL        string `json:"url"`
	Seeders    int    `json:"seeders"`
	Leechers   int    `json:"leechers"`
	Source     string `json:"source"`
	UploadUser string `json:"upload_user"`
	Size       int    `json:"size"`
}

TorrentResult represents a torrent result from a search

type TorrentState

type TorrentState string

TorrentState represents the torrent state

const (
	TorrentStateStopped         TorrentState = "stopped"
	TorrentStatePending         TorrentState = "pending"
	TorrentStateChecking        TorrentState = "checking"
	TorrentStateDownloadPending TorrentState = "download_pending"
	TorrentStateDownloading     TorrentState = "downloading"
	TorrentStateSeedPending     TorrentState = "seed_pending"
	TorrentStateSeeding         TorrentState = "seeding"
)

Possible torrent statuses

type TorrentStatus

type TorrentStatus struct {
	ID             string       `json:"id"`
	Name           string       `json:"name"`
	Ratio          float32      `json:"ratio"`
	IsFinished     bool         `json:"is_finished"`
	FilePaths      []string     `json:"file_paths"`
	DownloadRate   int          `json:"download_rate"`
	UploadRate     int          `json:"upload_rate"`
	TotalSize      int          `json:"total_size"`
	DownloadedSize int          `json:"downloaded_size"`
	UploadedSize   int          `json:"uploaded_size"`
	PercentDone    float32      `json:"percent_done"`
	State          TorrentState `json:"state"`
}

TorrentStatus represents the status of the downloaded torrent

type Torrentable

type Torrentable interface {
	GetTorrenters() []Torrenter
}

Torrentable represents a resource which can be torrented

type Torrenter

type Torrenter interface {
	Module
	GetTorrents(interface{}, *logrus.Entry) error
	SearchTorrents(string) ([]*Torrent, error)
}

Torrenter is an interface which allows to get torrent for a movie or a show

type Video

type Video interface {
	Subtitlable
	Detailable
	Torrentable

	SetFile(f File)
	GetFile() *File

	SetMetadata(*VideoMetadata)

	SetSubtitles([]*Subtitle)
	GetSubtitles() []*Subtitle

	SetTorrents([]*Torrent)
	GetTorrents() []*Torrent
}

Video represents a generic video type

type VideoMetadata

type VideoMetadata struct {
	DateAdded         time.Time  `json:"date_added"`
	Quality           Quality    `json:"quality"`
	ReleaseGroup      string     `json:"release_group"`
	AudioCodec        string     `json:"audio_codec"`
	VideoCodec        string     `json:"video_codec"`
	Container         string     `json:"container"`
	EmbeddedSubtitles []Language `json:"embedded_subtitles"`
}

VideoMetadata represents the metadata of a video

func (*VideoMetadata) Update

func (v *VideoMetadata) Update(metadata *VideoMetadata)

Update updates the metadata with new values

type VideoType

type VideoType string

VideoType represents the type of a video

const (
	TypeMovie   VideoType = "movie"
	TypeEpisode VideoType = "episode"
)

Possible video types

type WishedMovie

type WishedMovie struct {
	ImdbID    string    `json:"imdb_id"`
	Qualities []Quality `json:"qualities"`
}

WishedMovie represents a wished movie and its expected qualities

type WishedShow

type WishedShow struct {
	ImdbID    string    `json:"imdb_id"`
	Season    int       `json:"season_from"`
	Episode   int       `json:"episode_from"`
	Qualities []Quality `json:"qualities"`
}

WishedShow represents a wished show, its expected qualities and the season / episode to start tracking

type Wishlist

type Wishlist struct {
	WishlistConfig `xml:"-" json:"-"`

	Movies []*WishedMovie `json:"movies"`
	Shows  []*WishedShow  `json:"shows"`
	// contains filtered or unexported fields
}

Wishlist represents a user wishlist

func NewWishlist

func NewWishlist(wishlistConfig WishlistConfig, log *logrus.Entry) *Wishlist

NewWishlist returns a new wishlist

func (*Wishlist) AddMovie

func (w *Wishlist) AddMovie(movie *WishedMovie) error

AddMovie helps add a movie to the movie list, if the movie is already in the list, nothing happens

func (*Wishlist) AddShow

func (w *Wishlist) AddShow(show *WishedShow) error

AddShow adds a show to the show list, if the show is already in the list, the oldest is kept or added

func (*Wishlist) Fetch

func (w *Wishlist) Fetch() error

Fetch the informations from the wishlister an returns a merged wishlist TODO: merge the wishlists from the different wishlisters

type WishlistConfig

type WishlistConfig struct {
	Wishlisters           []Wishlister
	ShowDefaultQualities  []Quality `yaml:"show_default_qualities"`
	MovieDefaultQualities []Quality `yaml:"movie_default_qualities"`
}

WishlistConfig represents the wishlist configurations

type Wishlister

type Wishlister interface {
	Module
	GetMovieWishlist(*logrus.Entry) ([]*WishedMovie, error)
	GetShowWishlist(*logrus.Entry) ([]*WishedShow, error)
}

Wishlister is an interface which defines the behavior of the wishlister modules

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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