Don't use api unless the video is from the past 5 days, otherwise just use the upload date from youtube donwloader

change interface to int for now known field.
This commit is contained in:
Mark Beamer Jr 2020-07-30 15:37:14 -04:00 committed by Alex Grintsvayg
parent 4eba7200d8
commit 13543b20e9
No known key found for this signature in database
GPG key ID: AEB3F089F86A22B5
2 changed files with 11 additions and 4 deletions

View file

@ -59,7 +59,7 @@ func GetVideoInformation(config *sdk.APIConfig, videoID string, stopChan stop.Ch
tries := 0 tries := 0
GetTime: GetTime:
tries++ tries++
t, err := getUploadTime(config, videoID, ip) t, err := getUploadTime(config, videoID, ip, video.UploadDate)
if err != nil { if err != nil {
//slack(":warning: Upload time error: %v", err) //slack(":warning: Upload time error: %v", err)
if tries <= maxTries && (errors.Is(err, errNotScraped) || errors.Is(err, errUploadTimeEmpty) || errors.Is(err, errStatusParse) || errors.Is(err, errConnectionIssue)) { if tries <= maxTries && (errors.Is(err, errNotScraped) || errors.Is(err, errUploadTimeEmpty) || errors.Is(err, errStatusParse) || errors.Is(err, errConnectionIssue)) {
@ -158,7 +158,7 @@ func triggerScrape(videoID string, ip *net.TCPAddr) error {
//https://caa.iti.gr/caa/api/v4/videos/reports/h-tuxHS5lSM //https://caa.iti.gr/caa/api/v4/videos/reports/h-tuxHS5lSM
} }
func getUploadTime(config *sdk.APIConfig, videoID string, ip *net.TCPAddr) (string, error) { func getUploadTime(config *sdk.APIConfig, videoID string, ip *net.TCPAddr, uploadDate string) (string, error) {
//slack("Getting upload time for %s", videoID) //slack("Getting upload time for %s", videoID)
release, err := config.GetReleasedDate(videoID) release, err := config.GetReleasedDate(videoID)
if err != nil { if err != nil {
@ -170,6 +170,13 @@ func getUploadTime(config *sdk.APIConfig, videoID string, ip *net.TCPAddr) (stri
} }
} }
} }
ytdlUploadDate, err := time.Parse("20060102", uploadDate)
if err != nil {
logrus.Error(err)
}
if time.Now().Add(-5 * 24 * time.Hour).After(ytdlUploadDate) {
return ytdlUploadDate.Format(releaseTimeFormat), nil
}
client := getClient(ip) client := getClient(ip)
req, err := http.NewRequest(http.MethodGet, "https://caa.iti.gr/get_verificationV3?url=https://www.youtube.com/watch?v="+videoID, nil) req, err := http.NewRequest(http.MethodGet, "https://caa.iti.gr/get_verificationV3?url=https://www.youtube.com/watch?v="+videoID, nil)
if err != nil { if err != nil {
@ -314,7 +321,7 @@ func run(use string, args []string, withStdErr, withStdOut bool, stopChan stop.C
break break
} }
} }
logrus.Debug("Unkown error, returning failure: %s", err.Error()) logrus.Debugf("Unkown error, returning failure: %s", err.Error())
return nil, errors.Prefix("youtube-dl "+strings.Join(argsForCommand, " "), err) return nil, errors.Prefix("youtube-dl "+strings.Join(argsForCommand, " "), err)
} }
return strings.Split(strings.Replace(string(outLog), "\r\n", "\n", -1), "\n"), nil return strings.Split(strings.Replace(string(outLog), "\r\n", "\n", -1), "\n"), nil

View file

@ -121,7 +121,7 @@ type Format struct {
Ext string `json:"ext"` Ext string `json:"ext"`
FragmentBaseURL string `json:"fragment_base_url,omitempty"` FragmentBaseURL string `json:"fragment_base_url,omitempty"`
Filesize interface{} `json:"filesize"` Filesize interface{} `json:"filesize"`
Fps interface{} `json:"fps"` Fps int `json:"fps"`
Fragments []struct { Fragments []struct {
Path string `json:"path"` Path string `json:"path"`
Duration float64 `json:"duration,omitempty"` Duration float64 `json:"duration,omitempty"`