blob: eab5b2498085ea0aafb10ea224f68665d28462fc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
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(strings.ToLower(url), "youtube:") {
return &YoutubeImporter{}, nil
} else if strings.Contains(url, "vimeo.com") || strings.HasPrefix(strings.ToLower(url), "vimeo:") {
return &VimeoImporter{}, nil
} else {
return nil, ErrUnsupportedVideoURL
}
}
|