cmd: testing commands
Signed-off-by: HeshamTB <hishaminv@gmail.com>
This commit is contained in:
parent
f85c7cf3ac
commit
92dddc7ebe
57
cmd/googleurltest/main.go
Normal file
57
cmd/googleurltest/main.go
Normal file
@ -0,0 +1,57 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
fmt.Println(os.Args[0], " <url>")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
url, err := url.Parse(os.Args[1])
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Printf("url.Query(): %+v\n", url.Query())
|
||||
|
||||
resp, err := http.Get(url.String())
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if resp.StatusCode != 200 {
|
||||
fmt.Printf("http: got %d\n", resp.StatusCode)
|
||||
}
|
||||
|
||||
if url != resp.Request.URL {
|
||||
fmt.Printf("resp.Request.URL: %+v\n", resp.Request.URL)
|
||||
fmt.Printf("resp.Request.URL.Query(): %+v\n", resp.Request.URL.Query())
|
||||
}
|
||||
|
||||
time_s := url.Query().Get("expire")
|
||||
if time_s == "" {
|
||||
fmt.Println("url: expire key missing")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
time_ss, err := strconv.ParseInt(time_s, 10, 64)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
unix := time.Unix(time_ss, 0)
|
||||
duration := unix.Sub(time.Now())
|
||||
fmt.Printf("duration.String(): %v\n", duration.String())
|
||||
|
||||
}
|
10
cmd/watchfile/test
Normal file
10
cmd/watchfile/test
Normal file
@ -0,0 +1,10 @@
|
||||
test
|
||||
a
|
||||
test
|
||||
awdeafwqe
|
||||
test
|
||||
awd
|
||||
test
|
||||
test
|
||||
awdwd
|
||||
test
|
35
cmd/watchfile/watchfile.go
Normal file
35
cmd/watchfile/watchfile.go
Normal file
@ -0,0 +1,35 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/gohugoio/hugo/watcher/filenotify"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
w, err := filenotify.NewEventWatcher()
|
||||
if err != nil {
|
||||
log.Fatalln(err.Error())
|
||||
}
|
||||
defer w.Close()
|
||||
|
||||
err = w.Add("test")
|
||||
if err != nil {
|
||||
log.Fatalln(err.Error())
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case e, ok:= <- w.Events():
|
||||
if !ok {
|
||||
log.Println("channel closed")
|
||||
return
|
||||
}
|
||||
fmt.Printf("e: %v\n", e)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
32
cmd/ytdlpurldesc/main.go
Normal file
32
cmd/ytdlpurldesc/main.go
Normal file
@ -0,0 +1,32 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/lrstanley/go-ytdlp"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cmd := ytdlp.New().ExtractAudio().GetURL().GetDescription()
|
||||
res, err := cmd.Run(
|
||||
context.Background(),
|
||||
"https://www.youtube.com/watch?v=JD9IQRlQyh0",
|
||||
"https://www.youtube.com/watch?v=ZwkNTwWJP5k",
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("err: %v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
lines := strings.Split(res.Stdout, "\n")
|
||||
for _, line := range lines {
|
||||
fmt.Printf("line: %v\n", line)
|
||||
if strings.HasPrefix(line, "https://") {
|
||||
fmt.Println("probably link")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
57
cmd/ytfeed/main.go
Normal file
57
cmd/ytfeed/main.go
Normal file
@ -0,0 +1,57 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"gitea.hbanafa.com/hesham/yttopodcast/feed"
|
||||
)
|
||||
|
||||
var CHAN_ID *string = flag.String("id", "", "youtube channel id")
|
||||
|
||||
func main() {
|
||||
|
||||
flag.Parse()
|
||||
|
||||
if *CHAN_ID == "" {
|
||||
perr("provide channel id with -id <id>\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
url := fmt.Sprintf(feed.YT_FEED_URL, *CHAN_ID)
|
||||
perr(url + "\n")
|
||||
resp, err := http.Get(url)
|
||||
|
||||
if err != nil {
|
||||
perr(err.Error() + "\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
perr("http: endpoint returned %s\n", resp.Status)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
sc := bufio.NewReader(resp.Body)
|
||||
for {
|
||||
newl, err := sc.ReadString('\n')
|
||||
if err != nil {
|
||||
|
||||
if errors.Is(err, io.EOF) {
|
||||
break
|
||||
}
|
||||
perr(err.Error() + "\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Print(newl)
|
||||
}
|
||||
}
|
||||
|
||||
func perr(f string, args... any) {
|
||||
fmt.Fprintf(os.Stderr, f, args...)
|
||||
}
|
Loading…
Reference in New Issue
Block a user