Compare commits

..

17 Commits

Author SHA1 Message Date
f51d9597e9 set randompage as the startpage 2023-12-02 09:32:54 +01:00
af1de3a244 increase token validity 2022-11-30 23:30:24 +01:00
752200d42e order actor and tag api reply by name 2022-11-30 23:28:10 +01:00
39ed5cd7d8 Merge remote-tracking branch 'origin/morevidefiletypes'
# Conflicts:
#	apiGo/videoparser/VideoParser.go
2022-09-21 13:23:51 +02:00
5d409c3e23 fix correct redirects on tvshows page 2022-09-20 14:26:15 +02:00
05ea72a8ca fix ip of testserver 2022-06-25 14:37:51 +02:00
7476e2397d add a filewatcher to automatically reindex if new file is added 2022-06-25 14:02:25 +02:00
929e0c337d fix invalid links if videos are in subfolders 2022-05-22 20:48:04 +02:00
f7a0d8fa07 add housekeeping code to delete duplicated tags and videos 2022-05-05 21:32:35 +02:00
9faf457c89 add tag delete button if filtertag selected 2022-05-05 19:43:29 +02:00
11c1e25de5 update browserlist 2022-05-05 18:42:48 +02:00
3d845aaf04 Merge branch 'randompage_filter_tags' into 'master'
make tags on random page filterable

See merge request lukas/openmediacenter!61
2022-05-05 16:41:46 +00:00
7f98528fbe use seperate jobs for manual and auto runs 2022-05-05 18:06:41 +02:00
191fa5386d fix detached pipeline 2022-05-05 18:02:32 +02:00
9715012685 make tags on random page filterable 2022-05-05 17:46:59 +02:00
dfcb7f71d9 use correct filepath when checking if tv show episode already exits in databse 2021-09-30 10:49:33 +02:00
61ea42ef01 allow more videotypes than mp4 2021-09-27 17:33:05 +02:00
23 changed files with 414 additions and 221 deletions

View File

@ -108,18 +108,13 @@ Debian_Server:
- Minimize_Frontend - Minimize_Frontend
- Build_Backend - Build_Backend
Test_Server: .Test_Server_Common:
stage: deploy stage: deploy
image: luki42/ssh:latest image: luki42/ssh:latest
needs: needs:
- Frontend_Tests - Frontend_Tests
- Backend_Tests - Backend_Tests
- Debian_Server - Debian_Server
rules:
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH # run this always on default branch
- if: $CI_COMMIT_REF_NAME != $CI_DEFAULT_BRANCH # allow triggering this manually
when: manual
allow_failure: true
script: script:
- eval $(ssh-agent -s) - eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY" | ssh-add - - echo "$SSH_PRIVATE_KEY" | ssh-add -
@ -129,24 +124,38 @@ Test_Server:
- ssh root@192.168.0.42 "DEBIAN_FRONTEND=noninteractive apt-get --reinstall -y -qq install /tmp/OpenMediaCenter-*.deb && rm /tmp/OpenMediaCenter-*.deb" - ssh root@192.168.0.42 "DEBIAN_FRONTEND=noninteractive apt-get --reinstall -y -qq install /tmp/OpenMediaCenter-*.deb && rm /tmp/OpenMediaCenter-*.deb"
allow_failure: true allow_failure: true
Test_Server_2: Test_Server_CD:
extends: .Test_Server_Common
only:
refs:
- master
Test_Server_MANUAL:
extends: .Test_Server_Common
when: manual
.Test_Server_2_Common:
stage: deploy stage: deploy
image: luki42/ssh:latest image: luki42/ssh:latest
needs: needs:
- Frontend_Tests - Frontend_Tests
- Backend_Tests - Backend_Tests
- Debian_Server - Debian_Server
rules:
- if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH # run this always on default branch
- if: $CI_COMMIT_REF_NAME != $CI_DEFAULT_BRANCH # allow triggering this manually
when: manual
allow_failure: true
script: script:
- eval $(ssh-agent -s) - eval $(ssh-agent -s)
- echo "$SSH_PRIVATE_KEY_2" | ssh-add - - echo "$SSH_PRIVATE_KEY_2" | ssh-add -
- mkdir -p ~/.ssh - mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config' - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
- scp deb/OpenMediaCenter-*.deb root@192.168.0.209:/tmp/ - scp deb/OpenMediaCenter-*.deb root@192.168.0.44:/tmp/
- ssh root@192.168.0.209 "DEBIAN_FRONTEND=noninteractive apt-get --reinstall -y -qq install /tmp/OpenMediaCenter-*.deb && rm /tmp/OpenMediaCenter-*.deb" - ssh root@192.168.0.44 "DEBIAN_FRONTEND=noninteractive apt-get --reinstall -y -qq install /tmp/OpenMediaCenter-*.deb && rm /tmp/OpenMediaCenter-*.deb"
allow_failure: true allow_failure: true
Test_Server_2_CD:
extends: .Test_Server_2_Common
only:
refs:
- master
Test_Server_2_MANUAL:
extends: .Test_Server_2_Common
when: manual

