Compare commits
2 Commits
ee4d476b44
...
acce599f2d
Author | SHA1 | Date | |
---|---|---|---|
|
acce599f2d | ||
|
be16925ab4 |
@ -12,20 +12,6 @@ type SourceType struct {
|
||||
RegexSong *regexp.Regexp
|
||||
}
|
||||
|
||||
var SourceTypes = []SourceType{
|
||||
{Name: "Youtube", Regex: regexp.MustCompile(`(?i)\b(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})\b`)},
|
||||
{Name: "Musify", Regex: regexp.MustCompile(`(?i)https?://musify\.club/(artist|track|release)/[a-z\-0-9]+`)},
|
||||
}
|
||||
|
||||
func GetSourceType(name string) *SourceType {
|
||||
for i, st := range SourceTypes {
|
||||
if st.Name == name {
|
||||
return &SourceTypes[i]
|
||||
}
|
||||
}
|
||||
panic("couldn't find source type for " + name)
|
||||
}
|
||||
|
||||
type ObjectType string
|
||||
|
||||
const SongSource = ObjectType("song")
|
||||
|
@ -1,68 +0,0 @@
|
||||
package data
|
||||
|
||||
/*
|
||||
func TestYouTube(t *testing.T) {
|
||||
validUrls := []string{
|
||||
"https://www.youtube.com/watch?v=dQw4w9WgXcQ",
|
||||
"http://youtube.com/watch?v=dQw4w9WgXcQ",
|
||||
"https://youtu.be/dQw4w9WgXcQ",
|
||||
"www.youtube.com/watch?v=dQw4w9WgXcQ",
|
||||
"youtube.com/watch?v=dQw4w9WgXcQ",
|
||||
"youtu.be/dQw4w9WgXcQ",
|
||||
"https://www.youtube.com/embed/dQw4w9WgXcQ",
|
||||
"https://www.youtube.com/v/dQw4w9WgXcQ",
|
||||
"https://www.youtube.com/watch?feature=player_embedded&v=dQw4w9WgXcQ",
|
||||
"https://m.youtube.com/watch?v=dQw4w9WgXcQ",
|
||||
}
|
||||
invalidUrls := []string{
|
||||
"invalid.url",
|
||||
"https://example.com/notyoutube",
|
||||
}
|
||||
|
||||
st := GetSourceType("Youtube")
|
||||
|
||||
for _, u := range validUrls {
|
||||
_, err := st.NewSource(u)
|
||||
if err != nil {
|
||||
t.Errorf(`%q is a valid YouTube url`, u)
|
||||
}
|
||||
}
|
||||
|
||||
for _, u := range invalidUrls {
|
||||
_, err := st.NewSource(u)
|
||||
if err == nil {
|
||||
t.Errorf(`%q is an invalid YouTube url`, u)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestMusify(t *testing.T) {
|
||||
validUrls := []string{
|
||||
"https://musify.club/artist/plohoyparen-645023",
|
||||
"https://musify.club/track/plohoyparen-obgon-dve-sploshnie-poh-voobshe-9769231",
|
||||
"https://musify.club/release/plohoyparen-hello-my-name-2018-1029885",
|
||||
"https://musify.clUb/Release/plohoyParen-hello-my-name-2018-1029885",
|
||||
}
|
||||
invalidUrls := []string{
|
||||
"https://musify.club/",
|
||||
"https://musify.club/not-data-type",
|
||||
"https://m.youtube.com/watch?v=dQw4w9WgXcQ",
|
||||
}
|
||||
|
||||
st := GetSourceType("Musify")
|
||||
|
||||
for _, u := range validUrls {
|
||||
_, err := st.NewSource(u)
|
||||
if err != nil {
|
||||
t.Errorf(`%q is a valid musify url`, u)
|
||||
}
|
||||
}
|
||||
|
||||
for _, u := range invalidUrls {
|
||||
_, err := st.NewSource(u)
|
||||
if err == nil {
|
||||
t.Errorf(`%q is an invalid musify url`, u)
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
46
internal/plugin/youtube.go
Normal file
46
internal/plugin/youtube.go
Normal file
@ -0,0 +1,46 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
|
||||
"gitea.elara.ws/Hazel/music-kraken/internal/data"
|
||||
)
|
||||
|
||||
type Youtube struct {
|
||||
}
|
||||
|
||||
func (m Youtube) Name() string {
|
||||
return "Youtube"
|
||||
}
|
||||
|
||||
func (m Youtube) Regex() *regexp.Regexp {
|
||||
return regexp.MustCompile(`(?i)\b(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})\b`)
|
||||
}
|
||||
|
||||
func (m Youtube) RegexAlbum() *regexp.Regexp {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
func (m Youtube) RegexArtist() *regexp.Regexp {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
func (m Youtube) RegexSong() *regexp.Regexp {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
func (m Youtube) FetchAlbum(source data.Source) (data.Album, error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
func (m Youtube) FetchArtist(source data.Source) (data.Artist, error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
func (m Youtube) FetchSong(source data.Source) (data.Song, error) {
|
||||
panic("unimplemented")
|
||||
}
|
||||
|
||||
func (m Youtube) Search(query string) ([]data.MusicObject, error) {
|
||||
panic("unimplemented")
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user