From 4c33a0265fdf58db1f0486af126f7f80708b0190 Mon Sep 17 00:00:00 2001 From: objnull Date: Sun, 9 Jun 2024 16:28:38 -0400 Subject: [PATCH] Quality of Life changes --- main.go | 7 ++++++- src/puller.go | 38 +++++++++++++++++++++++--------------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/main.go b/main.go index 509095c..1dca6dc 100644 --- a/main.go +++ b/main.go @@ -32,6 +32,8 @@ func initPages() { // Based on this, what do we do? if usrInput == "1" { page = 1 + } else if usrInput == "2" { + backend.Running = false } }) /// Append page @@ -67,7 +69,7 @@ func initPages() { meta.Init("soundcloud", songURL) // Asking if the song name is correct - fmt.Println("Is your song's name: " + string(backend.CliGreen) + meta.Title + string(backend.CliWhite) + "?") + fmt.Println("Is your song's name: " + string(backend.CliGreen) + meta.Title + string(backend.CliWhite) + " by " + string(backend.CliYellow) + meta.Author + string(backend.CliWhite) + "?") fmt.Print("Select option [y/n]: ") // Scanning if the user likes what is shown @@ -81,6 +83,9 @@ func initPages() { fmt.Println() } + // Downloading the song + meta.Download() + // Switch back to main menu page = 0 }) diff --git a/src/puller.go b/src/puller.go index 4b85d97..8092f32 100644 --- a/src/puller.go +++ b/src/puller.go @@ -20,7 +20,7 @@ type SongMetadata struct { url string Title string - author string + Author string image string download string } @@ -114,20 +114,9 @@ func (s *SongMetadata) pullFromSoundCloud() { // Now we get specific elements like the title of the song: s.Title = strings.Split(htmldoc.GetTextContent(htmldoc.FindByID(htmldoc.doc, "trackTitle", "p")), ".mp3")[0] - s.author = strings.Split(htmldoc.GetTextContent(htmldoc.FindByID(htmldoc.doc, "trackUploader", "p")), "by ")[1] + s.Author = strings.Split(htmldoc.GetTextContent(htmldoc.FindByID(htmldoc.doc, "trackUploader", "p")), "by ")[1] s.download = htmldoc.GetElementAttr(htmldoc.FindByID(htmldoc.doc, "trackLink", "a"), "href") s.image = htmldoc.GetElementAttr(htmldoc.FindByID(htmldoc.doc, "trackThumbnail", "img"), "src") - - // Downloading the song and image - var filer Filer - - if !filer.DownloadFromURL(s.image, ".tmp", s.Title+".jpg") || !filer.DownloadFromURL(s.download, "out", s.Title+".mp3") { - fmt.Println("PULLER: Exiting process...") - return - } - - // Apply Metadata - s.ApplyMetadata() } func (s *SongMetadata) Init(songPlatform string, url string) { @@ -141,16 +130,31 @@ func (s *SongMetadata) Init(songPlatform string, url string) { s.pullFromSoundCloud() } } +func (s *SongMetadata) Download() { + // Downloading the song and image + var filer Filer + + if !filer.DownloadFromURL(s.image, ".tmp", s.Title+".jpg") || !filer.DownloadFromURL(s.download, "out", s.Title+".mp3") { + fmt.Println("PULLER: Exiting process...") + fmt.Println() + fmt.Println("Download " + string(CliRed) + "Failed" + string(CliWhite) + "!") + return + } + + // Apply Metadata + s.ApplyMetadata() +} func (s *SongMetadata) ApplyMetadata() { mp3Path := "out/" + s.Title + ".mp3" imagePath := ".tmp/" + s.Title + ".jpg" title := s.Title - author := s.author + author := s.Author // Open the MP3 file tag, err := id3v2.Open(mp3Path, id3v2.Options{Parse: true}) if err != nil { fmt.Println("PULLER: Error opening MP3 file:", err) + fmt.Println("Download " + string(CliRed) + "Failed" + string(CliWhite) + "!") return } defer tag.Close() @@ -163,6 +167,7 @@ func (s *SongMetadata) ApplyMetadata() { img, err := os.Open(imagePath) if err != nil { fmt.Println("PULLER: Error opening image file:", err) + fmt.Println("Download " + string(CliRed) + "Failed" + string(CliWhite) + "!") return } defer img.Close() @@ -170,6 +175,7 @@ func (s *SongMetadata) ApplyMetadata() { imgInfo, err := img.Stat() if err != nil { fmt.Println("PULLER: Error getting image info:", err) + fmt.Println("Download " + string(CliRed) + "Failed" + string(CliWhite) + "!") return } @@ -177,6 +183,7 @@ func (s *SongMetadata) ApplyMetadata() { _, err = img.Read(imgData) if err != nil { fmt.Println("PULLER: Error reading image data:", err) + fmt.Println("Download " + string(CliRed) + "Failed" + string(CliWhite) + "!") return } @@ -193,8 +200,9 @@ func (s *SongMetadata) ApplyMetadata() { // Save the changes if err = tag.Save(); err != nil { fmt.Println("PULLER: Error saving MP3 file:", err) + fmt.Println("Download " + string(CliRed) + "Failed" + string(CliWhite) + "!") return } - fmt.Println("Successfully downloaded song") + fmt.Println("Download " + string(CliGreen) + "Successful" + string(CliWhite) + "!") }