package tmdb import ( "fmt" "regexp" "strconv" ) var EpisodeRegex = regexp.MustCompile(`https?://(?:www\.)?themoviedb\.org/tv/([0-9]+)(?:-[A-Za-z0-9-]+)?/season/([0-9]+)/episode/([0-9]+)`) var MovieRegex = regexp.MustCompile(`https?://(?:www\.)?themoviedb\.org/movie/([0-9]+)(?:-[A-Za-z0-9-]+)?/?`) func Parse(url string) (inf Info, err error) { if m := EpisodeRegex.FindStringSubmatch(url); len(m) > 0 { var got int got, err = strconv.Atoi(m[1]) if err != nil { return } inf.ID = got got, err = strconv.Atoi(m[2]) if err != nil { return } inf.Season = got got, err = strconv.Atoi(m[3]) if err != nil { return } inf.Episode = got inf.Type = Series return } if m := MovieRegex.FindStringSubmatch(url); len(m) > 0 { var got int got, err = strconv.Atoi(m[1]) if err != nil { return } inf.ID = got inf.Type = Movie return } return inf, fmt.Errorf("failed to parse %s", url) }