addic7ed

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2019 License: MIT Imports: 11 Imported by: 1

README

Addic7ed API

Build Status Go Report Card Go Coverage Godoc

addic7ed is a Golang package to get subtitles from Addic7ed website. As Addic7ed website does not provide a proper API yet, this package uses search feature of website and scraps HTML results to build data.

Installation

As any golang package, just download it with go get.

go get -u github.com/matcornic/addic7ed

Usage

Searching all subtitles of a given TV show
c := addic7ed.New()
show, err := c.SearchAll("Shameless.US.S08E11.720p.HDTV.x264-BATV[ettv]") // Usually the name of the video file
if err != nil {
    panic(err)
}
fmt.Println(show.Name) // Output: Shameless (US) - 08x11 - A Gallagher Pedicure
fmt.Println(show.Subtitles) // Output: all subtitles with version, languages and download links

In order to find all the subtitles, this API:

  1. Use search.php page of Addic7ed API
  2. Parse the results

It means that if the tv show name is not precise enough, this API will not be able to find the exact TV show page.

Searching the best subtitle of a given TV show
c := addic7ed.New()
showName, subtitle, err := c.SearchBest("Shameless.US.S08E11.720p.HDTV.x264-BATV[ettv]", "English")
if err != nil {
    panic(err)
}
fmt.Println(showName) // Output: Shameless (US) - 08x11 - A Gallagher Pedicure
fmt.Println(subtitle) // Output: the best suitable subtitle in English language
fmt.Println(subtitle.Version) // Output: BATV
fmt.Println(subtitle.Language) // Output: English

// Download the subtitle to a given file name
err := subtitle.DownloadTo("Shameless.US.S08E11.720p.HDTV.x264-BATV[ettv].srt")
if err != nil {
    panic(err)
}

In order to search the best subtitle, this API:

  1. Filters subtitles of the given language. Here: English
  2. Scores similarities between the name of the show and available versions (combining Jaro-winkler distance and an internal weight)
    1. It means that the name of the show has to contain the version. Here: BATV
  3. Choose the version with the best score
  4. Choose the best subtitle of the chosen version (the most updated one)
Helper functions

Some helper functions are provided to adapt subtitles structure to the context

c := addic7ed.New()
show, err := c.SearchAll("Shameless.US.S08E11.720p.HDTV.x264-BATV[ettv]") // Usually the name of the video file
if err != nil {
    panic(err)
}

// Filter subtitles to keep only english subtitles
subtitles = show.Subtitles.Filter(WithLanguage("English"))
// Group by version
subtitlesByVersion = subtitles.GroupByVersion()
fmt.Println(subtitlesByVersion["BATV"]) // Output: print all english subtitles of BATV version

Available filter functions:

  • WithLanguage
  • WithVersion
  • WithVersionRegexp

Available groupBy functions:

  • GroupByVersion
  • GroupByLanguage

Contributing

See CONTRIBUTING.md

Licence

MIT. This package is not affiliated with Addic7ed website.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithLanguage

func WithLanguage(lang string) func(s Subtitle) bool

WithLanguage is a filter first-class function, used to keep subtitle with given language

func WithVersion

func WithVersion(version string) func(s Subtitle) bool

WithVersion is a filter first-class function, used to keep subtitle with given subtitle version

func WithVersionRegexp

func WithVersionRegexp(version *regexp.Regexp) func(s Subtitle) bool

WithVersionRegexp is a filter first-class function, used to keep subtitle with given subtitle version identified by a regex

Types

type Client

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

Client is the addic7ed client

func New

func New() *Client

New creates an Addic7ed client, ready to interact with.

func NewVerbose added in v0.2.0

func NewVerbose() *Client

NewVerbose creates a new client that will log verbosely to stdout

func (*Client) Debug added in v0.2.0

func (c *Client) Debug(isVerbose bool)

Debug is used to set logging to verbose

func (*Client) SearchAll

func (c *Client) SearchAll(showStr string) (Show, error)

SearchAll searches in the Addic7ed website for a given episode of a show showStr is usually the name of the video file that need to be searched but it could be any search that can be handled by Addic7ed website It returns the episode name and all found subtitles.

func (*Client) SearchBest

func (c *Client) SearchBest(showStr, lang string) (string, Subtitle, error)

SearchBest searches in the Addic7ed website for the best suitable subtitle of given episode of a show showStr is usually the name of the video file that need to be searched but it could be any search that can be handled by Addic7ed website lang is the language of the subtitle It returns the episode name and the found subtitle.

type Show

type Show struct {
	Name      string
	Subtitles Subtitles
}

Show defines a TV show with a name and associated subtitle

type Subtitle

type Subtitle struct {
	// Language is the Addic7ed language as seen in the website
	Language string
	// Version is the subtitle type/version, usually the name of the teams who ripped the tv show
	Version string
	// Link is the link to the subtitle from Addic7ed website
	Link string
}

Subtitle is a TV-Show subtitle

func (Subtitle) Download

func (s Subtitle) Download() (io.ReadCloser, error)

Download download the subtitle in-memory, in a closable reader

func (Subtitle) DownloadTo

func (s Subtitle) DownloadTo(path string) error

DownloadTo downloads the subtitle to a given path

func (Subtitle) IsOriginal

func (s Subtitle) IsOriginal() bool

IsOriginal checks whether the subtitle is original. It means that the subtitle comes with different version and this subtitle is the original one.

func (Subtitle) IsUpdated

func (s Subtitle) IsUpdated() bool

IsUpdated checks whether the subtitle is updated. It means that the subtitle comeswith different version and this subtitle is the updated one.

func (Subtitle) String

func (s Subtitle) String() string

type Subtitles

type Subtitles []Subtitle

Subtitles is a slice of subtitle

func (Subtitles) Filter

func (ss Subtitles) Filter(filter func(s Subtitle) bool) Subtitles

Filter filters out subtitles To use it, you have to provide a function that returns true for Subtitles to keep, and false to the one to ignore. See addic7ed.WithLanguage, addic7ed.WithVersion, addic7ed.WithVersionRegexp for built-in filters

func (Subtitles) GroupBy

func (ss Subtitles) GroupBy(property func(s Subtitle) string) map[string]Subtitles

GroupBy groups subtitles by a given property from the subtitle

func (Subtitles) GroupByLanguage

func (ss Subtitles) GroupByLanguage() map[string]Subtitles

GroupByLanguage groups subtitles by language

func (Subtitles) GroupByVersion

func (ss Subtitles) GroupByVersion() map[string]Subtitles

GroupByVersion groups subtitles by version

func (Subtitles) String

func (ss Subtitles) String() string

Jump to

Keyboard shortcuts

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