and // utilizing getid3 library by James Heinrich , // http://www.getid3.org. iTunes specific tag support by Warren Stone // // need to include the code to read id3 tags // also reads lots of different formats // we'll implement mp3, mpa (quicktime), asf (wma) and riff (wav/avi) // alter the path to your getid3 directory location require_once($id3LibPath); // lets make all of the user set variables xml compliant just in case $titleTAG = escChars ($titleTAG); $descriptionTAG = escChars ($descriptionTAG); $copyrightTAG = escChars ($copyrightTAG); $languageTAG = escChars ($languageTAG); $webMasterTAG = escChars ($webMasterTAG); $generatorTAG = escChars ($generatorTAG);; $rssImageTitleTAG = escChars ($rssImageTitleTAG); $summaryTAG = escChars ($summaryTAG); $authorTAG = escChars ($authorTAG); $ownerNameTAG = escChars ($ownerNameTAG); $ownerEmailTAG = escChars ($ownerEmailTAG); $topCategoryTAG = escChars ($topCategoryTAG); $subCategoryTAG = escChars ($subCategoryTAG); $keywordTAG = escChars ($keywordTAG); $imageTitleTAG = escChars ($imageTitleTAG); header('Content-type: text/xml', true); // path manipulations $rootMP3URL = "http://" . $_SERVER[HTTP_HOST] . $_SERVER[REQUEST_URI]; $rootMP3URL = substr($rootMP3URL, 0, strrpos ($rootMP3URL, "/")); // Trim off script name itself // add a slash to the audio path if it's not set to the current directory if ($audioPath != "./") $audioPath = $audioPath."/"; // let's remove the "dot" and any double slashes that might occur $filePath = str_replace("//","/", str_replace(".","", $audioPath)); print "\n"; print "\n"; print" \n"; // original dircaster channel info print" $filePath\n"; print" $audioPath\n"; print" $titleTAG\n"; print" $linkTAG\n"; print" $descriptionTAG\n"; print" $topCategoryTAG\n"; print" " . date("r") ."\n"; print" " . date("r") ."\n"; print" $languageTAG\n"; print" $copyrightTAG\n"; print" $generatorTAG\n"; print" $ownerEmailTAG ($ownerNameTAG)\n"; print" $webMasterTAG\n"; print" $ttlTAG\n\n"; // new itunes channel stuff // itunes author tag print" $authorTAG\n"; // itune subtitle tag print" $descriptionTAG\n"; // itunes category tags print" \n"; print" \n"; print" \n"; // itunes summary tag print" $summaryTAG\n"; // itunes owner tags print" \n"; print" $ownerNameTAG\n"; print" $ownerEmailTAG\n"; print" \n"; // itunes explicit tag print" $explicitTAG\n"; // image tags print" \n"; print" ".$rssImageUrlTAG."\n"; print" ".$rssImageTitleTAG."\n"; print" ".$rssImageLinkTAG."\n"; print" \n"; // itunes image link print" \n"; // item listing $dirArray = getDir($audioPath, $sftypes); // Get a list of the current directory while (list($filename, $filedate) = each($dirArray)AND $maxFeeds > 0) { $mp3file = new CMP3File; $mp3file->getid3 ($filename); echo "\n"; // title tag $title = str_replace("_", " ", $mp3file->title); if ($title == "") $title = str_replace("/","",strrchr($filename,"/")); echo ("".$title."\n"); // title string // note filename returns with the audio path as a prefix $url = $rootMP3URL."/". htmlentities(str_replace(" ", "%20", $filename)); echo ("".$linkTAG."\n"); //link string // artist $artist = $mp3file->artist; echo ("$ownerEmailTAG\n"); echo ("$mp3file->album\n"); echo ("$title - $mp3file->album - ".$artist."\n"); echo ("".date("r",$filedate)."\n"); echo ("mime_type\"/>\n"); echo ("$artist\n"); echo ("$mp3file->comment\n"); echo ("$keywordTAG\n"); // check to see if we want image info for each item if ($imageItemTAG == "yes") { echo ("\n"); } $fix_duration = $mp3file->duration; if (strlen($fix_duration) < 3) { $fix_duration = "00:00:".$fix_duration; } if (strlen($fix_duration) < 6) { $fix_duration = "00:".$fix_duration; } echo ("$fix_duration\n"); print "\n\n"; $maxFeed--; } print "\n\n"; // Functions and Classes function stripJunk ($text) { // Strip non-text characters for ($c=0; $c= 32 AND ord($text[$c]) <= 122) $outText.=$text[$c]; } return $outText; } function escChars ($text) { // Strip non-text characters $fixed = str_replace("&","&", $text); // ampersand $fixed = str_replace("<","<",$fixed); // less than $fixed = str_replace("","©",$fixed); // copyright $fixed = str_replace("'","'",$fixed); // apostrophe $fixed = str_replace("\"",""",$fixed); // double quotes $outText = str_replace(">",">",$fixed); // greater than return $outText; } class CMP3File { //properties var $title; var $artist; var $album; var $year; var $comment; var $genre; var $composer; var $copyright; var $mime_type; var $duration; // need to enter this with the audio folder prefix already attached to the filename function getid3 ($file) { // Initialize getID3 engine if (file_exists($file)) { //after verifying the file exists, $getID3 = new getID3; // Analyze file and store returned data in $ThisFileInfo $ThisFileInfo = $getID3->analyze($file); // Optional: copies data from all subarrays of [tags] into [comments] so // metadata is all available in one location for all tag formats // metainformation is always available under [tags] even if this is not called getid3_lib::CopyTagsToComments($ThisFileInfo); // Output desired information in whatever format you want // Note: all entries in [comments] or [tags] are arrays of strings // See structure.txt for information on what information is available where // or check out the output of /demos/demo.browse.php for a particular file // to see the full detail of what information is returned where in the array //echo @$ThisFileInfo['comments']['artist'][0]; // artist from any/all available tag formats $mim = @$ThisFileInfo['mime_type']; // artist from any/all available tag formats $dur = @$ThisFileInfo['playtime_string']; // play duration from any/all available tag formats switch (strrchr(strtolower($file), ".")) { case ".mp3"; $tit = @$ThisFileInfo['id3v2']['comments']['title'][0]; // artist from any/all available tag formats $alb = @$ThisFileInfo['id3v2']['comments']['album'][0]; // artist from any/all available tag formats $art = @$ThisFileInfo['id3v2']['comments']['artist'][0]; // artist from any/all available tag formats $com = @$ThisFileInfo['id3v2']['comments']['comment'][3]; // artist from any/all available tag formats $cmp = @$ThisFileInfo['id3v2']['comments']['composer'][0]; // artist from any/all available tag formats $gen = @$ThisFileInfo['id3v2']['comments']['genre'][0]; // artist from any/all available tag formats break; case ".m4a"; $tit = @$ThisFileInfo['quicktime']['comments']['title'][0]; // artist from any/all available tag formats $alb = @$ThisFileInfo['quicktime']['comments']['album'][0]; // artist from any/all available tag formats $art = @$ThisFileInfo['quicktime']['comments']['artist'][0]; // artist from any/all available tag formats $com = @$ThisFileInfo['quicktime']['comments']['comment'][0]; // artist from any/all available tag formats $cmp = @$ThisFileInfo['quicktime']['comments']['writer'][0]; // artist from any/all available tag formats // $gen = @$ThisFileInfo['quicktime']['comments']['genre'][0]; // artist from any/all available tag formats break; case ".m4b"; $tit = @$ThisFileInfo['quicktime']['comments']['title'][0]; // artist from any/all available tag formats $alb = @$ThisFileInfo['quicktime']['comments']['album'][0]; // artist from any/all available tag formats $art = @$ThisFileInfo['quicktime']['comments']['artist'][0]; // artist from any/all available tag formats $com = @$ThisFileInfo['quicktime']['comments']['comment'][0]; // artist from any/all available tag formats $cmp = @$ThisFileInfo['quicktime']['comments']['writer'][0]; // artist from any/all available tag formats // $gen = @$ThisFileInfo['quicktime']['comments']['genre'][0]; // artist from any/all available tag formats break; case ".mov"; $tit = @$ThisFileInfo['quicktime']['comments']['title'][0]; // artist from any/all available tag formats $alb = @$ThisFileInfo['quicktime']['comments']['album'][0]; // artist from any/all available tag formats $art = @$ThisFileInfo['quicktime']['comments']['artist'][0]; // artist from any/all available tag formats $com = @$ThisFileInfo['quicktime']['comments']['comment'][0]; // artist from any/all available tag formats $cmp = @$ThisFileInfo['quicktime']['comments']['director'][0]; // artist from any/all available tag formats // $gen = @$ThisFileInfo['quicktime']['comments']['genre'][0]; // artist from any/all available tag formats break; case ".asf"; $tit = @$ThisFileInfo['asf']['comments']['title'][0]; // artist from any/all available tag formats $alb = @$ThisFileInfo['asf']['comments']['album'][0]; // artist from any/all available tag formats $art = @$ThisFileInfo['asf']['comments']['artist'][0]; // artist from any/all available tag formats $com = @$ThisFileInfo['asf']['comments']['comment'][0]; // artist from any/all available tag formats $cmp = @$ThisFileInfo['asf']['comments']['composer'][0]; // artist from any/all available tag formats $gen = @$ThisFileInfo['asf']['comments']['genre'][0]; // artist from any/all available tag formats break; case ".wma"; $tit = @$ThisFileInfo['asf']['comments']['title'][0]; // artist from any/all available tag formats $alb = @$ThisFileInfo['asf']['comments']['album'][0]; // artist from any/all available tag formats $art = @$ThisFileInfo['asf']['comments']['artist'][0]; // artist from any/all available tag formats $com = @$ThisFileInfo['asf']['comments']['comment'][0]; // artist from any/all available tag formats $cmp = @$ThisFileInfo['asf']['comments']['composer'][0]; // artist from any/all available tag formats $gen = @$ThisFileInfo['asf']['comments']['genre'][0]; // artist from any/all available tag formats break; default; $tit = $file; // artist from any/all available tag formats } $this->title = escChars (stripJunk($tit)); $this->composer = escChars (stripJunk($cmp)); $this->album = escChars (stripJunk($alb)); $this->comment = escChars (stripJunk($com)); $this->copyright = escChars (stripJunk($cmp)); $this->artist = escChars (stripJunk($art)); $this->mime_type = escChars (stripJunk($mim)); $this->duration = escChars (stripJunk($dur)); return true; } else { return false; // file doesn't exist } } } // mp3Dir can be any directory BELOW the directory where dircaster.php resides function getDir($mp3Dir, $supported_file_types) { // Returns directory as array[file]=date in newest to oldest order $dirArray = array(); $diskdir = "./$mp3Dir/"; if (is_dir($diskdir)) { $dh = opendir($diskdir); while (($file = readdir($dh)) != false ) { if (filetype($diskdir . $file) == "file" && $file[0] != ".") { $fext = strrchr(strtolower($file), "."); if (strpos ($supported_file_types, $fext) > 0) { $ftime = filemtime($mp3Dir.$file); $dirArray[str_replace("./","",$mp3Dir).$file] = $ftime; } } } closedir($dh); } asort($dirArray); $dirArray = array_reverse($dirArray); return $dirArray; } /* Initial iTunes category listings /******************************************** Arts & Entertainment Sub-Categories for Arts & Entertainment: Architecture Books Design Entertainment Games Performing Arts Photography Poetry Science Fiction Audio Blogs Business Sub-Categories for Business: Careers Finance Investing Management Marketing Comedy Education Sub-Categories for Education: K-12 Higher Education Food Health Sub-Categories for Health: Diet & Nutrition Fitness Relationships Self-Help Sexuality International Sub-Categories for International: Australian Belgian Brazilian Canadian Chinese Dutch French German Hebrew Italian Japanese Norwegian Polish Portuguese Spanish Swedish Movies & Television Music News Politics Public Radio Religion & Spirituality Sub-Categories for Religion & Spirituality: Buddhism Christianity Islam Judaism New Age Philosophy Spirituality Science Sports Talk Radio Technology Sub-Categories for Technology: Computers Developers Gadgets Information Technology News Operating Systems Podcasting Smart Phones Text/Speech Travel /********************************************/ ?>