Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix for #341 -- only test for qq, I don't have chance to test other websites. #375

Merged
merged 4 commits into from
Feb 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ var (
OutputName string
// ExtractedData print extracted data
ExtractedData bool
// ChunkSize size of MB
ChunkSizeMB int
// UseAria2RPC Use Aria2 RPC to download
UseAria2RPC bool
// Aria2Token Aria2 RPC Token
Expand Down
12 changes: 6 additions & 6 deletions downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func writeFile(

// Save save url file
func Save(
urlData URL, refer, fileName string, bar *pb.ProgressBar,
urlData URL, refer, fileName string, bar *pb.ProgressBar, chunkSizeMB int,
) error {
var err error
filePath, err := utils.FilePath(fileName, urlData.Ext, false)
Expand Down Expand Up @@ -111,9 +111,9 @@ func Save(
if fileError != nil {
return fileError
}
if strings.Contains(urlData.URL, "googlevideo") {
if strings.Contains(urlData.URL, "googlevideo") || strings.Contains(urlData.URL, "qq.com") {
var start, end, chunkSize int64
chunkSize = 10 * 1024 * 1024
chunkSize = int64(chunkSizeMB) * 1024 * 1024
remainingSize := urlData.Size
if tempFileSize > 0 {
start = tempFileSize
Expand Down Expand Up @@ -169,7 +169,7 @@ func Save(
}

// Download download urls
func Download(v Data, refer string) error {
func Download(v Data, refer string, chunkSizeMB int) error {
v.genSortedStreams()
if config.ExtractedData {
jsonData, _ := json.MarshalIndent(v, "", " ")
Expand Down Expand Up @@ -253,7 +253,7 @@ func Download(v Data, refer string) error {
bar.Start()
if len(data.URLs) == 1 {
// only one fragment
err := Save(data.URLs[0], refer, title, bar)
err := Save(data.URLs[0], refer, title, bar, chunkSizeMB)
if err != nil {
return err
}
Expand All @@ -275,7 +275,7 @@ func Download(v Data, refer string) error {
wgp.Add()
go func(url URL, refer, fileName string, bar *pb.ProgressBar) {
defer wgp.Done()
err := Save(url, refer, fileName, bar)
err := Save(url, refer, fileName, bar, chunkSizeMB)
if err != nil {
errs = append(errs, err)
}
Expand Down
2 changes: 1 addition & 1 deletion downloader/downloader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestDownload(t *testing.T) {
},
}
for _, testCase := range testCases {
err := Download(testCase.data, "")
err := Download(testCase.data, "", 10)
if err != nil {
t.Error(err)
}
Expand Down
7 changes: 4 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func init() {
flag.StringVar(&config.OutputPath, "o", "", "Specify the output path")
flag.StringVar(&config.OutputName, "O", "", "Specify the output file name")
flag.BoolVar(&config.ExtractedData, "j", false, "Print extracted data")
flag.IntVar(&config.ChunkSizeMB, "cs", 5, "Print chunkSize size of MB")
flag.BoolVar(&config.UseAria2RPC, "aria2", false, "Use Aria2 RPC to download")
flag.StringVar(&config.Aria2Token, "aria2token", "", "Aria2 RPC Token")
flag.StringVar(&config.Aria2Addr, "aria2addr", "localhost:6800", "Aria2 Address")
Expand Down Expand Up @@ -84,7 +85,7 @@ func printError(url string, err error) {
)
}

func download(videoURL string) {
func download(videoURL string, chuckSizeMB int) {
var (
domain string
err error
Expand Down Expand Up @@ -160,7 +161,7 @@ func download(videoURL string) {
printError(item.URL, item.Err)
continue
}
err = downloader.Download(item, videoURL)
err = downloader.Download(item, videoURL, chuckSizeMB)
if err != nil {
printError(item.URL, err)
}
Expand Down Expand Up @@ -214,6 +215,6 @@ func main() {
}
}
for _, videoURL := range args {
download(strings.TrimSpace(videoURL))
download(strings.TrimSpace(videoURL), config.ChunkSizeMB)
}
}