fix lukas/openmediacenter#68 tmdb categories not indexed correctly

This commit is contained in:
lukas 2021-09-27 19:30:18 +02:00
parent e4f09eddac
commit 881281af70
4 changed files with 29 additions and 17 deletions

View File

@ -129,9 +129,9 @@ func addVideo(videoName string, fileName string, year int) {
if err != nil { if err != nil {
fmt.Printf("FFmpeg error occured: %s\n", err.Error()) fmt.Printf("FFmpeg error occured: %s\n", err.Error())
query := `INSERT INTO videos(movie_name,movie_url) VALUES (?,?)` // we insert the poster here also because it might not be nil when tmdb index is enabled.
err, insertid = database.Insert(query, videoName, fileName) query := `INSERT INTO videos(movie_name,movie_url,thumbnail) VALUES (?,?,?)`
err, insertid = database.Insert(query, videoName, fileName, poster)
} else { } else {
query := `INSERT INTO videos(movie_name,movie_url,poster,thumbnail,quality,length) VALUES (?,?,?,?,?,?)` query := `INSERT INTO videos(movie_name,movie_url,poster,thumbnail,quality,length) VALUES (?,?,?,?,?,?)`
err, insertid = database.Insert(query, videoName, fileName, ppic, poster, vinfo.Width, vinfo.Length) err, insertid = database.Insert(query, videoName, fileName, ppic, poster, vinfo.Width, vinfo.Length)
@ -211,22 +211,30 @@ func insertTMDBTags(ids []int, videoId int64) {
// now we check if the tag we want to add already exists // now we check if the tag we want to add already exists
tagId := createTagToDB(idGenre.Name) tagId := createTagToDB(idGenre.Name)
if tagId != -1 {
// now we add the tag // now we add the tag
query := fmt.Sprintf("INSERT INTO video_tags(video_id,tag_id) VALUES (%d,%d)", videoId, tagId) query := fmt.Sprintf("INSERT INTO video_tags(video_id,tag_id) VALUES (%d,%d)", videoId, tagId)
_ = database.Edit(query) _ = database.Edit(query)
} }
} }
}
// returns id of tag or creates it if not existing // returns id of tag or creates it if not existing
func createTagToDB(tagName string) int64 { func createTagToDB(tagName string) int64 {
query := fmt.Sprintf("SELECT tag_id FROM tags WHERE tag_name = %s", tagName) query := "SELECT tag_id FROM tags WHERE tag_name = ?"
var id int64 var id int64 = -1
err := database.QueryRow(query).Scan(&id) err := database.QueryRow(query, tagName).Scan(&id)
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
// tag doesn't exist -- add it // tag doesn't exist -- add it
query = fmt.Sprintf("INSERT INTO tags (tag_name) VALUES (%s)", tagName) query = "INSERT INTO tags (tag_name) VALUES (?)"
err, id = database.Insert(query) err, id = database.Insert(query, tagName)
if err != nil {
fmt.Println(err.Error())
}
} else if err != nil {
if err != nil {
fmt.Println(err.Error())
}
} }
return id return id
} }

View File

@ -23,7 +23,7 @@ func Parse(filename string, time uint64) (*string, *VidInfo, error) {
func decodePic(srcFileName string, decodeExtension string, time uint64) (pic *[]byte, info *VidInfo, err error) { func decodePic(srcFileName string, decodeExtension string, time uint64) (pic *[]byte, info *VidInfo, err error) {
var swsctx *gmf.SwsCtx var swsctx *gmf.SwsCtx
gmf.LogSetLevel(gmf.AV_LOG_ERROR) gmf.LogSetLevel(gmf.AV_LOG_PANIC)
stat, err := os.Stat(srcFileName) stat, err := os.Stat(srcFileName)
if err != nil { if err != nil {

View File

@ -205,10 +205,14 @@ func fetchGenres() *[]TMDBGenre {
return nil return nil
} }
var t []TMDBGenre type RespType struct {
Genres []TMDBGenre
}
var t RespType
err = json.Unmarshal(body, &t) err = json.Unmarshal(body, &t)
return &t return &t.Genres
} }
func GetGenres() *[]TMDBGenre { func GetGenres() *[]TMDBGenre {

View File

@ -56,8 +56,8 @@ create table if not exists videos
thumbnail mediumblob null, thumbnail mediumblob null,
poster mediumblob null, poster mediumblob null,
likes int default 0 null, likes int default 0 null,
quality int null, quality int default 0 null,
length int null comment 'in seconds', length int default 0 null comment 'in seconds',
create_date datetime default current_timestamp() null create_date datetime default current_timestamp() null
); );