我正在尝试创建一个YouTube到mp3项目。该项目会提示用户输入youtube视频网址,如下:
HTML
package main
import (
"fmt"
"runtime"
"sync"
)
var wg sync.WaitGroup
func main() {
ch := make(chan int, 10)
for i := 0; i < 10; i++ { // creates 10 go routines and adds to waitgroup
wg.Add(1)
go func() {
for j := 0; j < 10; j++ {
ch <- j
}
wg.Done() // indication of go routine is done to main routine
}()
}
go func(){
wg.Wait()
close(ch)
}()
fmt.Println(runtime.NumGoroutine())
for v := range ch { // range can be used since channel is closed
fmt.Println(v)
}
fmt.Println("About to exit program ...")
}
用于下载mp3歌曲的视图
<form method="POST" action="/download/">
{% csrf_token %}
<input placeholder="Please Enter Url" name="yturl" />
<button type="submit" >Download</button>
</form>
查看代码工作正常,当前歌曲已下载到我的项目文件夹中。现在,我将不指定要保存歌曲的用户下载文件夹路径,即,将文件保存在用户下载文件夹而不是项目文件夹中。