Compare commits
3 Commits
e9d1d20c63
...
e79e364ff9
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e79e364ff9 | ||
|
|
6bd957b09e | ||
|
|
4eab2bb874 |
@@ -100,16 +100,12 @@ func interpretCommand(command string, store musicObjectStore) (musicObjectStore,
|
|||||||
|
|
||||||
current := currentMusicObjects[index]
|
current := currentMusicObjects[index]
|
||||||
|
|
||||||
if len(current.GetSources()) <= 0 {
|
fetched, err := plugin.Fetch(current)
|
||||||
return store, errors.New("selected object has no sources to download")
|
|
||||||
}
|
|
||||||
|
|
||||||
currentMusicObjects, err = plugin.FetchList(current.GetSources()[0])
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return store, err
|
return store, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return append(store, currentMusicObjects), nil
|
return append(store, fetched.Related()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// search in every other case
|
// search in every other case
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ type MusicObject interface {
|
|||||||
Compile() MusicObject
|
Compile() MusicObject
|
||||||
GetIndices() []string
|
GetIndices() []string
|
||||||
Merge(other MusicObject) MusicObject
|
Merge(other MusicObject) MusicObject
|
||||||
|
Related() []MusicObject
|
||||||
}
|
}
|
||||||
|
|
||||||
func dedupeMusicObjects[T MusicObject](inputMusicObjects []T) []T {
|
func dedupeMusicObjects[T MusicObject](inputMusicObjects []T) []T {
|
||||||
@@ -71,6 +72,20 @@ type Song struct {
|
|||||||
Sources []Source
|
Sources []Source
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m Song) Related() []MusicObject {
|
||||||
|
res := []MusicObject{}
|
||||||
|
|
||||||
|
for _, a := range m.Artists {
|
||||||
|
res = append(res, a)
|
||||||
|
}
|
||||||
|
if m.Album.Name != "" {
|
||||||
|
res = append(res, m.Album)
|
||||||
|
}
|
||||||
|
|
||||||
|
res = append(res, m)
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
func (m Song) GetSources() []Source {
|
func (m Song) GetSources() []Source {
|
||||||
return m.Sources
|
return m.Sources
|
||||||
}
|
}
|
||||||
@@ -127,6 +142,20 @@ type Album struct {
|
|||||||
Sources []Source
|
Sources []Source
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m Album) Related() []MusicObject {
|
||||||
|
res := []MusicObject{}
|
||||||
|
|
||||||
|
for _, a := range m.Artists {
|
||||||
|
res = append(res, a)
|
||||||
|
}
|
||||||
|
res = append(res, m)
|
||||||
|
for _, a := range m.Songs {
|
||||||
|
res = append(res, a)
|
||||||
|
}
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
func (m Album) GetSources() []Source {
|
func (m Album) GetSources() []Source {
|
||||||
return m.Sources
|
return m.Sources
|
||||||
}
|
}
|
||||||
@@ -183,6 +212,16 @@ type Artist struct {
|
|||||||
Sources []Source
|
Sources []Source
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m Artist) Related() []MusicObject {
|
||||||
|
res := []MusicObject{m}
|
||||||
|
|
||||||
|
for _, a := range m.Albums {
|
||||||
|
res = append(res, a)
|
||||||
|
}
|
||||||
|
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
func (m Artist) GetSources() []Source {
|
func (m Artist) GetSources() []Source {
|
||||||
return m.Sources
|
return m.Sources
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ func compileSource(source data.Source) (data.Source, error) {
|
|||||||
return source, errors.New("couldn't find corresponding object source on " + sourceType.Name + " for " + source.Url)
|
return source, errors.New("couldn't find corresponding object source on " + sourceType.Name + " for " + source.Url)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Fetch(source data.Source) (data.MusicObject, error) {
|
func FetchSource(source data.Source) (data.MusicObject, error) {
|
||||||
// the fetch function without the post processing of the music objects
|
// the fetch function without the post processing of the music objects
|
||||||
source, err := compileSource(source)
|
source, err := compileSource(source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -147,39 +147,23 @@ func Fetch(source data.Source) (data.MusicObject, error) {
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func FetchList(source data.Source) ([]data.MusicObject, error) {
|
func Fetch(musicObject data.MusicObject) (data.MusicObject, error) {
|
||||||
res := []data.MusicObject{}
|
sources := musicObject.GetSources()
|
||||||
|
|
||||||
musicObject, err := Fetch(source)
|
if len(sources) <= 0 {
|
||||||
if err != nil {
|
return musicObject, errors.New("didn't find a source for object")
|
||||||
return res, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if a, ok := musicObject.(data.Song); ok {
|
for _, source := range sources {
|
||||||
for _, ar := range a.Artists {
|
newMusicObject, err := FetchSource(source)
|
||||||
res = append(res, ar)
|
if err != nil {
|
||||||
|
return musicObject, err
|
||||||
}
|
}
|
||||||
if a.Album.Name != "" {
|
|
||||||
res = append(res, a.Album, a)
|
musicObject = musicObject.Merge(newMusicObject)
|
||||||
}
|
|
||||||
} else if a, ok := musicObject.(data.Album); ok {
|
|
||||||
for _, ar := range a.Artists {
|
|
||||||
res = append(res, ar)
|
|
||||||
}
|
|
||||||
res = append(res, a)
|
|
||||||
for _, s := range a.Songs {
|
|
||||||
res = append(res, s)
|
|
||||||
}
|
|
||||||
} else if a, ok := musicObject.(data.Artist); ok {
|
|
||||||
res = append(res, a)
|
|
||||||
for _, al := range a.Albums {
|
|
||||||
res = append(res, al)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
res = append(res, musicObject)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return res, nil
|
return musicObject, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type SearchConfig struct {
|
type SearchConfig struct {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package plugin
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -328,8 +327,6 @@ func (m *Musify) FetchSong(source data.Source) (data.Song, error) {
|
|||||||
return song, errors.New("too many breadcrumbs on page")
|
return song, errors.New("too many breadcrumbs on page")
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("found breadcrumbs")
|
|
||||||
|
|
||||||
if artistAnchor := listPoints.Eq(2).Find("a"); artistAnchor != nil && artistAnchor.Length() > 0 {
|
if artistAnchor := listPoints.Eq(2).Find("a"); artistAnchor != nil && artistAnchor.Length() > 0 {
|
||||||
artist := data.Artist{}
|
artist := data.Artist{}
|
||||||
useArtist := true
|
useArtist := true
|
||||||
@@ -357,8 +354,6 @@ func (m *Musify) FetchSong(source data.Source) (data.Song, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if albumAnchor := listPoints.Eq(3).Find("a"); albumAnchor != nil && albumAnchor.Length() > 0 {
|
if albumAnchor := listPoints.Eq(3).Find("a"); albumAnchor != nil && albumAnchor.Length() > 0 {
|
||||||
fmt.Println("found album")
|
|
||||||
|
|
||||||
if href, exists := albumAnchor.Attr("href"); exists {
|
if href, exists := albumAnchor.Attr("href"); exists {
|
||||||
song.Album.Sources = append(song.Album.Sources, data.Source{
|
song.Album.Sources = append(song.Album.Sources, data.Source{
|
||||||
Url: musifyHost + href,
|
Url: musifyHost + href,
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ func TestRegister(t *testing.T) {
|
|||||||
func TestFetchSong(t *testing.T) {
|
func TestFetchSong(t *testing.T) {
|
||||||
RegisterPlugin(&MusifyTest{})
|
RegisterPlugin(&MusifyTest{})
|
||||||
|
|
||||||
s, err := Fetch(data.Source{
|
s, err := FetchSource(data.Source{
|
||||||
Url: "https://musify.club/track/linkin-park-in-the-end-3058",
|
Url: "https://musify.club/track/linkin-park-in-the-end-3058",
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ func TestFetchSong(t *testing.T) {
|
|||||||
func TestFetchAlbum(t *testing.T) {
|
func TestFetchAlbum(t *testing.T) {
|
||||||
RegisterPlugin(&MusifyTest{})
|
RegisterPlugin(&MusifyTest{})
|
||||||
|
|
||||||
a, err := Fetch(data.Source{
|
a, err := FetchSource(data.Source{
|
||||||
Url: "https://musify.club/release/linkin-park-hybrid-theory-2000-188",
|
Url: "https://musify.club/release/linkin-park-hybrid-theory-2000-188",
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -129,7 +129,7 @@ func TestFetchAlbum(t *testing.T) {
|
|||||||
func TestFetchArtist(t *testing.T) {
|
func TestFetchArtist(t *testing.T) {
|
||||||
RegisterPlugin(&MusifyTest{})
|
RegisterPlugin(&MusifyTest{})
|
||||||
|
|
||||||
a, err := Fetch(data.Source{
|
a, err := FetchSource(data.Source{
|
||||||
Url: "https://musify.club/artist/linkin-park-5",
|
Url: "https://musify.club/artist/linkin-park-5",
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -150,7 +150,7 @@ func TestFetchArtist(t *testing.T) {
|
|||||||
func TestFetchWrongUrl(t *testing.T) {
|
func TestFetchWrongUrl(t *testing.T) {
|
||||||
RegisterPlugin(&MusifyTest{})
|
RegisterPlugin(&MusifyTest{})
|
||||||
|
|
||||||
_, err := Fetch(data.Source{
|
_, err := FetchSource(data.Source{
|
||||||
Url: "https://musify.club/",
|
Url: "https://musify.club/",
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -162,7 +162,7 @@ func TestFetchWrongUrl(t *testing.T) {
|
|||||||
func TestNonExistentSourceType(t *testing.T) {
|
func TestNonExistentSourceType(t *testing.T) {
|
||||||
RegisterPlugin(&MusifyTest{})
|
RegisterPlugin(&MusifyTest{})
|
||||||
|
|
||||||
_, err := Fetch(data.Source{
|
_, err := FetchSource(data.Source{
|
||||||
Url: "https://musify.club/",
|
Url: "https://musify.club/",
|
||||||
SourceType: &data.SourceType{
|
SourceType: &data.SourceType{
|
||||||
Name: "doesn't exist",
|
Name: "doesn't exist",
|
||||||
|
|||||||
Reference in New Issue
Block a user