0xced / XCDYouTubeKit

YouTube video player for iOS, tvOS and macOS
MIT License
2.92k stars 626 forks source link

HD720 StreamUrl doesn't work properly in some videos #452

Closed kirian closed 4 years ago

kirian commented 4 years ago

Using the last sdk version 2.8.1, I would like to know why some streamUrls doesn't work properly in two videos:

1st Video:

This is the Youtube video identifier uslh4S-cgBQ which creates different streamURLs:

XCDYouTubeVideoQualityHD720 = https://r6---sn-h5q7dnel.googlevideo.com/videoplayback?expire=1570132789&ei=1f6VXYe0K42AVsuXj-AC&ip=188.84.26.33&id=o-AJOpTaEWeEBITvaZ3svokcjDWvRq5n_EvgmmrdTpreCW&itag=22&source=youtube&requiressl=yes&mm=31%2C29&mn=sn-h5q7dnel%2Csn-h5q7kned&ms=au%2Crdu&mv=m&mvi=5&pl=23&initcwndbps=878750&mime=video%2Fmp4&ratebypass=yes&dur=1069.487&lmt=1569842415585019&mt=1570111104&fvip=3&fexp=23842630&c=WEB&txp=3416222&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cmime%2Cratebypass%2Cdur%2Clmt&sig=ALgxI2wwRQIge9Ije1dIMfT1Dpd36HNUb0tVMi_Mtj9kOfm4lKNNkvkCIQDrBQrH2WypyH8ZctDxj1JKPp-pjFL6quSsl5QhQY3m4w%3D%3D&lsparams=mm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AHylml4wRAIgROffXMhKHqn8NzaDW2OITl7uA4I_fHEYueyZBRQOutECIDPbKV9sSQNsWSHzlNQH2tp7_8_sBzEW4yvloCopxpgr

XCDYouTubeVideoQualityMedium360 = https://r6---sn-h5q7dnel.googlevideo.com/videoplayback?expire=1570132789&ei=1f6VXYe0K42AVsuXj-AC&ip=188.84.26.33&id=o-AJOpTaEWeEBITvaZ3svokcjDWvRq5n_EvgmmrdTpreCW&itag=18&source=youtube&requiressl=yes&mm=31%2C29&mn=sn-h5q7dnel%2Csn-h5q7kned&ms=au%2Crdu&mv=m&mvi=5&pl=23&initcwndbps=878750&mime=video%2Fmp4&gir=yes&clen=79614100&ratebypass=yes&dur=1069.487&lmt=1569869311301381&mt=1570111104&fvip=3&fexp=23842630&c=WEB&txp=5531432&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cmime%2Cgir%2Cclen%2Cratebypass%2Cdur%2Clmt&sig=ALgxI2wwRAIgdA_vXaHx2TvON2OCOvwzumOV2mUp2427FUIX9PNZ5JYCIFIczPnzKMGnEKaditMQcmmNuaYGuw9T3TuGjRvF_wEW&lsparams=mm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AHylml4wRAIgROffXMhKHqn8NzaDW2OITl7uA4I_fHEYueyZBRQOutECIDPbKV9sSQNsWSHzlNQH2tp7_8_sBzEW4yvloCopxpgr

The HD720 streamUrl doesn't work but the Medium360 works fine. (You can directly reproduce the stream in the browser or iOS Demo project).

2nd Video:

I have another video (Youtube identifier MV1TP_edddc) which always reproduce only 11 seconds in HD720. Instead, in Medium360 works fine.

