Skip to content

Commit

Permalink
Refactor main.go to require only Spotify URL
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mdpe-ir committed Aug 23, 2023
1 parent 756cbc8 commit a00b861
Showing 1 changed file with 20 additions and 28 deletions.
48 changes: 20 additions & 28 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,52 +33,44 @@ 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
}

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)
Expand Down

0 comments on commit a00b861

Please sign in to comment.