Skip to content

Commit

Permalink
add max video height config setting
Browse files Browse the repository at this point in the history
  • Loading branch information
mejgun committed Sep 25, 2024
1 parent 3416f83 commit bc076be
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
1 change: 1 addition & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,5 +212,6 @@ func getNewApp(log logger.T, v config.SubConfigT) (app.Option, error) {
C: cch,
L: logger.NewLayer(log, fmt.Sprintf("[%s] app", v.Name)),
DefaultVideoHeight: v.DefaultVideoHeight,
MaxVideoHeight: v.MaxVideoHeight,
}, nil
}
6 changes: 5 additions & 1 deletion config.example.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
// web server listen port.
// DEFAULT 8080
"port": 8080,
// used if video height not set in request
// used if video height not set in request.
// DEFAULT 720
"default-video-height": 360,
// restrict maximum video height.
// DEFAULT 720
"max-video-height": 1080,
// logger config
"log": {
// log level
Expand Down Expand Up @@ -139,6 +142,7 @@
"my.streamer.example"
],
"default-video-height": 1080,
"max-video-height": 1080,
"extractor": {
"path": "direct"
},
Expand Down
26 changes: 19 additions & 7 deletions lib/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ type app struct {
name string
sites []string
log logger.T
defaultVideoHeight uint16
defaultVideoHeight uint64
maxVideoHeight uint64
}

type AppLogic struct {
Expand All @@ -45,7 +46,8 @@ type Option struct {
S streamer.T
C cache.T
L logger.T
DefaultVideoHeight uint16
DefaultVideoHeight uint64
MaxVideoHeight uint64
}

func New(log logger.T, def Option, opts []Option) *AppLogic {
Expand All @@ -63,6 +65,7 @@ func (t *AppLogic) set(log logger.T, def Option, opts []Option) {
extractor: def.X,
streamer: def.S,
defaultVideoHeight: def.DefaultVideoHeight,
maxVideoHeight: def.MaxVideoHeight,
}

t.appList = make([]app, 0)
Expand All @@ -75,6 +78,7 @@ func (t *AppLogic) set(log logger.T, def Option, opts []Option) {
sites: v.Sites,
log: v.L,
defaultVideoHeight: v.DefaultVideoHeight,
maxVideoHeight: v.MaxVideoHeight,
})
}
}
Expand Down Expand Up @@ -199,11 +203,19 @@ func parseQuery(query string) (string, uint64, string) {
}

func (t *app) fixRequest(link string, height uint64, format string) extractor_config.RequestT {
var h string
if height == 0 {
h = fmt.Sprintf("%d", t.defaultVideoHeight)
} else {
h = fmt.Sprintf("%d", height)
var (
h string
toS = func(d uint64) string {
return fmt.Sprintf("%d", d)
}
)
switch {
case height == 0:
h = toS(t.defaultVideoHeight)
case height > t.maxVideoHeight:
h = toS(t.maxVideoHeight)
default:
h = toS(height)
}
return extractor_config.RequestT{
URL: link,
Expand Down
7 changes: 6 additions & 1 deletion lib/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import (
type ConfigT struct {
PortInt uint16 `json:"port"`
Host string `json:"host"`
DefaultVideoHeight uint16 `json:"default-video-height"`
DefaultVideoHeight uint64 `json:"default-video-height"`
MaxVideoHeight uint64 `json:"max-video-height"`
Streamer streamer.ConfigT `json:"streamer"`
Extractor extractor_config.ConfigT `json:"extractor"`
Log logger_config.ConfigT `json:"log"`
Expand Down Expand Up @@ -53,6 +54,7 @@ func defaultConfig() ConfigT {
PortInt: 8080,
Host: "0.0.0.0",
DefaultVideoHeight: 720,
MaxVideoHeight: 720,
Streamer: streamer.ConfigT{
EnableErrorHeaders: &fls,
IgnoreMissingHeaders: &fls,
Expand Down Expand Up @@ -96,6 +98,9 @@ func appendConfig(src ConfigT, dst ConfigT) ConfigT {
if dst.DefaultVideoHeight == 0 {
dst.DefaultVideoHeight = src.DefaultVideoHeight
}
if dst.MaxVideoHeight == 0 {
dst.MaxVideoHeight = src.MaxVideoHeight
}
// streamer
if dst.Streamer.EnableErrorHeaders == nil {
dst.Streamer.EnableErrorHeaders = src.Streamer.EnableErrorHeaders
Expand Down

0 comments on commit bc076be

Please sign in to comment.