Skip to content

Latest commit

 

History

History
56 lines (43 loc) · 1.39 KB

File metadata and controls

56 lines (43 loc) · 1.39 KB

Addicted

GoDoc Go Report Card

Usage

package main

import (
        "context"
        "io"
        "os"

        "github.com/odwrtw/addicted"
)

func main() {
        ctx := context.Background()

        // Create a client
        client, err := addicted.NewWithAuth("username", "yourpassword")
        if err != nil {
            panic(err)
        }

        // Get subtitles for a show by name (House of Cards S01E01)
        subs, err := client.GetSubtitles(ctx, "House of Cards", 1, 1)
        if err != nil {
            panic(err)
        }

        // Filter by language
        subs = subs.FilterByLang("french")
        if len(subs) == 0 {
            panic("no subtitles found")
        }

        // Download the subtitle content
        rc, err := client.Download(ctx, subs[0])
        if err != nil {
            panic(err)
        }
        defer rc.Close()

        f, err := os.Create("subtitle.srt")
        if err != nil {
            panic(err)
        }
        defer f.Close()

        io.Copy(f, rc)
}