<?php

include( 'functions.inc' );

$mysqlhost "192.168.0.1";
$mysqluser"playlist";
$mysqlpassword "playlist";
$mysqldatabase "playlist";

$link2 mysql_connect$mysqlhost$mysqluser$mysqlpassword );
mysql_select_db$mysqldatabase );

function 
pls()
{
  
header"Content-Type: audio/x-scpls");
  
header'Content-disposition: attachment; filename=playlist.pls' );

  echo( 
"[playlist]\n" );

  
$sql "select count(*) as c from playlist2";
  
$result mysql_query$sql );

  if( ! ( 
$line mysql_fetch_array$resultMYSQL_ASSOC ) ) )
  {
      echo( 
"Not able to query server" );
      return;
  }
  else
  {
      
$count=$line['c'];
  }

  echo( 
"numberofentries=" $count "\n" );
  
$sql "select * from playlist2 order by 1";
  
$result mysql_query$sql );
  
$count 0;
  while( 
$line mysql_fetch_array$resultMYSQL_ASSOC ) )
  {
      echo( 
"File" . ++$count "=" $line['strFile'] . "\n" );
      echo( 
"Title" $count "=" . ( $line['strTitle'] != null $line['strTitle'] : "No title" ) . "\n" );
      echo( 
"Length" $count "=-1" "\n" );
  }
  echo( 
"Version=2" "\n" );
}

function 
m3u()
{
  
header"Content-Type: audio/x-mpegurl");
  
header'Content-disposition: attachment; filename=playlist.m3u' );

  echo( 
"#EXTM3u\n" );

  
$sql "select * from playlist2";
  
$result mysql_query$sql );

  if( ! ( 
$line mysql_fetch_array$resultMYSQL_ASSOC ) ) )
  {
    echo( 
"Not able to perform query" );
  }

  
$count 0;
  while( 
$line mysql_fetch_array$resultMYSQL_ASSOC ) )
  {
    echo( 
"#EXTINF:" . ++$count "," $line['strTitle'] . "\n" );
    echo( 
$line['strFile'] . "\n" );
  }

}

$type getVar"format" );

switch( 
$type )
{
  case 
"m3u":
  {
    
m3u();
    break;
  }

  default: 
  {
    
pls();
    break;
  }
}

?>