mirror of
				https://github.com/mickael-kerjean/filestash.git
				synced 2025-10-31 18:16:00 +08:00 
			
		
		
		
	fix (transcoding): video transcoding plugin in canary
This commit is contained in:
		| @ -281,7 +281,10 @@ export default function(render, { mime }) { | |||||||
|  |  | ||||||
|     // feature6: player control - keyboard shortcut |     // feature6: player control - keyboard shortcut | ||||||
|     effect(setup$.pipe( |     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) => { |         rxjs.tap((code) => { | ||||||
|             switch (code) { |             switch (code) { | ||||||
|             case "Space": |             case "Space": | ||||||
|  | |||||||
| @ -75,33 +75,26 @@ func init() { | |||||||
|  |  | ||||||
| 	Hooks.Register.Onload(func() { | 	Hooks.Register.Onload(func() { | ||||||
| 		blacklist_format() | 		blacklist_format() | ||||||
| 		if plugin_enable() == false { | 		plugin_enable() | ||||||
| 			return |  | ||||||
| 		} else if ffmpegIsInstalled == false { | 		cachePath := GetAbsolutePath(VideoCachePath) | ||||||
|  | 		os.RemoveAll(cachePath) | ||||||
|  | 		os.MkdirAll(cachePath, os.ModePerm) | ||||||
|  | 		if ffmpegIsInstalled == false { | ||||||
| 			Log.Warning("[plugin video transcoder] ffmpeg needs to be installed") | 			Log.Warning("[plugin video transcoder] ffmpeg needs to be installed") | ||||||
| 			return | 			return | ||||||
| 		} else if ffprobeIsInstalled == false { | 		} else if ffprobeIsInstalled == false { | ||||||
| 			Log.Warning("[plugin video transcoder] ffprobe needs to be installed") | 			Log.Warning("[plugin video transcoder] ffprobe needs to be installed") | ||||||
| 			return | 			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 { | 	Hooks.Register.HttpEndpoint(func(r *mux.Router, app *App) error { | ||||||
| 		r.HandleFunc(OverrideVideoSourceMapper, func(res http.ResponseWriter, req *http.Request) { | 		r.HandleFunc(OverrideVideoSourceMapper, func(res http.ResponseWriter, req *http.Request) { | ||||||
| 			res.Header().Set("Content-Type", GetMimeType(req.URL.String())) | 			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(`window.overrides["video-map-sources"] = function(sources){`)) | ||||||
| 			res.Write([]byte(`    return sources.map(function(source){`)) | 			res.Write([]byte(`    return sources.map(function(source){`)) | ||||||
|  |  | ||||||
| @ -118,10 +111,18 @@ func init() { | |||||||
| 		}) | 		}) | ||||||
| 		return nil | 		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() | 	query := req.URL.Query() | ||||||
| 	if query.Get("transcode") != "hls" { | 	if query.Get("transcode") != "hls" { | ||||||
| 		return reader, nil | 		return reader, nil | ||||||
| @ -171,7 +172,10 @@ func hls_playlist(reader io.ReadCloser, ctx *App, res *http.ResponseWriter, req | |||||||
| 	return NewReadCloserFromBytes([]byte(response)), nil | 	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"]) | 	segmentNumber, err := strconv.Atoi(mux.Vars(req)["segment"]) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		Log.Info("[plugin hls] invalid segment request '%s'", mux.Vars(req)["segment"]) | 		Log.Info("[plugin hls] invalid segment request '%s'", mux.Vars(req)["segment"]) | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 MickaelK
					MickaelK