Skip to content

Commit

Permalink
extractors/geekbang: optimization code
Browse files Browse the repository at this point in the history
  • Loading branch information
weiyongsheng committed Jun 3, 2019
1 parent 40b187a commit adf5202
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
15 changes: 5 additions & 10 deletions extractors/geekbang/geekbang.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type geekURLInfo struct {
Size int64
}

func geekM3u8(url string, totalSize int64) ([]geekURLInfo, int64, error) {
func geekM3u8(url string) ([]geekURLInfo, error) {
var (
data []geekURLInfo
temp geekURLInfo
Expand All @@ -40,21 +40,16 @@ func geekM3u8(url string, totalSize int64) ([]geekURLInfo, int64, error) {
)
urls, err := utils.M3u8URLs(url)
if err != nil {
return nil, 0, err
return nil, err
}
for _, u := range urls {
size = 0
// size, err = request.Size(u, url)
// if err != nil {
// return nil, 0, err
// }
temp = geekURLInfo{
URL: u,
Size: size,
}
data = append(data, temp)
}
return data, totalSize, nil
return data, nil
}

// Extract is the main function for extracting data
Expand Down Expand Up @@ -90,7 +85,7 @@ func Extract(url string) ([]downloader.Data, error) {
streams := make(map[string]downloader.Stream, len(geekData.Data.VideoMediaMap))

for key, media := range geekData.Data.VideoMediaMap {
m3u8URLs, totalSize, err := geekM3u8(media.URL, media.Size)
m3u8URLs, err := geekM3u8(media.URL)

if err != nil {
return downloader.EmptyList, err
Expand All @@ -107,7 +102,7 @@ func Extract(url string) ([]downloader.Data, error) {

streams[key] = downloader.Stream{
URLs: urls,
Size: totalSize,
Size: media.Size,
}
}

Expand Down
2 changes: 1 addition & 1 deletion extractors/geekbang/geekbang_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestDownload(t *testing.T) {
args: test.Args{
URL: "https://time.geekbang.org/course/detail/190-97203",
Title: "02 | 内容综述 - 玩转webpack",
Size: 38193140,
Size: 38556544,
},
},
}
Expand Down

0 comments on commit adf5202

Please sign in to comment.