• Forum
  • Doc
  • Screenshots
  • Download
  • Donate
  • Contributors
  • Contact
  • Follow @phpfreechat
  • DEMO
  • Board index ‹ Version 1.x branch ‹ Contributions (v1.x)
  • Change font size
  • FAQ
  • Register
  • Login

SHOUTcast now playing command: /np

Post a bug fix, a new feature, a theme ...

Moderators: OldWolf, re*s.t.a.r.s.*2

Post a reply
11 posts • Page 1 of 1

Postby Jaybird » Mon Jun 28, 2010 8:13 am

Here's a command script to touch a shoutcast server, and display whats playing in the chat room.
Just add it to the src/commands folder, rehash and type /np

You will need the ip:port of the shoutcast server you want to touch.

/src/commands/np.class.php
Code: Select all
<?php

require_once(dirname(__FILE__)."/../pfccommand.class.php");

class pfcCommand_np extends pfcCommand
{
  var $usage = "/np";

  function run(&$xml_reponse, $p)
  {
    $clientid    = $p["clientid"];
    $param       = $p["param"];
    $sender      = $p["sender"];
    $recipient   = $p["recipient"];
    $recipientid = $p["recipientid"];   

    $c  =& pfcGlobalConfig::Instance();
    $u  =& pfcUserConfig::Instance();
    $ct =& pfcContainer::Instance();
   
   $timeout = "5"; // Number of seconds before connecton times out - a higher value will slow the page down if any servers are offline

   $ip = "your.fm";  // ip or host name of the shoutcast server
   $port = "8000";  //port of the shoutcast stream

      $fp = @fsockopen($ip,$port,$errno,$errstr,$timeout);
      if (!$fp) 
         { 
         $listeners = "0";
         $msg = "<span class="red">ERROR [Connection refused / Server down]</span>";
         $error = "1";
         } 
      else
         { 
         fputs($fp, "GET /7.html HTTP/1.0rnUser-Agent: Mozillarnrn");
         while (!feof($fp)) 
            {
            $info = fgets($fp);
            }
         $info = str_replace('<HTML><meta http-equiv="Pragma" content="no-cache"></head><body>', "", $info);
         $info = str_replace('</body></html>', "", $info);
         $stats = explode(',', $info);
                  $title = $stats[6];
       
         }

         $cmdp = $p;
         $cmdp["recipient"] = $recipient;
         $cmdp["recipientid"] = $recipientid;
         $cmdp["param"] = _pfc('Now Playing: %s', $title);
         $cmd =& pfcCommand::Factory("notice");
         $cmd->run($xml_reponse, $cmdp);
  }
}

?>

Next, add this line of code to the end of the main.php for the languages you are using, they are located in the /i18n/ folder

example: /i18n/en_US/main.php (line 405)
Code: Select all
//line 51 in np.class.php
$GLOBALS["i18n"]["Now Playing: %s"] = "Now Playing: %s";

enjoy!
Last edited by Jaybird on Mon Jun 28, 2010 8:14 am, edited 1 time in total.
Jaybird
Member
 
Posts: 65
Joined: Mon Jun 28, 2010 7:59 am
Top

Postby DreadPirateVane » Mon Jun 28, 2010 4:41 pm

Awesome ,, i have installed the script but seems that when i run the /np command i get nothing at all,, not even an error message, i updated it to my server details too, do you have a working demo? or even a screen shot?

Thanx very much for the code work,, this will be handy for alot of net radio stations that use this chat, if not maybe now this script will entice them too,

Dread
Station Built by the Bands,, For the Fans!!
DreadPirateVane
Member
 
Posts: 47
Joined: Tue Dec 23, 2008 10:44 pm
Location: Kansas City, Mo.
  • Website
  • YIM
Top

Postby Jaybird » Mon Jun 28, 2010 6:24 pm

Not sure why it wouldn't work for you.. Make sure your host name, and port are correct..
Make sure you rehash, and make sure the Server your trying to touch is actually operating, b/c even tho it has the capability to show errors, I didn't code the error reporting to show up in the chat.. if the script times out, to the client, its like no command was issued..

here's a screen shot...

Image
Jaybird
Member
 
Posts: 65
Joined: Mon Jun 28, 2010 7:59 am
Top

Postby DreadPirateVane » Mon Jun 28, 2010 6:42 pm

ok,, so hmm i have mine installed with joomla,, as a module called jpfchat,, however, all the added commands have worked so far,, in fact i just added the quiz bot last night,, you are welcome to come take a look at the set up we have,, at www.infernalrockradio.com sorry but u gotta register but no email confirmation required is a +.

i see also you have it on the top co the chat too?, how, may i ask?,,

i am free on yahoo @ dpvane if PM would be easier.

Much appreciated
Dread
Station Built by the Bands,, For the Fans!!
DreadPirateVane
Member
 
Posts: 47
Joined: Tue Dec 23, 2008 10:44 pm
Location: Kansas City, Mo.
  • Website
  • YIM
Top

Postby Jaybird » Mon Jun 28, 2010 6:59 pm

