2020-03-28 05:16:45 +03:00
|
|
|
package importers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
ErrUnsupportedVideoURL = errors.New("error: unsupported video url")
|
|
|
|
)
|
|
|
|
|
|
|
|
type VideoInfo struct {
|
|
|
|
ID string `json:"id"`
|
|
|
|
Title string `json:"title"`
|
|
|
|
Description string `json:"description"`
|
|
|
|
|
|
|
|
VideoURL string `json:"video_url"`
|
|
|
|
ThumbnailURL string `json:"thumbnail_url"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type Importer interface {
|
|
|
|
GetVideoInfo(url string) (VideoInfo, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewImporter(url string) (Importer, error) {
|
|
|
|
if strings.Contains(url, "youtube.com") || strings.HasPrefix(url, "youtube:") {
|
|
|
|
return &YoutubeImporter{}, nil
|
2020-03-28 06:11:54 +03:00
|
|
|
} else if strings.Contains(url, "vimeo.com") || strings.HasPrefix(url, "vimeo:") {
|
2020-03-28 05:16:45 +03:00
|
|
|
return &VimeoImporter{}, nil
|
|
|
|
} else {
|
|
|
|
return nil, ErrUnsupportedVideoURL
|
|
|
|
}
|
|
|
|
}
|