{"id":43,"date":"2008-10-27T12:44:00","date_gmt":"2008-10-27T17:44:00","guid":{"rendered":"http:\/\/thaylin.info\/blog\/?p=43"},"modified":"2009-02-11T13:53:04","modified_gmt":"2009-02-11T18:53:04","slug":"pulling-in-mp3-library-folder","status":"publish","type":"post","link":"https:\/\/www.thaylin.com\/blog\/2008\/10\/27\/pulling-in-mp3-library-folder\/","title":{"rendered":"Pulling in mp3 library folder"},"content":{"rendered":"<p>So I have a client who wanted to have mp3&#8217;s that the user could listen to and also download. Since I&#8217;m very against having to constantly manage a clients content I wanted him to be able to have no problem adding and removing mp3 files. Normally, one might have an xml file that the user can update but that&#8217;s to prone to fail on the side of the client. So what to do&#8230;<\/p>\n<p><a href=\"http:\/\/getid3.sourceforge.net\/\">Enter getId3<\/a>. This is a super handy tool for anyone who would want to retrieve data about mp3 files via php. Granted, php isn&#8217;t that fastest and I have yet to test the speed of retrieval on a large scale, but as of now it seems to be a superb way to automatically generate my listing of mp3 files along with the data attributed to them.<\/p>\n<p>Here is my php file I created to give you an idea of what it can do:<\/p>\n<pre lang=\"php\" line=\"1\" colla=\"+\">\r\nrequire_once('..\/..\/..\/getid3\/getid3\/getid3.php');\r\n\r\necho \"\\n\\n\";\r\n\r\n\/\/ include getID3() library (can be in a different directory if full path is specified)\r\n\r\n\/\/ Initialize getID3 engine\r\n$getID3 = new getID3;\r\n\r\n$DirectoryToScan = '..\/mp3'; \/\/ change to whatever directory you want to scan\r\n$dir = opendir($DirectoryToScan);\r\n\r\nwhile (($file = readdir($dir)) !== false ) {\r\n$FullFileName = realpath($DirectoryToScan.'\/'.$file);\r\nif (is_file($FullFileName)) {\r\n set_time_limit(30);\r\n\r\n $ThisFileInfo = $getID3-&gt;analyze($FullFileName);\r\n\r\n getid3_lib::CopyTagsToComments($ThisFileInfo);\r\n\r\n \/\/ output desired information in whatever format you want\r\n echo \"\\t\\n\";\r\n  echo \"\\t\\t\\n\";\r\n  echo \"\\t\\t\\n\";\r\n  echo \"\\t\\t\\n\";\r\n\r\n echo \"\\t\\n\";\r\n}\r\n}\r\necho \"\\n\";<\/pre>\n<p>And here is my result<\/p>\n<pre lang=\"xml\" line=\"1\" colla=\"+\">\r\n<music>\r\n<song url=\"bobSong.mp3\" length = \"3:50\" bitrate = \"160 kbps\">\r\n<songartist><![CDATA[Bob]]><\/songartist>\r\n<songtitle><![CDATA[Bobs awesome song]]><\/songtitle>\r\n<songalbum><![CDATA[Bobs Awesome Album]]><\/songalbum>\r\n<\/song>\r\n<song url=\"bobSongTwo.mp3\" length = \"3:50\" bitrate = \"160 kbps\">\r\n<songartist><![CDATA[Bob]]><\/songartist>\r\n<songtitle><![CDATA[Bobs awesome remix]]><\/songtitle>\r\n<songalbum><![CDATA[Bobs Awesome Album]]><\/songalbum>\r\n<\/song>\r\n<\/music>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>So I have a client who wanted to have mp3&#8217;s that the user could listen to and also download. Since I&#8217;m very against having to constantly manage a clients content I wanted him to be able to have no problem adding and removing mp3 files. Normally, one might have an xml file that the user [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[6],"tags":[32,31],"_links":{"self":[{"href":"https:\/\/www.thaylin.com\/blog\/wp-json\/wp\/v2\/posts\/43"}],"collection":[{"href":"https:\/\/www.thaylin.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.thaylin.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.thaylin.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.thaylin.com\/blog\/wp-json\/wp\/v2\/comments?post=43"}],"version-history":[{"count":13,"href":"https:\/\/www.thaylin.com\/blog\/wp-json\/wp\/v2\/posts\/43\/revisions"}],"predecessor-version":[{"id":134,"href":"https:\/\/www.thaylin.com\/blog\/wp-json\/wp\/v2\/posts\/43\/revisions\/134"}],"wp:attachment":[{"href":"https:\/\/www.thaylin.com\/blog\/wp-json\/wp\/v2\/media?parent=43"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thaylin.com\/blog\/wp-json\/wp\/v2\/categories?post=43"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thaylin.com\/blog\/wp-json\/wp\/v2\/tags?post=43"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}