golift / starr

Starr Library: Fully functional go package to interact with Lidarr, Prowlarr, Radarr, Readarr, and Sonarr APIs.
https://golift.io/discord
MIT License
68 stars 18 forks source link

Copy Indexer structs example #164

Open davidnewhall opened 1 month ago

davidnewhall commented 1 month ago

This code will only be merged if someone finds it useful. Please leave a comment telling us how you used this code, and if it worked for you.

Example Usage:

import (
    "golift.io/starr"
    "golift.io/starr/orbit"
    "golift.io/starr/prowlarr"
    "golift.io/starr/sonarr"
)

func Main() {
    p := prowlarr.New(&starr.Config{
        URL:    "http://192.168.3.2:9696/prowlarr/",
        APIKey: "abc",
    })

    s := sonarr.New(&starr.Config{
        URL:    "http://192.168.3.2:8989/sonarr/",
        APIKey: "xyz",
    })

    indexers, err := p.GetIndexers()
    if err != nil {
        panic(err)
    }

    for _, indexer := range indexers {
        input := &sonarr.IndexerInput{
            EnableAutomaticSearch:   true,
            EnableInteractiveSearch: true,
            EnableRss:               true,
            DownloadClientID:        15, // probably need to do more hits to find this ID in Sonarr.
        }

        _, err = s.AddIndexer(starr.Must(orbit.CopyIndexer(indexer, input, false)))
        if err != nil {
            panic(err)
        }
    }
}