kkdai / youtube

Download Youtube Video in Golang
MIT License
3.3k stars 430 forks source link

Panic in v2.8.0 that is not occurring in 2.7.18 #290

Closed PylotLight closed 1 year ago

PylotLight commented 1 year ago

It's occurring on this ln485 in client.go

if c.client.androidVersion > 0 {
            return format.URL, nil
        }

It would appear the the issue is coming from: client clientInfo as my current value while debugging is: client: github.com/kkdai/youtube/v2.clientInfo nil

This is occurring on all links/urls, not anything in particular.

Exception has occurred: panic "runtime error: invalid memory address or nil pointer dereference" Stack: 4 0x0000000000ce1cf3 in github.com/kkdai/youtube/v2.(Client).GetStreamURLContext at /home/light/go/pkg/mod/github.com/kkdai/youtube/v2@v2.8.0/client.go:485 5 0x0000000000ce1b8c in github.com/kkdai/youtube/v2.(Client).GetStreamURL at /home/light/go/pkg/mod/github.com/kkdai/youtube/v2@v2.8.0/client.go:475 6 0x0000000000ce011b in github.com/kkdai/youtube/v2.(Client).GetStreamContext at /home/light/go/pkg/mod/github.com/kkdai/youtube/v2@v2.8.0/client.go:320 7 0x0000000000cdff7b in github.com/kkdai/youtube/v2.(Client).GetStream at /home/light/go/pkg/mod/github.com/kkdai/youtube/v2@v2.8.0/client.go:315 8 0x0000000000cf5ac5 in main.DownloadVideo at /home/light/goget/yt.go:63 9 0x0000000000cf5734 in main.GetMedia at /home/light/goget/yt.go:42 10 0x0000000000cf47e5 in main.DownloadHandler.func1 at /home/light/goget/web.go:62

norwnd commented 1 year ago

I think you are right about the origin of this panic, I was able to get it working in https://github.com/norwnd/youtube/releases/tag/v2.8.1, leaving it here in case somebody needs resolution fast.

I hope repo maintainers can get to this sooner or later and maybe prepare a proper fix (or borrow mine), I'd try to avoid the lazy initialization here which seems to be the culprit (the issue might show up in other places in the code we haven't hit so far).