yifysubs

package module
v0.0.0-...-c57d8c2 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2024 License: MIT Imports: 11 Imported by: 1

README

YIFY Subtitles client

GoDoc Go Report Card

Example

package main

import (
    "io"
    "log"
    "os"

    "github.com/odwrtw/yifysubs"
)

func main() {
    // Create a client.
    client := yifysubs.NewDefault()

    imdbID := "tt3758542"

    // Search subtitles.
    subtitles, err := client.SearchByLang(imdbID, "English")
    if err != nil {
        log.Fatalf("Failed to get subtitles: %s", err)
        return
    }

    log.Printf("Found %d subtitles for movie with IMDB ID %s", len(subtitles), imdbID)

    // There will always be a first subtitles, if no subtitles where to be
    // found, the search function would return an error.
    firstSub := subtitles[0]

    path := "/tmp/" + imdbID + ".srt"
    file, err := os.Create(path)
    if err != nil {
        log.Fatalf("Failed to create file: %s", err)
        return
    }
    defer file.Close()

    if _, err := io.Copy(file, firstSub); err != nil {
        log.Fatalf("Failed to copy file: %s", err)
        return
    }

    log.Printf("Subtitle written to %s", path)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoSubtitleFound = errors.New("yify: no subtitles found")
	ErrNoSubtitleData  = errors.New("yify: no subtitles data")
)

Custom errors

Functions

This section is empty.

Types

type Client

type Client struct {
	Endpoint string
}

Client represent a Client used to make Search

func New

func New(endpoint string) *Client

New return a new client

func NewDefault

func NewDefault() *Client

NewDefault return a new client with a default endpoint

func (*Client) Search

func (c *Client) Search(imdbID string) ([]*Subtitle, error)

Search will search Subtitles

func (*Client) SearchByLang

func (c *Client) SearchByLang(imdbID, lang string) ([]*Subtitle, error)

SearchByLang searches Subtitles with given language

type Subtitle

type Subtitle struct {
	Lang string

	Releases []string
	// contains filtered or unexported fields
}

Subtitle represents a Subtitle

func FilterByLang

func FilterByLang(subtitles []*Subtitle, language string) ([]*Subtitle, error)

FilterByLang will filter the subtitles by language

func (Subtitle) Close

func (s Subtitle) Close() error

Close implement the closer interface

func (*Subtitle) Read

func (s *Subtitle) Read(p []byte) (n int, err error)

Read implement the reader interface

Jump to

Keyboard shortcuts

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