Skip to content

Commit

Permalink
Retry get_video_info on status 404
Browse files Browse the repository at this point in the history
closes #192
  • Loading branch information
corny committed May 14, 2021
1 parent e954335 commit febe322
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package youtube
import (
"context"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log"
Expand Down Expand Up @@ -39,8 +40,19 @@ func (c *Client) GetVideoContext(ctx context.Context, url string) (*Video, error
func (c *Client) videoFromID(ctx context.Context, id string) (*Video, error) {
// Circumvent age restriction to pretend access through googleapis.com
eurl := "https://youtube.googleapis.com/v/" + id
var retried bool
var errStatus ErrUnexpectedStatusCode

retry:
// get_video_info can fail sometimes:
// https://github.com/kkdai/youtube/issues/192
body, err := c.httpGetBodyBytes(ctx, "https://www.youtube.com/get_video_info?video_id="+id+"&eurl="+eurl)
if err != nil {
if !retried && errors.As(err, &errStatus) && int(errStatus) == http.StatusNotFound {
retried = true
goto retry
}

return nil, err
}

Expand Down

0 comments on commit febe322

Please sign in to comment.