Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

I know mpg123 has the ability to play files according to a playlist, however after reading the manpage I wasn't ever really able to figure it out. I became fed up with have to play my songs individually one after the other in the terminal, and when my mpg123 * became insufficient I decided to write something that would achieve playlist parsing.

So, I wrote Music_System. Yes, I know its misleading, since it doesn't actually play anything. Really, it just uses regex to parse a text file and plays the files accordingly. Then, it uses the find utility to find the appropriate files and plays them accordingly via mpg123.

To do list: Long Term: a. I just recently discovered the SDL library modules on cpan. I would like to use the audio player to make this an independant audio player capable of playing more than mpeg layers 1, 2, and 3 -- mpg123's primary purpose. Short Term: a. Now that I have mastered ARGV use, I will make use of arguments to be able to specify the music directory to search in, as opposed to hardcoding it as I have currently done. I can implement this easily, and should have that done in a day or two. b. Also, when I used windows I was hooked on foobar2000. I really liked the internal DB it created to sort your music through. Now, I know plenty of players already do this, but I think it would make a good experiment to be able to parse the directory and create an internal hash db based off of the tags. Not quite sure how I'll accomplish this though, since the tags will have to be multi-dimensional. May just stick to multi dimensional arrays. This was posted for my friends to review, and also for dams at Insomnia (to prove I am actually doing something :p ).

Please don't laugh!

#!/usr/bin/perl # # # Music System # Diego Z Pineda # July 2013 # use strict; use warnings; sub nl () { print "\n"; print "\n" } sub clrw { chomp $_[0]; $_[0] =~ s/ +$// } my $file = $ARGV[0]; open (my $in, "<", "$file") or die "Can't open input-file: $!"; my @array_in; my @array_out; my @dpath; while (<$in>) { push @array_in, $_ } my $aii = $#array_in; my $iai = $aii + 1; for (my $i=0; $i<$iai; $i++) { my $t1 = "$array_in[$i]"; if ($t1 =~ s/^\# [0-9]+. //) { chomp $t1; $t1 =~ s/ $//; push @array_out, $t1 }} # chopmping all elements being pushed to array_out # will allow shell command to be evaluated. my $aoi = $#array_out; my $iao = $aoi + 1; my $p_dir = '/home/slug/Music'; my $m_dir; my $m_dir_pre = "$array_in[1]"; if ($m_dir_pre =~ s/^\# //) { $m_dir = $m_dir_pre } my $dir = "$p_dir/$m_dir"; clrw $dir; for (my $i=0; $i<$iao; $i++) { my $t1 = qx[find $dir -iname "*$array_out[$i].mp3*"]; chomp $t1; if ($t1 =~ m/\n/) { chomp $t1; my ($s1, $s2) = split('\n', "$t1"); clrw $s1; clrw $s2; push @dpath, $s1; push @dpath, $s2 } else { clrw $t1; push @dpath, $t1 }} my $dpi = $#dpath; my $idp = $dpi + 1; for (my $i=0; $i<$idp; $i++) { my $prog = 'mpg123'; my @args = ("$prog", '--cpu', 'SSE', "$dpath[$i]"); system(@args) == 0 or die "System args failed: $?" }

So, you take a playlist made with your favorite editor (mine is vim), and follow the given format. Note, because the player uses find, it will search the files for you. (A true playlist, so you don't have to add the file-list paths.. that would be bullshit.) It will also add multiple hits into the playlist! (Some push action for ya.)

# This is a tracklist for my # Deftones # Mix Playlist #1 # July 2013 # # 1. Diamond Eyes # 2. My Own Summer # 3. CMND_CTRL # 4. 7 Words # 5. Hexagram # 6. Minerva # 7. Knife Party # 8. Rocket Skates # 9. Royal # 10. Passenger (feat. Maynard James Keenan) # 11. Change (In The House Of Flies) # 12. Sextape

In reply to Playlist parser for mpg123 by slugman

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (5)
    As of 2018-06-20 23:37 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (117 votes). Check out past polls.