fix: panic when the resp data of resp is empty

pull/4/head
WorldObservationLog 7 months ago
parent 3743e8f2b6
commit cb7cff18c2
  1. 8
      main.go
  2. 6
      main_atmos.go
  3. 8
      main_select.go

@ -1013,7 +1013,11 @@ func getSongLyrics(songId string, storefront string, token string, userToken str
defer do.Body.Close() defer do.Body.Close()
obj := new(SongLyrics) obj := new(SongLyrics)
err = json.NewDecoder(do.Body).Decode(&obj) err = json.NewDecoder(do.Body).Decode(&obj)
return obj.Data[0].Attributes.Ttml, nil if obj.Data != nil {
return obj.Data[0].Attributes.Ttml, nil
} else {
return "", errors.New("failed to get lyrics")
}
} }
func writeCover(sanAlbumFolder, url string) error { func writeCover(sanAlbumFolder, url string) error {
@ -1159,7 +1163,7 @@ func rip(albumId string, token string, storefront string, userToken string) erro
fmt.Sprintf("cover=%s/cover.jpg", sanAlbumFolder), fmt.Sprintf("cover=%s/cover.jpg", sanAlbumFolder),
} }
tagsString := strings.Join(tags, ":") tagsString := strings.Join(tags, ":")
cmd := exec.Command("MP4Box","-itags", tagsString, trackPath) cmd := exec.Command("MP4Box", "-itags", tagsString, trackPath)
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {
fmt.Printf("Embed failed: %v\n", err) fmt.Printf("Embed failed: %v\n", err)
continue continue

@ -1019,7 +1019,11 @@ func getSongLyrics(songId string, storefront string, token string, userToken str
defer do.Body.Close() defer do.Body.Close()
obj := new(SongLyrics) obj := new(SongLyrics)
err = json.NewDecoder(do.Body).Decode(&obj) err = json.NewDecoder(do.Body).Decode(&obj)
return obj.Data[0].Attributes.Ttml, nil if obj.Data != nil {
return obj.Data[0].Attributes.Ttml, nil
} else {
return "", errors.New("failed to get lyrics")
}
} }
func writeCover(sanAlbumFolder, url string) error { func writeCover(sanAlbumFolder, url string) error {

@ -1012,7 +1012,11 @@ func getSongLyrics(songId string, storefront string, token string, userToken str
defer do.Body.Close() defer do.Body.Close()
obj := new(SongLyrics) obj := new(SongLyrics)
err = json.NewDecoder(do.Body).Decode(&obj) err = json.NewDecoder(do.Body).Decode(&obj)
return obj.Data[0].Attributes.Ttml, nil if obj.Data != nil {
return obj.Data[0].Attributes.Ttml, nil
} else {
return "", errors.New("failed to get lyrics")
}
} }
func writeCover(sanAlbumFolder, url string) error { func writeCover(sanAlbumFolder, url string) error {
@ -1194,7 +1198,7 @@ func rip(albumId string, token string, storefront string, userToken string) erro
fmt.Sprintf("cover=%s/cover.jpg", sanAlbumFolder), fmt.Sprintf("cover=%s/cover.jpg", sanAlbumFolder),
} }
tagsString := strings.Join(tags, ":") tagsString := strings.Join(tags, ":")
cmd := exec.Command("MP4Box","-itags", tagsString, trackPath) cmd := exec.Command("MP4Box", "-itags", tagsString, trackPath)
if err := cmd.Run(); err != nil { if err := cmd.Run(); err != nil {
fmt.Printf("Embed failed: %v\n", err) fmt.Printf("Embed failed: %v\n", err)
continue continue

Loading…
Cancel
Save