added compile to fetch
This commit is contained in:
		| @@ -46,6 +46,7 @@ func compileSourceType(source data.Source) (data.Source, error) { | ||||
| 	for _, st := range nameSourceType { | ||||
| 		if m := st.Regex.FindString(source.Url); m != "" { | ||||
| 			source.Url = m | ||||
| 			source.SourceType = &st | ||||
| 			return source, nil | ||||
| 		} | ||||
| 	} | ||||
| @@ -84,22 +85,6 @@ func compileSource(source data.Source) (data.Source, error) { | ||||
| 	return source, errors.New("couldn't find corresponding object source on " + sourceType.Name + " for " + source.Url) | ||||
| } | ||||
|  | ||||
| func dedupeSources(sources []data.Source) []data.Source { | ||||
| 	urls := map[string]interface{}{} | ||||
| 	deduped := []data.Source{} | ||||
|  | ||||
| 	for _, raw := range sources { | ||||
| 		parsed, _ := compileSource(raw) | ||||
|  | ||||
| 		if _, u := urls[parsed.Url]; !u { | ||||
| 			urls[parsed.Url] = true | ||||
| 			deduped = append(deduped, parsed) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return deduped | ||||
| } | ||||
|  | ||||
| func Fetch(source data.Source) (data.MusicObject, error) { | ||||
| 	// the fetch function without the post processing of the music objects | ||||
| 	source, err := compileSource(source) | ||||
| @@ -118,7 +103,8 @@ func Fetch(source data.Source) (data.MusicObject, error) { | ||||
| 		if err != nil { | ||||
| 			return song, err | ||||
| 		} | ||||
| 		song.Sources = dedupeSources(append(song.Sources, source)) | ||||
| 		song.Sources = append(song.Sources, source) | ||||
| 		song = song.Compile().(data.Song) | ||||
| 		return song, nil | ||||
| 	} | ||||
|  | ||||
| @@ -128,7 +114,8 @@ func Fetch(source data.Source) (data.MusicObject, error) { | ||||
| 		if err != nil { | ||||
| 			return album, err | ||||
| 		} | ||||
| 		album.Sources = dedupeSources(append(album.Sources, source)) | ||||
| 		album.Sources = append(album.Sources, source) | ||||
| 		album = album.Compile().(data.Album) | ||||
| 		return album, nil | ||||
| 	} | ||||
|  | ||||
| @@ -138,7 +125,8 @@ func Fetch(source data.Source) (data.MusicObject, error) { | ||||
| 		if err != nil { | ||||
| 			return artist, err | ||||
| 		} | ||||
| 		artist.Sources = dedupeSources(append(artist.Sources, source)) | ||||
| 		artist.Sources = append(artist.Sources, source) | ||||
| 		artist = artist.Compile().(data.Artist) | ||||
| 		return artist, nil | ||||
| 	} | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user