fix (transcoding): video transcoding plugin in canary

This commit is contained in:
MickaelK
2024-09-09 00:26:00 +10:00
parent 809423c710
commit ff2a88a581
2 changed files with 47 additions and 40 deletions

View File

@ -281,7 +281,10 @@ export default function(render, { mime }) {
// feature6: player control - keyboard shortcut
effect(setup$.pipe(
rxjs.switchMap(() => rxjs.fromEvent(document, "keydown").pipe(rxjs.map((e) => e.code))),
rxjs.switchMap(() => rxjs.merge(
rxjs.fromEvent(document, "keydown").pipe(rxjs.map((e) => e.code)),
rxjs.fromEvent($video, "click").pipe(rxjs.mapTo("Space")),
)),
rxjs.tap((code) => {
switch (code) {
case "Space":

View File

@ -75,33 +75,26 @@ func init() {
Hooks.Register.Onload(func() {
blacklist_format()
if plugin_enable() == false {
return
} else if ffmpegIsInstalled == false {
plugin_enable()
cachePath := GetAbsolutePath(VideoCachePath)
os.RemoveAll(cachePath)
os.MkdirAll(cachePath, os.ModePerm)
if ffmpegIsInstalled == false {
Log.Warning("[plugin video transcoder] ffmpeg needs to be installed")
return
} else if ffprobeIsInstalled == false {
Log.Warning("[plugin video transcoder] ffprobe needs to be installed")
return
}
cachePath := GetAbsolutePath(VideoCachePath)
os.RemoveAll(cachePath)
os.MkdirAll(cachePath, os.ModePerm)
Hooks.Register.ProcessFileContentBeforeSend(hls_playlist)
Hooks.Register.HttpEndpoint(func(r *mux.Router, app *App) error {
r.PathPrefix("/hls/hls_{segment}.ts").Handler(NewMiddlewareChain(
hls_transcode,
[]Middleware{SecureHeaders},
*app,
)).Methods("GET")
return nil
})
Hooks.Register.HttpEndpoint(func(r *mux.Router, app *App) error {
r.HandleFunc(OverrideVideoSourceMapper, func(res http.ResponseWriter, req *http.Request) {
res.Header().Set("Content-Type", GetMimeType(req.URL.String()))
if plugin_enable() == false {
return
}
res.Write([]byte(`window.overrides["video-map-sources"] = function(sources){`))
res.Write([]byte(` return sources.map(function(source){`))
@ -118,10 +111,18 @@ func init() {
})
return nil
})
Hooks.Register.HttpEndpoint(func(r *mux.Router, app *App) error {
r.PathPrefix("/hls/hls_{segment}.ts").Handler(NewMiddlewareChain(
hlsTranscodeHandler,
[]Middleware{SecureHeaders},
*app,
)).Methods("GET")
return nil
})
Hooks.Register.ProcessFileContentBeforeSend(hlsPlaylistHandler)
}
func hls_playlist(reader io.ReadCloser, ctx *App, res *http.ResponseWriter, req *http.Request) (io.ReadCloser, error) {
func hlsPlaylistHandler(reader io.ReadCloser, ctx *App, res *http.ResponseWriter, req *http.Request) (io.ReadCloser, error) {
query := req.URL.Query()
if query.Get("transcode") != "hls" {
return reader, nil
@ -171,7 +172,10 @@ func hls_playlist(reader io.ReadCloser, ctx *App, res *http.ResponseWriter, req
return NewReadCloserFromBytes([]byte(response)), nil
}
func hls_transcode(ctx *App, res http.ResponseWriter, req *http.Request) {
func hlsTranscodeHandler(ctx *App, res http.ResponseWriter, req *http.Request) {
if plugin_enable() == false {
return
}
segmentNumber, err := strconv.Atoi(mux.Vars(req)["segment"])
if err != nil {
Log.Info("[plugin hls] invalid segment request '%s'", mux.Vars(req)["segment"])