Add vimeo video importer
This commit is contained in:
parent
88b96784ab
commit
dab8ea9f1a
4 changed files with 50 additions and 3 deletions
1
go.mod
1
go.mod
|
@ -19,6 +19,7 @@ require (
|
||||||
github.com/mitchellh/mapstructure v1.2.2 // indirect
|
github.com/mitchellh/mapstructure v1.2.2 // indirect
|
||||||
github.com/mutschler/mt v0.0.0-20200120124658-d48aed259ff6 // indirect
|
github.com/mutschler/mt v0.0.0-20200120124658-d48aed259ff6 // indirect
|
||||||
github.com/prologic/bitcask v0.3.5
|
github.com/prologic/bitcask v0.3.5
|
||||||
|
github.com/prologic/vimeodl v0.0.0-20200328030915-d2b0e6272c23
|
||||||
github.com/renstrom/shortuuid v3.0.0+incompatible
|
github.com/renstrom/shortuuid v3.0.0+incompatible
|
||||||
github.com/rs/zerolog v1.18.0 // indirect
|
github.com/rs/zerolog v1.18.0 // indirect
|
||||||
github.com/rylio/ytdl v0.6.3-0.20200220142242-f3a87da86fb8
|
github.com/rylio/ytdl v0.6.3-0.20200220142242-f3a87da86fb8
|
||||||
|
|
6
go.sum
6
go.sum
|
@ -137,6 +137,12 @@ github.com/plar/go-adaptive-radix-tree v1.0.1/go.mod h1:Ot8d28EII3i7Lv4PSvBlF8ej
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/prologic/bitcask v0.3.5 h1:o5PekS/LTRXQvLmY/5oQxIgjdT5bwcxPLsrGmnyo3Yo=
|
github.com/prologic/bitcask v0.3.5 h1:o5PekS/LTRXQvLmY/5oQxIgjdT5bwcxPLsrGmnyo3Yo=
|
||||||
github.com/prologic/bitcask v0.3.5/go.mod h1:gl5FAhs5GhvmV6tEIQWwk9d/FD9vc8NC8Hs24/zU/4w=
|
github.com/prologic/bitcask v0.3.5/go.mod h1:gl5FAhs5GhvmV6tEIQWwk9d/FD9vc8NC8Hs24/zU/4w=
|
||||||
|
github.com/prologic/vimeodl v0.0.0-20200328022514-f93b4783a93d h1:z928AMwVg+Zrk4KoA+J47bMp3V9vxRl8t+izSGMA218=
|
||||||
|
github.com/prologic/vimeodl v0.0.0-20200328022514-f93b4783a93d/go.mod h1:uG4Pdd9lZNNkvQHFr70+Qi7im3/YYnBOtUCrqyZKwlw=
|
||||||
|
github.com/prologic/vimeodl v0.0.0-20200328023734-d27c4c341c4f h1:JXB97k4DcG3NxKEk6+WVUlpJzQvcuqoviHd1OUPky5g=
|
||||||
|
github.com/prologic/vimeodl v0.0.0-20200328023734-d27c4c341c4f/go.mod h1:uG4Pdd9lZNNkvQHFr70+Qi7im3/YYnBOtUCrqyZKwlw=
|
||||||
|
github.com/prologic/vimeodl v0.0.0-20200328030915-d2b0e6272c23 h1:2iUEG1ZXpjBoq11gFdlWOJStBN/3aW3MlY0V5QONZas=
|
||||||
|
github.com/prologic/vimeodl v0.0.0-20200328030915-d2b0e6272c23/go.mod h1:uG4Pdd9lZNNkvQHFr70+Qi7im3/YYnBOtUCrqyZKwlw=
|
||||||
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
||||||
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
|
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
|
||||||
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
||||||
|
|
|
@ -25,7 +25,7 @@ type Importer interface {
|
||||||
func NewImporter(url string) (Importer, error) {
|
func NewImporter(url string) (Importer, error) {
|
||||||
if strings.Contains(url, "youtube.com") || strings.HasPrefix(url, "youtube:") {
|
if strings.Contains(url, "youtube.com") || strings.HasPrefix(url, "youtube:") {
|
||||||
return &YoutubeImporter{}, nil
|
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
|
return &VimeoImporter{}, nil
|
||||||
} else {
|
} else {
|
||||||
return nil, ErrUnsupportedVideoURL
|
return nil, ErrUnsupportedVideoURL
|
||||||
|
|
|
@ -1,10 +1,50 @@
|
||||||
package importers
|
package importers
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/prologic/vimeodl"
|
||||||
|
)
|
||||||
|
|
||||||
type VimeoImporter struct{}
|
type VimeoImporter struct{}
|
||||||
|
|
||||||
func (i *VimeoImporter) GetVideoInfo(url string) (videoInfo VideoInfo, err error) {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue