Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SCRIPTS] PHP Auto-generated playlists (.m3u)
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message
beandog
Developer
Developer


Joined: 04 May 2003
Posts: 2063
Location: /usa/utah

PostPosted: Sun Jan 11, 2004 12:21 am    Post subject: [SCRIPTS] PHP Auto-generated playlists (.m3u) Reply with quote

What this does, along with fapg, is creates playlist files for all your album directories. So if you have "~/music/oggs/Enya - Watermark" it will create "~/music/Enya - Watermark.m3u"

First, download and install fapg.

Code:

wget http://royale.zerezo.com/fapg/fapg-0.1.tar.gz
tar -zxvf fapg-0.1.tar.gz
cd fapg-0.1
sudo make && make install


Second, copy this code and save it as m3u.php wherever you like.

Code:
#!/usr/bin/php
<?
    // Depending on your directory scheme for your music files, you'll have to change the music_dir variable
       
    $music_dir="/home/steve/music/oggs";
   chdir($music_dir);
   exec("rm *.m3u");
   
    $dir=opendir($music_dir);
      
    while($file=readdir($dir)) {
        if($file!="." && $file !="..") {
         $m3u=$file;
         $file=addslashes($file);
         $file=str_replace(" ","\ ",$file);
         $file=str_replace("(","\(",$file);
         $file=str_replace(")","\)",$file);
         $file=str_replace("&","\&",$file);

         system("/usr/local/bin/fapg --format=m3u ".$music_dir."/".$file." > \"$music_dir/../".$m3u.".m3u\"");
        }
      }
   
   closedir($dir);
   
?>


Third, from the command line, run:

Code:

php m3u.php


Last, try it out! :)

Code:

xmms "Enya - Watermark.m3u"


A few things to know about:
- It deletes all your existing .m3u files
- fapg can also create .pls and .html files. See fapg --help
- Depending on the names of your .ogg files, you may have to add more str_replace lines.[/b]

(I originally had a PHP CLI script that would search your ~/music directory, which was ported from Windows -> Gentoo, but for some reason wouldn't sort the files alphabetically. I tried figuring it out, but gave up and started using this instead: fapg Here's a PHP frontend for it though. It runs a little slower than my php script did, but hey .. it works.)
_________________
If it ain't broke, tweak it. packages | dvds | blurays | blog | wiki


Last edited by beandog on Thu May 06, 2004 1:36 pm; edited 1 time in total
Back to top
View user's profile Send private message
beandog
Developer
Developer


Joined: 04 May 2003
Posts: 2063
Location: /usa/utah

PostPosted: Tue Jan 13, 2004 7:50 pm    Post subject: Reply with quote

Thanks to Dennis Nienhüser for making an ebuild for fapg:

Code:
# Distributed under the terms of the GNU General Public License v2

S="${WORKDIR}/${P}"
DESCRIPTION="FAPG, the Fast Audio Playlist Generator"
HOMEPAGE="http://royale.zerezo.com/fapg/"
SRC_URI="http://royale.zerezo.com/fapg/${P}.tar.gz"

SLOT="0"
LICENSE="GPL-2"
KEYWORDS="~x86"

src_compile() {
   emake || die "Error during compiling."
}

src_install () {
   dodir /usr/bin
   dodir /usr/share/man/man1
   
   exeinto /usr/bin
   doexe fapg

   dodoc COPYING README
}
[/code]
_________________
If it ain't broke, tweak it. packages | dvds | blurays | blog | wiki
Back to top
View user's profile Send private message
beandog
Developer
Developer


Joined: 04 May 2003
Posts: 2063
Location: /usa/utah

PostPosted: Thu May 06, 2004 3:44 am    Post subject: Reply with quote

I've been meaning to rewrite this thing for ages .. here it is, in pure php + pear. You'll need File and File_Find pear packages installed / included to use it:

Code:

<?
   # settings
   $music_dir = '/home/steve/music/oggs';
   $playlist_dir = '/home/steve/music';
   $music_format = 'ogg';
   $playlist_format = 'm3u';
   
   require("File.php");
   require("File/Find.php");

   $file_find = new File_Find();
   $file = new File();

   chdir($playlist_dir);
   echo exec("rm *.".$playlist_format);

   $dir = $file_find->maptree($music_dir);

   $albums = $dir[0];

   array_shift($albums);   
   sort($albums);
   $albums = str_replace($music_dir."/","",$albums);

   foreach($albums as $key=>$value) {
      $grep = preg_grep("/".$albums[$key]."/",$dir[1]);
      sort($grep);
      #print_r($grep);
      $new_value = str_replace(" ","_",$value);
      foreach($grep as $key1=>$value1) {
         if( substr($value1, -3, 3) == $music_format )
            $file->writeLine($playlist_dir."/".$new_value.".m3u", $value1, FILE_MODE_APPEND);
      }
   }
?>

_________________
If it ain't broke, tweak it. packages | dvds | blurays | blog | wiki
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum