mirror of
https://github.com/mxpv/podsync.git
synced 2024-05-11 05:55:04 +00:00
Add nil checks to reduce panics
This commit is contained in:
@ -40,7 +40,7 @@ func (v *VimeoBuilder) queryChannel(feed *model.Feed) (*itunes.Podcast, error) {
|
||||
|
||||
ch, resp, err := v.client.Channels.Get(channelID)
|
||||
if err != nil {
|
||||
if resp.StatusCode == http.StatusNotFound {
|
||||
if resp != nil && resp.StatusCode == http.StatusNotFound {
|
||||
return nil, api.ErrNotFound
|
||||
}
|
||||
|
||||
@ -64,7 +64,7 @@ func (v *VimeoBuilder) queryGroup(feed *model.Feed) (*itunes.Podcast, error) {
|
||||
|
||||
gr, resp, err := v.client.Groups.Get(groupID)
|
||||
if err != nil {
|
||||
if resp.StatusCode == http.StatusNotFound {
|
||||
if resp != nil && resp.StatusCode == http.StatusNotFound {
|
||||
return nil, api.ErrNotFound
|
||||
}
|
||||
|
||||
@ -88,7 +88,7 @@ func (v *VimeoBuilder) queryUser(feed *model.Feed) (*itunes.Podcast, error) {
|
||||
|
||||
user, resp, err := v.client.Users.Get(userID)
|
||||
if err != nil {
|
||||
if resp.StatusCode == http.StatusNotFound {
|
||||
if resp != nil && resp.StatusCode == http.StatusNotFound {
|
||||
return nil, api.ErrNotFound
|
||||
}
|
||||
|
||||
@ -123,7 +123,11 @@ func (v *VimeoBuilder) queryVideos(getVideos getVideosFunc, podcast *itunes.Podc
|
||||
for {
|
||||
videos, response, err := getVideos(feed.ItemID, vimeo.OptPage(page), vimeo.OptPerPage(vimeoDefaultPageSize))
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to query videos (error %d %s)", response.StatusCode, response.Status)
|
||||
if response != nil {
|
||||
return errors.Wrapf(err, "failed to query videos (error %d %s)", response.StatusCode, response.Status)
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
for _, video := range videos {
|
||||
|
@ -358,13 +358,19 @@ func (yt *YouTubeBuilder) queryVideoDescriptions(
|
||||
|
||||
item.AddPubDate(&pubDate)
|
||||
|
||||
// Parse duration
|
||||
d, err := duration.FromString(video.ContentDetails.Duration)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to parse duration %s", video.ContentDetails.Duration)
|
||||
// Sometimes YouTube retrun empty content defailt, use arbitrary one
|
||||
var seconds int64 = 1
|
||||
|
||||
if video.ContentDetails != nil {
|
||||
// Parse duration
|
||||
d, err := duration.FromString(video.ContentDetails.Duration)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to parse duration %s", video.ContentDetails.Duration)
|
||||
}
|
||||
|
||||
seconds = int64(d.ToDuration().Seconds())
|
||||
}
|
||||
|
||||
seconds := int64(d.ToDuration().Seconds())
|
||||
item.AddDuration(seconds)
|
||||
|
||||
// Add download links
|
||||
|
Reference in New Issue
Block a user