- #!/usr/bin/perl
- use 5.14.0;
- use strict;
- use warnings;
- use diagnostics;
- use threads::shared;
- use Thread::Queue;
- my $total :shared = 0;
- my $disk_size = 1000000000;
- my @dirs;
- my %pcm :shared;
- my @opts = ('-q 0', '-V 2', '--silent', '--id3v2-only');
- my $q = Thread::Queue->new();
- if (!$ARGV[0] || ! -d $ARGV[0]) {
- say "Usage: " . basename($0) . " [FLAC directory]";
- exit;
- }
- foreach my $arg (@ARGV) {
- my $src = abs_path($arg);
- if (-d $src) {
- getdirs($src);
- }
- }
- sub gettags {
- my (%alltags, @mflac);
- foreach (@mflac) {
- if ($alltags{$tagname}) { next; }
- elsif ($tag[1]) {
- $alltags{$tagname} = $tag[1];
- } else {
- $alltags{$tagname} = 'null';
- }
- }
- }
- sub getdirs {
- }
- sub getfiles {
- my @files;
- my $fn = "$dn/$_";
- if (/.flac$/ && -f $fn) {
- }
- }
- }
- sub name {
- my %t = gettags($fn);
- my $tref = \%t;
- my $dest;
- checktags($fn, $tref);
- my @clean = ( $t{albumartist}, $t{album}, $t{discnumber}, $t{tracknumber}, $t{title} );
- $clean[$n] =~ s/[[:punct:]]*[()]*//g;
- }
- my @dest = ('home', 'sir', 'lame', $clean[0], $clean[1]);
- $newfn = $dest . $newfn;
- }
- sub decode {
- lock($total);
- }
- sub checktags {
- my %t = %{$tref};
- foreach my $tag ('discnumber', 'albumartist', 'album', 'tracknumber', 'title') {
- if (! $t{$tag}) {
- say "${fn}: missing '$tag' tag.";
- exit;
- }
- }
- }
- #say "Starting threads...";
- my @threads;
- for my $i (1..4) {
- }
- sub lame {
- my $started = 0;
- while ($q->pending() == 0 && $started == 0) {
- yield();
- next;
- }
- $started++;
- my $tid = threads->tid();
- while (my $fn = $q->dequeue_nb()) {
- my $oldfn = $fn;
- my ($newfn, $tref) = name($fn);
- my %t = %{$tref};
- foreach my $tag ('artist', 'title', 'album', 'tracknumber', 'date') {
- if ($t{$tag}) {
- given($tag) {
- when ('artist') {
- }
- when ('title') {
- }
- when ('album') {
- }
- when ('tracknumber') {
- }
- when ('date') {
- $t{date} =~ /[0-9]{4}/;
- }
- }
- }
- }
- say "thread${tid} ${fn}: encoding...";
- lock(%pcm);
- lock($total);
- }
- }
- my @files = getfiles($dn);
- my $album_size = 0;
- next;
- }
- # Check the size of the album to make more informed
- # decisions on when to yield in the next loop
- foreach my $fn (@files) {
- $album_size += $stat[7];
- }
- #say "\nDecoding files and storing in RAM...\n";
- foreach my $fn (@files) {
- until ($total < $disk_size) {
- yield();
- }
- DECODE: decode($fn);
- }
- #say "\nEncoding PCM data to LAME MP3...\n";
- #say "Enqueueing files";
- foreach my $fn (@files) {
- $q->enqueue($fn);
- }
- }
- say "All threads joined";
flac2lame perl script threaded
Posted by Anonymous on Tue 11th Sep 2012 01:04
raw | new post
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.
kpaste.net RSS