@@ 1,95 @@
+package main
+
+import (
+ "os"
+ "os/exec"
+ "io"
+ "net/http"
+ "encoding/xml"
+ "io/ioutil"
+ "fmt"
+ "strings"
+)
+
+type Channel struct {
+ ID string `xml:"yt:channelId"`
+ Name string `xml:"title"`
+ Videos []Video `xml:"entry"`
+}
+
+type Video struct {
+ XMLName xml.Name `xml:"entry"`
+ ID string `xml:"videoId"`
+ Title string `xml:"title"`
+ Date string `xml:"published"`
+}
+
+const usage string = `Usage: yt.go [option] <selection>
+add <channelID> Adds Channel ID to subscription list.
+list Lists all videos from subscriptions.
+help Prints usage.
+`
+
+func main() {
+ name := os.Args[0]
+ fmt.Println(name)
+
+ switch os.Args[1] {
+ case "add":
+ test, _ := readSubs()
+ addChannel(test)
+ case "list":
+ case "help":
+ fallthrough
+ default:
+ fmt.Printf("%s", usage)
+ }
+}
+
+func readSubs() (channels []string, err error) {
+ // hardcoded for now
+ data, err := ioutil.ReadFile("subs")
+ if err != nil {
+ return
+ }
+
+ channels = strings.Split(string(data), "\n")
+
+ return
+}
+
+func addChannel(subs []string) {
+ for _, k := range subs {
+ fmt.Println(k)
+ }
+
+ url := "https://www.youtube.com/feeds/videos.xml?channel_id=ID_HERE"
+ req, _ := http.NewRequest("GET", url, nil)
+ res, _ := http.DefaultClient.Do(req)
+ defer res.Body.Close()
+ body, _ := ioutil.ReadAll(res.Body)
+
+ var channel Channel
+ xml.Unmarshal(body, &channel)
+
+
+ var test string
+ for _, v := range channel.Videos {
+ fmt.Printf("[%.10s] %.20s - %.50s\n", v.Date, channel.Name, v.Title)
+ test += v.ID + "\n"
+ }
+ dmenuList(test)
+}
+
+func dmenuList(input string) {
+ cmd := exec.Command("dmenu", "-l", "10")
+ stdin, _ := cmd.StdinPipe()
+ go func() {
+ defer stdin.Close()
+ io.WriteString(stdin, input)
+ }()
+
+ out, _ := cmd.CombinedOutput()
+
+ fmt.Printf("%s\n", out)
+}