blob: c3098502de1fe9efa3719b0a2b3d053a4e5a12b4 (
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
34
35
36
37
|
package importers
import (
"fmt"
"strings"
"github.com/rylio/ytdl"
)
type YoutubeImporter struct{}
func (i *YoutubeImporter) GetVideoInfo(url string) (videoInfo VideoInfo, err error) {
if strings.HasPrefix(strings.ToLower(url), "youtube:") {
url = strings.TrimSpace(strings.SplitN(url, ":", 2)[1])
}
info, err := ytdl.GetVideoInfo(url)
if err != nil {
err = fmt.Errorf("error retriving youtube video info: %w", err)
return
}
videoURL, err := ytdl.DefaultClient.GetDownloadURL(info, info.Formats[0])
if err != nil {
err = fmt.Errorf("error retriving youtube video url: %w", err)
return
}
videoInfo.VideoURL = videoURL.String()
videoInfo.ThumbnailURL = info.GetThumbnailURL(ytdl.ThumbnailQualityHigh).String()
videoInfo.ID = info.ID
videoInfo.Title = info.Title
videoInfo.Description = info.Description
return
}
|