prefer IPv4 over IPv6

youtube sucks and they ban /64 subnet blocks on IPv6
This commit is contained in:
Niko Storni 2019-07-12 01:54:34 +02:00
parent 89fe1e99d6
commit bab01a6354

View file

@ -205,7 +205,7 @@ func getNextIP() (string, error) {
return nextIP, nil return nextIP, nil
} }
func (v *YoutubeVideo) download(youtubeAntiThrottle bool) error { func (v *YoutubeVideo) download(useIPv6 bool) error {
videoPath := v.getFullPath() videoPath := v.getFullPath()
err := os.Mkdir(v.videoDir(), 0750) err := os.Mkdir(v.videoDir(), 0750)
@ -221,7 +221,6 @@ func (v *YoutubeVideo) download(youtubeAntiThrottle bool) error {
return nil return nil
} }
useIPv4Env := os.Getenv("USE_IPV4")
ytdlArgs := []string{ ytdlArgs := []string{
"--no-progress", "--no-progress",
"--max-filesize", "--max-filesize",
@ -231,8 +230,7 @@ func (v *YoutubeVideo) download(youtubeAntiThrottle bool) error {
"--merge-output-format", "--merge-output-format",
"mp4", "mp4",
} }
useIPv4 := useIPv4Env != "" if useIPv6 {
if !useIPv4 || youtubeAntiThrottle {
sourceAddress, err := getNextIP() sourceAddress, err := getNextIP()
if err != nil { if err != nil {
return errors.Err(err) return errors.Err(err)
@ -402,11 +400,14 @@ func (v *YoutubeVideo) Sync(daemon *jsonrpc.Client, params SyncParams, existingV
return v.downloadAndPublish(daemon, params) return v.downloadAndPublish(daemon, params)
} }
var isThrottled bool
func (v *YoutubeVideo) downloadAndPublish(daemon *jsonrpc.Client, params SyncParams) (*SyncSummary, error) { func (v *YoutubeVideo) downloadAndPublish(daemon *jsonrpc.Client, params SyncParams) (*SyncSummary, error) {
err := v.download(false) err := v.download(isThrottled)
if err != nil { if err != nil {
if strings.Contains(err.Error(), "HTTP Error 429") { if strings.Contains(err.Error(), "HTTP Error 429") && !isThrottled {
err = v.download(true) isThrottled = true
err = v.download(isThrottled)
if err != nil { if err != nil {
return nil, errors.Prefix("download error", err) return nil, errors.Prefix("download error", err)
} }