Quality of Life changes
This commit is contained in:
parent
f2c7ecfef0
commit
4c33a0265f
2 changed files with 29 additions and 16 deletions
7
main.go
7
main.go
|
@ -32,6 +32,8 @@ func initPages() {
|
||||||
// Based on this, what do we do?
|
// Based on this, what do we do?
|
||||||
if usrInput == "1" {
|
if usrInput == "1" {
|
||||||
page = 1
|
page = 1
|
||||||
|
} else if usrInput == "2" {
|
||||||
|
backend.Running = false
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
/// Append page
|
/// Append page
|
||||||
|
@ -67,7 +69,7 @@ func initPages() {
|
||||||
meta.Init("soundcloud", songURL)
|
meta.Init("soundcloud", songURL)
|
||||||
|
|
||||||
// Asking if the song name is correct
|
// 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]: ")
|
fmt.Print("Select option [y/n]: ")
|
||||||
|
|
||||||
// Scanning if the user likes what is shown
|
// Scanning if the user likes what is shown
|
||||||
|
@ -81,6 +83,9 @@ func initPages() {
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Downloading the song
|
||||||
|
meta.Download()
|
||||||
|
|
||||||
// Switch back to main menu
|
// Switch back to main menu
|
||||||
page = 0
|
page = 0
|
||||||
})
|
})
|
||||||
|
|
|
@ -20,7 +20,7 @@ type SongMetadata struct {
|
||||||
url string
|
url string
|
||||||
|
|
||||||
Title string
|
Title string
|
||||||
author string
|
Author string
|
||||||
image string
|
image string
|
||||||
download string
|
download string
|
||||||
}
|
}
|
||||||
|
@ -114,20 +114,9 @@ func (s *SongMetadata) pullFromSoundCloud() {
|
||||||
|
|
||||||
// Now we get specific elements like the title of the song:
|
// 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.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.download = htmldoc.GetElementAttr(htmldoc.FindByID(htmldoc.doc, "trackLink", "a"), "href")
|
||||||
s.image = htmldoc.GetElementAttr(htmldoc.FindByID(htmldoc.doc, "trackThumbnail", "img"), "src")
|
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) {
|
func (s *SongMetadata) Init(songPlatform string, url string) {
|
||||||
|
@ -141,16 +130,31 @@ func (s *SongMetadata) Init(songPlatform string, url string) {
|
||||||
s.pullFromSoundCloud()
|
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() {
|
func (s *SongMetadata) ApplyMetadata() {
|
||||||
mp3Path := "out/" + s.Title + ".mp3"
|
mp3Path := "out/" + s.Title + ".mp3"
|
||||||
imagePath := ".tmp/" + s.Title + ".jpg"
|
imagePath := ".tmp/" + s.Title + ".jpg"
|
||||||
title := s.Title
|
title := s.Title
|
||||||
author := s.author
|
author := s.Author
|
||||||
|
|
||||||
// Open the MP3 file
|
// Open the MP3 file
|
||||||
tag, err := id3v2.Open(mp3Path, id3v2.Options{Parse: true})
|
tag, err := id3v2.Open(mp3Path, id3v2.Options{Parse: true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("PULLER: Error opening MP3 file:", err)
|
fmt.Println("PULLER: Error opening MP3 file:", err)
|
||||||
|
fmt.Println("Download " + string(CliRed) + "Failed" + string(CliWhite) + "!")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer tag.Close()
|
defer tag.Close()
|
||||||
|
@ -163,6 +167,7 @@ func (s *SongMetadata) ApplyMetadata() {
|
||||||
img, err := os.Open(imagePath)
|
img, err := os.Open(imagePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("PULLER: Error opening image file:", err)
|
fmt.Println("PULLER: Error opening image file:", err)
|
||||||
|
fmt.Println("Download " + string(CliRed) + "Failed" + string(CliWhite) + "!")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer img.Close()
|
defer img.Close()
|
||||||
|
@ -170,6 +175,7 @@ func (s *SongMetadata) ApplyMetadata() {
|
||||||
imgInfo, err := img.Stat()
|
imgInfo, err := img.Stat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("PULLER: Error getting image info:", err)
|
fmt.Println("PULLER: Error getting image info:", err)
|
||||||
|
fmt.Println("Download " + string(CliRed) + "Failed" + string(CliWhite) + "!")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,6 +183,7 @@ func (s *SongMetadata) ApplyMetadata() {
|
||||||
_, err = img.Read(imgData)
|
_, err = img.Read(imgData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("PULLER: Error reading image data:", err)
|
fmt.Println("PULLER: Error reading image data:", err)
|
||||||
|
fmt.Println("Download " + string(CliRed) + "Failed" + string(CliWhite) + "!")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,8 +200,9 @@ func (s *SongMetadata) ApplyMetadata() {
|
||||||
// Save the changes
|
// Save the changes
|
||||||
if err = tag.Save(); err != nil {
|
if err = tag.Save(); err != nil {
|
||||||
fmt.Println("PULLER: Error saving MP3 file:", err)
|
fmt.Println("PULLER: Error saving MP3 file:", err)
|
||||||
|
fmt.Println("Download " + string(CliRed) + "Failed" + string(CliWhite) + "!")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Successfully downloaded song")
|
fmt.Println("Download " + string(CliGreen) + "Successful" + string(CliWhite) + "!")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue