Skip to content

Commit

Permalink
you can now select playlist areas like 1-7, 8-20
Browse files Browse the repository at this point in the history
  • Loading branch information
Stegosawr committed Oct 3, 2019
1 parent 3c49dc5 commit d0f3d88
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
17 changes: 14 additions & 3 deletions utils/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,22 @@ import (
func NeedDownloadList(length int) []int {
if config.PlaylistItems != "" {
var items []int
var index int
var selStart, selEnd int
temp := strings.Split(config.PlaylistItems, ",")

for _, i := range temp {
index, _ = strconv.Atoi(strings.TrimSpace(i))
items = append(items, index)
selection := strings.Split(i, "-")
selStart, _ = strconv.Atoi(strings.TrimSpace(selection[0]))

if len(selection) >= 2 {
selEnd, _ = strconv.Atoi(strings.TrimSpace(selection[1]))
} else {
selEnd = selStart
}

for item := selStart; item <= selEnd; item++ {
items = append(items, item)
}
}
return items
}
Expand Down
24 changes: 24 additions & 0 deletions utils/download_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,30 @@ func TestNeedDownloadList(t *testing.T) {
items: "1, 3",
want: []int{1, 3},
},
{
name: "from to item selection 1",
args: args{
len: 10,
},
items: "1-3, 5, 7-8, 10",
want: []int{1, 2, 3, 5, 7, 8, 10},
},
{
name: "from to item selection 2",
args: args{
len: 10,
},
items: "1,2, 4 , 5, 7-8 , 10",
want: []int{1, 2, 4, 5, 7, 8, 10},
},
{
name: "from to item selection 3",
args: args{
len: 10,
},
items: "5-1, 2",
want: []int{2},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit d0f3d88

Please sign in to comment.