use correct filepath when checking if tv show episode already exits in databse
This commit is contained in:
parent
61ea42ef01
commit
dfcb7f71d9
@ -5,7 +5,6 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Jsonify(v interface{}) []byte {
|
func Jsonify(v interface{}) []byte {
|
||||||
@ -30,45 +29,3 @@ func DecodeRequest(request *http.Request, arg interface{}) error {
|
|||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// setField set a specific field of an object with an object provided
|
|
||||||
func setField(obj interface{}, name string, value interface{}) error {
|
|
||||||
structValue := reflect.ValueOf(obj).Elem()
|
|
||||||
structFieldValue := structValue.FieldByName(name)
|
|
||||||
|
|
||||||
if !structFieldValue.IsValid() {
|
|
||||||
return fmt.Errorf("no such field: %s in obj", name)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !structFieldValue.CanSet() {
|
|
||||||
return fmt.Errorf("cannot set %s field value", name)
|
|
||||||
}
|
|
||||||
|
|
||||||
structFieldType := structFieldValue.Type()
|
|
||||||
val := reflect.ValueOf(value)
|
|
||||||
|
|
||||||
if structFieldType != val.Type() {
|
|
||||||
if val.Type().ConvertibleTo(structFieldType) {
|
|
||||||
// if type is convertible - convert and set
|
|
||||||
structFieldValue.Set(val.Convert(structFieldType))
|
|
||||||
} else {
|
|
||||||
return fmt.Errorf("provided value %s type didn't match obj field type and isn't convertible", name)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// set value if type is the same
|
|
||||||
structFieldValue.Set(val)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// FillStruct fill a custom struct with objects of a map
|
|
||||||
func FillStruct(i interface{}, m map[string]interface{}) error {
|
|
||||||
for k, v := range m {
|
|
||||||
err := setField(i, k, v)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
@ -25,21 +25,18 @@ func startTVShowReindex(files []Show) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func insertEpisodesIfNotExisting(show Show) {
|
func insertEpisodesIfNotExisting(show Show) {
|
||||||
query := "SELECT tvshow_episodes.name, season, episode FROM tvshow_episodes JOIN tvshow t on t.id = tvshow_episodes.tvshow_id WHERE t.name=?"
|
query := "SELECT filename FROM tvshow_episodes JOIN tvshow t on t.id = tvshow_episodes.tvshow_id WHERE t.name=?"
|
||||||
rows := database.Query(query, show.Name)
|
rows := database.Query(query, show.Name)
|
||||||
|
|
||||||
var dbepisodes []string
|
var dbepisodes []string
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var epname string
|
var filename string
|
||||||
var season int
|
err := rows.Scan(&filename)
|
||||||
var episode int
|
|
||||||
err := rows.Scan(&epname, &season, &episode)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo no fixed mp4 extension here!
|
dbepisodes = append(dbepisodes, filename)
|
||||||
dbepisodes = append(dbepisodes, fmt.Sprintf("%s S%02dE%02d.mp4", epname, season, episode))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// get those episodes that are missing in db
|
// get those episodes that are missing in db
|
||||||
@ -84,6 +81,10 @@ VALUES (?, ?, ?, (SELECT tvshow.id FROM tvshow WHERE tvshow.name=?), ?, ?)`
|
|||||||
|
|
||||||
// difference returns the elements in `a` that aren't in `b`.
|
// difference returns the elements in `a` that aren't in `b`.
|
||||||
func difference(a, b []string) []string {
|
func difference(a, b []string) []string {
|
||||||
|
if b == nil || len(b) == 0 {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
mb := make(map[string]struct{}, len(b))
|
mb := make(map[string]struct{}, len(b))
|
||||||
for _, x := range b {
|
for _, x := range b {
|
||||||
mb[x] = struct{}{}
|
mb[x] = struct{}{}
|
||||||
@ -130,7 +131,10 @@ func getAllTVShows() *[]string {
|
|||||||
var res []string
|
var res []string
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var show string
|
var show string
|
||||||
rows.Scan(&show)
|
err := rows.Scan(&show)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
res = append(res, show)
|
res = append(res, show)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user