2020-03-28 05:16:45 +03:00
|
|
|
package importers
|
|
|
|
|
2024-12-23 19:54:59 +03:00
|
|
|
/*
|
2020-03-28 05:16:45 +03:00
|
|
|
import (
|
2021-03-25 14:36:39 +03:00
|
|
|
"context"
|
2020-03-28 05:16:45 +03:00
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2024-12-23 19:54:59 +03:00
|
|
|
ytdl "github.com/kkdai/youtube"
|
2020-03-28 05:16:45 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type YoutubeImporter struct{}
|
|
|
|
|
|
|
|
func (i *YoutubeImporter) GetVideoInfo(url string) (videoInfo VideoInfo, err error) {
|
2020-04-01 15:13:02 +03:00
|
|
|
if strings.HasPrefix(strings.ToLower(url), "youtube:") {
|
|
|
|
url = strings.TrimSpace(strings.SplitN(url, ":", 2)[1])
|
2020-03-28 05:16:45 +03:00
|
|
|
}
|
|
|
|
|
2021-03-25 14:36:39 +03:00
|
|
|
ctx := context.Background()
|
|
|
|
info, err := ytdl.GetVideoInfo(ctx, url)
|
2020-03-28 05:16:45 +03:00
|
|
|
if err != nil {
|
|
|
|
err = fmt.Errorf("error retriving youtube video info: %w", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-03-25 14:36:39 +03:00
|
|
|
ctx = context.Background()
|
|
|
|
videoURL, err := ytdl.DefaultClient.GetDownloadURL(ctx, info, info.Formats[0])
|
2020-03-28 05:16:45 +03:00
|
|
|
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
|
|
|
|
}
|
2024-12-23 19:54:59 +03:00
|
|
|
*/
|