~nature/yt-cli

af47b629152463ef16dd63072d607a349ef255cb — LordNature 1 year, 5 months ago ea8e7f5
main.go: Removed deprecated functions.

- Removed dmenuList, playVideo, and listVideos
  Functionality will be moved to wrapper script.
1 files changed, 0 insertions(+), 58 deletions(-)

M main.go
M main.go => main.go +0 -58
@@ 4,8 4,6 @@ import (
	"flag"
	"log"
	"os"
	"os/exec"
	"io"
	"net/http"
	"encoding/xml"
	"io/ioutil"


@@ 160,59 158,3 @@ func getVideos(chID string) (ch Channel, err error) {
	xml.Unmarshal(body, &ch)
	return
}

func listVideos(chs []Channel) (vid string, err error) {
	var input string
	for _, c := range chs {
		for i, v := range c.Videos {
			if i > 4 {
				break
			}
			input += fmt.Sprintf("[%.10s] %.20s - %.50s\n", v.Date, c.Name, v.Title)
		}
	}
	vid, err = dmenuList(input)
	if err != nil {
		return
	}
	// this is trash and needs to be fixed.
	for _, c := range chs {
		for i, v := range c.Videos {
			if i > 4 {
				break
			}
			orig := fmt.Sprintf("[%.10s] %.20s - %.50s\n", v.Date, c.Name, v.Title)
			if orig == vid {
				vid = v.ID
				break
			}
		}
	}
	return
}

func dmenuList(input string) (output string, err error) {
	cmd := exec.Command("dmenu", "-l", "10",)
	stdin, err := cmd.StdinPipe()
	if err != nil {
		return
	}
	go func() {
		defer stdin.Close()
		io.WriteString(stdin, input)
	}()

	out, err := cmd.CombinedOutput()
	if err != nil {
		return
	}

	output = string(out)
	return
}

func playVideo(id string) (err error) {
	cmd := exec.Command("mpv", "https://youtube.com/watch?v=" + id)
	err = cmd.Run()
	return
}