I want to understand all the parameters of a YouTube video as YouTube is now not using the HTTP range element but using its own range parameters inside its URL and thus I am not able to make a session using the Wireshark as i see so many HTTP 200 ok with video/x-flv and thus my player is not able to associate them as it reads the HTTP responses and its ranges. Here are the sample URLs what YouTube is sending for a single video. Is there any documetation available for this as well?
GET /videoplayback?algorithm=throttle-factor&burst=40&cp=U0hTTldOVF9FUUNOM19PSFhIOnBNNjJuUGVsZDZU&expire=1349736707&factor=1.25&fexp=922401%2C920704%2C912806%2C900711%2C913546%2C913556%2C925109%2C919003%2C920201%2C912706%2C900816&id=ee88421fc6a3f768&ip=90.84.144.49&ipbits=8&itag=34&keepalive=yes&key=yt1&ms=au&mt=1349713452&mv=m&newshard=yes&range=13-1781759&signature=84690C3B43F6FFBDD69E0E7009D0A6436946D642.904ADA59891696B5D1411665853784438D9E35D4&source=youtube&sparams=algorithm%2Cburst%2Ccp%2Cfactor%2Cid%2Cip%2Cipbits%2Citag%2Csource%2Cupn%2Cexpire&sver=3&upn=fc55lw1im0s HTTP/1.1
GET /videoplayback?algorithm=throttle-factor&burst=40&cp=U0hTTldOVF9FUUNOM19PSFhIOnBNNjJuUGVsZDZU&expire=1349736707&factor=1.25&fexp=922401%2C920704%2C912806%2C900711%2C913546%2C913556%2C925109%2C919003%2C920201%2C912706%2C900816&id=ee88421fc6a3f768&ip=90.84.144.49&ipbits=8&itag=34&keepalive=yes&key=yt1&ms=au&mt=1349713563&mv=m&newshard=yes&range=10690560-12472319&signature=84690C3B43F6FFBDD69E0E7009D0A6436946D642.904ADA59891696B5D1411665853784438D9E35D4&source=youtube&sparams=algorithm%2Cburst%2Ccp%2Cfactor%2Cid%2Cip%2Cipbits%2Citag%2Csource%2Cupn%2Cexpire&sver=3&upn=fc55lw1im0s&redirect_counter=1&cms_redirect=yes HTTP/1.1
GET /videoplayback?algorithm=throttle-factor&burst=40&cp=U0hTTldOVF9FUUNOM19PSFhIOnBNNjJuUGVsZDZU&expire=1349736707&factor=1.25&fexp=922401%2C920704%2C912806%2C900711%2C913546%2C913556%2C925109%2C919003%2C920201%2C912706%2C900816&id=ee88421fc6a3f768&ip=90.84.144.49&ipbits=8&itag=34&keepalive=yes&key=yt1&ms=au&mt=1349713452&mv=m&newshard=yes&range=12472320-14254079&signature=84690C3B43F6FFBDD69E0E7009D0A6436946D642.904ADA59891696B5D1411665853784438D9E35D4&source=youtube&sparams=algorithm%2Cburst%2Ccp%2Cfactor%2Cid%2Cip%2Cipbits%2Citag%2Csource%2Cupn%2Cexpire&sver=3&upn=fc55lw1im0s HTTP/1.1
There is no documentation for this sort of thing, and video streams are generally considered a "black box" from a developer's perspective.
For your question, see this thread.
Youtube streaming works providing 1.7MB chunk pieces controlled by range param, which indicate [start byte]-[end byte].
I'am also questioning similar issue here.
Related
My company runs a live web stream and has started duplicating this to YouTube. Unfortunately the staff won't check if it's live and internet issues cause our web encoder to stop encoding at times.
Is there a programmatic way I can tell if a channel is ACTUALLY streaming? i.e. if live video is coming out the channel and not just that "the channel is live"?
You may use Search: list.
Using this request returns a collection of search results that match the query parameters that you have specified in the API request. Add part=snippet in your request since this is a required parameter. Then, you may add the following optional parameters with their corresponding values in your HTTP request:
channelId=[channelId] - to search resources created by a particular channel.
type=video - to retrieve a particular type of resource
eventType=live - to return only active broadcasts. Please note that if you use eventType, also set the type parameter's value to video.
Combining all of these parameters, you may send HTTP request using the following format:
https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCXswCcAMb5bvEUIDEzXFGYg&type=video&eventType=live
To better filter your search, you may also opt to add more parameters that are listed in supported parameters.
Lastly, solution in this related SO post - How to check if YouTube channel is streaming live might also help.
SoundCloud's API has a nice endpoint for submitting a permalink and getting back information about the media there.
Given the many YouTube URL variants (i.e. http://www.youtube.com/watch?v=-<someID>, http://youtu.be/-<someID>, http://www.youtube.com/v/-<someID>?version=3&autohide=1, etc...) is there a way to request a Video Resource given a URL?
You can use Videos: list which returns a list of videos that match the API request parameters.
HTTP request:
GET https://www.googleapis.com/youtube/v3/videos
You can also add query parameters and additional properties in your HTTP request for multiple video resources properties as given in the documentation.
Sample requests to the YouTube API are shown in Sample API Requests.
https://www.googleapis.com/youtube/v3/videos?part=snippet&id={VIDEO_ID}&key={YOUR_API_KEY}
I have a special use case where I need to track a response header from AVPlayer while it is streaming an HLS playlist.
I searched in the internet and read the AVPlayer documentation and did not find any specific way to get this. I know that there is a way to get the HTTP response headers from the request made by the app but I could not find anything to get the response header for the requests made by the AVPlayer.
I spent weeks looking for a way to do this for both requests and responses for the playlist and chunk requests. The only way I was able to find that worked was by passing the playback request through a reverse proxy on the device. This allows you to intercept the request, add headers, send it to the real server, and then extract the headers from the response before returning it to the AVPlayer.
I made a simple example project (with lots of comments and documentation) here:
https://github.com/kevinjameshunt/AVPlayer-HTTP-Headers-Example
I use the youtube api v3 and i would like to understand how does the Etag. I would like to use it for what it takes to cache purpose but I do not know what to do in PHP.
Could you tell me the steps to follow once the etag recovered ? please. Thanks for help.
According to the youtube docs (https://developers.google.com/youtube/v3/getting-started#etags), an eTag is basically used to determine if a resource has changed. Use them for:
Optimization - Caching youtube resources in your app can reduce bandwidth and latency. When caching, store the eTag so that you can include it when getting a resource. If the resource has not changed, you will get a 304 response code (NOT MODIFIED), which means you can use your cached version. Otherwise, you will get the updated version of the resource.
Quota Usage - You can reduce the amount you tap into your quota by caching youtube data. The first time you get the resource, you will tap into your quota. Before displaying the resource, first check to see if your cached resource has changed, which will only cost you 1 quota unit. If the resource has not changed, youtube will return a 304 response. If it has changed, you can get the resource again, costing various quota units depending on what you are getting. For more on your quota: (https://developers.google.com/youtube/v3/getting-started#quota).
Overwrite protection - If you are overwriting a resource, including the eTag will ensure that you are not overwriting a newer version of the resource.
eTags are part of the HTTP 1.1 spec (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.19) and are used in the headers of the request/response. Here's a good article that talks about them at a low level: http://www.ibuildings.com/blog/2013/07/etags-uninitiated
As far as using eTags in PHP, I can only suggest a couple things since I've never done it. YouTube returns eTags for feeds AND individual items within a feed, and I'm not sure how to use them for individual items within a feed. But to get the original feed itself, essentially you would use curl and add the eTag to the header of your request (PHP cURL custom headers). You might also want to check out http_cache_etag (http://www.php.net/manual/en/function.http-cache-etag.php)
I was looking for similar information, but I couldn't find a clear example on the youtube website. On the other hand, it seems facebook is using a similar approach (Etags to check whether a resource has changed) and these two links I found on facebook developers area might be of help:
https://developers.facebook.com/docs/reference/ads-api/etags-reference/ and https://developers.facebook.com/blog/post/627/
The first one explains in a simpler and more detailed way how etags are used and provide some request/response examples.
The second link provides a PHP example on how to retrieve a resource and extract the etag and use it in a subsequent request.
Of course these links contain information related to facebook website, but for the great part they can be applied to youtube as well.
I am not sure if anyone would still be interested but I have posted an answer on how to use etag in using the youtube api here. The idea works not only for the youtube api. The post is quite long but hope it can help.
How do I play a track from a SoundCloud URL, which, for example, I got from the xml response from a query
<stream-url>https://api.soundcloud.com/tracks/31164607/stream</stream-url>
I should have thought that it would have been as easy as:
https://api.soundcloud.com/tracks/31164607/stream&client_id=my_client_id
yet I get
<error>401 - Unauthorized</error>
All I want to do is consume it in a Silverlight MediaElement, so all I need is set some url to the MediaElement's Source property.
I've checked an application that I wrote about 2 years ago, and THEN, accessing the stream url was as easy as this for a public track:
http://api.soundcloud.com/tracks/18163056/stream&consumer_key=MY_CONSUMER_KEY
however this no longer seems to work.
For example, all I had to do then in C# was:
MediaElement me = new MediaElement();
me.Source= new Url("http://api.soundcloud.com/tracks/18163056/stream&consumer_key=MY_CONSUMER_KEY");
me.Play();
Any hints would be appreciated.
I had a reply on a Microsoft forum that seems to imply that SoundCloud might not be possible to stream to Windows 8 Metro devices without consuming the whole stream before playback starts - which is quite worrying and would seem to imply that to make authentication possible, it would have to be done entirely in the url querystring insterad of using the header:
(The following reply is the answer to the following question: 'I am able to access an audio stream by http using the MediaElement, however I need to access it via https in which I need to add the oAuth info to the header of the initial request.
How is this done when using a MediaElement, and if it cannot be done, what is the workaround for consuming an audio feed in Metro 8 that requires header authentication to stream?')
"Direct access to the underlying network stream is not currently permitted by the MediaElement. Because of this there is currently no way to modify the header of the HTTP request to include any additional authentication information. That said, you do have control over the URL. You could theoretically setup an HTTP proxy service that translated the HTTP GET request parameters into the necessary oAuth credentials. Keep in mind that this is just a theoretical workaround. You may find different behavior in practice. Another theoretical workaround would be to handle the oAuth yourself via a raw stream socket and pass the retuned media data to the MediaElement via "Set Source" and a "Random Access Stream". Please keep in mind that this method has major limitations. in order to use a "Random Access Stream" with the ME you need to make sure all of the data is available before passing it to the ME."
The proxy service is not scalable for an application that is merely distributed for free as every stream would need to come via the proxy. And the raw stream socket, although getting around this, would mean that playback could not start until the whole file had downloaded - and this goes against all current UX (User Experience) guidelines.
So once again, if anyone has any tips, or info about how the whole authentication thing can be achieved in a querystring instead of using headers, I'd appreciate it!
I'm a little confused about whether you're referring to a public or a private track? If it's a public track, then you shouldn't need to send any authentication information, just your client id.
When I request https://api.soundcloud.com/tracks/31164607/stream?client_id=YOUR_CLIENT_ID then I get a 302 redirect to the proper mp3 stream.
Remember, adding parameters to a URL must start with a ? not &. This could (more than likely) be the reason why you are getting a 401 (SC is not picking up the client_id).
After authentication the link like this
http://api.soundcloud.com/tracks/103229681/stream?consumer_key=d61f17a08f86bfb1dea28539908bc9bf
is working fine. I am using Action Script.
I'm following up on Tom's reply because he calls attention to url character specificity. My HTTP requests randomly started failing today, and I was prefacing my client_Id with a ?. As soon as I changed that single ? to &, it started working. So in my case, SC wasn't picking up my client_Id because I used the wrong character. I think depending on where in the request we're talking about specifically, it's worth noting that differences between ? and & do make a difference.