Skip to content
/ tpb Public

thepiratebay scrapper written in go

Notifications You must be signed in to change notification settings

odwrtw/tpb

Repository files navigation

Golang scrapper for thepiratebay

Build Status Go Report Card GoDoc Coverage Status

Exemple

package main

import (
    "context"
    "fmt"
    "os"
    "time"

    "github.com/odwrtw/tpb"
)

func main() {
    if err := run(); err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
}

func run() error {
    // The client supports multiple endpoints and will try to use one that
    // works
    client := tpb.New(
        "https://fakeapibay.org",
        "https://apibay.org",
    )

    // You can create a context to cancel the search
    ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)
    defer cancel()

    // You can add search options or nil for the default options
    // torrents, err := client.Search(ctx, "Ubuntu", nil)
    // Or you can search within a given category
    torrents, err := client.Search(ctx, "Ubuntu", &tpb.SearchOptions{
        Category: tpb.Applications,
    })
    if err != nil {
        return err
    }

    for _, t := range torrents {
        fmt.Println("--------------")
        fmt.Printf("%s\nUploaded by %q (%d seeders / %d leechers)\nMagnet: %s",
            t.Name,
            t.User,
            t.Seeders,
            t.Leechers,
            t.Magnet(),
        )
    }

    return nil
}