Skip to content

Commit 3360114

Browse files
author
Your Name
committed
refactor: minor changes, check for amount of files in torrent
1 parent 795b9f0 commit 3360114

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

cmd/toru/stream.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,22 @@ func StreamTorrent(torfile string, cl *libtorrent.Client) (string, error) {
5959
}
6060
success.Success("Success!")
6161

62-
ep, _ := Prompt("Choose an episode")
63-
epInt, err := strconv.Atoi(ep)
64-
if err != nil {
65-
return "", errors.New("episode must be numeric")
66-
}
6762

68-
if epInt > len(t.Files()) {
69-
return "", errors.New("episode doesn't exist")
70-
}
63+
torrentFiles := len(t.Files())
64+
var episode int
7165

72-
link := cl.ServeTorrent(t, epInt)
66+
if torrentFiles != 1 {
67+
ep, _ := Prompt("Choose an episode")
68+
episode, err = strconv.Atoi(ep)
69+
if err != nil {
70+
return "", errors.New("episode must be numeric")
71+
}
72+
if episode > torrentFiles {
73+
return "", errors.New("episode doesn't exist")
74+
}
75+
}
76+
77+
link := cl.ServeTorrent(t, episode)
7378

7479
// consider deleting this as it sometimes conflicts with the fzf user interface
7580
go func() {

0 commit comments

Comments
 (0)