We have updated our Terms of Service and Privacy Policy.

Jump to content

- - - - -

Justin/twitch.tv Stream list for websites

  • Please log in to reply
6 replies to this topic

#1 Syipher


    Asuran Acolyte

  • Members
  • 57 posts
  • Guild Tag:[MM]
  • Server:Piken Square

Posted 16 April 2012 - 05:27 PM

Hey guys, as streaming is getting more and more popular lately MM's site admin (Ildjarn) and I (Syi) have been working on this project and we thought we would share it.

We basically have a page here that pulls our players streams from the justin.tv api and displays them in order of highest viewers first. It requires just basic css/html/php to use proven by the fact I wrote it...

Does the following:
  • Lists streams from twitch/justin.tv
  • Gives online/offline status
  • Gives viewer count
  • Gives thumbnail image
  • Gives bio (description)
  • Styles it out like a badman

Its not finished yet as there is one problem I cant overcome - the fact that if multiple streams have the same amount of viewers no ordering is done. If the view has 0 viewers then it works alright, just anything above that creates an problem. There seems to be an issue with the switch logic but I'll keep working on it. Any ideas to fix it would be appreciated.

Here is a link to all the files we used in a .rar file.

Edit: Updated the .rar file with more comments and changed the links to pictures so that they work when in the same folder as the php. Also added <html> tags so that you can plug and go with it. (Hopefully, let me know if theres an error)

I will admit now - im a noob programmer so dont hate me because its a ridiculously long-winded way of doing it but if anyone has any other suggestions of how it can be implemented I would love to talk about it.

The two main files are streamlist_with_ordering.php and streamlist_no_order.php. The first one does the ordering but requires a lot more effort to add new users. The second just adds the streams. But they should give you an idea of how it works.

Note on installation: put the php code where you want the stream list to show (inside the html).

Instructions to add streams:

1. To add a new user simply copy and paste one of the sections at the top (e.g. the bit commented "Sirius api pull") and change the api and url link to your own member.

2. Change the variables to +1 (i.e. viewers4 to viewers5, etc) and add the new one to the thumbnail, description and viewers check below.

3. Add a new entry to the title validation which sets a default title if the stream is not on.

4. Copy and paste the <div class="stream_main"> and everything inside it and change the php variables to match your new entry.

5 - only if you want ordering. The ordering is the annoying to bit to change. I've tried to keep it as clear as possible but im not gonna lie, it looks scruffy as hell :P

Anyway to add a new user, first add the new $viewer5 to the $viewarray. Then add a new set of placeholders which should be simple to follow. Then in the first switch add a new case with the new $viewers variable as its condition. Then comes the fun part. You have to copy and paste the same structure (the second switch) as the previous cases but edit it to fit the new variable.

I cant really explain how to do this in less than 2000 words but you should be able to get it from the current code.

Finally you need to go through each second/nested switch and add a 5th case (case 4) and add the code to deal with the 5th set of variables.

Again apologies that its so long winded but its just to give people an idea of how it can be done. If I have time over the next few months I'll try and come up with a lot neater way to do it. Maybe a plugin of sorts.

If anyone wants to discuss this/get more information I can be found on IRC #MushroomMayhem @ Quakenet.

P.S. Ildjarn says: This works in Joomla if you download the plugin which allows php in articles.


Edited by Syipher, 17 April 2012 - 01:55 PM.

  • 0

#2 Ildjarn


    Pale Tree Seedling

  • Members
  • 1 posts

Posted 16 April 2012 - 05:36 PM

Works in Joomla/wordpress any other CMS if you allow PHP code in articles. For Joomla i recomend using DirectPHP
  • 0

#3 Freelancer


    Team Legacy

  • New Members
  • 641 posts
  • Guild Tag:[TL]
  • Server:Isle of Janthir

Posted 16 April 2012 - 08:24 PM

Before I do mind if pick at the code a bit?

We have a system setup now via our front-end php on our IPB here.

I think we may be able to help each other optimize this. Let me know.
  • 0
ArenaJunkies Editor || www.twitch.tv/fr3elancer Streamer || Tales Of Tyria Co-Host

#4 Syipher


    Asuran Acolyte

  • Members
  • 57 posts
  • Guild Tag:[MM]
  • Server:Piken Square

Posted 16 April 2012 - 08:26 PM

Yeah go for it. Its just meant to give people an idea of how it can be done so everyone is free to take it and use it as they please.
  • 0

#5 darkorical


    Pale Tree Seedling

  • New Members
  • 1 posts

Posted 20 January 2013 - 08:15 AM

I was looking to do this same thing and I found this thread I was looking at the code on the non-ordered list and found a nifty way of shrinking it from 277 lines of code for 4 streams to 126 lines for an infinite number of streams (using an array for users and just looping through) it also makes it easier for other people to add more users to it. if you are interested I can share the final code.
  • 0

#6 Orochii


    Pale Tree Seedling

  • New Members
  • 1 posts

Posted 16 February 2013 - 04:12 PM

Hello, I registered just to say that the code works wonders. Thanks guys.

Also if anyone ended up improving the code and would like to share I'd be very thankful.
  • 0

#7 Omon


    Pale Tree Seedling

  • New Members
  • 1 posts

Posted 22 February 2013 - 07:52 AM

I am having trouble with this code. I am using wordpress 3.5.1 & the Insert PHP plugin.
My 2 main errors are:

1. Images do not load (Where am I suppose to place the images so that they load?)
2. I can't load info from the API as I get errors like this
Warning: file_get_contents(http://api.justin.tv/api/stream/list.json?channel=syipher) [function.file-get-contents]: failed to open stream: Connection refused in /srv/disk1/1299563/www/vexxgaming.co.nf/home/wp-content/plugins/insert-php/insert_php.php(48) : eval()’d code on line 37

  • 0

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users