✨ Add drop:tmdb command for adding shows/movies to watched log
This commit is contained in:
parent
21d27f8068
commit
88802020fe
10 changed files with 377 additions and 3 deletions
52
tmdb/parse.go
Normal file
52
tmdb/parse.go
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
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)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue