Episodes are now inserted into database
This commit is contained in:
@@ -132,6 +132,8 @@ CREATE TABLE tvshows(
|
|||||||
);
|
);
|
||||||
CREATE TABLE episodes(
|
CREATE TABLE episodes(
|
||||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
title TEXT,
|
||||||
|
show_title TEXT,
|
||||||
number INTEGER,
|
number INTEGER,
|
||||||
season INTEGER
|
season INTEGER
|
||||||
);
|
);
|
||||||
@@ -177,7 +179,7 @@ func scan_tvshow_root(root string, db *sql.DB) error {
|
|||||||
if file.IsDir() {
|
if file.IsDir() {
|
||||||
show_path := filepath.Join(root, file.Name())
|
show_path := filepath.Join(root, file.Name())
|
||||||
if insert_tvshow_nfo(show_path, stmt) {
|
if insert_tvshow_nfo(show_path, stmt) {
|
||||||
err = scan_tvshow_episodes(show_path)
|
err = scan_tvshow_episodes(show_path, tx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Could not scan for episodes in %v: %v", show_path, err)
|
fmt.Fprintf(os.Stderr, "Could not scan for episodes in %v: %v", show_path, err)
|
||||||
continue
|
continue
|
||||||
@@ -233,7 +235,7 @@ type Episode struct {
|
|||||||
Episode int `xml:"episode"`
|
Episode int `xml:"episode"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func scan_tvshow_episodes(show_dir string) error {
|
func scan_tvshow_episodes(show_dir string, tx *sql.Tx) error {
|
||||||
|
|
||||||
log.Infof("Scanning episodes for show %v\n", show_dir)
|
log.Infof("Scanning episodes for show %v\n", show_dir)
|
||||||
|
|
||||||
@@ -244,6 +246,12 @@ func scan_tvshow_episodes(show_dir string) error {
|
|||||||
|
|
||||||
num_episodes := 0
|
num_episodes := 0
|
||||||
|
|
||||||
|
stmt, err := tx.Prepare("insert into episodes(title, show_title, number, season) values(?, ?, ?, ?)")
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Could not prepare statement: %v", err)
|
||||||
|
}
|
||||||
|
defer stmt.Close()
|
||||||
|
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
ext := filepath.Ext(file.Name())
|
ext := filepath.Ext(file.Name())
|
||||||
nfo_path := filepath.Join(show_dir, file.Name())
|
nfo_path := filepath.Join(show_dir, file.Name())
|
||||||
@@ -285,6 +293,12 @@ func scan_tvshow_episodes(show_dir string) error {
|
|||||||
log.Debugf(" Episode %v\n", episode.Episode)
|
log.Debugf(" Episode %v\n", episode.Episode)
|
||||||
log.Debugf(" Show: %v\n", episode.ShowTitle)
|
log.Debugf(" Show: %v\n", episode.ShowTitle)
|
||||||
|
|
||||||
|
_, err = stmt.Exec(episode.Title, episode.ShowTitle, episode.Episode, episode.Season)
|
||||||
|
if err != nil {
|
||||||
|
log.Debugf("Could not insert episode %v of tvshow \"%v\" into database: %v\n", episode.Episode, episode.ShowTitle, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
num_episodes++
|
num_episodes++
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -294,7 +308,6 @@ func scan_tvshow_episodes(show_dir string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var log = logging.MustGetLogger("ikinuki-server")
|
var log = logging.MustGetLogger("ikinuki-server")
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|||||||
Reference in New Issue
Block a user