From a00b861fa2d3c0d6f5545dc97428c894891a1872 Mon Sep 17 00:00:00 2001 From: mahan Date: Wed, 23 Aug 2023 11:41:45 +0330 Subject: [PATCH] Refactor main.go to require only Spotify URL Streamline the user input process to require only Spotify URLs instead of a track name or URL. Removed the flexibility of inputting a track name as it leads to confusion and uncertainty about the input format. This change simplifies the user interaction with the application and it ensures that the correct format (Spotify URL) is always used, reducing the chance of error. Error messages and usage template are also updated accordingly to reflect this change. --- main.go | 48 ++++++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/main.go b/main.go index 3b9d89e..5a00479 100644 --- a/main.go +++ b/main.go @@ -33,11 +33,10 @@ func main() { os.Exit(0) } - isSpotifyUrl := true spotifyURL = args[0] if len(spotifyURL) == 0 { - fmt.Println("=> Spotify URL Or Trak Name required.") + fmt.Println("=> Spotify URL required.") _ = cmd.Help() return } @@ -45,40 +44,33 @@ func main() { splitURL := strings.Split(spotifyURL, "/") if len(splitURL) < 2 { - isSpotifyUrl = false - //fmt.Println("=> Please enter the url copied from the spotify client.") - //os.Exit(1) + fmt.Println("=> Please enter the url copied from the spotify client.") + os.Exit(1) } - if isSpotifyUrl { - spotifyID := splitURL[len(splitURL)-1] - if strings.Contains(spotifyID, "?") { - spotifyID = strings.Split(spotifyID, "?")[0] - } - - if strings.Contains(spotifyURL, "album") { - albumID = spotifyID - mdspotifydl.DownloadAlbum(ctx, albumID) - } else if strings.Contains(spotifyURL, "playlist") { - playlistID = spotifyID - mdspotifydl.DownloadPlaylist(ctx, playlistID) - } else if strings.Contains(spotifyURL, "track") { - trackID = spotifyID - mdspotifydl.DownloadSong(ctx, trackID) - } else { - fmt.Println("=> Only Spotify Album/Playlist/Track URL's are supported.") - _ = cmd.Help() - } + spotifyID := splitURL[len(splitURL)-1] + if strings.Contains(spotifyID, "?") { + spotifyID = strings.Split(spotifyID, "?")[0] } - if !isSpotifyUrl { - fmt.Println("=> Start searching in spotify for " + spotifyURL + " ...") - os.Exit(1) + if strings.Contains(spotifyURL, "album") { + albumID = spotifyID + mdspotifydl.DownloadAlbum(ctx, albumID) + } else if strings.Contains(spotifyURL, "playlist") { + playlistID = spotifyID + mdspotifydl.DownloadPlaylist(ctx, playlistID) + } else if strings.Contains(spotifyURL, "track") { + trackID = spotifyID + mdspotifydl.DownloadSong(ctx, trackID) + } else { + fmt.Println("=> Only Spotify Album/Playlist/Track URL's are supported.") + _ = cmd.Help() } + }, } - rootCmd.SetUsageTemplate(fmt.Sprintf("%s [spotify_url or track name] \n", mdspotifydl.AppUse)) + rootCmd.SetUsageTemplate(fmt.Sprintf("%s [spotify_url] \n", mdspotifydl.AppUse)) if err := rootCmd.Execute(); err != nil { fmt.Println(err)