at the top is a javascript/html audio player that I'm currently testing.. The now playing comes from a script that is similar to the /np script for the chat, but is touched via ajax, this script not only updates that area when the song changes, but also the page <title>.

I was thinking of going the route of a joomla integration or whatever, but just found it simpler to just code everything from scratch.. this version of the site is not on the live server yet, i'm still putting it together, then there will be about 2 months of testing before it's set live to the public..


EDIT: Just thought of something, what version of the SHOUTcast server are you using? They just recently released a new version of the server, my scripts are setup to use the old version, I'm not sure if they changed the /7.html or not.. can u provide the host:port of your radio stations main relay? I want to see if the page is still setup the same way, if not, I'll rewrite the script to work for the newer version too..
Last edited by Jaybird on Mon Jun 28, 2010 7:04 pm, edited 1 time in total.
Jaybird
Member
 
Posts: 65
Joined: Mon Jun 28, 2010 7:59 am
Top

Postby DreadPirateVane » Mon Jun 28, 2010 7:12 pm

Code: Select all
    $ip = "69.13.198.186";  // ip or host name of the shoutcast server
    $port = "8004";  //port of the shoutcast stream
Station Built by the Bands,, For the Fans!!
DreadPirateVane
Member
 
Posts: 47
Joined: Tue Dec 23, 2008 10:44 pm
Location: Kansas City, Mo.
  • Website
  • YIM
Top

Postby Jaybird » Mon Jun 28, 2010 7:27 pm

wierd.. the script should totally work..

Run this on the same server, and tell me if it spits back the correct information..

/test.php
Code: Select all
<?php

   $timeout = "5"; // Number of seconds before connecton times out - a higher value will slow the page down if any servers are offline

    $ip = "69.13.198.186";  // ip or host name of the shoutcast server
    $port = "8004";  //port of the shoutcast stream

      $fp = @fsockopen($ip,$port,$errno,$errstr,$timeout);
      if (!$fp) 
         { 
         $listeners = "0";
         $msg = "<span class="red">ERROR [Connection refused / Server down]</span>";
         $error = "1";
         } 
      else
         { 
         fputs($fp, "GET /7.html HTTP/1.0rnUser-Agent: Mozillarnrn");
         while (!feof($fp)) 
            {
            $info = fgets($fp);
            }
         $info = str_replace('<HTML><meta http-equiv="Pragma" content="no-cache"></head><body>', "", $info);
         $info = str_replace('</body></html>', "", $info);
         $stats = explode(',', $info);
          $title = $stats[6];
       
         }

echo $title;

?>

I tested your server from my system, using the same script, and it worked fine, there must be a conflict with joomla, or there is something about your php configuration that isn't compatible. The worse is, I can't duplicate the error, and there is no real way to debug it.. :/

try maybe turning on debug in your pfcglobalconfig
Jaybird
Member
 
Posts: 65
Joined: Mon Jun 28, 2010 7:59 am
Top

Postby DreadPirateVane » Mon Jun 28, 2010 7:46 pm

well it shows on my site fine,, but no go with the chatroom,,
Station Built by the Bands,, For the Fans!!
DreadPirateVane
Member
 
Posts: 47
Joined: Tue Dec 23, 2008 10:44 pm
Location: Kansas City, Mo.
  • Website
  • YIM
Top

Postby Jaybird » Mon Jun 28, 2010 8:47 pm

are you using 1.3 version of phpfreechat? that might be the problem, but I cannot give any support further then that, i'm not sure how the joomla integration changes things..
Jaybird
Member
 
Posts: 65
Joined: Mon Jun 28, 2010 7:59 am
Top

Postby DreadPirateVane » Mon Jun 28, 2010 8:52 pm

AHH HAA i found the problem,, it was my notice.class.php file,, i needed to update it,, once done works like a charm.

as far as i can tell the changes of jpfchat (changed the java script of the chat to use mootools) have no affect on most of the mods here,, one day i will compile a list of all the contributions along with thier instructions, for easy access.

Thanx again for this excellent script!
Last edited by DreadPirateVane on Mon Jun 28, 2010 8:56 pm, edited 1 time in total.
Station Built by the Bands,, For the Fans!!
DreadPirateVane
Member
 
Posts: 47
Joined: Tue Dec 23, 2008 10:44 pm
Location: Kansas City, Mo.
  • Website
  • YIM
Top

Postby Jaybird » Mon Jun 28, 2010 10:02 pm

awesome! glad u got it working.. btw.. that test.php if you touch it with ajax, it'll update when the song changes.. google "HttpRequest Ajax"

I've been thinking of that as well, changing the javascript, I really like jquery but it's incompatible with prototype.
Last edited by Jaybird on Mon Jun 28, 2010 10:05 pm, edited 1 time in total.
Jaybird
Member
 
Posts: 65
Joined: Mon Jun 28, 2010 7:59 am
Top


Post a reply
11 posts • Page 1 of 1

Return to Contributions (v1.x)

Who is online

Users browsing this forum: No registered users and 18 guests

  • Board index
  • The team • Delete all board cookies • All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
cron
Sign in
Wrong credentials
Sign up I forgot my password
.
jeu-gratuit.net | more partners
Fork me on GitHub