How to programmatically check if a live YouTube channel is streaming? - youtube

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.

Related

Youtube api not returning my live stream

I have created a new google account, then I have enabled youtube live streaming and started to stream. I have app key and access token for my user, but http get request to https://www.googleapis.com/youtube/v3/liveStreams?part=snippet&access_token=MY_TOKEN&key=MY_KEY&mine=true is returning zero results, meanwhile at the moment I have live stream.
What to do?
Try using LiveStreams.list instead. It returns a list of video streams that match the API request parameters. There's an example for your code reference.
I found the saving clue in this SO answer. To receive the list, one has to explicitly provide the broadcastType parameter to the query.
Acceptable values are:
all – Return all broadcasts.
event – Return only scheduled event broadcasts.
persistent – Return only persistent broadcasts.
If you find this answer useful, please make sure to upvote the linked answer (as well). I just copy-pasted this.

Resolving a Video Resource given a YouTube URL

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}

YouTube URL parameters issue. YouTube not using HTTP ranges

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.

How to I access a SoundCloud public stream?

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.

Twitter Streaming API - filtering by urls

I am trying to filter tweets from the Streaming API using a url in the track parameter. However I'm not getting the tweets I expect. My suspicion is that the filter doesn't apply to the expanded url and but to the automatically shortened url (t.co).
Can anyone confirm that this is the case? The Streaming Api docs don't even mention how the filtering is applied.
If this is the case does anyone have a workaround?
I'm using the extended URL with cURL. I get the live tweets on my terminal for a particular search parameter. You may like to look into this one.
curl https://stream.twitter.com/1/statuses/filter.json?track=SEARCH_PARAMETER -uUSERNAME:PASSWORD

Resources