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

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) {
var swsctx *gmf.SwsCtx
gmf.LogSetLevel(gmf.AV_LOG_ERROR)
gmf.LogSetLevel(gmf.AV_LOG_PANIC)
stat, err := os.Stat(srcFileName)
if err != nil {

View File

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

View File

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