Hi All! I wrote this today as a quickie fix for an easy problem. I have this directory full of directories for mp3 files. I wanted to be able to browse using a remote media player and play an entire album. The script below goes into each directory and generates an m3u file for that directory. (Will not generate an m3u if no mp3 files are present.) It's quick and dirty, but very useful if you have this same problem.

#!/usr/bin/perl -w use strict; use File::Find::Rule; # Change this next line to reflect your mp3 directory my @dirs_only = File::Find::Rule->directory()->in('/steeler/mp3'); foreach( @dirs_only ) { my $dir = $_; chdir( "$dir" ); chomp( my @files = `ls` ); my $files = `ls`; if (( $files =~ /\.mp3$/ ) or ( $files =~ /\.MP3$/ )) { my $current_dir = `pwd`; my $basename = `basename \"$current_dir\"`; $basename =~ s/\s//g; $basename =~ s/'//g; $basename =~ s/\.//g; my $m3u_file = "$basename".'.m3u'; print "Creating m3u file: $m3u_file\n"; open M3U, ">$m3u_file"; foreach( @files ){ print M3U "$_\n"; } close M3U; } }

This script assumes you are running on a unixy-type system, I'm sure some of those shelled-out commands won't work on windows.


In reply to Generate m3u files automatically by rementis

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.