XCDYouTubeVideoQualityHD720 = https://r3---sn-h5q7knes.googlevideo.com/videoplayback?expire=1570133411&ei=QgGWXe6FOsXeVPzkpLgF&ip=188.84.26.33&id=o-AOgNBm_31gZiAF4UftUjOa5A52d3WCz0GiYqQoWEhLjJ&itag=22&source=youtube&requiressl=yes&mm=31%2C29&mn=sn-h5q7knes%2Csn-h5q7dned&ms=au%2Crdu&mv=m&mvi=2&pl=23&initcwndbps=820000&mime=video%2Fmp4&ratebypass=yes&dur=3341.978&lmt=1569922629795759&mt=1570111736&fvip=3&fexp=23842630&c=WEB&txp=3416222&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cmime%2Cratebypass%2Cdur%2Clmt&sig=ALgxI2wwRgIhAM2Kq0iP3NrHoDzpvpbnwdL54SnuJJWwd__mVQczVW-_AiEAk4kDcfEJNJxyWU7OYS-Xcy1AbQqLWij99sf1DskUCzY%3D&lsparams=mm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AHylml4wRQIgIs8wWx_rlRQJ0Ncua3mlaES_OXAxs-FJesmsgGimvpoCIQCilE1A5NBGk8S1_RmVH5WpmrMxEfMtpDGCIk-618qiIg%3D%3D

XCDYouTubeVideoQualityMedium360 = https://r3---sn-h5q7knes.googlevideo.com/videoplayback?expire=1570133411&ei=QgGWXe6FOsXeVPzkpLgF&ip=188.84.26.33&id=o-AOgNBm_31gZiAF4UftUjOa5A52d3WCz0GiYqQoWEhLjJ&itag=18&source=youtube&requiressl=yes&mm=31%2C29&mn=sn-h5q7knes%2Csn-h5q7dned&ms=au%2Crdu&mv=m&mvi=2&pl=23&initcwndbps=820000&mime=video%2Fmp4&gir=yes&clen=255413567&ratebypass=yes&dur=3341.978&lmt=1570049067917581&mt=1570111736&fvip=3&fexp=23842630&c=WEB&txp=5531432&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cmime%2Cgir%2Cclen%2Cratebypass%2Cdur%2Clmt&sig=ALgxI2wwRgIhAJifQOcFdldl7x6Osu7x4XyD9E9ARP5UsFsfELK5m-BdAiEAk78CfPIDFMncUYSZJ-2H8JA9qVVleQf0tOHs6E_Y-kQ%3D&lsparams=mm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Cinitcwndbps&lsig=AHylml4wRQIgIs8wWx_rlRQJ0Ncua3mlaES_OXAxs-FJesmsgGimvpoCIQCilE1A5NBGk8S1_RmVH5WpmrMxEfMtpDGCIk-618qiIg%3D%3D

Do you have any idea about this issue? Thank you so much!

NOTE: After few days, these links do not work correctly because they have an expiration date but you can debug the issue using Demo iOS Project :)

yukitoto commented 4 years ago

I'm facing same problem.

SoneeJohn commented 4 years ago

YouTube sometimes doesn't server 720p in with itag=22. It uses a different version that doesn't contain audio.

yukitoto commented 4 years ago

@SoneeJohn Thank you. How can I know that 720p doesn't work?

CWftw commented 4 years ago

@SoneeJohn Although in our experience, and in the links above it says its itag 22. To repeat @yukitoto , how do we know if it won't play?

kirian commented 4 years ago

@SoneeJohn then, how do we know it? 🙄

SoneeJohn commented 4 years ago

I am sorry for my late reply on this. Sometimes YouTube might return a URL but with a non 2xx status code.

What I suggest is querying the URL before using them. However, I've yet to 720, 360, 240p all being unreachable. I might add this querying feature to the library in the future:

func query(url: URL, completionHandler: @escaping (Bool) -> Void) {
        var request = URLRequest(url: url)
        request.httpMethod = "HEAD"

        URLSession.shared.dataTask(with: request) { (_, response, error) in
            guard error == nil else {
                completionHandler(false)
                return
            }

            guard (response as! HTTPURLResponse).statusCode == 200 else {
                completionHandler(false)
                return
            }
            completionHandler(true)
        }.resume()
    }