This repository has been archived by the owner on Apr 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
80 lines (75 loc) · 1.74 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"bufio"
"fmt"
"github.com/zou2699/music-sd/pkg/netease"
"github.com/zou2699/music-sd/pkg/qq"
"log"
"os"
"strconv"
"strings"
"sync"
)
func main() {
for {
var name string
fmt.Println("请输入要搜索的歌曲,名称和歌手一起输入可以提高匹配(如 海阔天空 Beyond): ")
fmt.Scanln(&name)
//name = "海阔天空"
if name == "" {
continue
}
if name == "exit" {
os.Exit(0)
}
fmt.Println("开始搜索...")
musicList := netease.Search(name)
musicList = append(musicList, qq.Search(name)...)
for id, music := range musicList {
fmt.Printf("[%2d] %7s | %s %5sMB - %s - %s - %s\n", id, music.Source, music.Duration, music.Size, music.Title, music.Singer, music.Album)
}
fmt.Println("请输入要下载的歌曲序号, 多个序号用空格隔开: ")
inputReader := bufio.NewReader(os.Stdin)
input, err := inputReader.ReadString('\n')
if err != nil {
fmt.Println(err)
fmt.Printf("输入序号错误\n\n")
continue
}
//fmt.Println("src ", input)
ids := strings.Fields(input)
//_, err = fmt.Scanln(&ids)
//if err != nil {
// fmt.Println(err)
// fmt.Printf("输入序号错误\n\n")
// continue
//}
var wg sync.WaitGroup
for _, id := range ids {
i, err := strconv.Atoi(id)
if err != nil {
log.Panic(err)
}
if i > len(musicList)-1 {
fmt.Printf("输入序号 %d 过大,应小于 %d \n", i, len(musicList))
continue
}
music := musicList[i]
if music.Source == "QQ" {
wg.Add(1)
go func() {
qq.Download(music)
wg.Done()
}()
} else if music.Source == "NETEASE" {
wg.Add(1)
go func() {
netease.Download(music)
wg.Done()
}()
}
}
wg.Wait()
fmt.Printf("#########Done##########\n\n")
}
}