Closed nourserry closed 3 years ago
Hey @nourserry thanks for opening this issue. I've actually been meaning to fix the file name parsing but haven't gotten around to it. There is currently no sanitization for special characters which means the filename won't parse properly and cause the error "open file failed". I have made a quick fix which doesn't really solve all edge cases but will solve this for your specific problem. If you want to write some tests and solve more edge cases and contribute go look at the file title.go in the soundcloud package. I'm going to keep this issue open for anyone else who comes across more edge cases with file name parsing.
// GetTitle returns title of the song
// TODO: implement tests
func GetTitle(data []byte) string {
var title string
r := bytes.NewReader(data)
doc, err := goquery.NewDocumentFromReader(r)
if err != nil {
panic(err)
}
// the title of the song can be found in the meta tag from initial response
doc.Find("meta[property='twitter:title']").Each(func(i int, s *goquery.Selection) {
// get the data from found element's content attribute
data, exists := s.Attr("content")
if exists {
title = data
}
})
title = strings.ReplaceAll(title, "/", "")
fmt.Println(title)
return title
}
Hi Thanks for the quick fix, I add fixes for other character that may cause errors on Windows. I'm no coder, so this is probably not the best way to write it, but I tested it on Linux and it worked.
Closing since you have tested on other other operating systems.
Reference: PR #3
Ran into this when I tried to download a track Probably due to the / symbol.