summaryrefslogtreecommitdiff
path: root/importers/importer.go
blob: f5d4b3634e52a3643e3d211186117df64a2cae97 (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(url, "youtube:") {
		return &YoutubeImporter{}, nil
	} else if strings.Contains(url, "vimeo.com") || strings.HasPrefix(url, "vimeo:") {
		return &VimeoImporter{}, nil
	} else {
		return nil, ErrUnsupportedVideoURL
	}
}