Comments (3)
What I also tried is to write a web service based on youtube-dl that takes a video identifier and returns a HTTP 302 redirect to the video mp4 URL. […] it only works if your server is in the same region as the client
Here's a middle-ground solution: create a web service that provides enough data so this control could react to minor API changes without requiring app updates.
For example, these strings are hardcoded into the class: @"https://www.youtube.com/get_video_info?video_id=%@%@&ps=default&eurl=&gl=US&hl=%@"
, @"url_encoded_fmt_stream_map"
, @"thumbnail_url"
, @"iurlmaxres"
, @"embedded"
, @"detailpage"
, @"vevo"
, and @"&el="
. (This list isn't exhaustive.) YouTube could break most clients using this unauthorized endpoint by simply renaming some of these strings. Allowing them to be obtained remotely would make the class less brittle.
An even more robust solution would be for the client to GET the get_video_info
endpoint, attempt to find the correct URL, and upon failure, POST self.connectionData
to a web service, which might have updated logic for parsing out the correct URL. This would circumvent the region issue. Also, this would work well combined with the first solution, which could protect against moving the get_video_info
endpoint.
Of course, there are also some downsides:
- there are negative performance implications with both of these approaches
- this logic could add significant complexity to this simple class
- these approaches would violate "tell, don't ask" if implemented in the same class
That said, they could be used to make this class more flexible.
from xcdyoutubekit.
@steipete, I looked through the code and it appears that @0xced is using an unsupported YouTube endpoint to access the video streaming URL. YouTube has an endpoint called get_video_info that can be used like so:
https://www.youtube.com/get_video_info?video_id=793iPAXJYHQ&ps=default&eurl=&gl=US&hl=en It returns a URL encoded string which contains, among other things, a URL to the video's stream.
This Stack Overflow answer says that the endpoint in question isn't officially supported.
Here are the key points:
The method - (void) startVideoInfoRequest
(Line 101) initializes the video metadata download from YouTube endpoint.
The function DictionaryWithQueryStream
(line 17) converts the query string into a dictionary.
On line 157, the URL connection's delegate handles the completion of the info request.
On line 183, the URL is removed from the newly created dictionary and used.
I googled a bit, and found that the youtube.com/get_video_info endpoint is not officially supported, but seems the be the way to get a direct stream URL.
So in short, no it's nonstandard.
from xcdyoutubekit.
Indeed this API is not documented and might break. As I wrote in the README, the only official way of playing a YouTube video on iOS is with a UIWebView and the iframe player API. I really wanted to use a supported API so I tried PBYouTubeVideoViewController. Unfortunately the user experience — especially for a full-screen video — is terrible. The component itself is pretty good but it doesn’t have any control over the the video player and thus can’t fix these annoyances:
- You get embedded style controls even if you want to present in full screen
- You can’t use presentMoviePlayerViewControllerAnimated:
- Loading is slow
- You get the YouTube style activity indicator
- Rotating the video is not smooth
- I once managed to somehow get the YouTube desktop style video controls (red progress bar etc.)
What I also tried is to write a web service based on youtube-dl that takes a video identifier and returns a HTTP 302 redirect to the video mp4 URL. Since you have control over your server, you could quickly react if the get_video_info
URL stops working. But unfortunately it only works if your server is in the same region as the client else you might get a HTTP 403 error when trying to access the video mp4 URL. 😞
So, we are left with an unsupported API but a much better user experience…
from xcdyoutubekit.
Related Issues (20)
- Error Domain=XCDYouTubeVideoErrorDomain Code=-3 "(null)" HOT 4
- Can't get the streamUrl of Live Stream HOT 11
- CP=“This is not a P3P policy! See http://support.google.com/accounts/answer/151657?hl=en for more info.”
- No longer works: XCDYouTubeVideoErrorDomain error -3 HOT 22
- Unable to play youtube video in iOS app HOT 10
- getVideoWithIdentifier return XCDYouTubeVideoErrorDomain error HOT 25
- streamURL = nil for "LIVE NOW" videos(youtube). HOT 16
- (iOS) XCDYouTubeVideoErrorDomain: -2 with empty User Info for upcoming live stream HOT 2
- XCDYouTubeRequestTypeGetVideoInfo is resulting in a 404 response
- Error XCDYouTubeVideoErrorDomain -2 when i try open video HOT 23
- Error playing video HOT 11
- VIDEO NOT PLAYING (CHECK THIS BEFORE CREATING NEW) HOT 23
- Video Takes a Long Time to Load - Same video performs differently daily HOT 11
- Get StreamUrls from Id is nil HOT 1
- [XCDYouTubeKit] Failed to decode response Code: -3 HOT 7
- Live video plays for last 2:00:00 hours only.
- Cannot play video with XCDYouTubeVideoErrorDomain Code: -2
- live video
- The following content is not available on this app. HOT 1
- Emergency fix HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xcdyoutubekit.