Ok, I've stripped down this PHP code (probably can be stripped down more if i knew what else isnt needed). It outputs exactly what I need to make the XML file but it only outputs it to the current page and dont write it to an XML (xspf) file.
I need to add something like:
PHP Code:
echo $doc->saveXML();
$doc->save("playlist.xspf")
But I dont know how or where. Any help please?
PHP Code:
<?php
$myfeed = new RSSFeed();
// Open the current directory (or specify it) and grab only .mp3 and .wma files ...
$dir = opendir ("/var/www/music/");
while (false !== ($file = readdir($dir))) {
if (strpos($file, '.mp3',1)||strpos($file, '.wma',1) ) {
$myfeed->SetItem("http://192.168.0.10/music/$file", "$file", "");
}
}
// Output the XML File ... you could write it to the directory instead.
echo $myfeed->output();
class RSSFeed {
// VARIABLES
// channel vars
var $channel_url;
var $channel_title;
// items
var $items = array();
var $nritems;
// FUNCTIONS
// constructor
function RSSFeed() {
$this->nritems=0;
$this->channel_url='';
$this->channel_title='';
}
// set channel vars
function SetChannel($url, $title, $description, $lang, $copyright, $creator, $subject) {
$this->channel_url=$url;
$this->channel_title=$title;
}
// set item
function SetItem($url, $title, $description) {
$this->items[$this->nritems]['url']=$url;
$this->items[$this->nritems]['title']=$title;
$this->nritems++;
}
// output feed
function Output() {
$output = '<?xml version="1.0" encoding="UTF-8"?>'."\n";
$output .= '<playlist version="0" xmlns = "http://xspf.org/ns/0/">'."\n";
$output .= '<trackList>'."\n";
for($k=0; $k<$this->nritems; $k++) {
$output .= '<track>'."\n";
$output .= '<location>'.$this->items[$k]['url'].'</location>'."\n";
$output .= '<image></image>'."\n";
$output .= '<annotation>'.$this->items[$k]['title'].'</annotation>'."\n";
$output .= '</track>'."\n";
};
$output .= '</trackList>'."\n";
$output .= '</playlist>'."\n";
return $output;
}
};
?>
Bookmarks