✨ Watch video
This commit is contained in:
		
					parent
					
						
							
								1878224040
							
						
					
				
			
			
				commit
				
					
						2a19f3c8e9
					
				
			
		
					 4 changed files with 55 additions and 2 deletions
				
			
		|  | @ -22,6 +22,7 @@ var rootCmd = &cobra.Command{ | |||
| 		file := files.PickRandomFile() | ||||
| 		out := media.ProbeFile(file) | ||||
| 		fmt.Printf("%+v\n", out) | ||||
| 		media.Watch(out.Format.Path) | ||||
| 		stream := media.SelectAudioStream(out) | ||||
| 		fmt.Printf("Stream %d of %s: %+v\n", stream, out.Format.Path, out.Streams[stream]) | ||||
| 	}, | ||||
|  |  | |||
							
								
								
									
										4
									
								
								go.mod
									
										
									
									
									
								
							
							
						
						
									
										4
									
								
								go.mod
									
										
									
									
									
								
							|  | @ -6,9 +6,11 @@ require ( | |||
| 	github.com/BurntSushi/toml v1.3.2 | ||||
| 	github.com/adrg/xdg v0.4.0 | ||||
| 	github.com/akrennmair/slice v0.0.0-20220105203817-49445747ab81 | ||||
| 	github.com/creack/pty v1.1.18 | ||||
| 	github.com/kirsle/configdir v0.0.0-20170128060238-e45d2f54772f | ||||
| 	github.com/spf13/cobra v1.7.0 | ||||
| 	github.com/u2takey/ffmpeg-go v0.5.0 | ||||
| 	golang.org/x/term v0.11.0 | ||||
| ) | ||||
| 
 | ||||
| require ( | ||||
|  | @ -17,5 +19,5 @@ require ( | |||
| 	github.com/jmespath/go-jmespath v0.4.0 // indirect | ||||
| 	github.com/spf13/pflag v1.0.5 // indirect | ||||
| 	github.com/u2takey/go-utils v0.3.1 // indirect | ||||
| 	golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359 // indirect | ||||
| 	golang.org/x/sys v0.11.0 // indirect | ||||
| ) | ||||
|  |  | |||
							
								
								
									
										7
									
								
								go.sum
									
										
									
									
									
								
							
							
						
						
									
										7
									
								
								go.sum
									
										
									
									
									
								
							|  | @ -7,6 +7,8 @@ github.com/akrennmair/slice v0.0.0-20220105203817-49445747ab81/go.mod h1:jk5mJ+K | |||
| github.com/aws/aws-sdk-go v1.38.20 h1:QbzNx/tdfATbdKfubBpkt84OM6oBkxQZRw6+bW2GyeA= | ||||
| github.com/aws/aws-sdk-go v1.38.20/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro= | ||||
| github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= | ||||
| github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY= | ||||
| github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= | ||||
| github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||||
| github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||||
| github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||||
|  | @ -64,8 +66,11 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h | |||
| golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||||
| golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359 h1:2B5p2L5IfGiD7+b9BOoRMC6DgObAVZV+Fsp050NqXik= | ||||
| golang.org/x/sys v0.0.0-20211025201205-69cdffdb9359/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||||
| golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= | ||||
| golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||||
| golang.org/x/term v0.11.0 h1:F9tnn/DA/Im8nCwm+fX+1/eBwi4qFjRT++MhtVC4ZX0= | ||||
| golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU= | ||||
| golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||||
| golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= | ||||
| golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= | ||||
|  |  | |||
							
								
								
									
										45
									
								
								media/watch.go
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								media/watch.go
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,45 @@ | |||
| package media | ||||
| 
 | ||||
| import ( | ||||
| 	"github.com/creack/pty" | ||||
| 	"golang.org/x/term" | ||||
| 	"io" | ||||
| 	"os" | ||||
| 	"os/exec" | ||||
| 	"os/signal" | ||||
| 	"syscall" | ||||
| ) | ||||
| 
 | ||||
| func Watch(path string) { | ||||
| 	cmd := exec.Command("mpv", "--osd-fractions", "--term-osd=force", path) | ||||
| 	ptmx, err := pty.Start(cmd) | ||||
| 
 | ||||
| 	if err != nil { | ||||
| 		panic(err) | ||||
| 	} | ||||
| 	// Make sure to close the pty at the end. | ||||
| 	defer func() { ptmx.Close() }() // Best effort. | ||||
| 
 | ||||
| 	// Handle pty size. | ||||
| 	ch := make(chan os.Signal, 1) | ||||
| 	signal.Notify(ch, syscall.SIGWINCH) | ||||
| 	go func() { | ||||
| 		for range ch { | ||||
| 			pty.InheritSize(os.Stdin, ptmx) | ||||
| 		} | ||||
| 	}() | ||||
| 	ch <- syscall.SIGWINCH                        // Initial resize. | ||||
| 	defer func() { signal.Stop(ch); close(ch) }() // Cleanup signals when done. | ||||
| 
 | ||||
| 	// Set stdin in raw mode. | ||||
| 	oldState, err := term.MakeRaw(int(os.Stdin.Fd())) | ||||
| 	if err != nil { | ||||
| 		panic(err) | ||||
| 	} | ||||
| 	defer func() { term.Restore(int(os.Stdin.Fd()), oldState) }() // Best effort. | ||||
| 
 | ||||
| 	// Copy stdin to the pty and the pty to stdout. | ||||
| 	// NOTE: The goroutine will keep reading until the next keystroke before returning. | ||||
| 	go func() { io.Copy(ptmx, os.Stdin) }() | ||||
| 	io.Copy(os.Stdout, ptmx) | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue