Migrated to git.0x0001f346.de/andreas/utils
This commit is contained in:
parent
b6feda9345
commit
aee9952b8a
@ -5,10 +5,10 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
"git.0x0001f346.de/andreas/utils"
|
||||
"github.com/gocolly/colly"
|
||||
)
|
||||
|
||||
@ -108,22 +108,13 @@ func convertIMDbRuntimeIntoMinutes(s string) int64 {
|
||||
if strings.Contains(s, "H") {
|
||||
if strings.Contains(s, "M") {
|
||||
ss := strings.Split(strings.Replace(s, "M", "", -1), "H")
|
||||
return (convertStringToIntOrZeroOnError(ss[0]) * 60) + convertStringToIntOrZeroOnError(ss[1])
|
||||
return (utils.ConvertStringToIntOrZeroOnError(ss[0]) * 60) + utils.ConvertStringToIntOrZeroOnError(ss[1])
|
||||
}
|
||||
|
||||
return convertStringToIntOrZeroOnError(strings.Replace(s, "H", "", -1)) * 60
|
||||
return utils.ConvertStringToIntOrZeroOnError(strings.Replace(s, "H", "", -1)) * 60
|
||||
}
|
||||
|
||||
return convertStringToIntOrZeroOnError(strings.Replace(s, "M", "", -1))
|
||||
}
|
||||
|
||||
func convertStringToIntOrZeroOnError(s string) int64 {
|
||||
i, err := strconv.ParseInt(s, 10, 64)
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
|
||||
return i
|
||||
return utils.ConvertStringToIntOrZeroOnError(strings.Replace(s, "M", "", -1))
|
||||
}
|
||||
|
||||
func extractYearFromIMDbTitle(s string, title string) int64 {
|
||||
@ -138,7 +129,7 @@ func extractYearFromIMDbTitle(s string, title string) int64 {
|
||||
continue
|
||||
}
|
||||
|
||||
year := convertStringToIntOrZeroOnError(
|
||||
year := utils.ConvertStringToIntOrZeroOnError(
|
||||
strings.Replace(
|
||||
strings.Replace(chunck, "(", "", -1),
|
||||
")",
|
||||
|
@ -31,23 +31,6 @@ func TestConvertIMDbRuntimeIntoMinutes(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestConvertStringToIntOrZeroOnError(t *testing.T) {
|
||||
data := map[string]int64{
|
||||
"-13": -13,
|
||||
"0": 0,
|
||||
"13": 13,
|
||||
"Son Goku": 0,
|
||||
"1f346": 0,
|
||||
}
|
||||
|
||||
for d, expectedResult := range data {
|
||||
result := convertStringToIntOrZeroOnError(d)
|
||||
if result != expectedResult {
|
||||
t.Errorf("\ngot: %d\nwanted: %d\nfor: %q", result, expectedResult, d)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetIMDbIDFromQuery(t *testing.T) {
|
||||
data := map[string]string{
|
||||
"tt2861424": "tt2861424",
|
||||
|
Loading…
Reference in New Issue
Block a user