Skip to content

Commit

Permalink
v2.2.0, add TUI
Browse files Browse the repository at this point in the history
  • Loading branch information
horsaen committed Mar 24, 2024
1 parent 9cb2250 commit 52420cd
Show file tree
Hide file tree
Showing 10 changed files with 444 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
downloads
downloads
testing
21 changes: 21 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@ require (
)

require (
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/bubbletea v0.25.0 // indirect
github.com/charmbracelet/lipgloss v0.9.1 // indirect
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/rivo/uniseg v0.4.6 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/term v0.6.0 // indirect
golang.org/x/text v0.3.8 // indirect
)

require (
github.com/charmbracelet/bubbles v0.18.0
github.com/fogleman/ease v0.0.0-20170301025033-8da417bf1776
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
golang.org/x/sys v0.14.0 // indirect
Expand Down
38 changes: 38 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,18 +1,49 @@
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/charmbracelet/bubbles v0.18.0 h1:PYv1A036luoBGroX6VWjQIE9Syf2Wby2oOl/39KLfy0=
github.com/charmbracelet/bubbles v0.18.0/go.mod h1:08qhZhtIwzgrtBjAcJnij1t1H0ZRjwHyGsy6AL11PSw=
github.com/charmbracelet/bubbletea v0.25.0 h1:bAfwk7jRz7FKFl9RzlIULPkStffg5k6pNt5dywy4TcM=
github.com/charmbracelet/bubbletea v0.25.0/go.mod h1:EN3QDR1T5ZdWmdfDzYcqOCAps45+QIJbLOBxmVNWNNg=
github.com/charmbracelet/lipgloss v0.9.1 h1:PNyd3jvaJbg4jRHKWXnCj1akQm4rh8dbEzN1p/u1KWg=
github.com/charmbracelet/lipgloss v0.9.1/go.mod h1:1mPmG4cxScwUQALAAnacHaigiiHB9Pmr+v1VEawJl6I=
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 h1:q2hJAaP1k2wIvVRd/hEHD7lacgqrCPS+k8g1MndzfWY=
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/fogleman/ease v0.0.0-20170301025033-8da417bf1776 h1:VRIbnDWRmAh5yBdz+J6yFMF5vso1It6vn+WmM/5l7MA=
github.com/fogleman/ease v0.0.0-20170301025033-8da417bf1776/go.mod h1:9wvnDu3YOfxzWM9Cst40msBF1C2UdQgDv962oTxSuMs=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b h1:1XF24mVaiu7u+CFywTdcDo2ie1pzzhwjt6RHqzpMU34=
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho=
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8=
github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo=
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.6 h1:Sovz9sDSwbOz9tgUy8JpT+KgCkPYJEN/oYzlJiYTNLg=
github.com/rivo/uniseg v0.4.6/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/rodaine/table v1.1.1 h1:zBliy3b4Oj6JRmncse2Z85WmoQvDrXOYuy0JXCt8Qz8=
github.com/rodaine/table v1.1.1/go.mod h1:iqTRptjn+EVcrVBYtNMlJ2wrJZa3MpULUmcXFpfcziA=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand All @@ -21,10 +52,17 @@ github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpE
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
19 changes: 14 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@ import (
"horsaen/afreeca-downloader/plugins/panda"
"horsaen/afreeca-downloader/plugins/tiktok"
"horsaen/afreeca-downloader/tools"
"horsaen/afreeca-downloader/views"
"log"
"os"

tea "github.com/charmbracelet/bubbletea"
)

func main() {
tools.InitConfDir()
tools.Exists("downloads")

var username string

mode := flag.String("mode", "afreeca", "Mode")
mode := flag.String("mode", "tui", "Mode")
userArg := flag.String("username", "", "Streamer username")
playlist := flag.Bool("playlist", false, "Download bot playlists")
concurrently := flag.Bool("concurrent", false, "Download streams concurrently")
Expand All @@ -32,13 +37,11 @@ func main() {
tools.Version()
}

tools.Exists("downloads")

if *concurrently {
concurrent.Start()
}

if *userArg != "" || *playlist || *vod || *concurrently {
if *userArg != "" || *playlist || *vod || *concurrently || *mode == "tui" {
username = *userArg
} else {
fmt.Println("Enter username:")
Expand All @@ -49,7 +52,8 @@ func main() {
case "afreeca":
tools.Exists("downloads/Afreeca")
if *playlist {
afreeca.Playlist()
inputPlaylists := afreeca.GetPlaylists()
afreeca.Playlist(inputPlaylists)
} else if *vod {
var TitleNo string
fmt.Println("Enter title number:")
Expand All @@ -68,6 +72,11 @@ func main() {
panda.Start(username)
case "tiktok":
tiktok.Start(username)
case "tui":
p := tea.NewProgram(views.InitialModel())
if _, err := p.Run(); err != nil {
log.Fatal(err)
}
default:
fmt.Println("Mode not supported, exiting.")
os.Exit(1)
Expand Down
4 changes: 2 additions & 2 deletions plugins/afreeca/afreeca.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func Start(bjId string) {
}
}

func Playlist() {
inputPlaylists := GetPlaylists()
func Playlist(inputPlaylists []string) {
tools.Exists("downloads/Afreeca/Playlists")

playlists := ParsePlaylists(inputPlaylists)

Expand Down
2 changes: 1 addition & 1 deletion plugins/afreeca/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func Download(bjId string, nickname string, broad_no string, playlist string) bo

func DownloadPlaylists(playlists []string) {
now := time.Now().Format("200601021504")
tools.Exists("downloads/Afreeca/" + now)
tools.Exists("downloads/Afreeca/Playlists/" + now)

vodBase := "https://vod-archive-kr-cdn-z01.afreecatv.com"
length := len(playlists)
Expand Down
24 changes: 24 additions & 0 deletions tools/cli.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package tools

import (
"fmt"
"os"
"os/exec"
"runtime"

"github.com/muesli/termenv"
)

var (
term = termenv.EnvColorProfile()
)

func ClearCli() {
Expand All @@ -18,3 +25,20 @@ func ClearCli() {
cmd.Run()
}
}

// bubbletea tools
func Checkbox(label string, checked bool) string {
if checked {
return ColorFg("[x] "+label, "212")
}
return fmt.Sprintf("[ ] %s", label)
}

func ColorFg(val, color string) string {
return termenv.String(val).Foreground(term.Color(color)).String()
}

// Return a function that will colorize the foreground of a given string.
func MakeFgStyle(color string) func(string) string {
return termenv.Style{}.Foreground(term.Color(color)).Styled
}
123 changes: 123 additions & 0 deletions views/selections.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package views

import (
"fmt"
"horsaen/afreeca-downloader/plugins/concurrent"
"horsaen/afreeca-downloader/tools"
)

func Platforms(m model) string {
c := m.Platform

tpl := "Select Platform:\n\n"
tpl += "%s\n\n"
tpl += subtle("j/k, up/down: select") + dot + subtle("enter: choose") + dot + subtle("q, esc: quit")

Platforms := fmt.Sprintf(
"%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
tools.Checkbox("Afreeca", c == 0),
tools.Checkbox("Bigo", c == 1),
tools.Checkbox("Flex", c == 2),
tools.Checkbox("Kick", c == 3),
tools.Checkbox("Panda", c == 4),
tools.Checkbox("TikTok", c == 5),
tools.Checkbox("Concurrent", c == 6),
)

return fmt.Sprintf(tpl, Platforms)
}

func Modes(m model) string {
var msg string

switch m.Platform {
case 0:
msg = AfreecaModes(m)
case 1:
// bigo
msg = fmt.Sprintf(
"Username\n\n%s\n\n%s",
m.TextInput.View(),
"(esc to quit)",
) + "\n"
case 2:
// flex
msg = fmt.Sprintf(
"User ID:\n%s\n\n%s\n\n%s",
"https://www.flextv.co.kr/channels/"+keyword("xxxxxx")+"/live",
m.TextInput.View(),
"(esc to quit)",
) + "\n"
case 3:
// kick
msg = fmt.Sprintf(
"Username:\n\n%s\n\n%s",
m.TextInput.View(),
"(esc to quit)",
) + "\n"
case 4:
// panda
msg = fmt.Sprintf(
"Username:\n\n%s\n\n%s",
m.TextInput.View(),
"(esc to quit)",
) + "\n"
case 5:
// tiktok
msg = fmt.Sprintf(
"Username:\n\n%s\n\n%s",
m.TextInput.View(),
"(esc to quit)",
) + "\n"
case 6:
// concurrent dl
tools.ClearCli()
go concurrent.Start()
}

return msg
}

func AfreecaModes(m model) string {
c := m.Mode

tpl := "Select Mode:\n\n"
tpl += "%s\n\n"
tpl += subtle("j/k, up/down: select") + dot + subtle("enter: choose") + dot + subtle("q, esc: quit")

Modes := fmt.Sprintf(
"%s\n%s\n%s\n",
tools.Checkbox("Stream", c == 0),
tools.Checkbox("VOD", c == 1),
tools.Checkbox("Playlist", c == 2),
)

return fmt.Sprintf(tpl, Modes)
}

func Afreeca(m model) string {
var msg string

switch m.Mode {
case 0:
msg = fmt.Sprintf(
"Username:\n\n%s\n\n%s",
m.TextInput.View(),
"(esc to quit)",
) + "\n"
case 1:
msg = fmt.Sprintf(
"VOD ID:\n\n%s\n\n%s",
m.TextInput.View(),
"(esc to quit)",
) + "\n"
case 2:
msg = fmt.Sprintf(
"One m3u8 per line.\n\n%s\n\n%s",
m.TextArea.View(),
"(ctrl+c/esc to start download)",
) + "\n\n"
}

return msg
}
Loading

0 comments on commit 52420cd

Please sign in to comment.