Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
main: Specify the download range of the list
- Loading branch information
Showing
10 changed files
with
329 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ language: go | |
sudo: false | ||
|
||
go: | ||
- "1.9" | ||
- "1.10" | ||
|
||
script: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package utils | ||
|
||
import ( | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/iawia002/annie/config" | ||
) | ||
|
||
// ShouldExtract returns true, if we need to extract this format | ||
func ShouldExtract(format, bestQuality string) bool { | ||
extractAll := config.InfoOnly || config.ExtractedData | ||
if extractAll { | ||
return true | ||
} | ||
if config.Format != "" { | ||
if format != config.Format { | ||
return false | ||
} | ||
} else if format != bestQuality { | ||
return false | ||
} | ||
return true | ||
} | ||
|
||
// NeedDownloadList return the indices of playlist that need download | ||
func NeedDownloadList(length int) []int { | ||
if config.PlaylistItems != "" { | ||
var items []int | ||
var index int | ||
temp := strings.Split(config.PlaylistItems, ",") | ||
for _, i := range temp { | ||
index, _ = strconv.Atoi(i) | ||
items = append(items, index) | ||
} | ||
return items | ||
} | ||
start := config.PlaylistStart | ||
end := config.PlaylistEnd | ||
if config.PlaylistStart < 1 { | ||
start = 1 | ||
} | ||
if end == 0 { | ||
end = length | ||
} | ||
if end < start { | ||
end = start | ||
} | ||
return Range(start, end) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
package utils | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/iawia002/annie/config" | ||
) | ||
|
||
func TestShouldExtract(t *testing.T) { | ||
type args struct { | ||
format string | ||
bestQuality string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want bool | ||
infoOnly bool | ||
extractedData bool | ||
format string | ||
}{ | ||
{ | ||
name: "InfoOnly test", | ||
args: args{ | ||
format: "1", | ||
bestQuality: "2", | ||
}, | ||
want: true, | ||
infoOnly: true, | ||
}, | ||
{ | ||
name: "ExtractedData test", | ||
args: args{ | ||
format: "1", | ||
bestQuality: "2", | ||
}, | ||
want: true, | ||
extractedData: true, | ||
}, | ||
{ | ||
name: "Format test", | ||
args: args{ | ||
format: "bd", | ||
bestQuality: "bd2", | ||
}, | ||
want: true, | ||
format: "bd", | ||
}, | ||
{ | ||
name: "Format test2", | ||
args: args{ | ||
format: "bd2", | ||
bestQuality: "bd2", | ||
}, | ||
want: false, | ||
format: "bd", | ||
}, | ||
{ | ||
name: "bestQuality test", | ||
args: args{ | ||
format: "bd2", | ||
bestQuality: "bd2", | ||
}, | ||
want: true, | ||
}, | ||
{ | ||
name: "bestQuality test2", | ||
args: args{ | ||
format: "bd", | ||
bestQuality: "bd2", | ||
}, | ||
want: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
config.ExtractedData = tt.extractedData | ||
config.InfoOnly = tt.infoOnly | ||
config.Format = tt.format | ||
if got := ShouldExtract(tt.args.format, tt.args.bestQuality); got != tt.want { | ||
t.Errorf("ShouldExtract() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestNeedDownloadList(t *testing.T) { | ||
type args struct { | ||
len int | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want int | ||
start int | ||
end int | ||
items string | ||
}{ | ||
{ | ||
name: "start end test 1", | ||
args: args{ | ||
len: 3, | ||
}, | ||
start: 2, | ||
end: 2, | ||
want: 2, | ||
}, | ||
{ | ||
name: "start end test 2", | ||
args: args{ | ||
len: 3, | ||
}, | ||
end: 2, | ||
want: 1, | ||
}, | ||
{ | ||
name: "start end test 3", | ||
args: args{ | ||
len: 3, | ||
}, | ||
start: 2, | ||
end: 0, | ||
want: 2, | ||
}, | ||
{ | ||
name: "start end test 4", | ||
args: args{ | ||
len: 3, | ||
}, | ||
start: 2, | ||
end: 1, | ||
want: 2, | ||
}, | ||
{ | ||
name: "items test", | ||
args: args{ | ||
len: 3, | ||
}, | ||
items: "1, 3", | ||
want: 1, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
config.PlaylistStart = tt.start | ||
config.PlaylistEnd = tt.end | ||
config.PlaylistItems = tt.items | ||
if got := NeedDownloadList(tt.args.len); got[0] != tt.want { | ||
t.Errorf("NeedDownloadList() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.