Icecast Streaming Media Server Forum Index Icecast Streaming Media Server
Icecast is a Xiph Foundation Project
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Pls Help with Now Playing Script

 
Post new topic   Reply to topic    Icecast Streaming Media Server Forum Index -> Dev Branches
View previous topic :: View next topic  
Author Message
impactdj



Joined: 06 Apr 2010
Posts: 18

PostPosted: Wed Jun 23, 2010 8:46 pm    Post subject: Pls Help with Now Playing Script Reply with quote

Please can someone help me with a script? I've searched everywhere for ages now and have found a few but they do not do exactly what i'm after and i don't know php Confused

Basically my host only allows some functions so the php needs to use "fsockopen" as i know it works.

Just two rules:

If fsockopen is open then display the song artist/title

If fsockopen is closed then show Server Offline

I've tried loads now but the closest i got to one doesn't use fsockopen and the page keeps trying to load when server is offline instead of just displaying
Back to top
View user's profile Send private message
impactdj



Joined: 06 Apr 2010
Posts: 18

PostPosted: Thu Jun 24, 2010 11:32 am    Post subject: Reply with quote

The below would be perfect but it is for a shoutcast server and i need icecast:

Can anyone convert?

index.php
Code:

<html>
<head>
<script type="text/javascript" src="./jquery.js"></script>
<script type="text/javascript">
function updateNowPlaying(){
 $.ajax({
  url: "./now-playing.php",
  cache: false,
  success: function(html){
   $("#nowPlaying").html(html);
  }
 });
}
updateNowPlaying();
setInterval( "updateNowPlaying()", 10000 );
</script>
</head>
<body bgcolor="#171717">
<center>
<font size="3" color="ff0000"><b>
<div id="nowPlaying"></div></b>
</font>
</center>
</body>
</html>


now-playing.php
Code:

<?php
/*
Now Playing PHP script for SHOUTcast
This script is (C) MixStream.net 2008
Feel free to modify this free script
in any other way to suit your needs.
Version: v1.1
*/
/* ----------- Server configuration ---------- */
$ip = "host.host.net";
$port = "9999";
/* ----- No need to edit below this line ----- */
/* ------------------------------------------- */
$fp = @fsockopen($ip,$port,$errno,$errstr,1);
if (!$fp)
 {
 echo "OFF AIR - Tune In At 6pm"; // Diaplays when sever is offline
 }
 else
 {
 fputs($fp, "GET /7.html HTTP/1.0\r\nUser-Agent: Mozilla\r\n\r\n");
 while (!feof($fp))
  {
  $info = fgets($fp);
  }
 $info = str_replace('</body></html>', "", $info);
 $split = explode(',', $info);
 if (empty($split[6]) )
  {
  echo "The current song is not available"; // Diaplays when sever is online but no song title
  }
 else
  {
  $title = str_replace('\'', '`', $split[6]);
  $title = str_replace(',', ' ', $title);
  echo "$title"; // Diaplays song
  }
 }
?>
Back to top
View user's profile Send private message
karlH
Code Warrior
Code Warrior


Joined: 13 Jun 2005
Posts: 5476
Location: UK

PostPosted: Thu Jun 24, 2010 12:43 pm    Post subject: Reply with quote

does the icecast status2.xsl help you out at all, it would seem simpler than parsing html. All the php would need to do is http://icecast:port/status2.xsl?mount=/mountpint If you can change xsl or copy it, you can tailor it so only the title is reported, then it would be very trivial to read from php

karl.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
impactdj



Joined: 06 Apr 2010
Posts: 18

PostPosted: Thu Jun 24, 2010 1:32 pm    Post subject: Reply with quote

To be honest with you i wouldn't know Confused

I guess i'm looking for some one who'd be kind enough to write me a little script that uses fsockopen if possilbe, whether it grabs it from status.xsl or status2.xsl.

In order to acheive the below (baring in mind its a part time radio station so server will only be on at certain times)

if fsockopen then display: title/artist
if fsockclosed then display: "Server Offline"

the reason i particulaly like the shoutcast code above is as it uses ajax and automatically updates on a set interval
Back to top
View user's profile Send private message
karlH
Code Warrior
Code Warrior


Joined: 13 Jun 2005
Posts: 5476
Location: UK

PostPosted: Thu Jun 24, 2010 4:59 pm    Post subject: Reply with quote

just copy the status2.xsl to another file in webroot, and edit it so the the headings are gone and just the title is sent. Then your php can then just do the fsocklopen, a single fgets and then you have the title to echo, so generally it's

fsockopen...
fputs ("GET /mytitle.xsl?mount=/mystream HTTP/1.0\r\nUser-A....");
headers = fgets (.. eg HTTP 200 OK
$title = fgets (..
echo $title

karl.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
impactdj



Joined: 06 Apr 2010
Posts: 18

PostPosted: Thu Jun 24, 2010 8:46 pm    Post subject: Reply with quote

do you mean something like the below?

would you mind filling in the blanks? haven't got a clue what i'm doing with this lol!

here is the location of my status3.xsl: http://undergroundsoundz.kicks-ass.net:7500/status3.xsl

index.php
Code:

<html>
<head>
<script type="text/javascript" src="./jquery.js"></script>
<script type="text/javascript">
function updateNowPlaying(){
 $.ajax({
  url: "./now-playing.php",
  cache: false,
  success: function(html){
   $("#nowPlaying").html(html);
  }
 });
}
updateNowPlaying();
setInterval( "updateNowPlaying()", 10000 );
</script>
</head>
<body bgcolor="#171717">
<center>
<font size="3" color="ff0000"><b>
<div id="nowPlaying"></div></b>
</font>
</center>
</body>
</html>


now-playing.php
Code:

<?php
/* ----------- Server configuration ---------- */
$ip = "undergroundsoundz.kicks-ass.net";
$port = "7500";
/* ------------------------------------------- */
$fp = @fsockopen($ip,$port,$errno,$errstr,1);
if (!$fp)
 {
 echo "OFF AIR - Tune In At 6pm"; // Diaplays when sever is offline
 }
 else
 {
 fputs($fp, "GET /status3.xsl HTTP/1.0\r\nUser-Agent: Mozilla\r\n\r\n");
 headers = fgets(
 $title = fgets (
 echo $title
 }
?>
Back to top
View user's profile Send private message
impactdj



Joined: 06 Apr 2010
Posts: 18

PostPosted: Wed Jul 07, 2010 7:49 pm    Post subject: Reply with quote

Found a solution now everyone:

Check out my post here: http://icecast.imux.net/viewtopic.php?p=20516#20516
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Icecast Streaming Media Server Forum Index -> Dev Branches All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group
subRebel style by ktauber