fix issue with yt not returning a date

This commit is contained in:
Niko Storni 2022-08-11 18:01:55 +02:00
parent 9d93799d86
commit 42db3782ec
2 changed files with 21 additions and 8 deletions

View file

@ -3,7 +3,11 @@ package downloader
import ( import (
"testing" "testing"
"github.com/lbryio/ytsync/v5/ip_manager"
"github.com/lbryio/ytsync/v5/sdk" "github.com/lbryio/ytsync/v5/sdk"
"github.com/lbryio/lbry.go/v2/extras/stop"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -19,7 +23,10 @@ func TestGetPlaylistVideoIDs(t *testing.T) {
} }
func TestGetVideoInformation(t *testing.T) { func TestGetVideoInformation(t *testing.T) {
video, err := GetVideoInformation("zj7pXM9gE5M", nil, nil) s := stop.New()
ip, err := ip_manager.GetIPPool(s)
assert.NoError(t, err)
video, err := GetVideoInformation("zT_c6YhkXow", s.Ch(), ip)
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)
} }
@ -33,5 +40,4 @@ func Test_getUploadTime(t *testing.T) {
got, err := getUploadTime(&configs, "kDGOHNpRjzc", nil, "20060102") got, err := getUploadTime(&configs, "kDGOHNpRjzc", nil, "20060102")
assert.NoError(t, err) assert.NoError(t, err)
t.Log(got) t.Log(got)
} }

View file

@ -18,10 +18,11 @@ type YtdlVideo struct {
Tags []string `json:"tags"` Tags []string `json:"tags"`
IsLive bool `json:"is_live"` IsLive bool `json:"is_live"`
LiveStatus string `json:"live_status"` LiveStatus string `json:"live_status"`
ReleaseTimestamp int64 `json:"release_timestamp"` ReleaseTimestamp *int64 `json:"release_timestamp"`
uploadDateForReal *time.Time uploadDateForReal *time.Time
Availability string `json:"availability"` Availability string `json:"availability"`
ReleaseDate string `json:"release_date"` ReleaseDate string `json:"release_date"`
UploadDate string `json:"upload_date"`
//WasLive bool `json:"was_live"` //WasLive bool `json:"was_live"`
//Formats interface{} `json:"formats"` //Formats interface{} `json:"formats"`
@ -41,7 +42,6 @@ type YtdlVideo struct {
//LikeCount int `json:"like_count"` //LikeCount int `json:"like_count"`
//Channel string `json:"channel"` //Channel string `json:"channel"`
//ChannelFollowerCount int `json:"channel_follower_count"` //ChannelFollowerCount int `json:"channel_follower_count"`
//UploadDate string `json:"upload_date"`
//OriginalURL string `json:"original_url"` //OriginalURL string `json:"original_url"`
//WebpageURLBasename string `json:"webpage_url_basename"` //WebpageURLBasename string `json:"webpage_url_basename"`
//WebpageURLDomain string `json:"webpage_url_domain"` //WebpageURLDomain string `json:"webpage_url_domain"`
@ -94,13 +94,14 @@ func (v *YtdlVideo) GetUploadTime() time.Time {
// release timestamp from yt // release timestamp from yt
// release timestamp from morty // release timestamp from morty
// release date from yt // release date from yt
// upload date from yt
if v.uploadDateForReal != nil { if v.uploadDateForReal != nil {
return *v.uploadDateForReal return *v.uploadDateForReal
} }
var ytdlReleaseTimestamp time.Time var ytdlReleaseTimestamp time.Time
if v.ReleaseTimestamp > 0 { if v.ReleaseTimestamp != nil && *v.ReleaseTimestamp > 0 {
ytdlReleaseTimestamp = time.Unix(v.ReleaseTimestamp, 0).UTC() ytdlReleaseTimestamp = time.Unix(*v.ReleaseTimestamp, 0).UTC()
} }
//get morty timestamp //get morty timestamp
var mortyReleaseTimestamp time.Time var mortyReleaseTimestamp time.Time
@ -118,13 +119,19 @@ func (v *YtdlVideo) GetUploadTime() time.Time {
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)
} }
ytdlUploadDate, err := time.Parse("20060102", v.UploadDate)
if err != nil {
logrus.Error(err)
}
if !ytdlReleaseTimestamp.IsZero() { if !ytdlReleaseTimestamp.IsZero() {
v.uploadDateForReal = &ytdlReleaseTimestamp v.uploadDateForReal = &ytdlReleaseTimestamp
} else if !mortyReleaseTimestamp.IsZero() { } else if !mortyReleaseTimestamp.IsZero() {
v.uploadDateForReal = &mortyReleaseTimestamp v.uploadDateForReal = &mortyReleaseTimestamp
} else { } else if !ytdlReleaseDate.IsZero() {
v.uploadDateForReal = &ytdlReleaseDate v.uploadDateForReal = &ytdlReleaseDate
} else {
v.uploadDateForReal = &ytdlUploadDate
} }
return *v.uploadDateForReal return *v.uploadDateForReal
} }