1
0
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:
Maksym Pavlenko
2019-04-07 22:04:51 -07:00
parent 764eb11a43
commit da4b824e51
2 changed files with 19 additions and 9 deletions

View File

@ -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 {

View File

@ -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