2020-03-28 05:16:45 +03:00
|
|
|
package importers
|
|
|
|
|
2020-03-28 06:11:54 +03:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2021-07-13 01:34:56 +03:00
|
|
|
"git.mills.io/prologic/vimeodl"
|
2020-03-28 06:11:54 +03:00
|
|
|
)
|
2020-03-28 05:16:45 +03:00
|
|
|
|
|
|
|
type VimeoImporter struct{}
|
|
|
|
|
|
|
|
func (i *VimeoImporter) GetVideoInfo(url string) (videoInfo VideoInfo, err error) {
|
2020-04-01 15:13:02 +03:00
|
|
|
if strings.HasPrefix(strings.ToLower(url), "vimeo:") {
|
|
|
|
url = strings.TrimSpace(strings.SplitN(url, ":", 2)[1])
|
2020-03-28 06:11:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2022-11-08 01:20:23 +03:00
|
|
|
videoInfo.ID = fmt.Sprintf("%d", config.Video.Id)
|
2020-03-28 06:11:54 +03:00
|
|
|
videoInfo.Title = config.Video.Title
|
|
|
|
|
2020-03-28 05:16:45 +03:00
|
|
|
return
|
|
|
|
}
|