trakt: strip non alphanumeric characters from imdb id
This commit is contained in:
@@ -51,7 +51,10 @@ func (c *Client) GetShow(tvdbId string) (*Show, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// translate response
|
// translate response
|
||||||
return &(*b)[0].Show, nil
|
show := &(*b)[0].Show
|
||||||
|
show.Ids.Imdb = util.StripNonAlphaNumeric(show.Ids.Imdb)
|
||||||
|
|
||||||
|
return show, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) GetMovie(imdbId string) (*Movie, error) {
|
func (c *Client) GetMovie(imdbId string) (*Movie, error) {
|
||||||
@@ -92,5 +95,8 @@ func (c *Client) GetMovie(imdbId string) (*Movie, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// translate response
|
// translate response
|
||||||
return &(*b)[0].Movie, nil
|
movie := &(*b)[0].Movie
|
||||||
|
movie.Ids.Imdb = util.StripNonAlphaNumeric(movie.Ids.Imdb)
|
||||||
|
|
||||||
|
return movie, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/sha256"
|
|
||||||
"fmt"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@@ -22,11 +20,3 @@ func Atof64(val string, defaultVal float64) float64 {
|
|||||||
}
|
}
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
func AsSHA256(o interface{}) string {
|
|
||||||
// credits: https://blog.8bitzen.com/posts/22-08-2019-how-to-hash-a-struct-in-go
|
|
||||||
h := sha256.New()
|
|
||||||
h.Write([]byte(fmt.Sprintf("%v", o)))
|
|
||||||
|
|
||||||
return fmt.Sprintf("%x", h.Sum(nil))
|
|
||||||
}
|
|
||||||
14
util/hash.go
Normal file
14
util/hash.go
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/sha256"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
func AsSHA256(o interface{}) string {
|
||||||
|
// credits: https://blog.8bitzen.com/posts/22-08-2019-how-to-hash-a-struct-in-go
|
||||||
|
h := sha256.New()
|
||||||
|
h.Write([]byte(fmt.Sprintf("%v", o)))
|
||||||
|
|
||||||
|
return fmt.Sprintf("%x", h.Sum(nil))
|
||||||
|
}
|
||||||
20
util/string.go
Normal file
20
util/string.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package util
|
||||||
|
|
||||||
|
import "regexp"
|
||||||
|
|
||||||
|
var (
|
||||||
|
reStripNonAlphaNumeric *regexp.Regexp
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
reg, err := regexp.Compile("[^a-zA-Z0-9]+")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
reStripNonAlphaNumeric = reg
|
||||||
|
}
|
||||||
|
|
||||||
|
func StripNonAlphaNumeric(value string) string {
|
||||||
|
// credits: https://golangcode.com/how-to-remove-all-non-alphanumerical-characters-from-a-string/
|
||||||
|
return reStripNonAlphaNumeric.ReplaceAllString(value, "")
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user