• 0

Only Showing Online Streams?


Question

Hello everyone, I run a gaming website for League of Legends called DominateDominion.com and some people stream their gameplay. I was wondering how I go about having a section on my website or forum that only shows streams that are online broadcasting? Here is an example. http://solomid.net/streams.php It's only showing streams that are currently online and also has featured ones. I am trying to get the same thing with a randomly rotating featured one but don't know where to begin. Any help is much appreciated. Thanks!

Link to comment
https://www.neowin.net/forum/topic/1076477-only-showing-online-streams/
Share on other sites

9 answers to this question

Recommended Posts

  • 0

Are you aware of the JTV gaming category API (AKA Twitch.tv) available as an XML here http://api.justin.tv/api/stream/list.xml?category=gaming

For League of Legends specific games this should suffice http://api.justin.tv/api/stream/list.xml?category=gaming&meta_game=League%20of%20Legends

Parse that XML using PHP's simplexml or whatever you want to use. You can check for featured in the XML schema and using PHP's rand() will get you a random number for use with random streams.

  • 0

Are you aware of the JTV gaming category API (AKA Twitch.tv) available as an XML here http://api.justin.tv...category=gaming

For League of Legends specific games this should suffice http://api.justin.tv...%20of%20Legends

Parse that XML using PHP's simplexml or whatever you want to use. You can check for featured in the XML schema and using PHP's rand() will get you a random number for use with random streams.

So i'm not really sure what XML is or parsing. Know of any guides that would tell me how to do what you're saying?

  • 0

If you have never used XML parsing then maybe the json API would be easier?

I quickly came up with this:

<?php

$json = file_get_contents("http://api.justin.tv/api/stream/list.json?category=gaming&meta_game=League%20of%20Legends");

$elements = json_decode($json);

foreach ($elements as $element) {

	    /*$channel = get_object_vars($element->channel);
	    print_r(array_keys($channel)); // Use this to print out all available keys for the channel array
	   */
	    echo '<strong>', $element->title, '</strong> | '; // Prints out stream title
	    echo $element->stream_count, '<br />'; // Prints out stream viewer count

	    echo '<a href="', $element->channel->channel_url, '">'; // Enables hyperlink to channel
	    echo '<img src="', $element->channel->screen_cap_url_large, '" />'; // Prints out an image
	    echo '</a>';

	    //$element->channel->embed_code; // Prints out a embedded flash video

	    echo '<br /><br />';
}

Try run that on your web server. It requires error trapping and file caching from that URL for a better experience. But basically it prints out the title of the stream, stream viewer numbers and an image of the channel with a hyperlink back to twitch.

  • 0

Its PHP. So you need to save this as a .php file then upload to your web server.

Then you can direct your web browser to open the .php file from the webserver then it should load.

Edit: you can't just pasted it into WordPress or something. It has to run long side WordPress unless you want to try to create a WordPress plug-in which will complicate things.

Or you could use this for WordPress instead http://wordpress.org/extend/plugins/exec-php/ (I've never used WordPress, so I can't really help on that).

  • 0

Its PHP. So you need to save this as a .php file then upload to your web server.

Then you can direct your web browser to open the .php file from the webserver then it should load.

Edit: you can't just pasted it into WordPress or something. It has to run long side WordPress unless you want to try to create a WordPress plug-in which will complicate things.

Or you could use this for WordPress instead http://wordpress.org...ugins/exec-php/ (I've never used WordPress, so I can't really help on that).

I tried that plug-in you linked me, but it didn't work. Nothing showed up when I pasted the code. So I guess i'll try to do the first way you mentioned. So I just go to my server, create a new page title whatever.php with the code you gave me? Then If i go to that page it will show live streams?

  • 0

Yes. Play around. Obviously, make sure you take backups before you commit anything live.

The best way to develop these things is by using a local PHP web server so if you mess anything up, then it doesn't matter. Though if that isn't possible, then make sure you don't overwrite anything you currently have on your web server.

BTW this is the output of the script:

nM0Z0.png

As you can see, you'll need to style it up somewhat using HTML & CSS. Other users here could implement this for you for a little fee if you are not confident enough to undertake it.

  • 0

You can change the game by changing the "game=" URL. Look on twitch.tv for the exact title they use for the game then for example use http://api.justin.tv/api/stream/list.json?category=gaming&meta_game=dominion

If they do not categorise it as a separate game for whatever reason, then you may need to do check the conditions for known users to stream, or check some other element. E.g.

For checking against users:

