add tvshow syntax to db
basic tvshow api request to show available tvshows limit randompage videos to 3 improve settings object to remove one useless copy
This commit is contained in:
@ -15,6 +15,7 @@ const (
|
||||
TagNode = iota
|
||||
SettingsNode = iota
|
||||
ActorNode = iota
|
||||
TVShowNode = iota
|
||||
)
|
||||
|
||||
type actionStruct struct {
|
||||
@ -36,10 +37,11 @@ func AddHandler(action string, apiNode int, n interface{}, h func() []byte) {
|
||||
}
|
||||
|
||||
func ServerInit() {
|
||||
http.Handle(APIPREFIX+"/video", oauth.ValidateToken(videoHandler))
|
||||
http.Handle(APIPREFIX+"/tags", oauth.ValidateToken(tagHandler))
|
||||
http.Handle(APIPREFIX+"/settings", oauth.ValidateToken(settingsHandler))
|
||||
http.Handle(APIPREFIX+"/actor", oauth.ValidateToken(actorHandler))
|
||||
http.Handle(APIPREFIX+"/video", oauth.ValidateToken(handlefunc, VideoNode))
|
||||
http.Handle(APIPREFIX+"/tags", oauth.ValidateToken(handlefunc, TagNode))
|
||||
http.Handle(APIPREFIX+"/settings", oauth.ValidateToken(handlefunc, SettingsNode))
|
||||
http.Handle(APIPREFIX+"/actor", oauth.ValidateToken(handlefunc, ActorNode))
|
||||
http.Handle(APIPREFIX+"/tvshow", oauth.ValidateToken(handlefunc, TVShowNode))
|
||||
|
||||
// initialize oauth service and add corresponding auth routes
|
||||
oauth.InitOAuth()
|
||||
@ -65,22 +67,6 @@ func handleAPICall(action string, requestBody string, apiNode int) []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
func actorHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
handlefunc(rw, req, ActorNode)
|
||||
}
|
||||
|
||||
func videoHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
handlefunc(rw, req, VideoNode)
|
||||
}
|
||||
|
||||
func tagHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
handlefunc(rw, req, TagNode)
|
||||
}
|
||||
|
||||
func settingsHandler(rw http.ResponseWriter, req *http.Request) {
|
||||
handlefunc(rw, req, SettingsNode)
|
||||
}
|
||||
|
||||
func handlefunc(rw http.ResponseWriter, req *http.Request, node int) {
|
||||
// only allow post requests
|
||||
if req.Method != "POST" {
|
||||
|
@ -61,6 +61,22 @@ func readActorsFromResultset(rows *sql.Rows) []types.Actor {
|
||||
return result
|
||||
}
|
||||
|
||||
// ID - Name : pay attention to the order!
|
||||
func readTVshowsFromResultset(rows *sql.Rows) []types.TVShow {
|
||||
result := []types.TVShow{}
|
||||
for rows.Next() {
|
||||
var vid types.TVShow
|
||||
err := rows.Scan(&vid.Id, &vid.Name)
|
||||
if err != nil {
|
||||
panic(err.Error()) // proper error handling instead of panic in your app
|
||||
}
|
||||
result = append(result, vid)
|
||||
}
|
||||
rows.Close()
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func jsonify(v interface{}) []byte {
|
||||
// jsonify results
|
||||
str, err := json.Marshal(v)
|
||||
|
@ -29,17 +29,21 @@ func getSettingsFromDB() {
|
||||
Pasword bool
|
||||
MediacenterName string
|
||||
VideoPath string
|
||||
TVShowPath string
|
||||
}
|
||||
|
||||
regexMatchUrl := regexp.MustCompile("^http(|s):\\/\\/([0-9]){1,3}\\.([0-9]){1,3}\\.([0-9]){1,3}\\.([0-9]){1,3}:[0-9]{1,5}")
|
||||
regexMatchUrl := regexp.MustCompile("^http(|s)://([0-9]){1,3}\\.([0-9]){1,3}\\.([0-9]){1,3}\\.([0-9]){1,3}:[0-9]{1,5}")
|
||||
videoUrl := regexMatchUrl.FindString(sett.VideoPath)
|
||||
tvshowurl := regexMatchUrl.FindString(sett.TVShowPath)
|
||||
serverVideoPath := strings.TrimPrefix(sett.VideoPath, videoUrl)
|
||||
serverTVShowPath := strings.TrimPrefix(sett.TVShowPath, tvshowurl)
|
||||
|
||||
res := InitialDataTypeResponse{
|
||||
DarkMode: sett.DarkMode,
|
||||
Pasword: sett.Pasword != "-1",
|
||||
MediacenterName: sett.Mediacenter_name,
|
||||
MediacenterName: sett.MediacenterName,
|
||||
VideoPath: serverVideoPath,
|
||||
TVShowPath: serverTVShowPath,
|
||||
}
|
||||
|
||||
str, _ := json.Marshal(res)
|
||||
@ -74,6 +78,11 @@ func reIndexHandling() {
|
||||
return database.ManualSuccessResponse(nil)
|
||||
})
|
||||
|
||||
AddHandler("startTVShowReindex", SettingsNode, nil, func() []byte {
|
||||
videoparser.StartTVShowReindex()
|
||||
return database.ManualSuccessResponse(nil)
|
||||
})
|
||||
|
||||
AddHandler("cleanupGravity", SettingsNode, nil, func() []byte {
|
||||
videoparser.StartCleanup()
|
||||
return nil
|
||||
|
15
apiGo/api/TVShows.go
Normal file
15
apiGo/api/TVShows.go
Normal file
@ -0,0 +1,15 @@
|
||||
package api
|
||||
|
||||
import "openmediacenter/apiGo/database"
|
||||
|
||||
func AddTvshowHandlers() {
|
||||
var dT struct {
|
||||
TagId int
|
||||
Force bool
|
||||
}
|
||||
AddHandler("getTVShows", TVShowNode, &dT, func() []byte {
|
||||
query := "SELECT id, name FROM tvshow"
|
||||
rows := database.Query(query)
|
||||
return jsonify(readTVshowsFromResultset(rows))
|
||||
})
|
||||
}
|
@ -37,7 +37,7 @@ func deleteFromDB() {
|
||||
return database.ManualSuccessResponse(err)
|
||||
} else {
|
||||
// check with regex if its the key constraint error
|
||||
r, _ := regexp.Compile("^.*a foreign key constraint fails.*$")
|
||||
r := regexp.MustCompile("^.*a foreign key constraint fails.*$")
|
||||
if r.MatchString(err.Error()) {
|
||||
return []byte(`{"result":"not empty tag"}`)
|
||||
} else {
|
||||
|
@ -48,7 +48,7 @@ func InitOAuth() {
|
||||
})
|
||||
}
|
||||
|
||||
func ValidateToken(f http.HandlerFunc) http.HandlerFunc {
|
||||
func ValidateToken(f func(rw http.ResponseWriter, req *http.Request, node int), node int) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
_, err := srv.ValidationBearerToken(r)
|
||||
if err != nil {
|
||||
@ -56,6 +56,6 @@ func ValidateToken(f http.HandlerFunc) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
f.ServeHTTP(w, r)
|
||||
f(w, r, node)
|
||||
}
|
||||
}
|
||||
|
@ -7,12 +7,12 @@ type VideoUnloadedType struct {
|
||||
|
||||
type FullVideoType struct {
|
||||
MovieName string
|
||||
MovieId int
|
||||
MovieId uint32
|
||||
MovieUrl string
|
||||
Poster string
|
||||
Likes int
|
||||
Quality int
|
||||
Length int
|
||||
Likes uint64
|
||||
Quality uint16
|
||||
Length uint16
|
||||
Tags []Tag
|
||||
SuggestedTag []Tag
|
||||
Actors []Actor
|
||||
@ -20,22 +20,22 @@ type FullVideoType struct {
|
||||
|
||||
type Tag struct {
|
||||
TagName string
|
||||
TagId int
|
||||
TagId uint32
|
||||
}
|
||||
|
||||
type Actor struct {
|
||||
ActorId int
|
||||
ActorId uint32
|
||||
Name string
|
||||
Thumbnail string
|
||||
}
|
||||
|
||||
type StartData struct {
|
||||
VideoNr int
|
||||
FullHdNr int
|
||||
HDNr int
|
||||
SDNr int
|
||||
DifferentTags int
|
||||
Tagged int
|
||||
VideoNr uint32
|
||||
FullHdNr uint32
|
||||
HDNr uint32
|
||||
SDNr uint32
|
||||
DifferentTags uint32
|
||||
Tagged uint32
|
||||
}
|
||||
|
||||
type SettingsType struct {
|
||||
@ -47,10 +47,15 @@ type SettingsType struct {
|
||||
TMDBGrabbing bool
|
||||
DarkMode bool
|
||||
|
||||
VideoNr int
|
||||
VideoNr uint32
|
||||
DBSize float32
|
||||
DifferentTags int
|
||||
TagsAdded int
|
||||
DifferentTags uint32
|
||||
TagsAdded uint32
|
||||
|
||||
PathPrefix string
|
||||
}
|
||||
|
||||
type TVShow struct {
|
||||
Id uint32
|
||||
Name string
|
||||
}
|
||||
|
@ -15,35 +15,24 @@ func GetPassword() *string {
|
||||
}
|
||||
|
||||
type SettingsType struct {
|
||||
DarkMode bool
|
||||
Pasword string
|
||||
Mediacenter_name string
|
||||
VideoPath string
|
||||
DarkMode bool
|
||||
Pasword string
|
||||
MediacenterName string
|
||||
VideoPath string
|
||||
TVShowPath string
|
||||
}
|
||||
|
||||
func LoadSettings() *SettingsType {
|
||||
query := "SELECT DarkMode, password, mediacenter_name, video_path from settings"
|
||||
query := "SELECT DarkMode, password, mediacenter_name, video_path, episode_path from settings"
|
||||
|
||||
type RawSettingsType struct {
|
||||
DarkMode int
|
||||
Pasword string
|
||||
Mediacenter_name string
|
||||
VideoPath string
|
||||
}
|
||||
result := SettingsType{}
|
||||
var darkmode uint8
|
||||
|
||||
result := RawSettingsType{}
|
||||
|
||||
err := database.QueryRow(query).Scan(&result.DarkMode, &result.Pasword, &result.Mediacenter_name, &result.VideoPath)
|
||||
err := database.QueryRow(query).Scan(&darkmode, &result.Pasword, &result.MediacenterName, &result.VideoPath, &result.TVShowPath)
|
||||
if err != nil {
|
||||
fmt.Println("error while parsing db data: " + err.Error())
|
||||
}
|
||||
|
||||
res := SettingsType{
|
||||
DarkMode: result.DarkMode != 0,
|
||||
Pasword: result.Pasword,
|
||||
Mediacenter_name: result.Mediacenter_name,
|
||||
VideoPath: result.VideoPath,
|
||||
}
|
||||
|
||||
return &res
|
||||
result.DarkMode = darkmode != 0
|
||||
return &result
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ func main() {
|
||||
api.AddSettingsHandlers()
|
||||
api.AddTagHandlers()
|
||||
api.AddActorsHandlers()
|
||||
api.AddTvshowHandlers()
|
||||
|
||||
// add the static files
|
||||
static.ServeStaticFiles()
|
||||
|
@ -54,6 +54,11 @@ func StartReindex() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// StartTVShowReindex reindex dir walks for TVShow reindex
|
||||
func StartTVShowReindex() {
|
||||
// todo implement walking through dirs and reindex!
|
||||
}
|
||||
|
||||
func GetStatusMessage() *StatusMessage {
|
||||
msg := StatusMessage{
|
||||
Messages: messageBuffer,
|
||||
|
Reference in New Issue
Block a user