add release date to videopage

improve reindex db insertion logic
This commit is contained in:
2021-09-28 10:52:18 +02:00
parent 0df96a093f
commit 3588df7c4f
7 changed files with 49 additions and 32 deletions

View File

@ -103,7 +103,6 @@ func ProcessVideo(fileNameOrig string) {
// add a video to the database
func addVideo(videoName string, fileName string, year int) {
var ppic *string
var poster *string
var tmdbData *tmdb.VideoTMDB
var err error
var insertid int64
@ -113,32 +112,29 @@ func addVideo(videoName string, fileName string, year int) {
// if TMDB grabbing is enabled serach in api for video...
if mSettings.TMDBGrabbing {
tmdbData = tmdb.SearchVideo(videoName, year)
if tmdbData != nil {
// and tmdb pic as thumbnail
poster = &tmdbData.Thumbnail
}
}
// parse pic from 4min frame
ppic, vinfo, err := thumbnail.Parse(vidFolder+fileName, 240)
// use parsed pic also for poster pic
if poster == nil {
poster = ppic
}
ppic, vinfo, ffmpegErr := thumbnail.Parse(vidFolder+fileName, 240)
if err != nil {
fmt.Printf("FFmpeg error occured: %s\n", err.Error())
// 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)
if ffmpegErr == nil {
if mSettings.TMDBGrabbing && tmdbData != nil {
query := `INSERT INTO videos(movie_name,movie_url,poster,thumbnail,quality,length,release_date) VALUES (?,?,?,?,?,?,?)`
err, insertid = database.Insert(query, videoName, fileName, ppic, tmdbData.Thumbnail, vinfo.Width, vinfo.Length, tmdbData.ReleaseDate)
} else {
// insert without tmdb info
query := `INSERT INTO videos(movie_name,movie_url,poster,thumbnail,quality,length) VALUES (?,?,?,?,?,?)`
err, insertid = database.Insert(query, videoName, fileName, ppic, ppic, vinfo.Width, vinfo.Length)
}
} 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)
fmt.Printf("FFmpeg error occured: %s\n", ffmpegErr.Error())
// add default tags
if vinfo.Width != 0 && err == nil {
insertSizeTag(uint(vinfo.Width), uint(insertid))
if mSettings.TMDBGrabbing && tmdbData != nil {
query := `INSERT INTO videos(movie_name,movie_url,thumbnail,release_date) VALUES (?,?,?,?)`
err, insertid = database.Insert(query, videoName, fileName, tmdbData.Thumbnail, tmdbData.ReleaseDate)
} else {
query := `INSERT INTO videos(movie_name,movie_url) VALUES (?,?)`
err, insertid = database.Insert(query, videoName, fileName)
}
}
@ -147,6 +143,13 @@ func addVideo(videoName string, fileName string, year int) {
return
}
if ffmpegErr == nil {
// add default tags
if vinfo.Width != 0 {
insertSizeTag(uint(vinfo.Width), uint(insertid))
}
}
// add tmdb tags
if mSettings.TMDBGrabbing && tmdbData != nil {
insertTMDBTags(tmdbData.GenreIds, insertid)

View File

@ -15,10 +15,11 @@ const baseUrl = "https://api.themoviedb.org/3/"
const pictureBase = "https://image.tmdb.org/t/p/w500"
type VideoTMDB struct {
Thumbnail string
Overview string
Title string
GenreIds []int
Thumbnail string
Overview string
Title string
ReleaseDate string
GenreIds []int
}
type TVShowTMDB struct {
@ -120,10 +121,11 @@ cont:
}
result := VideoTMDB{
Thumbnail: thumbnail,
Overview: tmdbVid.Overview,
Title: tmdbVid.Title,
GenreIds: tmdbVid.GenreIds,
Thumbnail: thumbnail,
Overview: tmdbVid.Overview,
Title: tmdbVid.Title,
ReleaseDate: tmdbVid.ReleaseDate,
GenreIds: tmdbVid.GenreIds,
}
return &result