diff options
Diffstat (limited to 'importers')
| -rw-r--r-- | importers/importer.go | 2 | ||||
| -rw-r--r-- | importers/vimeo_importer.go | 44 |
2 files changed, 43 insertions, 3 deletions
diff --git a/importers/importer.go b/importers/importer.go index c74d621..f5d4b36 100644 --- a/importers/importer.go +++ b/importers/importer.go @@ -25,7 +25,7 @@ type Importer interface { 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:") { + } else if strings.Contains(url, "vimeo.com") || strings.HasPrefix(url, "vimeo:") { return &VimeoImporter{}, nil } else { return nil, ErrUnsupportedVideoURL diff --git a/importers/vimeo_importer.go b/importers/vimeo_importer.go index 5d5ed02..9983a69 100644 --- a/importers/vimeo_importer.go +++ b/importers/vimeo_importer.go @@ -1,10 +1,50 @@ package importers -import "fmt" +import ( + "fmt" + "strings" + + "github.com/prologic/vimeodl" +) type VimeoImporter struct{} func (i *VimeoImporter) GetVideoInfo(url string) (videoInfo VideoInfo, err error) { - err = fmt.Errorf("Not Implemented") + if strings.HasPrefix(url, "vimeo:") { + url = strings.TrimPrefix(url, "vimeo:") + } + + if !strings.HasPrefix(url, "http") { + url = "https://player.vimeo.com/video/" + url + } + + if !strings.HasPrefix(url, "https://player.vimeo.com/video/") { + playerURL, err := vimeodl.GetPlayerURL(url) + if err != nil { + err := fmt.Errorf("error finding player url: %w", err) + return VideoInfo{}, err + } + url = playerURL + } + + if !strings.HasSuffix(url, "/") { + url += "/" + } + + url += "config" + + config, err := vimeodl.GetVideoConfig(url) + if err != nil { + err := fmt.Errorf("error retrieving video config: %w", err) + return VideoInfo{}, err + } + + videoInfo.VideoURL = vimeodl.PickBestVideo(config) + + videoInfo.ThumbnailURL = vimeodl.PickBestThumbnail(config) + + videoInfo.ID = string(config.Video.Id) + videoInfo.Title = config.Video.Title + return } |
