add release date to videopage

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

View File

@ -276,14 +276,14 @@ func loadVideosHandlers() {
return return
} }
query := fmt.Sprintf(`SELECT movie_name,movie_url,movie_id,thumbnail,poster,likes,quality,length query := fmt.Sprintf(`SELECT movie_name,movie_url,movie_id,thumbnail,poster,likes,quality,length,release_date
FROM videos WHERE movie_id=%d`, args.MovieId) FROM videos WHERE movie_id=%d`, args.MovieId)
var res types.FullVideoType var res types.FullVideoType
var poster []byte var poster []byte
var thumbnail []byte var thumbnail []byte
err := database.QueryRow(query).Scan(&res.MovieName, &res.MovieUrl, &res.MovieId, &thumbnail, &poster, &res.Likes, &res.Quality, &res.Length) err := database.QueryRow(query).Scan(&res.MovieName, &res.MovieUrl, &res.MovieId, &thumbnail, &poster, &res.Likes, &res.Quality, &res.Length, &res.ReleaseDate)
if err != nil { if err != nil {
fmt.Printf("Error getting full data list of videoid - %d", args.MovieId) fmt.Printf("Error getting full data list of videoid - %d", args.MovieId)
fmt.Println(err.Error()) fmt.Println(err.Error())

View File

@ -10,6 +10,7 @@ type FullVideoType struct {
MovieId uint32 MovieId uint32
MovieUrl string MovieUrl string
Poster string Poster string
ReleaseDate *string
Likes uint64 Likes uint64
Quality uint16 Quality uint16
Length uint16 Length uint16

View File

@ -9,6 +9,7 @@ import (
"log" "log"
"openmediacenter/apiGo/api/types" "openmediacenter/apiGo/api/types"
"openmediacenter/apiGo/config" "openmediacenter/apiGo/config"
"os"
) )
var db *sql.DB var db *sql.DB
@ -37,9 +38,10 @@ func InitDB() error {
} }
} }
log.Printf("Running Database migrations!") fmt.Println("Running Database migrations!")
// perform database migrations // perform database migrations
goose.SetBaseFS(embedMigrations) goose.SetBaseFS(embedMigrations)
goose.SetLogger(log.New(os.Stdout, "", 0))
// set mysql dialect // set mysql dialect
err = goose.SetDialect("mysql") err = goose.SetDialect("mysql")

View File

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

View File

@ -18,6 +18,7 @@ type VideoTMDB struct {
Thumbnail string Thumbnail string
Overview string Overview string
Title string Title string
ReleaseDate string
GenreIds []int GenreIds []int
} }
@ -123,6 +124,7 @@ cont:
Thumbnail: thumbnail, Thumbnail: thumbnail,
Overview: tmdbVid.Overview, Overview: tmdbVid.Overview,
Title: tmdbVid.Title, Title: tmdbVid.Title,
ReleaseDate: tmdbVid.ReleaseDate,
GenreIds: tmdbVid.GenreIds, GenreIds: tmdbVid.GenreIds,
} }

View File

@ -32,6 +32,7 @@ interface mystate {
movieName: string; movieName: string;
likes: number; likes: number;
quality: number; quality: number;
releaseDate: string | null;
length: number; length: number;
tags: TagType[]; tags: TagType[];
suggesttag: TagType[]; suggesttag: TagType[];
@ -54,6 +55,7 @@ export class Player extends React.Component<Props, mystate> {
movieName: '', movieName: '',
likes: 0, likes: 0,
quality: 0, quality: 0,
releaseDate: null,
length: 0, length: 0,
tags: [], tags: [],
suggesttag: [], suggesttag: [],
@ -131,6 +133,11 @@ export class Player extends React.Component<Props, mystate> {
<b>{this.state.quality}p</b> Quality! <b>{this.state.quality}p</b> Quality!
</SideBarItem> </SideBarItem>
) : null} ) : null}
{this.state.releaseDate !== null ? (
<SideBarItem>
<b>{this.state.releaseDate}</b> released!
</SideBarItem>
) : null}
{this.state.length !== 0 ? ( {this.state.length !== 0 ? (
<SideBarItem> <SideBarItem>
<b>{Math.round(this.state.length / 60)}</b> Minutes of length! <b>{Math.round(this.state.length / 60)}</b> Minutes of length!
@ -323,6 +330,7 @@ export class Player extends React.Component<Props, mystate> {
movieName: result.MovieName, movieName: result.MovieName,
likes: result.Likes, likes: result.Likes,
quality: result.Quality, quality: result.Quality,
releaseDate: result.ReleaseDate,
length: result.Length, length: result.Length,
tags: result.Tags, tags: result.Tags,
suggesttag: result.SuggestedTag, suggesttag: result.SuggestedTag,

View File

@ -8,6 +8,7 @@ export namespace VideoTypes {
MovieName: string; MovieName: string;
Likes: number; Likes: number;
Quality: number; Quality: number;
ReleaseDate: string | null;
Length: number; Length: number;
Tags: TagType[]; Tags: TagType[];
SuggestedTag: TagType[]; SuggestedTag: TagType[];