-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
118 lines (103 loc) · 3.61 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package main
import (
"fmt"
"log"
"os/exec"
"github.com/gdamore/tcell/v2"
"github.com/rivo/tview"
)
func main() {
// Channels to choose from
channels := []string{
"lofi hip hop radio",
"sythwave radio",
"peaceful piano radio",
"dark ambient radio",
"lofi sleep radio",
"liquid dnb radio",
"chill house radio",
"roots reggae radio",
"bossa nova radio",
"tokyo night drive radio",
"edm radio",
}
// everything always must be tokyo night or catpuccin
tview.Styles.PrimitiveBackgroundColor = tcell.NewRGBColor(24, 25, 38) // Background
tview.Styles.ContrastBackgroundColor = tcell.NewRGBColor(32, 34, 46) // Darker Background
tview.Styles.MoreContrastBackgroundColor = tcell.NewRGBColor(40, 42, 54) // Even Darker Background
tview.Styles.BorderColor = tcell.NewRGBColor(103, 109, 138) // Comment
tview.Styles.TitleColor = tcell.NewRGBColor(198, 208, 245) // Foreground
tview.Styles.GraphicsColor = tcell.NewRGBColor(103, 109, 138) // Comment
tview.Styles.PrimaryTextColor = tcell.NewRGBColor(198, 208, 245) // Foreground
tview.Styles.SecondaryTextColor = tcell.NewRGBColor(130, 137, 174) // Light Comment
tview.Styles.TertiaryTextColor = tcell.NewRGBColor(76, 80, 112) // Dark Comment
tview.Styles.InverseTextColor = tcell.NewRGBColor(24, 25, 38) // Background
tview.Styles.ContrastSecondaryTextColor = tcell.NewRGBColor(198, 208, 245) // Foreground
app := tview.NewApplication()
list := tview.NewList().
ShowSecondaryText(false)
for _, channel := range channels {
// Add channels to the list
list.AddItem(channel, "", 0, nil)
}
list.SetDoneFunc(func() {
app.Stop()
})
list.SetSelectedFunc(func(index int, mainText string, secondaryText string, shortcut rune) {
url := getStreamURL(mainText)
openStreamlink(url)
app.Stop()
})
list.SetBorder(true).SetTitle("Select Channel to Open in Streamlink").SetTitleAlign(tview.AlignLeft)
// Add key event handler
app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
if event.Key() == tcell.KeyRune && event.Rune() == 'q' {
app.Stop()
}
return event
})
if err := app.SetRoot(list, true).Run(); err != nil {
log.Fatalf("Error running application: %v", err)
}
}
// getStreamURL returns the stream URL based on the channel name
func getStreamURL(channel string) string {
switch channel {
case "lofi hip hop radio":
return "https://www.youtube.com/watch?v=jfKfPfyJRdk"
case "sythwave radio":
return "https://www.youtube.com/watch?v=4xDzrJKXOOY"
case "peaceful piano radio":
return "https://www.youtube.com/watch?v=4oStw0r33so"
case "dark ambient radio":
return "https://www.youtube.com/watch?v=S_MOd40zlYU"
case "lofi sleep radio":
return "https://www.youtube.com/watch?v=rUxyKA_-grg"
case "liquid dnb radio":
return "https://www.youtube.com/watch?v=Cwq3AFyV044"
case "chill house radio":
return "https://www.youtube.com/watch?v=36YnV9STBqc"
case "roots reggae radio":
return "https://www.youtube.com/watch?v=UKPK4D4D4zw"
case "bossa nova radio":
return "https://www.youtube.com/watch?v=nM6A9HRp6wY"
case "tokyo night drive radio":
return "https://www.youtube.com/watch?v=Lcdi9O2XB4E"
case "edm radio":
return "https://www.youtube.com/watch?v=whACSpi2zQ8"
default:
return ""
}
}
// openStreamlink runs the streamlink command with the given URL
func openStreamlink(url string) {
if url == "" {
fmt.Println("No URL provided.")
return
}
cmd := exec.Command("streamlink", url, "480p")
if err := cmd.Start(); err != nil {
log.Fatalf("Error starting streamlink: %v", err)
}
fmt.Printf("Opening stream: %s\n", url)
}