add checks for buggy livestreams

This commit is contained in:
Niko Storni 2021-12-29 17:47:46 -05:00
parent 84790720ff
commit 3c18ae8de2
3 changed files with 110 additions and 95 deletions

View file

@ -1,105 +1,114 @@
package ytdl package ytdl
import ( import "time"
"time"
)
type YtdlVideo struct { type YtdlVideo struct {
UploadDate string `json:"upload_date"` ID string `json:"id"`
UploadDateForReal time.Time // you need to manually set this since the value in the API doesn't include the time Title string `json:"title"`
Extractor string `json:"extractor"` Formats []struct {
Series interface{} `json:"series"` FormatId string `json:"format_id"`
Format string `json:"format"` FormatNote string `json:"format_note"`
Vbr interface{} `json:"vbr"` Ext string `json:"ext"`
Chapters interface{} `json:"chapters"` Protocol string `json:"protocol"`
Height int `json:"height"` Acodec string `json:"acodec"`
LikeCount interface{} `json:"like_count"` Vcodec string `json:"vcodec"`
Duration int `json:"duration"` Url string `json:"url"`
Fulltitle string `json:"fulltitle"` Width int `json:"width,omitempty"`
PlaylistIndex interface{} `json:"playlist_index"` Height int `json:"height,omitempty"`
Album interface{} `json:"album"` Fragments []struct {
ViewCount int `json:"view_count"` Path string `json:"path"`
Playlist interface{} `json:"playlist"` Duration float64 `json:"duration"`
Title string `json:"title"` } `json:"fragments,omitempty"`
Filename string `json:"_filename"` AudioExt string `json:"audio_ext"`
Creator interface{} `json:"creator"` VideoExt string `json:"video_ext"`
Ext string `json:"ext"` Format string `json:"format"`
ID string `json:"id"` Resolution string `json:"resolution"`
DislikeCount interface{} `json:"dislike_count"` HttpHeaders struct {
AverageRating float64 `json:"average_rating"` UserAgent string `json:"User-Agent"`
Abr float64 `json:"abr"` Accept string `json:"Accept"`
UploaderURL string `json:"uploader_url"` AcceptEncoding string `json:"Accept-Encoding"`
Categories []string `json:"categories"` AcceptLanguage string `json:"Accept-Language"`
Fps float64 `json:"fps"` } `json:"http_headers"`
StretchedRatio interface{} `json:"stretched_ratio"` Asr int `json:"asr,omitempty"`
SeasonNumber interface{} `json:"season_number"` Filesize int64 `json:"filesize,omitempty"`
Annotations interface{} `json:"annotations"` SourcePreference int `json:"source_preference,omitempty"`
WebpageURLBasename string `json:"webpage_url_basename"` Quality int `json:"quality,omitempty"`
Acodec string `json:"acodec"` Tbr float64 `json:"tbr,omitempty"`
DisplayID string `json:"display_id"` Language string `json:"language,omitempty"`
//RequestedFormats []RequestedFormat `json:"requested_formats"` LanguagePreference int `json:"language_preference,omitempty"`
//AutomaticCaptions struct{} `json:"automatic_captions"` Abr float64 `json:"abr,omitempty"`
DownloaderOptions struct {
HttpChunkSize int `json:"http_chunk_size"`
} `json:"downloader_options,omitempty"`
Container string `json:"container,omitempty"`
Fps int `json:"fps,omitempty"`
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"` Description string `json:"description"`
Tags []string `json:"tags"` UploadDate string `json:"upload_date"`
Track interface{} `json:"track"` UploadDateForReal time.Time `json:"upload_date_for_real"`
RequestedSubtitles interface{} `json:"requested_subtitles"`
StartTime interface{} `json:"start_time"`
Uploader string `json:"uploader"` Uploader string `json:"uploader"`
UploaderId string `json:"uploader_id"`
UploaderUrl string `json:"uploader_url"`
ChannelID string `json:"channel_id"`
ChannelUrl string `json:"channel_url"`
Duration int `json:"duration"`
ViewCount int `json:"view_count"`
AgeLimit int `json:"age_limit"`
WebpageUrl string `json:"webpage_url"`
Categories []string `json:"categories"`
Tags []string `json:"tags"`
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"`
ExtractorKey string `json:"extractor_key"` ExtractorKey string `json:"extractor_key"`
FormatID string `json:"format_id"` DisplayId string `json:"display_id"`
EpisodeNumber interface{} `json:"episode_number"` DurationString string `json:"duration_string"`
UploaderID string `json:"uploader_id"` ReleaseDate string `json:"release_date"`
//Subtitles struct{} `json:"subtitles"` Asr int `json:"asr"`
ReleaseYear interface{} `json:"release_year"` FormatId string `json:"format_id"`
Thumbnails []Thumbnail `json:"thumbnails"` FormatNote string `json:"format_note"`
License interface{} `json:"license"` SourcePreference int `json:"source_preference"`
Artist interface{} `json:"artist"` Fps int `json:"fps"`
AgeLimit int `json:"age_limit"` Height int `json:"height"`
ReleaseDate interface{} `json:"release_date"` Quality int `json:"quality"`
AltTitle interface{} `json:"alt_title"` Tbr float64 `json:"tbr"`
Thumbnail string `json:"thumbnail"` Url string `json:"url"`
ChannelID string `json:"channel_id"` Width int `json:"width"`
IsLive interface{} `json:"is_live"` Language string `json:"language"`
Width int `json:"width"` LanguagePreference int `json:"language_preference"`
EndTime interface{} `json:"end_time"` Ext string `json:"ext"`
WebpageURL string `json:"webpage_url"` Vcodec string `json:"vcodec"`
Formats []Format `json:"formats"` Acodec string `json:"acodec"`
ChannelURL string `json:"channel_url"` DynamicRange string `json:"dynamic_range"`
Resolution interface{} `json:"resolution"` Protocol string `json:"protocol"`
Vcodec string `json:"vcodec"` VideoExt string `json:"video_ext"`
} AudioExt string `json:"audio_ext"`
Vbr float64 `json:"vbr"`
type RequestedFormat struct { Abr int `json:"abr"`
Asr interface{} `json:"asr"` Format string `json:"format"`
Tbr float64 `json:"tbr"` Resolution string `json:"resolution"`
Container string `json:"container"` FilesizeApprox float64 `json:"filesize_approx"`
Language interface{} `json:"language"` HttpHeaders struct {
Format string `json:"format"`
URL string `json:"url"`
Vcodec string `json:"vcodec"`
FormatNote string `json:"format_note"`
Height int `json:"height"`
Width int `json:"width"`
Ext string `json:"ext"`
FragmentBaseURL string `json:"fragment_base_url"`
Filesize interface{} `json:"filesize"`
Fps float64 `json:"fps"`
ManifestURL string `json:"manifest_url"`
Protocol string `json:"protocol"`
FormatID string `json:"format_id"`
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"` UserAgent string `json:"User-Agent"`
Accept string `json:"Accept"`
AcceptEncoding string `json:"Accept-Encoding"`
AcceptLanguage string `json:"Accept-Language"`
} `json:"http_headers"` } `json:"http_headers"`
Fragments []struct { Fulltitle string `json:"fulltitle"`
Path string `json:"path"` Epoch int `json:"epoch"`
Duration float64 `json:"duration,omitempty"`
} `json:"fragments"`
Acodec string `json:"acodec"`
Abr int `json:"abr,omitempty"`
} }
type Format struct { type Format struct {
@ -135,10 +144,11 @@ type Format struct {
type Thumbnail struct { type Thumbnail struct {
URL string `json:"url"` URL string `json:"url"`
Width int `json:"width"` Preference int `json:"preference"`
Resolution string `json:"resolution"`
ID string `json:"id"` ID string `json:"id"`
Height int `json:"height"` Height int `json:"height"`
Width int `json:"width"`
Resolution string `json:"resolution"`
} }
type HTTPHeaders struct { type HTTPHeaders struct {

View file

@ -89,6 +89,7 @@ var ErrorsNoRetry = []string{
"Premiere will begin shortly", "Premiere will begin shortly",
"cannot unmarshal number 0.0", "cannot unmarshal number 0.0",
"default youtube thumbnail found", "default youtube thumbnail found",
"livestream is likely bugged",
} }
var WalletErrors = []string{ var WalletErrors = []string{
"Not enough funds to cover this transaction", "Not enough funds to cover this transaction",

View file

@ -789,6 +789,10 @@ func (v *YoutubeVideo) downloadAndPublish(daemon *jsonrpc.Client, params SyncPar
logUtils.SendErrorToSlack("%s is %s long and the minimum is %s", v.id, dur.String(), minDuration.String()) logUtils.SendErrorToSlack("%s is %s long and the minimum is %s", v.id, dur.String(), minDuration.String())
return nil, errors.Err("video is too short to process") return nil, errors.Err("video is too short to process")
} }
buggedLivestream := v.youtubeInfo.WasLive && time.Unix(v.youtubeInfo.ReleaseTimestamp, 0).After(time.Now().AddDate(0, 0, -1)) && int(dur.Seconds())%7200 == 0
if buggedLivestream {
return nil, errors.Err("livestream is likely bugged as it was published less than 24 hours ago and has a length of %s", dur.String())
}
for { for {
err = v.download() err = v.download()
if err != nil && strings.Contains(err.Error(), "HTTP Error 429") { if err != nil && strings.Contains(err.Error(), "HTTP Error 429") {