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
}
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)
var res types.FullVideoType
var poster []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 {
fmt.Printf("Error getting full data list of videoid - %d", args.MovieId)
fmt.Println(err.Error())

View File

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

View File

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

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

View File

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

View File

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