Skip to content

Commit 54c7d02

Browse files
committed
scraper implemented. Stream Getting successfully started on my PC. Need to update Readme.md for Beta Release
1 parent c54174e commit 54c7d02

File tree

4 files changed

+47
-27
lines changed

4 files changed

+47
-27
lines changed

cmd/search.go

+19-12
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
)
2020

2121
// searchCmd represents the search command
22-
var searchCmd = &cobra.Command{
22+
var SearchCmd = &cobra.Command{
2323
Use: "search",
2424
Short: "A brief description of your command",
2525
Long: `A longer description that spans multiple lines and likely contains examples
@@ -62,7 +62,6 @@ func Search(cmd *cobra.Command, args []string) error {
6262
var err error
6363
movieSet, seriesSet, bothSet, err = CheckIfSearchFlagsSet(cmd, args)
6464
if err != nil {
65-
fmt.Println(err)
6665
return err
6766
}
6867
if bothSet {
@@ -80,36 +79,44 @@ func Search(cmd *cobra.Command, args []string) error {
8079

8180
context := scraper.NewQueryContext("movie", MovieName, defaultTarget)
8281
query := core.NewSearchQuery(context)
83-
var results []scraper.Result
8482
if err != nil {
8583
return err
8684
}
8785
// Adding wait group to wait for search results to come before rendering the list model.
8886
var wg sync.WaitGroup
8987

9088
wg.Add(1)
91-
errc := make(chan error)
92-
resultsc := make(chan []scraper.Result)
89+
errc := make(chan error, 1)
90+
resultc := make(chan scraper.Result, 1)
91+
resultLen := make(chan int, 1)
9392
go func() {
9493
// Decrement the counter when the go routine completes
9594
defer wg.Done()
96-
// Call the function check
95+
var err error
96+
var results []scraper.Result
9797
results, err = query.Search()
9898
if err != nil {
9999
errc <- err
100100
}
101-
resultsc <- results
101+
resultLen <- len(results)
102+
for _, result := range results {
103+
resultc <- result
104+
}
105+
wg.Wait()
102106
}()
103-
wg.Wait()
104107
//Stream will be called by tui
105-
results, err = <-resultsc, <-errc
106108
if err != nil {
107109
return err
108110
}
111+
results := make([]scraper.Result, <-resultLen)
112+
for i := 0; i < len(results); i++ {
113+
results[i] = <-resultc
114+
}
109115
err = tui.RenderListModelView("", results)
110116
if err != nil {
111117
return err
112118
}
119+
tui.StartStream()
113120
}
114121
if seriesSet {
115122
SeriesName = cmd.Flag("series").Value.String()
@@ -123,15 +130,15 @@ func Search(cmd *cobra.Command, args []string) error {
123130
// }
124131

125132
func init() {
126-
yastCmd.AddCommand(searchCmd)
133+
yastCmd.AddCommand(SearchCmd)
127134

128135
// Here you will define your flags and configuration settings.
129136

130137
// Cobra supports Persistent Flags which will work for this command
131138
// and all subcommands, e.g.:
132139
// searchCmd.PersistentFlags().String("foo", "", "A help for foo")
133-
searchCmd.Flags().StringVarP(&MovieName, "movie", "m", "", "name of the movie to be searched")
134-
searchCmd.Flags().StringVar(&SeriesName, "series", "", "name of the series to be searched")
140+
SearchCmd.Flags().StringVarP(&MovieName, "movie", "m", "", "name of the movie to be searched")
141+
SearchCmd.Flags().StringVar(&SeriesName, "series", "", "name of the series to be searched")
135142
// Cobra supports local flags which will only run when this command
136143
// is called directly, e.g.:
137144
// searchCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")

tests/webtorrent_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package test
22

33
import (
4-
// "os/exec"
4+
//"os/exec"
55
"testing"
66
)
77

88
func TestWebTorrentAPI(t *testing.T) {
9-
// magnet := "magnet:?xt=urn:btih:4C9B41D664D7B6B23F0BF39AE185858CBADDA3FF&dn=SpiderMan+No+Way+Home+2021+1080p+HD-TS+V3+Line+Audio+x264+AAC&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Fexodus.desync.com%3A6969%2Fannounce&tr=udp%3A%2F%2F9.rarbg.me%3A2970%2Fannounce&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.tiny-vps.com%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.internetwarriors.net%3A1337%2Fannounce&tr=udp%3A%2F%2Fopentor.org%3A2710%2Fannounce&tr=udp%3A%2F%2Ftracker.torrent.eu.org%3A451%2Fannounce&tr=udp%3A%2F%2Fexplodie.org%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.moeking.me%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.cyberia.is%3A6969%2Fannounce&tr=udp%3A%2F%2F9.rarbg.me%3A2980%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2940%2Fannounce&tr=udp%3A%2F%2Ftracker.uw0.xyz%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=http%3A%2F%2Ftracker.openbittorrent.com%3A80%2Fannounce&tr=udp%3A%2F%2Fopentracker.i2p.rocks%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.internetwarriors.net%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969%2Fannounce&tr=udp%3A%2F%2Fcoppersurfer.tk%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.zer0day.to%3A1337%2Fannounce"
9+
// magnet := "magnet:?xt=urn:btih:9A5ADF68BA5ABECB534BD2DBCB53DF9D13FDCDA3&dn=Spider-Man.Far.from.Home.2019.720p.BluRay.x264-NeZu&tr=udp%3A%2F%2F9.rarbg.com%3A2800%2Fannounce&tr=udp%3A%2F%2F9.rarbg.me%3A2750%2Fannounce&tr=udp%3A%2F%2F9.rarbg.to%3A2730%2Fannounce&tr=udp%3A%2F%2Fdenis.stalker.upeer.me%3A6969%2Fannounce&tr=udp%3A%2F%2Fexodus.desync.com%3A6969%2Fannounce&tr=udp%3A%2F%2Fopen.stealth.si%3A80%2Fannounce&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.internetwarriors.net%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.pirateparty.gr%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.torrent.eu.org%3A451%2Fannounce&tr=udp%3A%2F%2Ftracker.opentrackr.org%3A1337%2Fannounce&tr=http%3A%2F%2Ftracker.openbittorrent.com%3A80%2Fannounce&tr=udp%3A%2F%2Fopentracker.i2p.rocks%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.internetwarriors.net%3A1337%2Fannounce&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969%2Fannounce&tr=udp%3A%2F%2Fcoppersurfer.tk%3A6969%2Fannounce&tr=udp%3A%2F%2Ftracker.zer0day.to%3A1337%2Fannounce"
1010

1111
// cmd := exec.Command("webtorrent", magnet, "--vlc")
1212
// if err := cmd.Run(); err != nil {

tui/listmodel.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ func (m ListModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
133133
}
134134

135135
switch {
136+
case tea.Quit():
137+
return nil, tea.Quit
136138
case key.Matches(msg, m.keys.toggleSpinner):
137139
cmd := m.list.ToggleSpinner()
138140
return m, cmd
@@ -198,7 +200,17 @@ func newItemDelegate(keys *delegateKeyMap) list.DefaultDelegate {
198200
case key.Matches(msg, keys.choose):
199201
//webtorrent api call
200202
SetMagnetChoice(magnet)
201-
StartStream()
203+
// var wg sync.WaitGroup
204+
// wg.Add(1)
205+
// go func() {
206+
// defer wg.Done()
207+
// err := StartStream()
208+
// if err != nil {
209+
// panic(err)
210+
// }
211+
// }()
212+
// wg.Wait()
213+
return tea.Quit
202214
//return m.NewStatusMessage(statusMessageStyle("You chose " + title))
203215
}
204216
}

tui/stream.go

+13-12
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,23 @@ import (
1414
)
1515

1616
//Need to implement getMagnet from Function Model.
17-
func GenerateCommand(magnet, defaultPlayer string) string {
18-
var cmdStr string
19-
if defaultPlayer == "vlc" {
20-
cmdStr = fmt.Sprintf("webtorrent %s --%s", magnet, defaultPlayer)
21-
}
22-
if defaultPlayer == "web-torrent" {
23-
cmdStr = fmt.Sprintf("webtorrent %s", magnet)
24-
}
25-
return cmdStr
26-
}
17+
// func GenerateCommand(magnet, defaultPlayer string) string {
18+
// var cmdStr string
19+
// if defaultPlayer == "vlc" {
20+
// cmdStr = fmt.Sprintf("webtorrent %s --%s", magnet, defaultPlayer)
21+
// }
22+
// if defaultPlayer == "web-torrent" {
23+
// cmdStr = fmt.Sprintf("webtorrent %s", magnet)
24+
// }
25+
// return cmdStr
26+
// }
2727

2828
func StartStream() error {
2929
fmt.Printf("Stream is Starting!!\n")
30+
fmt.Printf("If Movie is not playing, prefer movie with higher seeds.")
3031
chosenMagnet := GetMagnetFromListModel()
31-
cmdStr := GenerateCommand(chosenMagnet, GetPlayerChoice())
32-
cmd := exec.Command(cmdStr)
32+
cmdStr := "webtorrent"
33+
cmd := exec.Command(cmdStr, chosenMagnet, "--vlc")
3334
if err := cmd.Run(); err != nil {
3435
return fmt.Errorf("error starting stream: %v", err)
3536
}

0 commit comments

Comments
 (0)