Assembla home | Assembla project page
 

Changeset 1107

Show
Ignore:
Timestamp:
10/22/08 22:26:24 (1 year ago)
Author:
Pernod
Message:

Now playing track details are now retrieved from internet radio servers.

Fixes #167

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/swisscenter/base/capabilities.php

    r1095 r1107  
    378378 
    379379#------------------------------------------------------------------------------------------------- 
     380# Returns the POD (Picture On Demand) parameter to pass to the hardware player that controls how 
     381# an audio stream with images will be synchronized together. 
     382#------------------------------------------------------------------------------------------------- 
     383 
     384function stream_pod_type() 
     385{ 
     386  $result = 1;  // Default values for players unless we discover otherwise. 
     387 
     388  switch ( get_player_type() ) 
     389  { 
     390    case 'POPCORN': 
     391         $result = 2; 
     392         break; 
     393  } 
     394 
     395  return $result; 
     396} 
     397 
     398#------------------------------------------------------------------------------------------------- 
    380399# The transition effect to use between "Now Playing" screens. 
    381400# 
  • trunk/swisscenter/base/image_screens.php

    r1013 r1107  
    8383  //------------------------------------------------------------------------------------------------ 
    8484 
    85   function station_playing_image( $station_name
     85  function station_playing_image( $station_name, $now_playing
    8686  { 
    8787    $title_text_size  = font_size( 24, SCREEN_COORDS); 
     
    9494    $image->resize( convert_x(1000,SCREEN_COORDS), convert_y(1000,SCREEN_COORDS), 0, false);     
    9595    wrap( $image,$station_name, $title_x, $title_y, convert_x(500,SCREEN_COORDS), $title_text_col, $title_text_size); 
     96    $title_y+=($title_text_size*2.5); 
     97    wrap( $image,$now_playing, $title_x, $title_y, convert_x(500,SCREEN_COORDS), $title_text_col, $title_text_size); 
    9698    return $image;     
    9799  } 
  • trunk/swisscenter/base/playlist.php

    r1095 r1107  
    244244function play_internet_radio( $playlist_url, $station_name ) 
    245245{ 
    246   return 'href="'.$playlist_url.'" pod="1,1,'.server_address().'music_radio_image.php?'.current_session().'&list=&station='.urlencode($station_name).'"'; 
     246  return 'href="'.$playlist_url.'" pod="'.stream_pod_type().',1,'.server_address().'music_radio_image.php?'.current_session().'&list=&station='.urlencode($station_name).'&playlist='.urlencode($playlist_url).'"'; 
    247247} 
    248248 
  • trunk/swisscenter/music_radio_image.php

    r1030 r1107  
    77  require_once( realpath(dirname(__FILE__).'/base/capabilities.php')); 
    88 
     9  /** 
     10   * Returns the track title currently being played by the ShoutCast server. 
     11   * 
     12   * @param integer $host 
     13   * @param integer $port 
     14   * @return string 
     15   */ 
     16  function shoutcast_now_playing($host, $port) 
     17  { 
     18    send_to_log(5,'Connecting to ShoutCast server '.$host.':'.$port); 
     19    $fp = @fsockopen($host,$port,$errno,$errstr,10); 
     20    if (!$fp)  
     21    {  
     22      send_to_log(5,'- Connection refused'); // Displays when sever is offline 
     23    }  
     24    else 
     25    {  
     26      fputs($fp, "GET /7.html HTTP/1.0\r\nUser-Agent: Mozilla\r\n\r\n"); 
     27      while (!feof($fp))  
     28      { 
     29        $info = fgets($fp); 
     30      } 
     31      $info = str_replace('</body></html>', "", $info); 
     32      $split = explode(',', $info); 
     33      if (empty($split[6]) ) 
     34      { 
     35        send_to_log(5,'- The current song is not available'); // Displays when server is online but no song title 
     36      } 
     37      else 
     38      { 
     39        $title = str_replace('\'', '`', $split[6]); 
     40        $title = str_replace(',', ' ', $title); 
     41        send_to_log(5,'- Now playing "'.$title.'"');  
     42        return $title; // Displays song 
     43      } 
     44    } 
     45  } 
     46   
     47  if ( empty($_REQUEST["host"]) || empty($_REQUEST["port"]) ) 
     48  { 
     49    // Retrieve server details from playlist (pls) (3 attempts) 
     50    $i=0; 
     51    send_to_log(6,'Attempting to obtain server details from radio playlist');  
     52    while ( $i < 3 && empty($info) ) 
     53    { 
     54      if ( ($info = file_get_contents(urldecode(un_magic_quote($_REQUEST["playlist"])))) == false ) 
     55        send_to_log(6,'- Attempt '.$i.': Failed to download playlist'); 
     56      elseif ( preg_match('/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}):(\d{1,5})/', $info, $host) == 0 ) 
     57        send_to_log(6,'- Failed to find internet radio server in playlist:', $info); 
     58      else 
     59        send_to_log(6,'- Radio server found at '.$host[1].':'.$host[2]); 
     60      $i++; 
     61    } 
     62  } 
     63  else 
     64  { 
     65    $host[1] = $_REQUEST["host"]; 
     66    $host[2] = $_REQUEST["port"]; 
     67  } 
     68   
    969  if ( isset($_REQUEST["list"])) 
    1070  { 
    1171    // List of images to display to the user (changes every 30 seconds) 
    1272    $server     = server_address(); 
    13     $url        = $server."music_radio_image.php?".current_session()."&station=".urlencode(un_magic_quote($_REQUEST["station"]))."&x=.jpg"; 
     73    $station    = un_magic_quote($_REQUEST["station"]); 
     74    $url        = $server."music_radio_image.php?".current_session()."&host=".$host[1]."&port=".$host[2]. 
     75                          "&station=".urlencode($station)."&x=.jpg"; 
    1476    $transition = now_playing_transition(); 
    15     echo "3600|$transition| |$url|\n"; 
    16     echo "3600|$transition| |$url|\n"; 
     77    echo "30|$transition| |$url|\n"; 
     78    echo "30|$transition| |$url|\n"; 
    1779  } 
    1880  else 
    1981  { 
    20     // Generate and display the "Now Playing" screen.     
    21     $image = station_playing_image(un_magic_quote($_REQUEST["station"])); 
     82    // Generate and display the "Now Playing" screen. 
     83    $playing = shoutcast_now_playing($host[1], $host[2]); 
     84    $image   = station_playing_image(un_magic_quote($_REQUEST["station"]), $playing); 
    2285    $image->output('jpeg'); 
    2386  } 
  • trunk/swisscenter/music_radio_urls.php

    r914 r1107  
    1414    preg_match('/\bURL=.*\n?/',$contents,$matches); 
    1515    $url = substr($matches[0],4); 
    16     return play_internet_radio($url, file_noext($url)); 
     16    return play_internet_radio($url, file_noext($file)); 
    1717  } 
    1818