2020-07-27 23:14:06 +02:00
|
|
|
package ytdl
|
|
|
|
|
2021-12-30 19:17:11 +01:00
|
|
|
import (
|
|
|
|
"math"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/lbryio/ytsync/v5/sdk"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
)
|
2020-07-28 17:05:24 +02:00
|
|
|
|
2020-07-27 23:14:06 +02:00
|
|
|
type YtdlVideo struct {
|
2021-12-29 23:47:46 +01:00
|
|
|
ID string `json:"id"`
|
|
|
|
Title string `json:"title"`
|
|
|
|
Formats []struct {
|
|
|
|
FormatId string `json:"format_id"`
|
|
|
|
FormatNote string `json:"format_note"`
|
|
|
|
Ext string `json:"ext"`
|
|
|
|
Protocol string `json:"protocol"`
|
|
|
|
Acodec string `json:"acodec"`
|
|
|
|
Vcodec string `json:"vcodec"`
|
|
|
|
Url string `json:"url"`
|
|
|
|
Width int `json:"width,omitempty"`
|
|
|
|
Height int `json:"height,omitempty"`
|
|
|
|
Fragments []struct {
|
|
|
|
Path string `json:"path"`
|
|
|
|
Duration float64 `json:"duration"`
|
|
|
|
} `json:"fragments,omitempty"`
|
|
|
|
AudioExt string `json:"audio_ext"`
|
|
|
|
VideoExt string `json:"video_ext"`
|
|
|
|
Format string `json:"format"`
|
|
|
|
Resolution string `json:"resolution"`
|
|
|
|
HttpHeaders struct {
|
|
|
|
UserAgent string `json:"User-Agent"`
|
|
|
|
Accept string `json:"Accept"`
|
|
|
|
AcceptEncoding string `json:"Accept-Encoding"`
|
|
|
|
AcceptLanguage string `json:"Accept-Language"`
|
|
|
|
} `json:"http_headers"`
|
2022-01-06 15:15:04 +01:00
|
|
|
Asr float64 `json:"asr,omitempty"`
|
2021-12-29 23:47:46 +01:00
|
|
|
Filesize int64 `json:"filesize,omitempty"`
|
|
|
|
SourcePreference int `json:"source_preference,omitempty"`
|
|
|
|
Quality int `json:"quality,omitempty"`
|
|
|
|
Tbr float64 `json:"tbr,omitempty"`
|
|
|
|
Language string `json:"language,omitempty"`
|
|
|
|
LanguagePreference int `json:"language_preference,omitempty"`
|
|
|
|
Abr float64 `json:"abr,omitempty"`
|
|
|
|
DownloaderOptions struct {
|
|
|
|
HttpChunkSize int `json:"http_chunk_size"`
|
|
|
|
} `json:"downloader_options,omitempty"`
|
|
|
|
Container string `json:"container,omitempty"`
|
2022-01-06 15:15:04 +01:00
|
|
|
Fps float64 `json:"fps,omitempty"`
|
2021-12-29 23:47:46 +01:00
|
|
|
DynamicRange string `json:"dynamic_range,omitempty"`
|
|
|
|
Vbr float64 `json:"vbr,omitempty"`
|
|
|
|
FilesizeApprox float64 `json:"filesize_approx,omitempty"`
|
|
|
|
} `json:"formats"`
|
|
|
|
Thumbnails []Thumbnail `json:"thumbnails"`
|
|
|
|
Thumbnail string `json:"thumbnail"`
|
|
|
|
Description string `json:"description"`
|
2020-07-27 23:14:06 +02:00
|
|
|
UploadDate string `json:"upload_date"`
|
2021-12-30 19:17:11 +01:00
|
|
|
uploadDateForReal *time.Time `json:"upload_date_for_real"`
|
2021-12-29 23:47:46 +01:00
|
|
|
Uploader string `json:"uploader"`
|
|
|
|
UploaderId string `json:"uploader_id"`
|
|
|
|
UploaderUrl string `json:"uploader_url"`
|
|
|
|
ChannelID string `json:"channel_id"`
|
|
|
|
ChannelUrl string `json:"channel_url"`
|
2020-07-27 23:14:06 +02:00
|
|
|
Duration int `json:"duration"`
|
|
|
|
ViewCount int `json:"view_count"`
|
2021-12-29 23:47:46 +01:00
|
|
|
AgeLimit int `json:"age_limit"`
|
|
|
|
WebpageUrl string `json:"webpage_url"`
|
2020-07-27 23:14:06 +02:00
|
|
|
Categories []string `json:"categories"`
|
|
|
|
Tags []string `json:"tags"`
|
2021-12-29 23:47:46 +01:00
|
|
|
PlayableInEmbed bool `json:"playable_in_embed"`
|
|
|
|
IsLive bool `json:"is_live"`
|
|
|
|
WasLive bool `json:"was_live"`
|
|
|
|
LiveStatus string `json:"live_status"`
|
|
|
|
ReleaseTimestamp int64 `json:"release_timestamp"`
|
|
|
|
LikeCount int `json:"like_count"`
|
|
|
|
Channel string `json:"channel"`
|
|
|
|
Availability string `json:"availability"`
|
|
|
|
WebpageUrlBasename string `json:"webpage_url_basename"`
|
|
|
|
WebpageUrlDomain string `json:"webpage_url_domain"`
|
|
|
|
Extractor string `json:"extractor"`
|
2020-07-27 23:14:06 +02:00
|
|
|
ExtractorKey string `json:"extractor_key"`
|
2021-12-29 23:47:46 +01:00
|
|
|
DisplayId string `json:"display_id"`
|
|
|
|
DurationString string `json:"duration_string"`
|
|
|
|
ReleaseDate string `json:"release_date"`
|
2022-01-06 15:15:04 +01:00
|
|
|
Asr float64 `json:"asr"`
|
2021-12-29 23:47:46 +01:00
|
|
|
FormatId string `json:"format_id"`
|
|
|
|
FormatNote string `json:"format_note"`
|
|
|
|
SourcePreference int `json:"source_preference"`
|
2022-01-06 15:15:04 +01:00
|
|
|
Fps float64 `json:"fps"`
|
2021-12-29 23:47:46 +01:00
|
|
|
Height int `json:"height"`
|
|
|
|
Quality int `json:"quality"`
|
|
|
|
Tbr float64 `json:"tbr"`
|
|
|
|
Url string `json:"url"`
|
|
|
|
Width int `json:"width"`
|
|
|
|
Language string `json:"language"`
|
|
|
|
LanguagePreference int `json:"language_preference"`
|
|
|
|
Ext string `json:"ext"`
|
|
|
|
Vcodec string `json:"vcodec"`
|
|
|
|
Acodec string `json:"acodec"`
|
|
|
|
DynamicRange string `json:"dynamic_range"`
|
|
|
|
Protocol string `json:"protocol"`
|
|
|
|
VideoExt string `json:"video_ext"`
|
|
|
|
AudioExt string `json:"audio_ext"`
|
|
|
|
Vbr float64 `json:"vbr"`
|
2022-01-06 15:15:04 +01:00
|
|
|
Abr float64 `json:"abr"`
|
2021-12-29 23:47:46 +01:00
|
|
|
Format string `json:"format"`
|
|
|
|
Resolution string `json:"resolution"`
|
|
|
|
FilesizeApprox float64 `json:"filesize_approx"`
|
|
|
|
HttpHeaders struct {
|
2020-07-28 18:47:28 +02:00
|
|
|
UserAgent string `json:"User-Agent"`
|
2021-12-29 23:47:46 +01:00
|
|
|
Accept string `json:"Accept"`
|
|
|
|
AcceptEncoding string `json:"Accept-Encoding"`
|
|
|
|
AcceptLanguage string `json:"Accept-Language"`
|
2020-07-28 18:47:28 +02:00
|
|
|
} `json:"http_headers"`
|
2021-12-29 23:47:46 +01:00
|
|
|
Fulltitle string `json:"fulltitle"`
|
|
|
|
Epoch int `json:"epoch"`
|
2020-07-28 18:47:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type Format struct {
|
2021-06-17 17:51:21 +02:00
|
|
|
Asr int `json:"asr"`
|
|
|
|
Filesize int `json:"filesize"`
|
|
|
|
FormatID string `json:"format_id"`
|
|
|
|
FormatNote string `json:"format_note"`
|
|
|
|
Fps interface{} `json:"fps"`
|
|
|
|
Height interface{} `json:"height"`
|
|
|
|
Quality int `json:"quality"`
|
|
|
|
Tbr float64 `json:"tbr"`
|
|
|
|
URL string `json:"url"`
|
|
|
|
Width interface{} `json:"width"`
|
|
|
|
Ext string `json:"ext"`
|
|
|
|
Vcodec string `json:"vcodec"`
|
|
|
|
Acodec string `json:"acodec"`
|
|
|
|
Abr float64 `json:"abr,omitempty"`
|
|
|
|
DownloaderOptions struct {
|
|
|
|
HTTPChunkSize int `json:"http_chunk_size"`
|
|
|
|
} `json:"downloader_options,omitempty"`
|
|
|
|
Container string `json:"container,omitempty"`
|
|
|
|
Format string `json:"format"`
|
|
|
|
Protocol string `json:"protocol"`
|
|
|
|
HTTPHeaders struct {
|
|
|
|
UserAgent string `json:"User-Agent"`
|
|
|
|
AcceptCharset string `json:"Accept-Charset"`
|
|
|
|
Accept string `json:"Accept"`
|
|
|
|
AcceptEncoding string `json:"Accept-Encoding"`
|
|
|
|
AcceptLanguage string `json:"Accept-Language"`
|
|
|
|
} `json:"http_headers"`
|
|
|
|
Vbr float64 `json:"vbr,omitempty"`
|
2020-07-28 18:47:28 +02:00
|
|
|
}
|
|
|
|
|
2020-07-27 23:14:06 +02:00
|
|
|
type Thumbnail struct {
|
|
|
|
URL string `json:"url"`
|
2021-12-29 23:47:46 +01:00
|
|
|
Preference int `json:"preference"`
|
2020-07-27 23:14:06 +02:00
|
|
|
ID string `json:"id"`
|
|
|
|
Height int `json:"height"`
|
2021-12-29 23:47:46 +01:00
|
|
|
Width int `json:"width"`
|
|
|
|
Resolution string `json:"resolution"`
|
2020-07-27 23:14:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type HTTPHeaders struct {
|
|
|
|
AcceptCharset string `json:"Accept-Charset"`
|
|
|
|
AcceptLanguage string `json:"Accept-Language"`
|
|
|
|
AcceptEncoding string `json:"Accept-Encoding"`
|
|
|
|
Accept string `json:"Accept"`
|
|
|
|
UserAgent string `json:"User-Agent"`
|
|
|
|
}
|
2021-12-30 19:17:11 +01:00
|
|
|
|
|
|
|
func (v *YtdlVideo) GetUploadTime() time.Time {
|
|
|
|
if v.uploadDateForReal != nil {
|
|
|
|
return *v.uploadDateForReal
|
|
|
|
}
|
|
|
|
|
|
|
|
release, err := sdk.GetAPIsConfigs().GetReleasedDate(v.ID)
|
|
|
|
if err != nil {
|
|
|
|
logrus.Error(err)
|
|
|
|
}
|
|
|
|
ytdlUploadDate, err := time.Parse("20060102", v.UploadDate)
|
|
|
|
if err != nil {
|
|
|
|
logrus.Error(err)
|
|
|
|
}
|
|
|
|
if v.ReleaseTimestamp != 0 {
|
|
|
|
ytdlUploadDate = time.Unix(v.ReleaseTimestamp, 0)
|
|
|
|
}
|
|
|
|
if release != nil {
|
|
|
|
sqlTime, err := time.ParseInLocation(time.RFC3339, release.ReleaseTime, time.UTC)
|
|
|
|
if err == nil {
|
|
|
|
hoursDiff := math.Abs(sqlTime.Sub(ytdlUploadDate).Hours())
|
|
|
|
if hoursDiff > 48 {
|
|
|
|
logrus.Infof("upload day from APIs differs from the ytdl one by more than 2 days.")
|
|
|
|
} else {
|
|
|
|
v.uploadDateForReal = &sqlTime
|
|
|
|
return sqlTime
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
logrus.Error(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
v.uploadDateForReal = &ytdlUploadDate
|
|
|
|
return ytdlUploadDate
|
|
|
|
}
|