Episode nfo files are now parsed
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
|
||||||
|
|
||||||
_ "github.com/mattn/go-sqlite3"
|
_ "github.com/mattn/go-sqlite3"
|
||||||
|
|
||||||
@@ -227,29 +226,68 @@ type Episode struct {
|
|||||||
XMLName xml.Name `xml:"episodedetails"`
|
XMLName xml.Name `xml:"episodedetails"`
|
||||||
Title string `xml:"title"`
|
Title string `xml:"title"`
|
||||||
ShowTitle string `xml:"showtitle"`
|
ShowTitle string `xml:"showtitle"`
|
||||||
Year int `xml:"year"`
|
Season int `xml:"season"`
|
||||||
|
Episode int `xml:"episode"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func scan_tvshow_episodes(show_dir string) error {
|
func scan_tvshow_episodes(show_dir string) error {
|
||||||
|
|
||||||
|
fmt.Printf("Scanning episodes for show %v\n", show_dir)
|
||||||
|
|
||||||
files, err := ioutil.ReadDir(show_dir)
|
files, err := ioutil.ReadDir(show_dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Could not enumerate files in folder: %v", err)
|
return fmt.Errorf("Could not enumerate files in folder: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Regex to see if filename contains SXXEYY string
|
num_episodes := 0
|
||||||
var re = regexp.MustCompile(".*S(\\d+)E(\\d+).*")
|
|
||||||
|
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
parts := re.FindStringSubmatch(file.Name())
|
ext := filepath.Ext(file.Name())
|
||||||
if len(parts) != 3 {
|
nfo_path := filepath.Join(show_dir, file.Name())
|
||||||
fmt.Fprintf(os.Stderr, "Filename \"%v\" failed regex capture (%v)\n", file.Name(), len(parts))
|
|
||||||
|
if file.Name() == "tvshow.nfo" {
|
||||||
|
continue
|
||||||
|
} else if ext == ".nfo" {
|
||||||
|
fmt.Printf("Found nfo file: \"%v\"\n", file.Name())
|
||||||
|
} else {
|
||||||
|
fmt.Printf("Skipping file \"%v\", not an nfo file\n", file.Name())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fmt.Printf("%v: S%vE%v\n", file.Name(), parts[1], parts[2])
|
|
||||||
|
|
||||||
|
fmt.Printf("%v\n", file.Name())
|
||||||
|
|
||||||
|
nfo_file, err := os.OpenFile(nfo_path, os.O_RDONLY, 0755)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "Could not open nfo file \"%v\": %v", nfo_path, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
defer nfo_file.Close()
|
||||||
|
|
||||||
|
// try to parse nfo file
|
||||||
|
data, err := ioutil.ReadAll(nfo_file)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "ERROR: Could not read data from nfo file \"%v\": %v\n", nfo_path, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var episode Episode
|
||||||
|
|
||||||
|
err = xml.Unmarshal(data, &episode)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, "ERROR: Could not parse contents of nfo file \"%v\": %v\n", nfo_path, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf(" Title: %v\n", episode.Title)
|
||||||
|
fmt.Printf(" Season %v\n", episode.Season)
|
||||||
|
fmt.Printf(" Episode %v\n", episode.Episode)
|
||||||
|
fmt.Printf(" Show: %v\n", episode.ShowTitle)
|
||||||
|
|
||||||
|
num_episodes++
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Found %v episodes\n", num_episodes)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user