From 96796bfc0db4d7984f9b7428035922d1b2bc75ae Mon Sep 17 00:00:00 2001 From: mejgun Date: Sat, 14 Aug 2021 19:00:54 +0300 Subject: [PATCH] go version upd & warn fixs --- .gitignore | 3 ++- build.sh | 25 +++++++++++++------------ go.mod | 3 +++ parser.go | 2 +- streamer.go | 15 ++++++++++----- 5 files changed, 29 insertions(+), 19 deletions(-) create mode 100644 go.mod diff --git a/.gitignore b/.gitignore index 6dd29b7..25593bb 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -bin/ \ No newline at end of file +bin/ +all.md5 diff --git a/build.sh b/build.sh index aa2fd8e..0361ee5 100755 --- a/build.sh +++ b/build.sh @@ -7,23 +7,24 @@ GoBin=go BinDir="bin" FilePrefix="yt-proxy" -OSListStr="aix android darwin dragonfly freebsd hurd illumos js linux nacl netbsd openbsd plan9 solaris windows zos" +OSListStr="aix android darwin dragonfly freebsd hurd illumos ios js linux nacl netbsd openbsd plan9 solaris windows zos" OSList=($OSListStr) -ArchListStr="386 amd64 amd64p32 arm armbe arm64 arm64be ppc64 ppc64le mips mipsle mips64 mips64le mips64p32 mips64p32le ppc riscv riscv64 s390 s390x sparc sparc64 wasm" +ArchListStr="386 amd64 amd64p32 arm armbe arm64 arm64be ppc64 ppc64le loong64 mips mipsle mips64 mips64le mips64p32 mips64p32le ppc riscv riscv64 s390 s390x sparc sparc64 wasm" ArchList=($ArchListStr) -Total=$((${#OSList[@]}*${#ArchList[@]})) +Total=$((${#OSList[@]} * ${#ArchList[@]})) +Md5File="all.md5" -mkdir -p ${BinDir} -for OS in ${OSListStr} -do - for ARCH in ${ArchListStr} - do +date >${Md5File} + +mkdir -p ${BinDir} || exit +rm ${BinDir}/${FilePrefix}* -rf || exit +for OS in ${OSListStr}; do + for ARCH in ${ArchListStr}; do echo $Total ${OS}/${ARCH} - File=${FilePrefix}-${OS}-${ARCH} - GOPATH=$(pwd) GOOS=${OS} GOARCH=${ARCH} $GoBin build -ldflags '-s -w' -o ${BinDir}/${File} > /dev/null 2>&1 && cd ${BinDir} && md5sum ${File} > ${File}.md5sum && cd .. - ((Total=Total-1)) + File=${FilePrefix}-${OS}-${ARCH} + GOOS=${OS} GOARCH=${ARCH} $GoBin build -ldflags '-s -w' -o ${BinDir}/${File} >/dev/null 2>&1 && cd ${BinDir} && md5sum ${File} >>../${Md5File} && cd .. + ((Total = Total - 1)) done done - diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..e327f39 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module yt-proxy + +go 1.16 diff --git a/parser.go b/parser.go index 9f34bd0..000e9ab 100644 --- a/parser.go +++ b/parser.go @@ -96,7 +96,7 @@ func runCmd(cmd *exec.Cmd) (string, error) { cmd.Stderr = &stderr err := cmd.Run() toS := func(s bytes.Buffer) string { - return strings.TrimSpace(string(s.Bytes())) + return strings.TrimSpace(s.String()) } outStr, errStr := toS(stdout), toS(stderr) if err != nil { diff --git a/streamer.go b/streamer.go index 6870755..4dcd828 100644 --- a/streamer.go +++ b/streamer.go @@ -13,7 +13,7 @@ import ( "strings" ) -const appVersion = "0.6" +const appVersion = "0.6.1" const defaultVideoHeight = "720" const defaultVideoFormat = "mp4" @@ -32,8 +32,7 @@ func main() { } else { extractor = getYTDL() } - var requests chan requestChan - requests = make(chan requestChan) + var requests = make(chan requestChan) var links linksCache links.cache = make(map[string]lnkT) debug := getDebugFunc(flags.enableDebug) @@ -129,7 +128,10 @@ func playVideo( if res.StatusCode == 206 { w.WriteHeader(http.StatusPartialContent) } - io.Copy(w, res.Body) + _, err = io.Copy(w, res.Body) + if err != nil { + log.Println("Proxy error", err) + } log.Printf("%s disconnected\n", req.RemoteAddr) } @@ -162,7 +164,10 @@ func getSendErrorVideoFunc(errorHeaders bool, errorVideo corruptedT) sendErrorVi w.Header().Set(hdrs[i], errs[i]) } } - w.Write(errorVideo.file) + _, err = w.Write(errorVideo.file) + if err != nil { + log.Println("Cannot send error video", err) + } } }