#!/usr/bin/perl # # # Music System # Diego Z Pineda # July 2013 # dzpineda86@gmail.com 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: $?" }