From 88b96784ab4fd19b13d0076d64a95300483363ca Mon Sep 17 00:00:00 2001 From: James Mills Date: Sat, 28 Mar 2020 12:16:45 +1000 Subject: Refactored video importers --- importers/importer.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 importers/importer.go (limited to 'importers/importer.go') diff --git a/importers/importer.go b/importers/importer.go new file mode 100644 index 0000000..c74d621 --- /dev/null +++ b/importers/importer.go @@ -0,0 +1,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, "youtube.com") || strings.HasPrefix(url, "youtube:") { + return &VimeoImporter{}, nil + } else { + return nil, ErrUnsupportedVideoURL + } +} -- cgit v1.2.3