View File

@ -25,7 +25,7 @@ func getActorsFromDB() {
* @apiSuccess {string} .Thumbnail Portrait Thumbnail * @apiSuccess {string} .Thumbnail Portrait Thumbnail
*/ */
api.AddHandler("getAllActors", api.ActorNode, api.PermUser, func(context api.Context) { api.AddHandler("getAllActors", api.ActorNode, api.PermUser, func(context api.Context) {
query := "SELECT actor_id, name, thumbnail FROM actors" query := "SELECT actor_id, name, thumbnail FROM actors ORDER BY name ASC"
context.Json(readActorsFromResultset(database.Query(query))) context.Json(readActorsFromResultset(database.Query(query)))
}) })

View File

@ -7,7 +7,6 @@ import (
"openmediacenter/apiGo/database" "openmediacenter/apiGo/database"
"openmediacenter/apiGo/videoparser" "openmediacenter/apiGo/videoparser"
"os" "os"
"path/filepath"
) )
func addUploadHandler() { func addUploadHandler() {
@ -31,11 +30,11 @@ func addUploadHandler() {
break break
} }
// todo allow more video formats than mp4
// only allow valid extensions // only allow valid extensions
if filepath.Ext(part.FileName()) != ".mp4" { if !videoparser.ValidVideoSuffix(part.FileName()) {
continue continue
} }
vidpath := PathPrefix + mSettings.VideoPath + part.FileName() vidpath := PathPrefix + mSettings.VideoPath + part.FileName()
dst, err := os.OpenFile(vidpath, os.O_WRONLY|os.O_CREATE, 0644) dst, err := os.OpenFile(vidpath, os.O_WRONLY|os.O_CREATE, 0644)
if err != nil { if err != nil {

View File

@ -78,7 +78,7 @@ func getFromDB() {
* @apiSuccess {string} TagName name of the Tag * @apiSuccess {string} TagName name of the Tag
*/ */
api.AddHandler("getAllTags", api.TagNode, api.PermUser, func(context api.Context) { api.AddHandler("getAllTags", api.TagNode, api.PermUser, func(context api.Context) {
query := "SELECT tag_id,tag_name from tags" query := "SELECT tag_id,tag_name from tags ORDER BY tag_name ASC"
context.Json(readTagsFromResultset(database.Query(query))) context.Json(readTagsFromResultset(database.Query(query)))
}) })
} }

View File

@ -1,8 +1,8 @@
package api package api
import ( import (
"encoding/json"
"fmt" "fmt"
"math/rand"
"net/url" "net/url"
"openmediacenter/apiGo/api/api" "openmediacenter/apiGo/api/api"
"openmediacenter/apiGo/api/types" "openmediacenter/apiGo/api/types"
@ -10,6 +10,7 @@ import (
"openmediacenter/apiGo/database" "openmediacenter/apiGo/database"
"os" "os"
"strconv" "strconv"
"strings"
) )
func addVideoHandlers() { func addVideoHandlers() {
@ -163,53 +164,65 @@ func getVideoHandlers() {
*/ */
api.AddHandler("getRandomMovies", api.VideoNode, api.PermUser, func(context api.Context) { api.AddHandler("getRandomMovies", api.VideoNode, api.PermUser, func(context api.Context) {
var args struct { var args struct {
Number int Number int
Seed *int TagFilter []uint32
} }
if api.DecodeRequest(context.GetRequest(), &args) != nil { if api.DecodeRequest(context.GetRequest(), &args) != nil {
context.Text("unable to decode request") context.Text("unable to decode request")
return return
} }
// if Seed argument not passed generate random seed
if args.Seed == nil {
r := rand.Int()
args.Seed = &r
}
var result struct { var result struct {
Tags []types.Tag Tags []types.Tag
Videos []types.VideoUnloadedType Videos []types.VideoUnloadedType
} }
query := fmt.Sprintf("SELECT movie_id,movie_name FROM videos ORDER BY RAND(%d) LIMIT %d", *args.Seed, args.Number) whereclause := "WHERE 1"
result.Videos = readVideosFromResultset(database.Query(query)) if len(args.TagFilter) > 0 {
d, _ := json.Marshal(args.TagFilter)
vals := strings.Trim(string(d), "[]")
var ids string whereclause = fmt.Sprintf("WHERE tag_id IN (%s)", vals)
for i := range result.Videos {
ids += "video_tags.video_id=" + strconv.Itoa(result.Videos[i].MovieId)
if i < len(result.Videos)-1 {
ids += " OR "
}
} }
// add the corresponding tags query := fmt.Sprintf(`
query = fmt.Sprintf(`SELECT t.tag_name,t.tag_id FROM video_tags SELECT video_tags.video_id,v.movie_name FROM video_tags join videos v on v.movie_id = video_tags.video_id
%s
group by video_id
ORDER BY RAND()
LIMIT %d`, whereclause, args.Number)
result.Videos = readVideosFromResultset(database.Query(query))
if len(result.Videos) > 0 {
var ids string
for i := range result.Videos {
ids += "video_tags.video_id=" + strconv.Itoa(result.Videos[i].MovieId)
if i < len(result.Videos)-1 {
ids += " OR "
}
}
// add the corresponding tags
query = fmt.Sprintf(`SELECT t.tag_name,t.tag_id FROM video_tags
INNER JOIN tags t on video_tags.tag_id = t.tag_id INNER JOIN tags t on video_tags.tag_id = t.tag_id
WHERE %s WHERE %s
GROUP BY t.tag_id`, ids) GROUP BY t.tag_id`, ids)
rows := database.Query(query) rows := database.Query(query)
if rows != nil {
for rows.Next() { for rows.Next() {
var tag types.Tag var tag types.Tag
err := rows.Scan(&tag.TagName, &tag.TagId) err := rows.Scan(&tag.TagName, &tag.TagId)
if err != nil { if err != nil {
panic(err.Error()) // proper Error handling instead of panic in your app panic(err.Error()) // proper Error handling instead of panic in your app
}
// append to final array
result.Tags = append(result.Tags, tag)
}
} }
// append to final array } else {
result.Tags = append(result.Tags, tag) result.Tags = []types.Tag{}
} }
context.Json(result) context.Json(result)

View File

@ -21,7 +21,7 @@ func (p Perm) String() string {
} }
const SignKey = "89013f1753a6890c6090b09e3c23ff43" const SignKey = "89013f1753a6890c6090b09e3c23ff43"
const TokenExpireHours = 24 const TokenExpireHours = 8760
type Token struct { type Token struct {
Token string Token string

View File

@ -5,7 +5,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"reflect"
) )
func Jsonify(v interface{}) []byte { func Jsonify(v interface{}) []byte {
@ -30,45 +29,3 @@ func DecodeRequest(request *http.Request, arg interface{}) error {
return err return err
} }
// setField set a specific field of an object with an object provided
func setField(obj interface{}, name string, value interface{}) error {
structValue := reflect.ValueOf(obj).Elem()
structFieldValue := structValue.FieldByName(name)
if !structFieldValue.IsValid() {
return fmt.Errorf("no such field: %s in obj", name)
}
if !structFieldValue.CanSet() {
return fmt.Errorf("cannot set %s field value", name)
}
structFieldType := structFieldValue.Type()
val := reflect.ValueOf(value)
if structFieldType != val.Type() {
if val.Type().ConvertibleTo(structFieldType) {
// if type is convertible - convert and set
structFieldValue.Set(val.Convert(structFieldType))
} else {
return fmt.Errorf("provided value %s type didn't match obj field type and isn't convertible", name)
}
} else {
// set value if type is the same
structFieldValue.Set(val)
}
return nil
}
// FillStruct fill a custom struct with objects of a map
func FillStruct(i interface{}, m map[string]interface{}) error {
for k, v := range m {
err := setField(i, k, v)
if err != nil {
return err
}
}
return nil
}

View File

@ -5,6 +5,7 @@ go 1.16
require ( require (
github.com/3d0c/gmf v0.0.0-20210925211039-e278e6e53b16 github.com/3d0c/gmf v0.0.0-20210925211039-e278e6e53b16
github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/fsnotify/fsnotify v1.5.4
github.com/go-sql-driver/mysql v1.6.0 github.com/go-sql-driver/mysql v1.6.0
github.com/pelletier/go-toml/v2 v2.0.0-beta.3 github.com/pelletier/go-toml/v2 v2.0.0-beta.3
github.com/pressly/goose/v3 v3.1.0 github.com/pressly/goose/v3 v3.1.0

View File

@ -9,6 +9,8 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/denisenkom/go-mssqldb v0.10.0/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= 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 h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= 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-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14= github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14=
@ -82,8 +84,9 @@ golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 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/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad h1:ntjMns5wyP/fN65tdBD4g8J5w8n015+iIIs9rtjXkY0=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 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.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=

View File

@ -0,0 +1,18 @@
package housekeeping
import "fmt"
func RunHouseKeepingTasks() {
fmt.Println("Runnint houskeeping tasks!")
fmt.Println("Deduplicating Tags")
deduplicateTags()
fmt.Println("Deduplicating Tags assigned to videos")
deduplicateVideoTags()
fmt.Println("Fix missing video metadata like ratio")
fixMissingMetadata()
fmt.Println("Finished housekeeping")
}

View File

@ -0,0 +1,5 @@
package housekeeping
func fixMissingMetadata() {
// todo
}

View File

@ -0,0 +1,86 @@
package housekeeping
import (
"fmt"
"openmediacenter/apiGo/database"
)
func deduplicateTags() {
// find all duplicate tags
// gives first occurence of duplicate
query := `
SELECT
tag_name
FROM
tags
GROUP BY tag_name
HAVING COUNT(tag_name) > 1`
rows := database.Query(query)
duplicates := []string{}
if rows != nil {
for rows.Next() {
var id string
err := rows.Scan(&id)
if err != nil {
panic(err.Error()) // proper Error handling instead of panic in your app
}
duplicates = append(duplicates, id)
}
} else {
// nothing to do
return
}
fmt.Print("deleting duplicate tag ids: ")
fmt.Println(duplicates)
for _, el := range duplicates {
query := fmt.Sprintf("SELECT tag_id FROM tags WHERE tag_name='%s'", el)
rows := database.Query(query)
ids := []uint32{}
for rows.Next() {
var id uint32
err := rows.Scan(&id)
if err != nil {
panic(err.Error()) // proper Error handling instead of panic in your app
}
ids = append(ids, id)
}
// id to copy other data to
mainid := ids[0]
// ids to copy from
copyids := ids[1:]
fmt.Printf("Migrating %s\n", el)
migrateTags(mainid, copyids)
}
}
func migrateTags(destid uint32, sourcids []uint32) {
querytempl := `
UPDATE video_tags
SET
tag_id = %d
WHERE
tag_id = %d`
for _, id := range sourcids {
err := database.Edit(fmt.Sprintf(querytempl, destid, id))
if err != nil {
fmt.Printf("failed to set id from %d to %d\n", id, destid)
return
}
fmt.Printf("Merged %d into %d\n", id, destid)
// now lets delete this tag
query := fmt.Sprintf(`DELETE FROM tags WHERE tag_id=%d`, id)
err = database.Edit(query)
if err != nil {
fmt.Printf("failed to delete Tag %d", id)
return
}
}
}

View File

@ -0,0 +1,37 @@
package housekeeping
import (
"fmt"
"openmediacenter/apiGo/database"
)
func deduplicateVideoTags() {
// gives first occurence of duplicate
query := `
SELECT
tag_id, video_id, count(tag_id)
FROM
video_tags
GROUP BY tag_id, video_id
HAVING COUNT(tag_id) > 1`
rows := database.Query(query)
if rows != nil {
for rows.Next() {
var tagid uint32
var vidid uint32
var nr uint32
err := rows.Scan(&tagid, &vidid, &nr)
if err != nil {
panic(err.Error()) // proper Error handling instead of panic in your app
}
// now lets delete this tag
query := fmt.Sprintf(`DELETE FROM video_tags WHERE tag_id=%d AND video_id=%d LIMIT %d`, tagid, vidid, nr-1)
err = database.Edit(query)
if err != nil {
fmt.Printf("failed to delete Tag %d + vid %d", tagid, vidid)
return
}
}
}
}

View File

@ -1,11 +1,13 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
"openmediacenter/apiGo/api" "openmediacenter/apiGo/api"
api2 "openmediacenter/apiGo/api/api" api2 "openmediacenter/apiGo/api/api"
"openmediacenter/apiGo/config" "openmediacenter/apiGo/config"
"openmediacenter/apiGo/database" "openmediacenter/apiGo/database"
"openmediacenter/apiGo/housekeeping"
"openmediacenter/apiGo/static" "openmediacenter/apiGo/static"
"openmediacenter/apiGo/videoparser" "openmediacenter/apiGo/videoparser"
"os" "os"
@ -17,6 +19,8 @@ func main() {
const port uint16 = 8081 const port uint16 = 8081
errc := make(chan error, 1) errc := make(chan error, 1)
housekPTr := flag.Bool("HouseKeeping", false, "Run housekeeping tasks")
config.Init() config.Init()
// todo some verbosity logger or sth // todo some verbosity logger or sth
@ -29,9 +33,16 @@ func main() {
} }
defer database.Close() defer database.Close()
// check if we should run the housekeeping tasks
if *housekPTr {
housekeeping.RunHouseKeepingTasks()
return
}
api.AddHandlers() api.AddHandlers()
videoparser.SetupSettingsWebsocket() videoparser.SetupSettingsWebsocket()
videoparser.InitFileWatcher()
// add the static files // add the static files
static.ServeStaticFiles() static.ServeStaticFiles()

View File

@ -0,0 +1,58 @@
package videoparser
import (
"github.com/fsnotify/fsnotify"
"log"
"openmediacenter/apiGo/config"
"openmediacenter/apiGo/database"
"strings"
)
func InitFileWatcher() {
watcher, err := fsnotify.NewWatcher()
if err != nil {
log.Fatal("NewWatcher failed: ", err)
}
mSettings, _, _ := database.GetSettings()
vidFolder := config.GetConfig().General.ReindexPrefix + mSettings.VideoPath
epsfolder := config.GetConfig().General.ReindexPrefix + mSettings.EpisodePath
defer watcher.Close()
go func() {
for {
select {
case event, ok := <-watcher.Events:
if !ok {
return
}
// start new reindex
// (may be optimized by checking here if added file is video
// and start reindex just for one file)
if strings.Contains(event.Name, vidFolder) {
StartReindex()
} else if strings.Contains(event.Name, epsfolder) {
StartTVShowReindex()
} else {
log.Printf("Event in wrong folder: %s %s\n", event.Name, event.Op)
}
case err, ok := <-watcher.Errors:
if !ok {
return
}
log.Println("error:", err)
}
}
}()
err = watcher.Add(vidFolder)
if err != nil {
log.Println("Adding of file watcher failed: ", err)
}
err = watcher.Add(epsfolder)
if err != nil {
log.Println("Adding of file watcher failed: ", err)
}
}

View File

@ -25,20 +25,18 @@ func startTVShowReindex(files []Show) {
} }
func insertEpisodesIfNotExisting(show Show) { func insertEpisodesIfNotExisting(show Show) {
query := "SELECT tvshow_episodes.name, season, episode FROM tvshow_episodes JOIN tvshow t on t.id = tvshow_episodes.tvshow_id WHERE t.name=?" query := "SELECT filename FROM tvshow_episodes JOIN tvshow t on t.id = tvshow_episodes.tvshow_id WHERE t.name=?"
rows := database.Query(query, show.Name) rows := database.Query(query, show.Name)
var dbepisodes []string var dbepisodes []string
for rows.Next() { for rows.Next() {
var epname string var filename string
var season int err := rows.Scan(&filename)
var episode int
err := rows.Scan(&epname, &season, &episode)
if err != nil { if err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())
} }
dbepisodes = append(dbepisodes, fmt.Sprintf("%s S%02dE%02d.mp4", epname, season, episode)) dbepisodes = append(dbepisodes, filename)
} }
// get those episodes that are missing in db // get those episodes that are missing in db
@ -83,6 +81,10 @@ VALUES (?, ?, ?, (SELECT tvshow.id FROM tvshow WHERE tvshow.name=?), ?, ?)`
// difference returns the elements in `a` that aren't in `b`. // difference returns the elements in `a` that aren't in `b`.
func difference(a, b []string) []string { func difference(a, b []string) []string {
if b == nil || len(b) == 0 {
return a
}
mb := make(map[string]struct{}, len(b)) mb := make(map[string]struct{}, len(b))
for _, x := range b { for _, x := range b {
mb[x] = struct{}{} mb[x] = struct{}{}
@ -129,7 +131,10 @@ func getAllTVShows() *[]string {
var res []string var res []string
for rows.Next() { for rows.Next() {
var show string var show string
rows.Scan(&show) err := rows.Scan(&show)
if err != nil {
continue
}
res = append(res, show) res = append(res, show)
} }

View File

@ -6,7 +6,6 @@ import (
"openmediacenter/apiGo/config" "openmediacenter/apiGo/config"
"openmediacenter/apiGo/database" "openmediacenter/apiGo/database"
"os" "os"
"path/filepath"
"strings" "strings"
) )
@ -15,6 +14,20 @@ type StatusMessage struct {
ContentAvailable bool ContentAvailable bool
} }
func getVideoTypes() []string {
return []string{".mp4", ".mov", ".mkv", ".flv", ".avi", ".mpeg", ".m4v"}
}
func ValidVideoSuffix(filename string) bool {
validExts := getVideoTypes()
for _, validExt := range validExts {
if strings.HasSuffix(filename, validExt) {
return true
}
}
return false
}
func StartReindex() bool { func StartReindex() bool {
fmt.Println("starting reindex..") fmt.Println("starting reindex..")
SendEvent("start") SendEvent("start")
@ -33,22 +46,19 @@ func StartReindex() bool {
return false return false
} }
var files []string filelist, err := ioutil.ReadDir(vidFolder)
err := filepath.Walk(vidFolder, func(path string, info os.FileInfo, err error) error {
if err != nil {
fmt.Println(err.Error())
return err
}
if !info.IsDir() && strings.HasSuffix(info.Name(), ".mp4") {
files = append(files, info.Name())
}
return nil
})
if err != nil { if err != nil {
fmt.Println(err.Error()) fmt.Println(err.Error())
return false
} }
var files []string
for _, file := range filelist {
if !file.IsDir() && ValidVideoSuffix(file.Name()) {
files = append(files, file.Name())
}
}
// start reindex process // start reindex process
AppendMessage("Starting Reindexing!") AppendMessage("Starting Reindexing!")
InitDeps(&mSettings) InitDeps(&mSettings)
@ -107,7 +117,7 @@ func StartTVShowReindex() {
} }
for _, epfile := range episodefiles { for _, epfile := range episodefiles {
if strings.HasSuffix(epfile.Name(), ".mp4") { if ValidVideoSuffix(epfile.Name()) {
elem.files = append(elem.files, epfile.Name()) elem.files = append(elem.files, epfile.Name())
} }
} }

View File

@ -90,12 +90,14 @@ describe('<HomePage/>', function () {
const wrapper = shallow(<HomePage/>); const wrapper = shallow(<HomePage/>);
// expect those default values // expect those default values
expect(wrapper.state().sortby).toBe(0); expect(wrapper.state().sortby).toBe('Date Added');
expect(wrapper.instance().sortState).toBe(SortBy.date);
expect(wrapper.instance().tagState).toBe(DefaultTags.all); expect(wrapper.instance().tagState).toBe(DefaultTags.all);
wrapper.instance().onDropDownItemClick(SortBy.name); wrapper.instance().onDropDownItemClick(SortBy.name, 'namesort');
expect(wrapper.state().sortby).toBe(SortBy.name); expect(wrapper.state().sortby).toBe('namesort');
expect(wrapper.instance().sortState).toBe(SortBy.name);
}); });
}); });

View File

@ -29,7 +29,7 @@ interface state {
subtitle: string; subtitle: string;
data: VideoTypes.VideoUnloadedType[]; data: VideoTypes.VideoUnloadedType[];
selectionnr: number; selectionnr: number;
sortby: SortBy; sortby: string;
} }
/** /**
@ -39,33 +39,9 @@ export class HomePage extends React.Component<Props, state> {
/** keyword variable needed temporary store search keyword */ /** keyword variable needed temporary store search keyword */
keyword = ''; keyword = '';
/**
* get text label from sort type
* @param type SortBy type
*/
getLabelFromSortType(type: SortBy): String {
switch (type) {
case SortBy.date:
return 'Date Added';
case SortBy.length:
return 'Length';
case SortBy.likes:
return 'Most likes';
case SortBy.name:
return 'Name';
case SortBy.random:
return 'Random';
default:
return '';
}
}
constructor(props: Props) { constructor(props: Props) {
super(props); super(props);
// get previously stored location from localstorage
const storedSelection = global.localStorage.getItem('sortby');
this.state = { this.state = {
sideinfo: { sideinfo: {
VideoNr: 0, VideoNr: 0,
@ -78,10 +54,11 @@ export class HomePage extends React.Component<Props, state> {
subtitle: 'All Videos', subtitle: 'All Videos',
data: [], data: [],
selectionnr: 0, selectionnr: 0,
sortby: storedSelection == null ? SortBy.date : parseInt(storedSelection, 10) sortby: 'Date Added'
}; };
} }
sortState = SortBy.random;
tagState = DefaultTags.all; tagState = DefaultTags.all;
componentDidMount(): void { componentDidMount(): void {
@ -110,7 +87,7 @@ export class HomePage extends React.Component<Props, state> {
fetchVideoData(): void { fetchVideoData(): void {
callAPI( callAPI(
APINode.Video, APINode.Video,
{action: 'getMovies', Tag: this.tagState.TagId, Sort: this.state.sortby}, {action: 'getMovies', Tag: this.tagState.TagId, Sort: this.sortState},
(result: {Videos: VideoTypes.VideoUnloadedType[]; TagName: string}) => { (result: {Videos: VideoTypes.VideoUnloadedType[]; TagName: string}) => {
this.setState({ this.setState({
data: result.Videos, data: result.Videos,
@ -213,25 +190,15 @@ export class HomePage extends React.Component<Props, state> {
<span className={style.sortbyLabel}>Sort By: </span> <span className={style.sortbyLabel}>Sort By: </span>
<div className={style.dropdown}> <div className={style.dropdown}>
<span className={style.dropbtn}> <span className={style.dropbtn}>
<span>{this.getLabelFromSortType(this.state.sortby)}</span> <span>{this.state.sortby}</span>
<FontAwesomeIcon style={{marginLeft: 3, paddingBottom: 3}} icon={faSortDown} size='1x' /> <FontAwesomeIcon style={{marginLeft: 3, paddingBottom: 3}} icon={faSortDown} size='1x' />
</span> </span>
<div className={style.dropdownContent}> <div className={style.dropdownContent}>
<span onClick={(): void => this.onDropDownItemClick(SortBy.date)}> <span onClick={(): void => this.onDropDownItemClick(SortBy.date, 'Date Added')}>Date Added</span>
{this.getLabelFromSortType(SortBy.date)} <span onClick={(): void => this.onDropDownItemClick(SortBy.likes, 'Most likes')}>Most likes</span>
</span> <span onClick={(): void => this.onDropDownItemClick(SortBy.random, 'Random')}>Random</span>
<span onClick={(): void => this.onDropDownItemClick(SortBy.likes)}> <span onClick={(): void => this.onDropDownItemClick(SortBy.name, 'Name')}>Name</span>
{this.getLabelFromSortType(SortBy.likes)} <span onClick={(): void => this.onDropDownItemClick(SortBy.length, 'Length')}>Length</span>
</span>
<span onClick={(): void => this.onDropDownItemClick(SortBy.random)}>
{this.getLabelFromSortType(SortBy.random)}
</span>
<span onClick={(): void => this.onDropDownItemClick(SortBy.name)}>
{this.getLabelFromSortType(SortBy.name)}
</span>
<span onClick={(): void => this.onDropDownItemClick(SortBy.length)}>
{this.getLabelFromSortType(SortBy.length)}
</span>
</div> </div>
</div> </div>
</div> </div>
@ -247,12 +214,10 @@ export class HomePage extends React.Component<Props, state> {
* @param type type of sort action * @param type type of sort action
* @param name new header title * @param name new header title
*/ */
onDropDownItemClick(type: SortBy): void { onDropDownItemClick(type: SortBy, name: string): void {
this.setState({sortby: type}, (): void => { this.sortState = type;
global.localStorage.setItem('sortby', type.toString()); this.setState({sortby: name});
this.fetchVideoData();
this.fetchVideoData();
});
} }
} }

View File

@ -2,16 +2,21 @@ import React from 'react';
import style from './RandomPage.module.css'; import style from './RandomPage.module.css';
import SideBar, {SideBarTitle} from '../../elements/SideBar/SideBar'; import SideBar, {SideBarTitle} from '../../elements/SideBar/SideBar';
import Tag from '../../elements/Tag/Tag'; import Tag from '../../elements/Tag/Tag';
import PageTitle from '../../elements/PageTitle/PageTitle'; import PageTitle, {Line} from '../../elements/PageTitle/PageTitle';
import VideoContainer from '../../elements/VideoContainer/VideoContainer'; import VideoContainer from '../../elements/VideoContainer/VideoContainer';
import {APINode, callAPI} from '../../utils/Api'; import {APINode, callAPI} from '../../utils/Api';
import {TagType} from '../../types/VideoTypes'; import {TagType} from '../../types/VideoTypes';
import {VideoTypes} from '../../types/ApiTypes'; import {VideoTypes} from '../../types/ApiTypes';
import {addKeyHandler, removeKeyHandler} from '../../utils/ShortkeyHandler'; import {addKeyHandler, removeKeyHandler} from '../../utils/ShortkeyHandler';
import {IconButton} from '../../elements/GPElements/Button';
import {faMinusCircle, faPlusCircle} from '@fortawesome/free-solid-svg-icons';
import AddTagPopup from '../../elements/Popups/AddTagPopup/AddTagPopup';
interface state { interface state {
videos: VideoTypes.VideoUnloadedType[]; videos: VideoTypes.VideoUnloadedType[];
tags: TagType[]; tags: TagType[];
filterTags: TagType[];
addTagPopup: boolean;
} }
interface GetRandomMoviesType { interface GetRandomMoviesType {
@ -25,30 +30,19 @@ interface GetRandomMoviesType {
class RandomPage extends React.Component<{}, state> { class RandomPage extends React.Component<{}, state> {
readonly LoadNR = 3; readonly LoadNR = 3;
// random seed to load videos, remains page reload.
seed = this.genRandInt();
constructor(props: {}) { constructor(props: {}) {
super(props); super(props);
// get previously stored location from localstorage
const storedseed = global.localStorage.getItem('randpageseed');
if (storedseed != null) {
this.seed = parseInt(storedseed, 10);
}
this.state = { this.state = {
addTagPopup: false,
videos: [], videos: [],
tags: [] tags: [],
filterTags: []
}; };
this.keypress = this.keypress.bind(this); this.keypress = this.keypress.bind(this);
} }
genRandInt(): number {
return Math.floor(Math.random() * 2147483647) + 1;
}
componentDidMount(): void { componentDidMount(): void {
addKeyHandler(this.keypress); addKeyHandler(this.keypress);
@ -62,55 +56,76 @@ class RandomPage extends React.Component<{}, state> {
render(): JSX.Element { render(): JSX.Element {
return ( return (
<div> <div>
<PageTitle title='Random Videos' subtitle='4pc' /> <PageTitle title='Random Videos' subtitle='3pc' />
<SideBar> <SideBar>
<SideBarTitle>Visible Tags:</SideBarTitle> <SideBarTitle>Visible Tags:</SideBarTitle>
{this.state.tags.map((m) => ( {this.state.tags.map((m) => (
<Tag key={m.TagId} tagInfo={m} /> <Tag key={m.TagId} tagInfo={m} />
))} ))}
<Line />
<SideBarTitle>Filter Tags:</SideBarTitle>
{this.state.filterTags.map((m) => (
<Tag key={m.TagId} tagInfo={m} />
))}
<IconButton
title='Add'
icon={faPlusCircle}
onClick={(): void => {
this.setState({addTagPopup: true});
}}
/>
{this.state.filterTags.length > 0 ? (
<IconButton
title='Remove All'
icon={faMinusCircle}
onClick={(): void => {
this.setState({filterTags: []}, (): void => {
this.loadShuffledvideos(this.LoadNR);
});
}}
/>
) : (
<></>
)}
</SideBar> </SideBar>
{this.state.videos.length !== 0 ? ( {this.state.videos.length !== 0 ? <VideoContainer data={this.state.videos} /> : <div>No Data found!</div>}
<VideoContainer data={this.state.videos}> <div className={style.Shufflebutton}>
<div className={style.Shufflebutton}> <button onClick={(): void => this.loadShuffledvideos(this.LoadNR)} className={style.btnshuffle}>
<button onClick={(): void => this.shuffleclick()} className={style.btnshuffle}> Shuffle
Shuffle </button>
</button> </div>
</div> {this.state.addTagPopup ? (
</VideoContainer> <AddTagPopup
) : ( onHide={(): void => this.setState({addTagPopup: false})}
<div>No Data found!</div> submit={(tagId: number, tagName: string): void => {
)} this.setState({filterTags: [...this.state.filterTags, {TagId: tagId, TagName: tagName}]}, (): void => {
this.loadShuffledvideos(this.LoadNR);
});
}}
/>
) : null}
</div> </div>
); );
} }
/**
* click handler for shuffle btn
*/
shuffleclick(): void {
this.genSeed();
this.loadShuffledvideos(this.LoadNR);
}
genSeed(): void {
this.seed = this.genRandInt();
global.localStorage.setItem('randpageseed', this.seed.toString());
}
/** /**
* load random videos from backend * load random videos from backend
* @param nr number of videos to load * @param nr number of videos to load
*/ */
loadShuffledvideos(nr: number): void { loadShuffledvideos(nr: number): void {
callAPI<GetRandomMoviesType>(APINode.Video, {action: 'getRandomMovies', Number: nr, Seed: this.seed}, (result) => { callAPI<GetRandomMoviesType>(
this.setState({videos: []}); // needed to trigger rerender of main videoview APINode.Video,
this.setState({ {action: 'getRandomMovies', Number: nr, TagFilter: this.state.filterTags.map((t) => t.TagId)},
videos: result.Videos, (result) => {
tags: result.Tags this.setState({videos: []}); // needed to trigger rerender of main videoview
}); this.setState({
}); videos: result.Videos,
tags: result.Tags
});
}
);
} }
/** /**
@ -120,8 +135,7 @@ class RandomPage extends React.Component<{}, state> {
private keypress(event: KeyboardEvent): void { private keypress(event: KeyboardEvent): void {
// bind s to shuffle // bind s to shuffle
if (event.key === 's') { if (event.key === 's') {
this.genSeed(); this.loadShuffledvideos(3);
this.loadShuffledvideos(this.LoadNR);
} }
} }
} }

View File

@ -66,7 +66,7 @@ export class EpisodePage extends React.Component<Props, State> {
export const EpisodeTile = (props: {episode: Episode}): JSX.Element => { export const EpisodeTile = (props: {episode: Episode}): JSX.Element => {
const themestyle = GlobalInfos.getThemeStyle(); const themestyle = GlobalInfos.getThemeStyle();
return ( return (
<Link to={'/tvplayer/' + props.episode.ID}> <Link to={'/media/tvplayer/' + props.episode.ID}>
<div className={tileStyle.tile + ' ' + themestyle.secbackground + ' ' + themestyle.textcolor}> <div className={tileStyle.tile + ' ' + themestyle.secbackground + ' ' + themestyle.textcolor}>
<FontAwesomeIcon <FontAwesomeIcon
style={{ style={{

View File

@ -55,7 +55,7 @@ export class TVShowPage extends React.Component<Props, State> {
(result) => callback(result) (result) => callback(result)
); );
}} }}
linkPath={'/tvshows/' + elem.Id} linkPath={'/media/tvshows/' + elem.Id}
/> />
)} )}
data={this.state.loading ? [] : this.data} data={this.state.loading ? [] : this.data}

View File

@ -3538,9 +3538,9 @@ caniuse-api@^3.0.0:
lodash.uniq "^4.5.0" lodash.uniq "^4.5.0"
caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001125, caniuse-lite@^1.0.30001219: caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001125, caniuse-lite@^1.0.30001219:
version "1.0.30001236" version "1.0.30001336"
resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001236.tgz#0a80de4cdf62e1770bb46a30d884fc8d633e3958" resolved "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001336.tgz"
integrity sha512-o0PRQSrSCGJKCPZcgMzl5fUaj5xHe8qA2m4QRvnyY4e1lITqoNkr7q/Oh1NcpGSy0Th97UZ35yoKcINPoq7YOQ== integrity sha512-/YxSlBmL7iKXTbIJ48IQTnAOBk7XmWsxhBF1PZLOko5Dt9qc4Pl+84lfqG3Tc4EuavurRn1QLoVJGxY2iSycfw==
capture-exit@^2.0.0: capture-exit@^2.0.0:
version "2.0.0" version "2.0.0"