From d06fe3433eb92f0ac12542db6fb2ff7f4e9129e0 Mon Sep 17 00:00:00 2001 From: cybardev Date: Mon, 1 Apr 2024 20:29:47 -0300 Subject: [PATCH 01/19] re: simplify logic --- cmd/ytgo/yt.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/cmd/ytgo/yt.go b/cmd/ytgo/yt.go index d8654aa..0898ef9 100644 --- a/cmd/ytgo/yt.go +++ b/cmd/ytgo/yt.go @@ -7,7 +7,7 @@ import ( "strings" ) -const VERSION string = "v3.0.12" +const VERSION string = "v3.0.13" const ( C_RED string = "\x1b[31m" @@ -60,13 +60,12 @@ func main() { if err != nil { log.Fatalln(err) } else if v == nil { - return - } - if d { - fmt.Println(v.Id.URL()) return + } else if d { + fmt.Println(v.Id.URL()) + } else { + err = v.Play(m) } - err = v.Play(m) if err != nil { log.Fatalln(err) } From 3558d803164324e2cc0be7426de26ed696701cb9 Mon Sep 17 00:00:00 2001 From: cybardev Date: Sun, 17 Nov 2024 03:21:20 -0400 Subject: [PATCH 02/19] feat: add prompt mode --- cmd/ytgo/yt.go | 62 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 9 deletions(-) diff --git a/cmd/ytgo/yt.go b/cmd/ytgo/yt.go index 0898ef9..ab8572f 100644 --- a/cmd/ytgo/yt.go +++ b/cmd/ytgo/yt.go @@ -1,9 +1,12 @@ package main import ( + "bufio" "flag" "fmt" "log" + "os" + "os/signal" "strings" ) @@ -19,9 +22,9 @@ const ( func main() { // specify available flags var ( - d, i, m, u, ver bool - n int - query string + d, i, m, p, u, ver bool + n int + query string ) // parse CLI args @@ -29,6 +32,7 @@ func main() { flag.BoolVar(&d, "d", false, "Display URL only") flag.BoolVar(&i, "i", false, "Interactive selection") flag.BoolVar(&m, "m", false, "Play music only") + flag.BoolVar(&p, "p", false, "Prompt mode") flag.BoolVar(&u, "u", false, "Play from URL") flag.IntVar(&n, "n", 1, "Play nth media") flag.Parse() @@ -39,17 +43,41 @@ func main() { return } + var v *Video + var err error + reader := bufio.NewReader(os.Stdin) + + // handle SIGINT (^C) in prompt mode + if p { + go func() { + sigchan := make(chan os.Signal, 1) + signal.Notify(sigchan, os.Interrupt) + <-sigchan + fmt.Printf("\n%sExiting...%s\n", C_CYAN, C_RESET) + os.Exit(0) + }() + } + // get search query - query = strings.Join(flag.Args(), " ") + if p { + query = getQuery(reader) + } else { + query = strings.Join(flag.Args(), " ") + } + +loop: if query == "" { - flag.Usage() - fmt.Println() - log.Fatalln("no query provided") + if p { + fmt.Println("No search query provided.") + goto endloop + } else { + flag.Usage() + fmt.Println() + log.Fatalln("no query provided") + } } // play media from YT or display URL - var v *Video - var err error if u { v, err = GetVideoFromURL(query) } else if i { @@ -69,4 +97,20 @@ func main() { if err != nil { log.Fatalln(err) } + +endloop: + if p { + query = getQuery(reader) + goto loop + } +} + +func getQuery(r *bufio.Reader) string { + fmt.Printf("%sEnter search query:%s ", C_CYAN, C_RESET) + q, err := r.ReadString('\n') + if err != nil { + log.Fatalln(err) + } + q = strings.TrimSpace(q) + return q } From c5f7ebdd1393fa7668712ec5a5419afd60745a2c Mon Sep 17 00:00:00 2001 From: cybardev Date: Sun, 17 Nov 2024 03:25:38 -0400 Subject: [PATCH 03/19] update: new version --- cmd/ytgo/yt.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/ytgo/yt.go b/cmd/ytgo/yt.go index ab8572f..877888d 100644 --- a/cmd/ytgo/yt.go +++ b/cmd/ytgo/yt.go @@ -10,7 +10,7 @@ import ( "strings" ) -const VERSION string = "v3.0.13" +const VERSION string = "v3.1.0" const ( C_RED string = "\x1b[31m" From 6ff6d5c045c115acf2c217935bfd681dd4d23250 Mon Sep 17 00:00:00 2001 From: cybardev Date: Sun, 17 Nov 2024 04:11:34 -0400 Subject: [PATCH 04/19] re: reorder tests --- cmd/ytgo/yt_test.go | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/cmd/ytgo/yt_test.go b/cmd/ytgo/yt_test.go index 0fb12cb..c29434a 100644 --- a/cmd/ytgo/yt_test.go +++ b/cmd/ytgo/yt_test.go @@ -32,6 +32,24 @@ func TestVersion(t *testing.T) { } } +func TestGetShortcut(t *testing.T) { + var ctrlMap map[int]rune = map[int]rune{ + 0: rune(48), + 1: rune(48 + 1), + 9: rune(48 + 9), + 10: rune(87 + 10), + 36: rune(87 + 36), + 37: 0, + -1: 0, + } + for i, r := range ctrlMap { + symbol := getShortcut(i) + if symbol != r { + t.Errorf("Expected shortcut to be %d, got %d", r, symbol) + } + } +} + func TestGetRequest(t *testing.T) { var wg sync.WaitGroup wg.Add(len(vs)) @@ -134,21 +152,3 @@ func testGottenVideo(v *Video, t *testing.T) { t.Error("URL does not match pattern:", v.Id.URL()) } } - -func TestGetShortcut(t *testing.T) { - var ctrlMap map[int]rune = map[int]rune{ - 0: rune(48), - 1: rune(48 + 1), - 9: rune(48 + 9), - 10: rune(87 + 10), - 36: rune(87 + 36), - 37: 0, - -1: 0, - } - for i, r := range ctrlMap { - symbol := getShortcut(i) - if symbol != r { - t.Errorf("Expected shortcut to be %d, got %d", r, symbol) - } - } -} From 7bf6b1cbe875317b80c2fb6950ee4c0f06f3ef34 Mon Sep 17 00:00:00 2001 From: cybardev Date: Sun, 17 Nov 2024 05:24:43 -0400 Subject: [PATCH 05/19] re: replace bufio.Reader with bufio.Scanner --- cmd/ytgo/yt.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/cmd/ytgo/yt.go b/cmd/ytgo/yt.go index 877888d..feccfbb 100644 --- a/cmd/ytgo/yt.go +++ b/cmd/ytgo/yt.go @@ -45,7 +45,7 @@ func main() { var v *Video var err error - reader := bufio.NewReader(os.Stdin) + scanner := bufio.NewScanner(os.Stdin) // handle SIGINT (^C) in prompt mode if p { @@ -60,7 +60,7 @@ func main() { // get search query if p { - query = getQuery(reader) + query = getQuery(scanner) } else { query = strings.Join(flag.Args(), " ") } @@ -100,17 +100,16 @@ loop: endloop: if p { - query = getQuery(reader) + query = getQuery(scanner) goto loop } } -func getQuery(r *bufio.Reader) string { +func getQuery(s *bufio.Scanner) string { fmt.Printf("%sEnter search query:%s ", C_CYAN, C_RESET) - q, err := r.ReadString('\n') - if err != nil { + s.Scan() + if err := s.Err(); err != nil { log.Fatalln(err) } - q = strings.TrimSpace(q) - return q + return s.Text() } From 79090811d2c52ef70938c3d6ab77d5fda5acfab1 Mon Sep 17 00:00:00 2001 From: cybardev Date: Sun, 17 Nov 2024 21:22:46 -0400 Subject: [PATCH 06/19] feat: use readline for better prompts --- cmd/ytgo/yt.go | 45 +++++++++++++++++++-------------------------- go.mod | 1 + go.sum | 7 +++++++ 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/cmd/ytgo/yt.go b/cmd/ytgo/yt.go index feccfbb..682817c 100644 --- a/cmd/ytgo/yt.go +++ b/cmd/ytgo/yt.go @@ -1,13 +1,12 @@ package main import ( - "bufio" "flag" "fmt" "log" - "os" - "os/signal" "strings" + + "github.com/chzyer/readline" ) const VERSION string = "v3.1.0" @@ -43,24 +42,24 @@ func main() { return } + // declare necessary vars var v *Video var err error - scanner := bufio.NewScanner(os.Stdin) - - // handle SIGINT (^C) in prompt mode - if p { - go func() { - sigchan := make(chan os.Signal, 1) - signal.Notify(sigchan, os.Interrupt) - <-sigchan - fmt.Printf("\n%sExiting...%s\n", C_CYAN, C_RESET) - os.Exit(0) - }() - } + var rl *readline.Instance // get search query if p { - query = getQuery(scanner) + // create line reader for search + rl, err = readline.New(fmt.Sprintf("%sSearch:%s ", C_CYAN, C_RESET)) + if err != nil { + log.Fatalln(err) + } + defer rl.Close() + + query, err = rl.Readline() + if err != nil { + return // on EOF/SIGINT + } } else { query = strings.Join(flag.Args(), " ") } @@ -100,16 +99,10 @@ loop: endloop: if p { - query = getQuery(scanner) + query, err = rl.Readline() + if err != nil { + return // on EOF/SIGINT + } goto loop } } - -func getQuery(s *bufio.Scanner) string { - fmt.Printf("%sEnter search query:%s ", C_CYAN, C_RESET) - s.Scan() - if err := s.Err(); err != nil { - log.Fatalln(err) - } - return s.Text() -} diff --git a/go.mod b/go.mod index 90a14e0..ed9efa3 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/cybardev/ytgo/v3 go 1.22 require ( + github.com/chzyer/readline v1.5.1 github.com/gdamore/tcell/v2 v2.7.1 github.com/rivo/tview v0.0.0-20240225120200-5605142ca62e ) diff --git a/go.sum b/go.sum index 5062651..8e6242b 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,9 @@ +github.com/chzyer/logex v1.2.1 h1:XHDu3E6q+gdHgsdTPH6ImJMIp436vR6MPtH8gP05QzM= +github.com/chzyer/logex v1.2.1/go.mod h1:JLbx6lG2kDbNRFnfkgvh4eRJRPX1QCoOIWomwysCBrQ= +github.com/chzyer/readline v1.5.1 h1:upd/6fQk4src78LMRzh5vItIt361/o4uq553V8B5sGI= +github.com/chzyer/readline v1.5.1/go.mod h1:Eh+b79XXUwfKfcPLepksvw2tcLE/Ct21YObkaSkeBlk= +github.com/chzyer/test v1.0.0 h1:p3BQDXSxOhOG0P9z6/hGnII4LGiEPOYBhs8asl/fC04= +github.com/chzyer/test v1.0.0/go.mod h1:2JlltgoNkt4TW/z9V/IzDdFaMTM2JPIi26O1pF38GC8= github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko= github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg= github.com/gdamore/tcell/v2 v2.7.1 h1:TiCcmpWHiAU7F0rA2I3S2Y4mmLmO9KHxJ7E1QhYzQbc= @@ -27,6 +33,7 @@ golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= From a22e90d4d9ad4c2f0eec60d025f7c5194abd634f Mon Sep 17 00:00:00 2001 From: cybardev Date: Sun, 17 Nov 2024 21:23:40 -0400 Subject: [PATCH 07/19] re: comments --- cmd/ytgo/yt.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/ytgo/yt.go b/cmd/ytgo/yt.go index 682817c..e3318d3 100644 --- a/cmd/ytgo/yt.go +++ b/cmd/ytgo/yt.go @@ -58,7 +58,7 @@ func main() { query, err = rl.Readline() if err != nil { - return // on EOF/SIGINT + return // exit on EOF/SIGINT } } else { query = strings.Join(flag.Args(), " ") @@ -101,7 +101,7 @@ endloop: if p { query, err = rl.Readline() if err != nil { - return // on EOF/SIGINT + return // exit on EOF/SIGINT } goto loop } From d062142a6ee5a36f3fab95bbb81204c7acb20051 Mon Sep 17 00:00:00 2001 From: cybardev Date: Sun, 17 Nov 2024 21:46:00 -0400 Subject: [PATCH 08/19] re: handle type conversion error --- cmd/ytgo/resparse.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/ytgo/resparse.go b/cmd/ytgo/resparse.go index 84ff171..4779b70 100644 --- a/cmd/ytgo/resparse.go +++ b/cmd/ytgo/resparse.go @@ -2,6 +2,7 @@ package main import ( "encoding/json" + "errors" "fmt" "regexp" "strconv" @@ -17,8 +18,12 @@ func (r VideoRes) Parse() (*Video, error) { if err != nil { return nil, err } - k := j.(map[string]interface{})["videoDetails"].(map[string]interface{}) - return getVideoFromDetails(&k) + k, ok := j.(map[string]interface{})["videoDetails"].(map[string]interface{}) + if ok { + return getVideoFromDetails(&k) + } else { + return &Video{}, errors.New("interface type mismatch") + } } func getVideoFromDetails(j *map[string]interface{}) (*Video, error) { From 05f1797d99f534abb6eedd90d13f513b216ac231 Mon Sep 17 00:00:00 2001 From: cybardev Date: Sun, 17 Nov 2024 21:57:25 -0400 Subject: [PATCH 09/19] re: raise error on non-OK HTTP response status --- cmd/ytgo/search.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/ytgo/search.go b/cmd/ytgo/search.go index cb72280..99ef9f0 100644 --- a/cmd/ytgo/search.go +++ b/cmd/ytgo/search.go @@ -43,6 +43,10 @@ func GetRequest(url string) (string, error) { } defer res.Body.Close() + if res.StatusCode != 200 { + return "", errors.New("HTTP response status not OK") + } + body, err := io.ReadAll(res.Body) if err != nil { return "", err From d067517640a8af29b4dedac0ac0cb89ffe6ea646 Mon Sep 17 00:00:00 2001 From: cybardev Date: Sun, 17 Nov 2024 22:21:23 -0400 Subject: [PATCH 10/19] fix: skip YT-blocked test in pipeline --- .github/workflows/test.yml | 2 +- cmd/ytgo/yt_test.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0644900..176bc6d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,7 @@ jobs: run: go build -C cmd/ytgo -o "../../bin/ytgo" - name: Run tests - run: go test -v -coverprofile=coverage.out ./cmd/ytgo + run: go test -short -v -coverprofile=coverage.out ./cmd/ytgo - name: Report Coverage uses: shogo82148/actions-goveralls@v1 diff --git a/cmd/ytgo/yt_test.go b/cmd/ytgo/yt_test.go index c29434a..2ddfee8 100644 --- a/cmd/ytgo/yt_test.go +++ b/cmd/ytgo/yt_test.go @@ -71,6 +71,10 @@ func TestGetRequest(t *testing.T) { } func TestGetVideoFromURL(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode") + } + var wg sync.WaitGroup wg.Add(len(vs)) From 1add6fbe2b623f5e16a8b4d7176dd2d1425452b1 Mon Sep 17 00:00:00 2001 From: cybardev Date: Sun, 17 Nov 2024 22:21:23 -0400 Subject: [PATCH 11/19] fix: skip YT-blocked test in pipeline --- .github/workflows/test.yml | 2 +- cmd/ytgo/yt_test.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0644900..176bc6d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,7 @@ jobs: run: go build -C cmd/ytgo -o "../../bin/ytgo" - name: Run tests - run: go test -v -coverprofile=coverage.out ./cmd/ytgo + run: go test -short -v -coverprofile=coverage.out ./cmd/ytgo - name: Report Coverage uses: shogo82148/actions-goveralls@v1 diff --git a/cmd/ytgo/yt_test.go b/cmd/ytgo/yt_test.go index c29434a..9a8ef78 100644 --- a/cmd/ytgo/yt_test.go +++ b/cmd/ytgo/yt_test.go @@ -71,6 +71,10 @@ func TestGetRequest(t *testing.T) { } func TestGetVideoFromURL(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode") + } + var wg sync.WaitGroup wg.Add(len(vs)) @@ -109,6 +113,10 @@ func TestGetSearchResults(t *testing.T) { } func TestGetVideoFromSearch(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode") + } + var wg sync.WaitGroup wg.Add(len(qs)) From 2a73d50137f7db4a323c10ac707657596c810196 Mon Sep 17 00:00:00 2001 From: cybardev Date: Sun, 17 Nov 2024 22:30:30 -0400 Subject: [PATCH 12/19] fix: update GitHub Action dependency --- .github/workflows/build.yml | 2 +- .github/workflows/release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8842678..c3e9206 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,7 +29,7 @@ jobs: go build -C cmd/ytgo -o "../../bin/ytgo-${GOOS}-${GOARCH}${EXT}" - name: Upload ${{ matrix.os }}-${{ matrix.arch }} binary - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: ytgo-${{ matrix.os }}-${{ matrix.arch }} path: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 64f0dc8..8e8bcb8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Download binaries - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v4 with: path: | bin/ From 68b3e0eccb3b18b8af8a9b5061993e822870fe25 Mon Sep 17 00:00:00 2001 From: cybardev Date: Sun, 17 Nov 2024 22:30:30 -0400 Subject: [PATCH 13/19] fix: update GitHub Action dependencies --- .github/workflows/build.yml | 6 +++--- .github/workflows/refresh-pkg.yml | 4 ++-- .github/workflows/release.yml | 2 +- .github/workflows/test.yml | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8842678..b179abb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,10 +13,10 @@ jobs: arch: [amd64, arm64] steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version: "1.22" @@ -29,7 +29,7 @@ jobs: go build -C cmd/ytgo -o "../../bin/ytgo-${GOOS}-${GOARCH}${EXT}" - name: Upload ${{ matrix.os }}-${{ matrix.arch }} binary - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: ytgo-${{ matrix.os }}-${{ matrix.arch }} path: | diff --git a/.github/workflows/refresh-pkg.yml b/.github/workflows/refresh-pkg.yml index 8bb144c..b7a9214 100644 --- a/.github/workflows/refresh-pkg.yml +++ b/.github/workflows/refresh-pkg.yml @@ -14,10 +14,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version: "1.22" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 64f0dc8..8e8bcb8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Download binaries - uses: actions/download-artifact@v2 + uses: actions/download-artifact@v4 with: path: | bin/ diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 176bc6d..f61cbcd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,10 +9,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: go-version: "1.22" From ecbd831c2420498d885aa3b361d0d03e211691cc Mon Sep 17 00:00:00 2001 From: cybardev Date: Mon, 18 Nov 2024 00:19:01 -0400 Subject: [PATCH 14/19] re: make efficient use of labels --- cmd/ytgo/yt.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/cmd/ytgo/yt.go b/cmd/ytgo/yt.go index e3318d3..3e0df6f 100644 --- a/cmd/ytgo/yt.go +++ b/cmd/ytgo/yt.go @@ -56,10 +56,7 @@ func main() { } defer rl.Close() - query, err = rl.Readline() - if err != nil { - return // exit on EOF/SIGINT - } + goto endloop } else { query = strings.Join(flag.Args(), " ") } From f7e71a6dfc32b1c26eeea91b76688df81d12ddee Mon Sep 17 00:00:00 2001 From: cybardev Date: Mon, 18 Nov 2024 00:20:14 -0400 Subject: [PATCH 15/19] update: new version --- cmd/ytgo/yt.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/ytgo/yt.go b/cmd/ytgo/yt.go index 3e0df6f..378fe1f 100644 --- a/cmd/ytgo/yt.go +++ b/cmd/ytgo/yt.go @@ -9,7 +9,7 @@ import ( "github.com/chzyer/readline" ) -const VERSION string = "v3.1.0" +const VERSION string = "v3.1.1" const ( C_RED string = "\x1b[31m" From 3afd013ab2babff9d93b8b366c3863b6cf87fefa Mon Sep 17 00:00:00 2001 From: cybardev Date: Mon, 18 Nov 2024 00:25:43 -0400 Subject: [PATCH 16/19] docs: update usage instructions --- README.md | 63 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index f5207d0..b29baa8 100644 --- a/README.md +++ b/README.md @@ -14,41 +14,41 @@ Click to navigate. -- [Dependencies](#dependencies) -- [Installation](#installation) - - [Manual](#manual) - - [With Go](#with-go) -- [Usage](#usage) - - [Examples](#examples) -- [Credits](#credits) +- [Dependencies](#dependencies) +- [Installation](#installation) + - [Manual](#manual) + - [With Go](#with-go) +- [Usage](#usage) + - [Examples](#examples) +- [Credits](#credits) ### Dependencies -- [mpv][mpv] -- [yt-dlp][ytdl] -- [ffmpeg][ffmpeg] +- [mpv][mpv] +- [yt-dlp][ytdl] +- [ffmpeg][ffmpeg] ### Installation #### Manual -- Download the file from the Releases page: [ytgo-{os}-{arch}][release] +- Download the file from the Releases page: [ytgo-{os}-{arch}][release] - - **PS**: Make sure to choose the right binary for your OS and architecture + - **PS**: Make sure to choose the right binary for your OS and architecture -- Place it on your `$PATH` and make it executable. +- Place it on your `$PATH` and make it executable. #### With Go > **Link to package**: [pkg.go.dev/github.com/cybardev/ytgo/v3][gopkg] -- Run the following command: +- Run the following command: ```sh go install github.com/cybardev/ytgo/v3/cmd/ytgo@latest ``` -- Ensure `$GOPATH/bin` is added to `$PATH`. An easy way is to add this line to `~/.profile`: +- Ensure `$GOPATH/bin` is added to `$PATH`. An easy way is to add this line to `~/.profile`: ```sh export PATH="$(go env GOPATH)/bin:$PATH" @@ -63,50 +63,51 @@ Output of `ytgo -h`: ```sh Usage of ytgo: - -d Display URL only - -i Interactive selection - -m Play music only + -d Display URL only + -i Interactive selection + -m Play music only -n int - Play nth media (default 1) - -u Play from URL - -v Display version + Play nth media (default 1) + -p Prompt mode + -u Play from URL + -v Display version ``` **HINT**: [Here][mpv_hotkeys]'s a list of mpv keyboard shortcuts for your convenience. #### Examples -- Play a video: +- Play a video: `ytgo rickroll` -- Play an audio: +- Play an audio: `ytgo -m gurenge band cover` -- Play the third search result: +- Play the third search result: `ytgo -n 3 racing into the night` -- Play an audio from URL: +- Play an audio from URL: `ytgo -u -m "https://www.youtube.com/watch?v=y6120QOlsfU"` - - **PS**: The URL must be quoted to avoid parsing by the shell + - **PS**: The URL must be quoted to avoid parsing by the shell -- Find the URL of a video: +- Find the URL of a video: `ytgo -d hotaru maiko fujita` -- Interactive selection mode: +- Interactive selection mode: `ytgo -i marmot scream meme` ### Credits -- [pystardust][pystardust]'s [ytfzf][ytfzf] -- [This article][article] I found during my quest to implement a simplified version of ytfzf in Python3 -- [StackOverflow answer][regex] used for the regex `var ytInitialData = ({.*?});` +- [pystardust][pystardust]'s [ytfzf][ytfzf] +- [This article][article] I found during my quest to implement a simplified version of ytfzf in Python3 +- [StackOverflow answer][regex] used for the regex `var ytInitialData = ({.*?});` From b2ba9c9fcd48c76797a33142440c653ce269c6d9 Mon Sep 17 00:00:00 2001 From: cybardev Date: Mon, 18 Nov 2024 00:25:50 -0400 Subject: [PATCH 17/19] update: new version --- cmd/ytgo/yt.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/ytgo/yt.go b/cmd/ytgo/yt.go index 378fe1f..80087de 100644 --- a/cmd/ytgo/yt.go +++ b/cmd/ytgo/yt.go @@ -9,7 +9,7 @@ import ( "github.com/chzyer/readline" ) -const VERSION string = "v3.1.1" +const VERSION string = "v3.1.2" const ( C_RED string = "\x1b[31m" From c24fc19ff43f7fbfb15e314466bbfef91df3b4c9 Mon Sep 17 00:00:00 2001 From: cybardev Date: Mon, 18 Nov 2024 00:41:03 -0400 Subject: [PATCH 18/19] re: unified variable declarations --- cmd/ytgo/yt.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/cmd/ytgo/yt.go b/cmd/ytgo/yt.go index 80087de..fa3ead0 100644 --- a/cmd/ytgo/yt.go +++ b/cmd/ytgo/yt.go @@ -19,11 +19,15 @@ const ( ) func main() { - // specify available flags var ( + // command-line args d, i, m, p, u, ver bool n int - query string + // declare vars + err error + query string + v *Video + rl *readline.Instance ) // parse CLI args @@ -42,11 +46,6 @@ func main() { return } - // declare necessary vars - var v *Video - var err error - var rl *readline.Instance - // get search query if p { // create line reader for search From e363cedc45653caa66a62e8baabe944c570ca0c7 Mon Sep 17 00:00:00 2001 From: cybardev Date: Mon, 18 Nov 2024 00:41:27 -0400 Subject: [PATCH 19/19] update: new version --- cmd/ytgo/yt.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/ytgo/yt.go b/cmd/ytgo/yt.go index fa3ead0..50424e9 100644 --- a/cmd/ytgo/yt.go +++ b/cmd/ytgo/yt.go @@ -9,7 +9,7 @@ import ( "github.com/chzyer/readline" ) -const VERSION string = "v3.1.2" +const VERSION string = "v3.1.3" const ( C_RED string = "\x1b[31m"