Skip to content

Commit

Permalink
added handling of custom Trakt API CLient ID
Browse files Browse the repository at this point in the history
  • Loading branch information
elgatito committed Dec 25, 2019
1 parent 86214aa commit 4733002
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
11 changes: 11 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ type Configuration struct {
AutoScrapeLimitMovies int
AutoScrapeInterval int

TraktClientID string
TraktClientSecret string
TraktUsername string
TraktToken string
TraktRefreshToken string
Expand Down Expand Up @@ -552,6 +554,8 @@ func Reload() *Configuration {
AutoScrapeLimitMovies: settings["autoscrape_limit_movies"].(int),
AutoScrapeInterval: settings["autoscrape_interval"].(int),

TraktClientID: settings["trakt_client_id"].(string),
TraktClientSecret: settings["trakt_client_secret"].(string),
TraktUsername: settings["trakt_username"].(string),
TraktToken: settings["trakt_token"].(string),
TraktRefreshToken: settings["trakt_refresh_token"].(string),
Expand Down Expand Up @@ -644,6 +648,13 @@ func Reload() *Configuration {
LocalOnlyClient: settings["local_only_client"].(bool),
}

if newConfig.TraktClientID == "" {
newConfig.TraktClientID = "2f911cee953f0af7833191d2b929e9a842bf8752e6b1afb458c8ff9ffc1d2c85"
}
if newConfig.TraktClientSecret == "" {
newConfig.TraktClientSecret = "b290a36c1144c4baa937dcc9023b3cd44398cca46975928a3d833f7593f00980"
}

// Fallback for old configuration with additional storage variants
if newConfig.DownloadStorage > 1 {
newConfig.DownloadStorage = 1
Expand Down
20 changes: 8 additions & 12 deletions trakt/trakt.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ import (
const (
// APIURL ...
APIURL = "https://api.trakt.tv"
// ClientID ...
ClientID = "2f911cee953f0af7833191d2b929e9a842bf8752e6b1afb458c8ff9ffc1d2c85"
// ClientSecret ...
ClientSecret = "b290a36c1144c4baa937dcc9023b3cd44398cca46975928a3d833f7593f00980"
// APIVersion ...
APIVersion = "2"
)
Expand Down Expand Up @@ -569,7 +565,7 @@ func getIntFromHeader(headers http.Header, key string) (res int) {
func Get(endPoint string, params url.Values) (resp *napping.Response, err error) {
header := http.Header{
"Content-type": []string{"application/json"},
"trakt-api-key": []string{ClientID},
"trakt-api-key": []string{config.Get().TraktClientID},
"trakt-api-version": []string{APIVersion},
"User-Agent": []string{UserAgent},
"Cookie": []string{Cookies},
Expand Down Expand Up @@ -605,7 +601,7 @@ func GetWithAuth(endPoint string, params url.Values) (resp *napping.Response, er
header := http.Header{
"Content-type": []string{"application/json"},
"Authorization": []string{fmt.Sprintf("Bearer %s", config.Get().TraktToken)},
"trakt-api-key": []string{ClientID},
"trakt-api-key": []string{config.Get().TraktClientID},
"trakt-api-version": []string{APIVersion},
"User-Agent": []string{UserAgent},
"Cookie": []string{Cookies},
Expand Down Expand Up @@ -658,7 +654,7 @@ func Post(endPoint string, payload *bytes.Buffer) (resp *napping.Response, err e
header := http.Header{
"Content-type": []string{"application/json"},
"Authorization": []string{fmt.Sprintf("Bearer %s", config.Get().TraktToken)},
"trakt-api-key": []string{ClientID},
"trakt-api-key": []string{config.Get().TraktClientID},
"trakt-api-version": []string{APIVersion},
"User-Agent": []string{UserAgent},
"Cookie": []string{Cookies},
Expand Down Expand Up @@ -699,7 +695,7 @@ func GetCode() (code *Code, err error) {
"Cookie": []string{Cookies},
}
params := napping.Params{
"client_id": ClientID,
"client_id": config.Get().TraktClientID,
}.AsUrlValues()

req := napping.Request{
Expand Down Expand Up @@ -744,8 +740,8 @@ func GetToken(code string) (resp *napping.Response, err error) {
}
params := napping.Params{
"code": code,
"client_id": ClientID,
"client_secret": ClientSecret,
"client_id": config.Get().TraktClientID,
"client_secret": config.Get().TraktClientSecret,
}.AsUrlValues()

req := napping.Request{
Expand Down Expand Up @@ -829,8 +825,8 @@ func RefreshToken() (resp *napping.Response, err error) {
}
params := napping.Params{
"refresh_token": config.Get().TraktRefreshToken,
"client_id": ClientID,
"client_secret": ClientSecret,
"client_id": config.Get().TraktClientID,
"client_secret": config.Get().TraktClientSecret,
"redirect_uri": "urn:ietf:wg:oauth:2.0:oob",
"grant_type": "refresh_token",
}.AsUrlValues()
Expand Down

0 comments on commit 4733002

Please sign in to comment.