From 0df96a093f8ce875094381253eca06ab602568e3 Mon Sep 17 00:00:00 2001 From: lukas Date: Tue, 28 Sep 2021 00:36:14 +0200 Subject: [PATCH 1/2] add automatic database migrations with goose --- .gitlab-ci.yml | 2 - apiGo/api/api/Auth.go | 17 --- apiGo/database/Database.go | 28 +++- .../migrations/20210927231631_init.sql | 122 ++++++++++++++++++ .../migrations/20210927235150_relese_date.sql | 12 ++ apiGo/go.mod | 6 +- apiGo/go.sum | 119 +++++------------ apiGo/main.go | 7 +- deb/OpenMediaCenter/DEBIAN/postinst | 4 - 9 files changed, 196 insertions(+), 121 deletions(-) create mode 100644 apiGo/database/migrations/20210927231631_init.sql create mode 100644 apiGo/database/migrations/20210927235150_relese_date.sql diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 34ed729..6442c6c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -93,11 +93,9 @@ Debian_Server: - vers=$(grep -Po '"version":.*?[^\\]",' package.json | grep -Po '[0-9]+\.[0-9]+\.[0-9]+') # parse the version out of package .json - cd deb - mkdir -p "./OpenMediaCenter/var/www/openmediacenter/videos/" - - mkdir -p "./OpenMediaCenter/tmp/" - mkdir -p "./OpenMediaCenter/usr/bin/" - cp -r ../build/* ./OpenMediaCenter/var/www/openmediacenter/ - cp ../apiGo/openmediacenter ./OpenMediaCenter/usr/bin/ - - cp ../database.sql ./OpenMediaCenter/tmp/openmediacenter.sql - 'echo "Version: ${vers}" >> ./OpenMediaCenter/DEBIAN/control' - chmod -R 0775 * - dpkg-deb --build OpenMediaCenter diff --git a/apiGo/api/api/Auth.go b/apiGo/api/api/Auth.go index 982fde0..e03930d 100644 --- a/apiGo/api/api/Auth.go +++ b/apiGo/api/api/Auth.go @@ -3,16 +3,11 @@ package api import ( "fmt" "github.com/dgrijalva/jwt-go" - "gopkg.in/oauth2.v3" - "gopkg.in/oauth2.v3/server" - "net/http" "openmediacenter/apiGo/database" "strconv" "time" ) -var srv *server.Server - type Perm uint8 const ( @@ -103,15 +98,3 @@ func InitOAuth() { }) }) } - -func ValidateToken(f func(rw http.ResponseWriter, req *http.Request, node int, tokenInfo *oauth2.TokenInfo), node int) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - tokeninfo, err := srv.ValidationBearerToken(r) - if err != nil { - http.Error(w, err.Error(), http.StatusBadRequest) - return - } - - f(w, r, node, &tokeninfo) - } -} diff --git a/apiGo/database/Database.go b/apiGo/database/Database.go index e72723d..08be737 100644 --- a/apiGo/database/Database.go +++ b/apiGo/database/Database.go @@ -2,8 +2,11 @@ package database import ( "database/sql" + "embed" "fmt" _ "github.com/go-sql-driver/mysql" + "github.com/pressly/goose/v3" + "log" "openmediacenter/apiGo/api/types" "openmediacenter/apiGo/config" ) @@ -11,7 +14,10 @@ import ( var db *sql.DB var DBName string -func InitDB() { +//go:embed migrations/*.sql +var embedMigrations embed.FS + +func InitDB() error { dbconf := config.GetConfig().Database DBName = dbconf.DBName @@ -21,15 +27,31 @@ func InitDB() { // if there is an error opening the connection, handle it if err != nil { - fmt.Printf("Error while connecting to database! - %s\n", err.Error()) + return fmt.Errorf("Error while connecting to database! - %s\n", err.Error()) } if db != nil { ping := db.Ping() if ping != nil { - fmt.Printf("Error while connecting to database! - %s\n", ping.Error()) + return fmt.Errorf("Error while connecting to database! - %s\n", ping.Error()) } } + + log.Printf("Running Database migrations!") + // perform database migrations + goose.SetBaseFS(embedMigrations) + + // set mysql dialect + err = goose.SetDialect("mysql") + if err != nil { + return err + } + + if err := goose.Up(db, "migrations"); err != nil { + return err + } + + return nil } func Query(query string, args ...interface{}) *sql.Rows { diff --git a/apiGo/database/migrations/20210927231631_init.sql b/apiGo/database/migrations/20210927231631_init.sql new file mode 100644 index 0000000..2ccb02e --- /dev/null +++ b/apiGo/database/migrations/20210927231631_init.sql @@ -0,0 +1,122 @@ +-- +goose Up +-- +goose StatementBegin +create table if not exists actors +( + actor_id int auto_increment + primary key, + name varchar(50) null, + thumbnail mediumblob null +) + comment 'informations about different actors'; +-- +goose StatementEnd +-- +goose StatementBegin +create table if not exists settings +( + video_path varchar(255) null, + episode_path varchar(255) null, + password varchar(32) default '-1' null, + mediacenter_name varchar(32) default 'OpenMediaCenter' null, + TMDB_grabbing tinyint null, + DarkMode tinyint default 0 null +); +-- +goose StatementEnd +-- +goose StatementBegin +create table if not exists tags +( + tag_id int auto_increment + primary key, + tag_name varchar(50) null +); +-- +goose StatementEnd +-- +goose StatementBegin +create table if not exists tvshow +( + name varchar(100) null, + thumbnail mediumblob null, + id int auto_increment + primary key, + foldername varchar(100) null +); +-- +goose StatementEnd +-- +goose StatementBegin +create table if not exists tvshow_episodes +( + id int auto_increment + primary key, + name varchar(100) null, + season int null, + poster mediumblob null, + tvshow_id int null, + episode int null, + filename varchar(100) null, + constraint tvshow_episodes_tvshow_id_fk + foreign key (tvshow_id) references tvshow (id) +); +-- +goose StatementEnd +-- +goose StatementBegin +create table if not exists videos +( + movie_id int auto_increment + primary key, + movie_name varchar(200) null, + movie_url varchar(250) null, + thumbnail mediumblob null, + poster mediumblob null, + likes int default 0 null, + quality int default 0 null, + length int default 0 null comment 'in seconds', + create_date datetime default current_timestamp() null +); +-- +goose StatementEnd +-- +goose StatementBegin +create table if not exists actors_videos +( + actor_id int null, + video_id int null, + constraint actors_videos_actors_id_fk + foreign key (actor_id) references actors (actor_id), + constraint actors_videos_videos_movie_id_fk + foreign key (video_id) references videos (movie_id) +); +-- +goose StatementEnd +-- +goose StatementBegin +create index if not exists actors_videos_actor_id_index + on actors_videos (actor_id); +-- +goose StatementEnd +-- +goose StatementBegin +create index if not exists actors_videos_video_id_index + on actors_videos (video_id); +-- +goose StatementEnd +-- +goose StatementBegin +create table if not exists video_tags +( + tag_id int null, + video_id int null, + constraint video_tags_tags_tag_id_fk + foreign key (tag_id) references tags (tag_id), + constraint video_tags_videos_movie_id_fk + foreign key (video_id) references videos (movie_id) + on delete cascade +); + +-- +goose StatementEnd +-- +goose StatementBegin +INSERT IGNORE INTO tags (tag_id, tag_name) +VALUES (2, 'fullhd'); +-- +goose StatementEnd +-- +goose StatementBegin +INSERT IGNORE INTO tags (tag_id, tag_name) +VALUES (3, 'lowquality'); +-- +goose StatementEnd +-- +goose StatementBegin +INSERT IGNORE INTO tags (tag_id, tag_name) +VALUES (4, 'hd'); +-- +goose StatementEnd +-- +goose StatementBegin +INSERT IGNORE INTO settings (video_path, episode_path, password, mediacenter_name) +VALUES ('./videos/', './tvshows/', -1, 'OpenMediaCenter'); + + +-- +goose StatementEnd + +-- +goose Down diff --git a/apiGo/database/migrations/20210927235150_relese_date.sql b/apiGo/database/migrations/20210927235150_relese_date.sql new file mode 100644 index 0000000..673843c --- /dev/null +++ b/apiGo/database/migrations/20210927235150_relese_date.sql @@ -0,0 +1,12 @@ +-- +goose Up +-- +goose StatementBegin +alter table videos + add release_date date null; + +-- +goose StatementEnd + +-- +goose Down +-- +goose StatementBegin +alter table videos + drop release_date; +-- +goose StatementEnd diff --git a/apiGo/go.mod b/apiGo/go.mod index 95ee12d..89ff76c 100644 --- a/apiGo/go.mod +++ b/apiGo/go.mod @@ -5,9 +5,9 @@ go 1.16 require ( github.com/3d0c/gmf v0.0.0-20210925211039-e278e6e53b16 github.com/dgrijalva/jwt-go v3.2.0+incompatible - github.com/go-sql-driver/mysql v1.5.0 + github.com/go-sql-driver/mysql v1.6.0 github.com/pelletier/go-toml/v2 v2.0.0-beta.3 - golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 - gopkg.in/oauth2.v3 v3.12.0 + github.com/pressly/goose/v3 v3.1.0 + golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 nhooyr.io/websocket v1.8.7 ) diff --git a/apiGo/go.sum b/apiGo/go.sum index dd89002..3556c6c 100644 --- a/apiGo/go.sum +++ b/apiGo/go.sum @@ -1,19 +1,14 @@ -cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/3d0c/gmf v0.0.0-20210925211039-e278e6e53b16 h1:LX3XWmS88yKgWJcMXb8vusphpDBe9+6LTI9FyHeFFWQ= github.com/3d0c/gmf v0.0.0-20210925211039-e278e6e53b16/go.mod h1:0QMRcUq2JsDECeAq7bj4h79k7XbhtTsrPUQf6G7qfPs= -github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU= -github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY= +github.com/ClickHouse/clickhouse-go v1.4.5/go.mod h1:EaI/sW7Azgz9UATzd5ZdZHRUhHgv5+JMS9NSr2smCJI= +github.com/bkaradzic/go-lz4 v1.0.0/go.mod h1:0YdlkowM3VswSROI7qDxhRvJ3sLhlFrRRwjwegp5jy4= +github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/denisenkom/go-mssqldb v0.10.0/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= -github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072/go.mod h1:duJ4Jxv5lDcvg4QuQr0oowTf7dz4/CR8NtyCooz9HL8= -github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo= -github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= -github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/gavv/httpexpect v2.0.0+incompatible h1:1X9kcRshkSKEjNJJxX9Y9mQ5BRfbxU5kORdjhlA1yX8= -github.com/gavv/httpexpect v2.0.0+incompatible/go.mod h1:x+9tiU1YnrOvnB725RkpoLv1M62hOWzwo5OXotisrKc= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14= @@ -25,134 +20,78 @@ github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD87 github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY= github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= -github.com/go-session/session v3.1.2+incompatible/go.mod h1:8B3iivBQjrz/JtC68Np2T1yBBLxTan3mn/3OM0CyRt0= -github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs= -github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= +github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= +github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee h1:s+21KNqlpePfkah2I+gwHF8xmJWRjooY+5248k6m4A0= github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo= github.com/gobwas/pool v0.2.0 h1:QEmUOlnSjWtnpRGHF3SauEiOsy82Cup83Vf2LcMlnc8= github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw= github.com/gobwas/ws v1.0.2 h1:CoAavW/wd/kulfZmSIBt6p24n4j7tHgNVCjsfHVNUbo= github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM= -github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= github.com/golang/protobuf v1.3.5 h1:F768QJ1E9tib+q5Sc8MkdJi1RxLTbRcTf8LJV56aRls= github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk= github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk= -github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM= github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/imkira/go-interpol v1.1.0 h1:KIiKr0VSG2CUW1hl1jpiyuzuJeKUUpC8iM1AIE7N1Vk= -github.com/imkira/go-interpol v1.1.0/go.mod h1:z0h2/2T3XF8kyEPpRgJ3kmNv+C43p+I/CoI+jC3w2iA= +github.com/jmoiron/sqlx v1.2.0/go.mod h1:1FEQNm3xlJgrMD+FBdI9+xvCksHtbpVBBw5dYhBSsks= github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= -github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= -github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k= -github.com/klauspost/compress v1.8.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.10.3 h1:OP96hzwJVBIHYU52pVTI6CczrxPvrGfgqF9N5eTO0Q8= github.com/klauspost/compress v1.10.3/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= -github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= -github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= +github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/lib/pq v1.10.2/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= +github.com/mattn/go-sqlite3 v1.14.8 h1:gDp86IdQsN/xWjIEmr9MF6o9mpksUgh0fu+9ByFxzIU= +github.com/mattn/go-sqlite3 v1.14.8/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/moul/http2curl v1.0.0 h1:dRMWoAtb+ePxMlLkrCbAqh4TlPHXvoGUSQ323/9Zahs= -github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ= -github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/ginkgo v1.10.2/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= -github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/pelletier/go-toml/v2 v2.0.0-beta.3 h1:PNCTU4naEJ8mKal97P3A2qDU74QRQGlv4FXiL1XDqi4= github.com/pelletier/go-toml/v2 v2.0.0-beta.3/go.mod h1:aNseLYu/uKskg0zpr/kbr2z8yGuWtotWf/0BpGIAL2Y= +github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= -github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= -github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= -github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= +github.com/pressly/goose/v3 v3.1.0 h1:V2Ulfm2XL9GtYNmrPUNFHieimf6diwADyMObnuuR2Mc= +github.com/pressly/goose/v3 v3.1.0/go.mod h1:tYsY0oL0yd48jg15POIZfOZiu66mqWpfDd/nJ28KWyU= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.7.1-0.20210427113832-6241f9ab9942 h1:t0lM6y/M5IiUZyvbBTcngso8SZEZICH7is9B6g/obVU= github.com/stretchr/testify v1.7.1-0.20210427113832-6241f9ab9942/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/tidwall/btree v0.0.0-20170113224114-9876f1454cf0 h1:QnyrPZZvPmR0AtJCxxfCtI1qN+fYpKTKJ/5opWmZ34k= -github.com/tidwall/btree v0.0.0-20170113224114-9876f1454cf0/go.mod h1:huei1BkDWJ3/sLXmO+bsCNELL+Bp2Kks9OLyQFkzvA8= -github.com/tidwall/buntdb v1.1.0 h1:H6LzK59KiNjf1nHVPFrYj4Qnl8d8YLBsYamdL8N+Bao= -github.com/tidwall/buntdb v1.1.0/go.mod h1:Y39xhcDW10WlyYXeLgGftXVbjtM0QP+/kpz8xl9cbzE= -github.com/tidwall/gjson v1.3.2 h1:+7p3qQFaH3fOMXAJSrdZwGKcOO/lYdGS0HqGhPqDdTI= -github.com/tidwall/gjson v1.3.2/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls= -github.com/tidwall/grect v0.0.0-20161006141115-ba9a043346eb h1:5NSYaAdrnblKByzd7XByQEJVT8+9v0W/tIY0Oo4OwrE= -github.com/tidwall/grect v0.0.0-20161006141115-ba9a043346eb/go.mod h1:lKYYLFIr9OIgdgrtgkZ9zgRxRdvPYsExnYBsEAd8W5M= -github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc= -github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E= -github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= -github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= -github.com/tidwall/rtree v0.0.0-20180113144539-6cd427091e0e h1:+NL1GDIUOKxVfbp2KoJQD9cTQ6dyP2co9q4yzmT9FZo= -github.com/tidwall/rtree v0.0.0-20180113144539-6cd427091e0e/go.mod h1:/h+UnNGt0IhNNJLkGikcdcJqm66zGD/uJGMRxK/9+Ao= -github.com/tidwall/tinyqueue v0.0.0-20180302190814-1e39f5511563 h1:Otn9S136ELckZ3KKDyCkxapfufrqDqwmGjcHfAyXRrE= -github.com/tidwall/tinyqueue v0.0.0-20180302190814-1e39f5511563/go.mod h1:mLqSmt7Dv/CNneF2wfcChfN1rvapyQr01LGKnKex0DQ= github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs= github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= -github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= -github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -github.com/valyala/fasthttp v1.6.0 h1:uWF8lgKmeaIewWVPwi4GRq2P6+R46IgYZdxWtM+GtEY= -github.com/valyala/fasthttp v1.6.0/go.mod h1:FstJa9V+Pj9vQ7OJie2qMHdwemEDaDiSdBnvPM1Su9w= -github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio= -github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c= -github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU= -github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0= -github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ= -github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74= -github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y= -github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 h1:6fRhSjgLCkTD3JnJxvaJ4Sj+TYblw757bqYgZaOq5ZY= -github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0/go.mod h1:/LWChgwKmvncFJFHJ7Gvn9wZArjbV5/FppcK2fKk/tI= -github.com/yudai/gojsondiff v1.0.0 h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCOA= -github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg= -github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M= -github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM= -github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 h1:k7pJ2yAPLPgbskkFdhRCsA77k2fySZ1zf2zCjvQCiIM= -golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= -golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0= +golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= -gopkg.in/oauth2.v3 v3.12.0 h1:yOffAPoolH/i2JxwmC+pgtnY3362iPahsDpLXfDFvNg= -gopkg.in/oauth2.v3 v3.12.0/go.mod h1:XEYgKqWX095YiPT+Aw5y3tCn+7/FMnlTFKrupgSiJ3I= -gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= -gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/apiGo/main.go b/apiGo/main.go index b2a547e..f93e28f 100644 --- a/apiGo/main.go +++ b/apiGo/main.go @@ -15,6 +15,7 @@ import ( func main() { fmt.Println("init OpenMediaCenter server") const port uint16 = 8081 + errc := make(chan error, 1) config.Init() @@ -22,7 +23,10 @@ func main() { fmt.Printf("Use verbose output: %t\n", config.GetConfig().General.VerboseLogging) fmt.Printf("Videopath prefix: %s\n", config.GetConfig().General.ReindexPrefix) - database.InitDB() + err := database.InitDB() + if err != nil { + errc <- err + } defer database.Close() api.AddHandlers() @@ -33,7 +37,6 @@ func main() { static.ServeStaticFiles() // init api - errc := make(chan error, 1) go func() { errc <- api2.ServerInit(port) }() diff --git a/deb/OpenMediaCenter/DEBIAN/postinst b/deb/OpenMediaCenter/DEBIAN/postinst index 697899b..493ff0e 100755 --- a/deb/OpenMediaCenter/DEBIAN/postinst +++ b/deb/OpenMediaCenter/DEBIAN/postinst @@ -6,10 +6,6 @@ ln -sf /etc/nginx/sites-available/OpenMediaCenter.conf /etc/nginx/sites-enabled/ mysql -uroot -pPASS -e "CREATE DATABASE IF NOT EXISTS mediacenter;" mysql -uroot -pPASS -e "CREATE USER IF NOT EXISTS 'mediacenteruser'@'localhost' IDENTIFIED BY 'mediapassword';" mysql -uroot -pPASS -e "GRANT ALL PRIVILEGES ON mediacenter . * TO 'mediacenteruser'@'localhost';" -mysql -u mediacenteruser -pmediapassword mediacenter < /tmp/openmediacenter.sql - -# removed unused sql style file -rm /tmp/openmediacenter.sql # correct user rights chown -R www-data:www-data /var/www/openmediacenter From 3588df7c4fb7de5b8d4bdb534d0d7cc5512f4b47 Mon Sep 17 00:00:00 2001 From: lukas Date: Tue, 28 Sep 2021 10:52:18 +0200 Subject: [PATCH 2/2] add release date to videopage improve reindex db insertion logic --- apiGo/api/Video.go | 4 +-- apiGo/api/types/Types.go | 1 + apiGo/database/Database.go | 4 ++- apiGo/videoparser/ReIndexVideos.go | 45 ++++++++++++++++-------------- apiGo/videoparser/tmdb/TMDBApi.go | 18 ++++++------ src/pages/Player/Player.tsx | 8 ++++++ src/types/ApiTypes.ts | 1 + 7 files changed, 49 insertions(+), 32 deletions(-) diff --git a/apiGo/api/Video.go b/apiGo/api/Video.go index 09886cb..fa76621 100644 --- a/apiGo/api/Video.go +++ b/apiGo/api/Video.go @@ -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()) diff --git a/apiGo/api/types/Types.go b/apiGo/api/types/Types.go index bb85f3b..680617f 100644 --- a/apiGo/api/types/Types.go +++ b/apiGo/api/types/Types.go @@ -10,6 +10,7 @@ type FullVideoType struct { MovieId uint32 MovieUrl string Poster string + ReleaseDate *string Likes uint64 Quality uint16 Length uint16 diff --git a/apiGo/database/Database.go b/apiGo/database/Database.go index 08be737..fc0981a 100644 --- a/apiGo/database/Database.go +++ b/apiGo/database/Database.go @@ -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") diff --git a/apiGo/videoparser/ReIndexVideos.go b/apiGo/videoparser/ReIndexVideos.go index 239d7d9..14fa757 100644 --- a/apiGo/videoparser/ReIndexVideos.go +++ b/apiGo/videoparser/ReIndexVideos.go @@ -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) diff --git a/apiGo/videoparser/tmdb/TMDBApi.go b/apiGo/videoparser/tmdb/TMDBApi.go index 8a36aa9..802117a 100644 --- a/apiGo/videoparser/tmdb/TMDBApi.go +++ b/apiGo/videoparser/tmdb/TMDBApi.go @@ -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 diff --git a/src/pages/Player/Player.tsx b/src/pages/Player/Player.tsx index 768eece..2d86029 100644 --- a/src/pages/Player/Player.tsx +++ b/src/pages/Player/Player.tsx @@ -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 { movieName: '', likes: 0, quality: 0, + releaseDate: null, length: 0, tags: [], suggesttag: [], @@ -131,6 +133,11 @@ export class Player extends React.Component { {this.state.quality}p Quality! ) : null} + {this.state.releaseDate !== null ? ( + + {this.state.releaseDate} released! + + ) : null} {this.state.length !== 0 ? ( {Math.round(this.state.length / 60)} Minutes of length! @@ -323,6 +330,7 @@ export class Player extends React.Component { movieName: result.MovieName, likes: result.Likes, quality: result.Quality, + releaseDate: result.ReleaseDate, length: result.Length, tags: result.Tags, suggesttag: result.SuggestedTag, diff --git a/src/types/ApiTypes.ts b/src/types/ApiTypes.ts index 3f5a26f..389c196 100644 --- a/src/types/ApiTypes.ts +++ b/src/types/ApiTypes.ts @@ -8,6 +8,7 @@ export namespace VideoTypes { MovieName: string; Likes: number; Quality: number; + ReleaseDate: string | null; Length: number; Tags: TagType[]; SuggestedTag: TagType[];