if ($element->channel->login == 'dominionuser') {

echo $element->channel->embed_code; // This will display the flash video for dominionuser

}

You probably don't want to embed the actual stream from that example, but you may want to display a picture, number of viewers etc.

The code to achieve this is quite simple. I suggest you play around.

Also enabling:

$channel = get_object_vars($element->channel);

print_r(array_keys($channel));

Will print out a list of all the channel information keys. The keys allows you do find the correct key names to allow you to get the language with $element->channel->language or if they are featured using $element->channel->featured for example. Though there's a lot of them you can use.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • There is a saying in my country: "The wolf has a thick neck because he does his own work." Let that sink in
    • Interesting image choice... reminds me of the human centipede poster
    • Get $50 of aloSIM Mobile Data Traveler eSim credit for just $24.97 by Steven Parker Today's highlighted deal comes via our Apps + Software section of the Neowin Deals store, where you can save 50% off aloSIM Mobile Data Traveler Lifetime eSim Credit: Pay $24.97 for $50. Stay connected affordably in 120+ countries/regions with your own lifetime eSIM! An eSIM is a digital SIM card. It's basically just mobile data. Once it's activated on your device, it can connect you to data networks in other countries – giving you an internet connection with NO roaming charges. With aloSIM, you can load prepaid eSIM data packages onto your phone, tablet, or computer. Your lifetime eSIM never expires, so it's yours forever and there are never any monthly charges. You'll get $50 in eSIM data credit, which is almost always enough to cover all your data roaming needs for a full year. But if you run out of data, you can always top up your lifetime eSIM and stay connected internationally. Pay $24.97 for a lifetime eSIM with $50 in travel data credit Use your eSIM to join data networks in 120+ countries Install your lifetime eSIM on a compatible device to roam on local data networks Your lifetime eSIM never expires, and can be topped up with more data anytime Many data packages cost as little as $4.50 and last 7 days. Depending on the package you choose, the length of time varies. Good to know Length of access: lifetime For NEW customers only Instant digital redemption Once you add your $50 credit to your aloSim account you have up to 12-months to use it — after that your credit will expire When you pay for a data plan you also get a free phone number (via Hushed) for the same duration of your plan that was purchased - IE 7 day eSim plan gives you a free 7-day phone number Purchased coupon must be redeemed and used within 12 months This deal is not stackable (one offer per aloSIM account) A $4.50 data package will last 7 days The data DOES expire, and you WILL NOT have any leftover data for your next trip unless it takes place within the validity period. While the eSIM never expires, the actual data package is only valid for the length of time stated at purchase (i.e. seven days after activation, 30 days after activation, etc.) So if you buy a seven-day package and only use a tiny bit, that package is still going to expire after seven days. Access options: mobile (check compatibility) Max number of device(s): 1 Updates included Here's the deal: This aloSIM Mobile Data Traveler eSim $50 Credit normally costs ... $50, but it can be yours for just $24.97 for a limited time, a saving of $25 (50% off). For specifications, and license info please click the link below. Get this aloSIM Mobile Data Traveler eSim for just $24.97 (was $50) Although priced in U.S. dollars, this deal is available for digital purchase worldwide. Support queries If you have queries or need support for any of the Neowin Deals, please use the contact form here. Neowin Deals are managed and sold by StackCommerce who represent Neowin on an affiliate basis. Why we post these deals We post these because we earn commission on each sale so as not to rely solely on advertising, which many of our readers block. It all helps toward paying staff reporters, servers and hosting costs. So for those that keep moaning and complaining, be thankful we're still online for you to even do that. Other ways to support Neowin Whitelist Neowin by not blocking our ads Create a free member account to see fewer ads Make a donation to support our day to day running costs Subscribe to Neowin - for $14 a year, or $28 a year for an ad-free experience Disclosure: Neowin benefits from revenue of each sale made through our branded deals site powered by StackCommerce.
  • Recent Achievements

    • First Post
      DrWankel earned a badge
      First Post
    • Reacting Well
      DrWankel earned a badge
      Reacting Well
    • Week One Done
      Supreme Spray LV earned a badge
      Week One Done
    • One Month Later
      Genuinetonerink- Dubai earned a badge
      One Month Later
    • Week One Done
      Genuinetonerink- Dubai earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      498
    2. 2
      +Edouard
      158
    3. 3
      PsYcHoKiLLa
      90
    4. 4
      Steven P.
      74
    5. 5
      Michael Scrip
      72
  • Tell a friend

    Love Neowin? Tell a friend!