diff --git a/config-example.json b/config-example.json new file mode 100644 index 0000000..990d769 --- /dev/null +++ b/config-example.json @@ -0,0 +1,7 @@ +{ + "BotToken": "your_bot_token", + "SonarrAPIURL": "http://example.com/tv/api/", + "SonarrAPIKey": "your key", + "PlexPyAPIURL": "http://example.com/plexpy/api/v2", + "PlexPyAPIKey": "your key" + } \ No newline at end of file diff --git a/config.json b/config.json deleted file mode 100644 index 8bfa7a7..0000000 --- a/config.json +++ /dev/null @@ -1,5 +0,0 @@ -{ -"Token": "546410284:AAHXKhEsAB5OZTrAXCFI4kiZSFjN5i0h_wk", -"SonarrAPIURL": "http://dvr.linuxrocker.com/tv/api/", -"SonarrAPIKey": "69e7a095a1c94f42b150380864a6c92a" -} \ No newline at end of file diff --git a/go_telegram b/go_telegram index ae5505c..5a910e9 100755 Binary files a/go_telegram and b/go_telegram differ diff --git a/main.go b/main.go index bbefbe1..141497e 100644 --- a/main.go +++ b/main.go @@ -13,43 +13,43 @@ import ( // Config - Specify what to look for in Config file var Config struct { - BotToken string - SonarrAPIURL string - SonarrAPIKey string - PlexPyAPIURL string - PlexPyAPIKey string - RadarrAPIURL string - RadarrAPIKey string - CouchPotatoAPIURL string - CouchPotatoAPIKey string - PlexAPIURL string - PlexAPIKey string + BotToken string + SonarrAPIURL string + SonarrAPIKey string + PlexPyAPIURL string + PlexPyAPIKey string + // RadarrAPIURL string + // RadarrAPIKey string + // CouchPotatoAPIURL string + // CouchPotatoAPIKey string + // PlexAPIURL string + // PlexAPIKey string } func sonarrStatus(message *tbot.Message) { - response, err := http.Get(Config.SonarrAPIURL + "system/status?apikey=" + Config.SonarrAPIKey) + r, err := http.Get(Config.SonarrAPIURL + "system/status?apikey=" + Config.SonarrAPIKey) if err != nil { log.Fatal(err) os.Exit(1) } - responseData, err := ioutil.ReadAll(response.Body) + rd, err := ioutil.ReadAll(r.Body) if err != nil { log.Fatal(err) } - message.Replyf("%s", responseData) + message.Replyf("%s", rd) } func sonarrVersion(message *tbot.Message) { - response, err := http.Get(Config.SonarrAPIURL + "system/status?apikey=" + Config.SonarrAPIKey) + r, err := http.Get(Config.SonarrAPIURL + "system/status?apikey=" + Config.SonarrAPIKey) if err != nil { log.Fatal(err) } - responseData, err := ioutil.ReadAll(response.Body) + rd, err := ioutil.ReadAll(r.Body) if err != nil { log.Fatal(err) } @@ -58,19 +58,42 @@ func sonarrVersion(message *tbot.Message) { Version string `json:"version"` } - version := Version{} - jsonErr := json.Unmarshal(responseData, &version) - if jsonErr != nil { - log.Fatal(jsonErr) + v := Version{} + jv := json.Unmarshal(rd, &v) + if jv != nil { + log.Fatal(jv) } - message.Replyf("%s", version.Version) + message.Replyf("%s", v.Version) } -// func activeSteamers(message *tbot.Message) { -// response, err := http.Get(Config.PlexAPIURL + "api/v2?apikey=" + Config.PlexAPIKey + "&cmd=") -// } +func activeSteamers(message *tbot.Message) { + r, err := http.Get(Config.PlexPyAPIURL + "?apikey=" + Config.PlexPyAPIKey + "&cmd=get_activity") + if err != nil { + log.Fatal(err) + } + + rd, err := ioutil.ReadAll(r.Body) + if err != nil { + log.Fatal(err) + } + + type Activity struct { + StreamCount int `json:"stream_count"` + StreamCountDirectPlay int `json:"stream_count_direct_play"` + StreamCountDirectStream int `json:"stream_count_direct_stream"` + StreamCountTranscode int `json:"stream_count_transcode"` + } + + a := Activity{} + ja := json.Unmarshal(rd, &a) + if ja != nil { + log.Fatal(ja) + } + + message.Replyf("Stream Count: %v \nStream Count (Direct Play): %v \nStream Count (Direct Stream): %v \nStream Count (Transcode): %v", a.StreamCount, a.StreamCountDirectPlay, a.StreamCountDirectStream, a.StreamCountTranscode) +} func main() { c := flag.String("c", "./config.json", "Specify the configuration file.") @@ -100,6 +123,8 @@ func main() { bot.HandleFunc("/sonarr_version", sonarrVersion) + bot.HandleFunc("/activity", activeSteamers) + // Start Listening err = bot.ListenAndServe() log.Fatal(err)