2021-07-26 17:26:39 -07:00
|
|
|
package scraper
|
|
|
|
|
2021-08-03 15:38:19 -07:00
|
|
|
import (
|
|
|
|
"fmt"
|
2021-08-04 23:41:58 -07:00
|
|
|
"sort"
|
2021-12-23 15:12:01 -05:00
|
|
|
"path"
|
2021-08-03 15:38:19 -07:00
|
|
|
)
|
|
|
|
|
2021-08-04 23:41:58 -07:00
|
|
|
type VideoID int64
|
|
|
|
|
|
|
|
// TODO video-source-user: extract source user information (e.g., someone shares a video
|
|
|
|
// from someone else).
|
2021-08-01 15:52:04 -07:00
|
|
|
|
2021-07-26 17:26:39 -07:00
|
|
|
type Video struct {
|
2021-08-01 15:52:04 -07:00
|
|
|
ID VideoID
|
2021-07-26 17:26:39 -07:00
|
|
|
TweetID TweetID
|
2021-10-10 16:06:47 -07:00
|
|
|
Width int
|
|
|
|
Height int
|
2021-08-04 23:41:58 -07:00
|
|
|
RemoteURL string
|
|
|
|
LocalFilename string
|
2021-12-23 15:12:01 -05:00
|
|
|
|
|
|
|
ThumbnailRemoteUrl string
|
|
|
|
ThumbnailLocalPath string
|
|
|
|
|
2021-07-26 17:26:39 -07:00
|
|
|
IsDownloaded bool
|
2021-10-04 21:06:53 -07:00
|
|
|
IsGif bool
|
2021-07-26 17:26:39 -07:00
|
|
|
}
|
2021-08-03 15:38:19 -07:00
|
|
|
|
2021-08-04 23:41:58 -07:00
|
|
|
func ParseAPIVideo(apiVideo APIExtendedMedia, tweet_id TweetID) Video {
|
|
|
|
variants := apiVideo.VideoInfo.Variants
|
|
|
|
sort.Sort(variants)
|
|
|
|
|
|
|
|
local_filename := fmt.Sprintf("%d.mp4", tweet_id)
|
|
|
|
|
|
|
|
return Video{
|
|
|
|
ID: VideoID(apiVideo.ID),
|
|
|
|
TweetID: tweet_id,
|
2021-10-10 16:06:47 -07:00
|
|
|
Width: apiVideo.OriginalInfo.Width,
|
|
|
|
Height: apiVideo.OriginalInfo.Height,
|
2021-08-04 23:41:58 -07:00
|
|
|
RemoteURL: variants[0].URL,
|
|
|
|
LocalFilename: local_filename,
|
2021-12-23 15:12:01 -05:00
|
|
|
|
|
|
|
ThumbnailRemoteUrl: apiVideo.MediaURLHttps,
|
|
|
|
ThumbnailLocalPath: path.Base(apiVideo.MediaURLHttps),
|
|
|
|
|
2021-08-04 23:41:58 -07:00
|
|
|
IsDownloaded: false,
|
2021-10-04 21:06:53 -07:00
|
|
|
IsGif: apiVideo.Type == "animated_gif",
|
2021-08-04 23:41:58 -07:00
|
|
|
}
|
|
|
|
}
|