@@ -20,16 +20,26 @@ func main() {
2020 var albumID int
2121 if result , err := broadcast .Search (keyword ); err != nil {
2222 panic (err )
23+ } else if len (result .Data .AlbumViews .Albums ) == 0 {
24+ fmt .Println ("not found any albums by keyword:" , keyword )
25+ return
2326 } else {
24- if len (result .Data .AlbumViews .Albums ) > 0 {
25- album := result .Data .AlbumViews .Albums [0 ].AlbumInfo
26- albumID = album .ID
27+ albumTitle := make ([]string , 0 )
28+ albumMap := make (map [string ]int , 0 )
29+ for _ , v := range result .Data .AlbumViews .Albums {
30+ albumTitle = append (albumTitle , v .AlbumInfo .Title )
31+ albumMap [v .AlbumInfo .Title ] = v .AlbumInfo .ID
32+ }
2733
28- fmt .Println ("find album" , album .Title )
29- } else {
30- fmt .Println ("not found any albums by keyword:" , keyword )
34+ selector := & survey.Select {
35+ Message : "Select a album" ,
36+ Options : albumTitle ,
37+ }
38+ var choose string
39+ if err = survey .AskOne (selector , & choose ); err != nil {
3140 return
3241 }
42+ albumID = albumMap [choose ]
3343 }
3444
3545 tracks , err := broadcast .GetTrackList (albumID , 1 , false )
@@ -54,15 +64,6 @@ func main() {
5464 fmt .Println ("start to play" , choose )
5565 trackInfo := trackMap [choose ]
5666 play (trackInfo )
57-
58- //if resp, err := http.Get(playURL); err != nil {
59- // fmt.Println(err)
60- //} else {
61- // data, _ := io.ReadAll(resp.Body)
62- // buffer := bytes.NewReader(data)
63- //
64- // play(playio.SeekerWithoutCloser(buffer))
65- //}
6667 }
6768}
6869
0 commit comments