implemented fetch call
This commit is contained in:
@@ -65,6 +65,7 @@ func Shell() {
|
|||||||
fmt.Println("== MusicKraken Shell ==")
|
fmt.Println("== MusicKraken Shell ==")
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
|
||||||
|
currentMusicObjects := []data.MusicObject{}
|
||||||
for {
|
for {
|
||||||
fmt.Print("> ")
|
fmt.Print("> ")
|
||||||
|
|
||||||
@@ -75,13 +76,35 @@ func Shell() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
searchResults, err := plugin.Search(line, plugin.SearchConfig{IgnoreErrors: false})
|
line = strings.TrimSpace(line)
|
||||||
|
|
||||||
|
if index, err := strconv.Atoi(line); err == nil {
|
||||||
|
if index >= len(currentMusicObjects) {
|
||||||
|
fmt.Println("\n" + line + " is out of bounds")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
current := currentMusicObjects[index]
|
||||||
|
|
||||||
|
if len(current.GetSources()) <= 0 {
|
||||||
|
fmt.Println("\nselected has no sources to download")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
currentMusicObjects, err = plugin.FetchList(current.GetSources()[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
currentMusicObjects, err = plugin.Search(line, plugin.SearchConfig{IgnoreErrors: false})
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
printResults(searchResults)
|
printResults(currentMusicObjects)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -147,6 +147,41 @@ func Fetch(source data.Source) (data.MusicObject, error) {
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func FetchList(source data.Source) ([]data.MusicObject, error) {
|
||||||
|
res := []data.MusicObject{}
|
||||||
|
|
||||||
|
musicObject, err := Fetch(source)
|
||||||
|
if err != nil {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if a, ok := musicObject.(data.Song); ok {
|
||||||
|
for _, ar := range a.Artists {
|
||||||
|
res = append(res, ar)
|
||||||
|
}
|
||||||
|
if a.Album.Name != "" {
|
||||||
|
res = append(res, a.Album, a)
|
||||||
|
}
|
||||||
|
} else if a, ok := musicObject.(data.Album); ok {
|
||||||
|
for _, ar := range a.Artists {
|
||||||
|
res = append(res, ar)
|
||||||
|
}
|
||||||
|
res = append(res, a)
|
||||||
|
for _, s := range a.Songs {
|
||||||
|
res = append(res, s)
|
||||||
|
}
|
||||||
|
} else if a, ok := musicObject.(data.Artist); ok {
|
||||||
|
res = append(res, a)
|
||||||
|
for _, al := range a.Albums {
|
||||||
|
res = append(res, al)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
res = append(res, musicObject)
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
type SearchConfig struct {
|
type SearchConfig struct {
|
||||||
IgnoreErrors bool
|
IgnoreErrors bool
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user