diff --git a/main.go b/main.go index deccbe1..84a1b7f 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,7 @@ package main import ( "flag" - "github.com/BharatKalluri/spotifydl/src" + "github.com/BharatKalluri/spotifydl/src" ) func main() { diff --git a/src/downloader.go b/src/downloader.go index bf45609..92167a2 100644 --- a/src/downloader.go +++ b/src/downloader.go @@ -1,7 +1,6 @@ package spotifydl import ( - "fmt" "os" "github.com/rylio/ytdl" @@ -9,8 +8,6 @@ import ( // Downloader is a function to download files func Downloader(url string) { - fmt.Println("Download started", url) - vid, _ := ytdl.GetVideoInfo(url) audioTracks := ytdl.FormatList{} diff --git a/src/start.go b/src/start.go index 6cdc2d7..9e6cd48 100644 --- a/src/start.go +++ b/src/start.go @@ -3,6 +3,8 @@ package spotifydl import ( "fmt" + "github.com/gosuri/uiprogress" + "github.com/gosuri/uiprogress/util/strutil" "github.com/zmb3/spotify" ) @@ -15,16 +17,31 @@ func Start(username *string, pid *string) { playlistID := spotify.ID(*pid) trackListJSON, _ := cli.UserClient.GetPlaylistTracks(*username, playlistID) for _, val := range trackListJSON.Tracks { - fmt.Println("Added ", val.Track.Name) cli.TrackList = append(cli.TrackList, val.Track) } + fmt.Println("👍 Found", len(cli.TrackList), "tracks") + fmt.Println("🎵 Searching and downloading tracks") + uiprogress.Start() + bar := uiprogress.AddBar(len(cli.TrackList) - 1) + + bar.AppendCompleted() + bar.PrependFunc(func(b *uiprogress.Bar) string { + return " 🔍 " + strutil.Resize(cli.TrackList[b.Current()].Name, 30) + }) for _, val := range cli.TrackList { cli.YoutubeIDList = append(cli.YoutubeIDList, GetYoutubeIds(string(val.Name)+" "+string(val.Album.Name)+" music video")) + bar.Incr() } - + bar2 := uiprogress.AddBar(len(cli.TrackList) - 1) + bar2.AppendCompleted() + bar2.PrependFunc(func(b *uiprogress.Bar) string { + return " ⬇️ " + strutil.Resize(cli.TrackList[b.Current()].Name, 30) + }) for _, track := range cli.YoutubeIDList { ytURL := "https://www.youtube.com/watch?v=" + track Downloader(ytURL) + bar2.Incr() } + uiprogress.Stop() }