Fixing build issues
This commit is contained in:
parent
57e3c50e04
commit
eb454af34f
|
@ -25,6 +25,15 @@ import (
|
||||||
"github.com/layeh/gumble/gumble_ffmpeg"
|
"github.com/layeh/gumble/gumble_ffmpeg"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var youtubePlaylistPattern = `https?:\/\/www\.youtube\.com\/playlist\?list=([\w-]+)`
|
||||||
|
var youtubeVideoPatterns = []string{
|
||||||
|
`https?:\/\/www\.youtube\.com\/watch\?v=([\w-]+)(\&t=\d*m?\d*s?)?`,
|
||||||
|
`https?:\/\/youtube\.com\/watch\?v=([\w-]+)(\&t=\d*m?\d*s?)?`,
|
||||||
|
`https?:\/\/youtu.be\/([\w-]+)(\?t=\d*m?\d*s?)?`,
|
||||||
|
`https?:\/\/youtube.com\/v\/([\w-]+)(\?t=\d*m?\d*s?)?`,
|
||||||
|
`https?:\/\/www.youtube.com\/v\/([\w-]+)(\?t=\d*m?\d*s?)?`,
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------
|
// ---------------
|
||||||
// YOUTUBE SERVICE
|
// YOUTUBE SERVICE
|
||||||
// ---------------
|
// ---------------
|
||||||
|
@ -39,43 +48,34 @@ func (y YouTube) ServiceName() string {
|
||||||
|
|
||||||
// Checks to see if service will accept URL
|
// Checks to see if service will accept URL
|
||||||
func (y YouTube) URLRegex(url string) bool {
|
func (y YouTube) URLRegex(url string) bool {
|
||||||
youtubePatterns := []string{
|
return RegexpFromURL(url, append(youtubeVideoPatterns, []string{youtubePlaylistPattern}...)) != nil
|
||||||
`https?:\/\/www\.youtube\.com\/watch\?v=([\w-]+)(\&t=\d*m?\d*s?)?`,
|
|
||||||
`https?:\/\/youtube\.com\/watch\?v=([\w-]+)(\&t=\d*m?\d*s?)?`,
|
|
||||||
`https?:\/\/youtu.be\/([\w-]+)(\?t=\d*m?\d*s?)?`,
|
|
||||||
`https?:\/\/youtube.com\/v\/([\w-]+)(\?t=\d*m?\d*s?)?`,
|
|
||||||
`https?:\/\/www.youtube.com\/v\/([\w-]+)(\?t=\d*m?\d*s?)?`,
|
|
||||||
`https?:\/\/www\.youtube\.com\/playlist\?list=([\w-]+)`,
|
|
||||||
}
|
}
|
||||||
matchFound := false
|
|
||||||
|
|
||||||
for _, pattern := range youtubePatterns {
|
func RegexpFromURL(url string, patterns []string) *regexp.Regexp {
|
||||||
|
for _, pattern := range patterns {
|
||||||
if re, err := regexp.Compile(pattern); err == nil {
|
if re, err := regexp.Compile(pattern); err == nil {
|
||||||
if re.MatchString(url) {
|
if re.MatchString(url) {
|
||||||
matchFound = true
|
return re
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
return matchFound
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates the requested song/playlist and adds to the queue
|
// Creates the requested song/playlist and adds to the queue
|
||||||
func (y YouTube) NewRequest(user *gumble.User, url string) error {
|
func (y YouTube) NewRequest(user *gumble.User, url string) error {
|
||||||
shortURL := ""
|
var shortURL, startOffset = ""
|
||||||
startOffset := ""
|
|
||||||
youtubePlaylistPattern := `https?:\/\/www\.youtube\.com\/playlist\?list=([\w-]+)`
|
|
||||||
|
|
||||||
if re, err := regexp.Compile(youtubePlaylistPattern); err == nil {
|
if re, err := regexp.Compile(youtubePlaylistPattern); err == nil {
|
||||||
if re.MatchString(url) {
|
if re.MatchString(url) {
|
||||||
if dj.HasPermission(user.Name, dj.conf.Permissions.AdminAddPlaylists) {
|
if dj.HasPermission(user.Name, dj.conf.Permissions.AdminAddPlaylists) {
|
||||||
shortURL = re.FindStringSubmatch(url)[1]
|
shortURL = re.FindStringSubmatch(url)[1]
|
||||||
NewYouTubePlaylist(user.Name, shortURL)
|
_, err := NewYouTubePlaylist(user.Name, shortURL)
|
||||||
|
return err
|
||||||
} else {
|
} else {
|
||||||
return errors.New("NO_PLAYLIST_PERMISSION")
|
return errors.New("NO_PLAYLIST_PERMISSION")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
re = RegexpFromURL(url, youtubeVideoPatterns)
|
||||||
matches := re.FindAllStringSubmatch(url, -1)
|
matches := re.FindAllStringSubmatch(url, -1)
|
||||||
shortURL = matches[0][1]
|
shortURL = matches[0][1]
|
||||||
if len(matches[0]) == 3 {
|
if len(matches[0]) == 3 {
|
||||||
|
@ -83,7 +83,6 @@ func (y YouTube) NewRequest(user *gumble.User, url string) error {
|
||||||
}
|
}
|
||||||
NewYouTubeSong(user.Name, shortURL, startOffset, nil)
|
NewYouTubeSong(user.Name, shortURL, startOffset, nil)
|
||||||
}
|
}
|
||||||
return nil
|
|
||||||
} else {
|
} else {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue