Skip to content

Instantly share code, notes, and snippets.

@Brawdunoir
Created September 6, 2024 21:11
Show Gist options
  • Save Brawdunoir/d89a79eea9fcbd0cb2d917ec145c924a to your computer and use it in GitHub Desktop.
Save Brawdunoir/d89a79eea9fcbd0cb2d917ec145c924a to your computer and use it in GitHub Desktop.
Compare movie collection for sharewood private tracker. Usage in main.go comments.
module main
go 1.23
require github.com/bitfield/script v0.22.1
require (
github.com/itchyny/gojq v0.12.13 // indirect
github.com/itchyny/timefmt-go v0.1.5 // indirect
mvdan.cc/sh/v3 v3.7.0 // indirect
)
package main
import (
"os"
"strconv"
"strings"
"time"
"github.com/bitfield/script"
)
/*
Set API_KEY environment variable.
Set SLEEP_TIME_MS environment variable to sleep time in milliseconds (optional, default 200)
Example:
API_KEY=1234567890 SLEEP_TIME_MS=500 go run main.go < input.txt > output.txt
*/
func main() {
apiKey := os.Getenv("API_KEY")
if apiKey == "" {
panic("API_KEY environment variable is not set")
}
sleepTime := os.Getenv("SLEEP_TIME_MS")
if sleepTime == "" {
sleepTime = "200"
}
urlPrefix := "https://www.sharewood.tv/api/" + apiKey + "/search?subcategory=9&name="
movies, err := script.Stdin().Replace(" - ", " ").Replace("(", "").Replace(")", "").Slice()
if err != nil {
panic(err)
}
for _, movie := range movies {
url := urlPrefix + movie
result, err := script.Get(url).JQ(".[].slug").Slice()
if err != nil {
panic(err)
}
if len(result) == 0 {
println("Not found," + movie)
} else {
println("Found," + movie + ",results=" + strings.Join(result, ","))
}
sleepTimeInt, err := strconv.Atoi(sleepTime)
if err != nil {
panic(err)
}
time.Sleep(time.Millisecond * time.Duration(sleepTimeInt))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment