Compare commits
2 Commits
82c541653c
...
04e8378f3f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
04e8378f3f | ||
|
|
293de8b473 |
@@ -50,6 +50,9 @@ func printResults(musicObjects []data.MusicObject) {
|
|||||||
if len(sources) > 0 {
|
if len(sources) > 0 {
|
||||||
for _, source := range sources {
|
for _, source := range sources {
|
||||||
results[i] += "\n\t- " + source.SourceType.Name + " " + string(source.ObjectType) + " " + source.Url
|
results[i] += "\n\t- " + source.SourceType.Name + " " + string(source.ObjectType) + " " + source.Url
|
||||||
|
if source.AudioUrl != "" {
|
||||||
|
results[i] += "\n\t " + source.AudioUrl
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
results[i] = color.StrikeThrough + results[i] + color.Reset
|
results[i] = color.StrikeThrough + results[i] + color.Reset
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ func ZeroPad(num int, length int) string {
|
|||||||
|
|
||||||
func IsNumeric(num string) bool {
|
func IsNumeric(num string) bool {
|
||||||
for _, c := range num {
|
for _, c := range num {
|
||||||
if c >= '0' && c <= '9' {
|
if c < '0' || c > '9' {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -280,6 +280,39 @@ func (m *Musify) Search(query common.Query) ([]data.MusicObject, error) {
|
|||||||
return musicObjects, nil
|
return musicObjects, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type parsedSongUrl struct {
|
||||||
|
id string
|
||||||
|
name string
|
||||||
|
url string
|
||||||
|
}
|
||||||
|
|
||||||
|
func newParsedSongUrl(rawUrl string) (parsedSongUrl, error) {
|
||||||
|
res := parsedSongUrl{
|
||||||
|
url: rawUrl,
|
||||||
|
}
|
||||||
|
|
||||||
|
parsed, err := url.Parse(rawUrl)
|
||||||
|
if err != nil {
|
||||||
|
return res, err
|
||||||
|
}
|
||||||
|
|
||||||
|
dirs := strings.Split(parsed.Path, "/")
|
||||||
|
correctPart := dirs[len(dirs)-1]
|
||||||
|
split := strings.Split(correctPart, "-")
|
||||||
|
if len(split) < 2 {
|
||||||
|
return res, errors.New("last part of path has to consist of at least one - " + correctPart)
|
||||||
|
}
|
||||||
|
|
||||||
|
res.id = strings.TrimSpace(split[len(split)-1])
|
||||||
|
res.name = strings.Join(split[:len(split)-1], "-")
|
||||||
|
|
||||||
|
if !common.IsNumeric(res.id) {
|
||||||
|
return res, errors.New("last elem (id) has to be numeric " + res.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (m *Musify) FetchSong(source data.Source) (data.Song, error) {
|
func (m *Musify) FetchSong(source data.Source) (data.Song, error) {
|
||||||
song := data.Song{
|
song := data.Song{
|
||||||
Sources: []data.Source{
|
Sources: []data.Source{
|
||||||
@@ -298,14 +331,19 @@ func (m *Musify) FetchSong(source data.Source) (data.Song, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Download URL
|
// Download URL
|
||||||
/*
|
|
||||||
doc.Find("a[itemprop='audio']").Each(func(i int, anchor *goquery.Selection) {
|
doc.Find("a[itemprop='audio']").Each(func(i int, anchor *goquery.Selection) {
|
||||||
href, exists := anchor.Attr("href")
|
if href, _ := anchor.Attr("href"); true {
|
||||||
if exists {
|
// will be the source first added at the begining
|
||||||
source.AudioURL = p.host + href
|
song.Sources[0].AudioUrl = musifyHost + href
|
||||||
|
} else {
|
||||||
|
// http://musify.club/track/dl/7141298/crystal-f-sekundenschlaf.mp3
|
||||||
|
parsed, err := newParsedSongUrl(song.Sources[0].Url)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
song.Sources[0].AudioUrl = "http://musify.club/track/dl/" + parsed.id + "/" + parsed.name + ".mp3"
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
*/
|
|
||||||
|
|
||||||
// Song detail
|
// Song detail
|
||||||
var listElement *goquery.Selection
|
var listElement *goquery.Selection
|
||||||
|
|||||||
Reference in New Issue
Block a user