#!/usr/bin/php
(.*?)
@';
preg_match_all($pattern, $page, $matches=array());
if(empty($matches[0])){
echo "No matches found!\n";
exit;
}
$songs = array();
foreach($matches[1] as $i=>$title){
$relative_url = $matches[2][$i];
$full_url = "http://".$url['host'].$relative_url;
$type = $matches[3][$i];
$filename = substr($relative_url, strrpos($relative_url, '/')+1);
array_push($songs, array('title'=>$title, 'url'=>$full_url, 'type'=>$type, 'filename'=>$filename));
}
$pattern ='@Band/Artist: (.*?)@';
preg_match($pattern, $page, $matches);
$artist = $matches[1];
$pattern = '@Venue: (.*?)@';
preg_match($pattern, $page, $matches);
$venue = $matches[1];
$pattern = '@Date: (.*?)@';
preg_match($pattern, $page, $matches);
$date = $matches[1];
$album = "Live at $venue ($date)";
$i=1;
foreach($songs as $song){
echo "Fetching {$song['title']} - {$song['url']}\n";
echo 'wget '.$song['url']."\n";
exec('wget '.$song['url']);
if(!is_file($song['filename'])){
echo "{$song['filename']} didn't fetch correctly!\n";
continue;
}
if($song['type']=='flac'){
$new_filename = str_replace(".flac", ".wav", $song['filename']);
echo "Converting {$song['filename']} from FLAC to WAV\n";
exec('flac -do '.$new_filename.' '.$song['filename']);
if(!is_file($new_filename)){
echo "{$song['filename']} didn't convert correctly\n";
continue;
}
echo "Removing .flac file for $new_filename\n";
exec('rm '.$song['filename']);
$song['type']='wav';
$song['filename']= $new_filename;
}
if($song['type']=='shn'){
$new_filename = str_replace(".shn", ".wav", $song['filename']);
echo "Converting {$song['filename']} from Shorten to WAV\n";
exec('shorten -x '.$song['filename'].' '.$new_filename);
if(!is_file($new_filename)){
echo "{$song['filename']} didn't convert correctly\n";
continue;
}
echo "Removing .shn file for $new_filename\n";
exec('rm '.$song['filename']);
$song['type']='wav';
$song['filename']= $new_filename;
}
if($song['type']=='wav'){
$new_filename = str_replace(".wav", ".mp3", $song['filename']);
echo "Converting {$song['filename']} from WAV to MP3\n";
echo "lame -v --id3v2-only --tt \"{$song['title']}\" --ta \"$artist\" --tl \"$album\" --tn $i {$song['filename']} $new_filename\n";
exec("lame -v --id3v2-only --tt \"{$song['title']}\" --ta \"$artist\" --tl \"$album\" --tn $i {$song['filename']} $new_filename");
if(!is_file($new_filename)){
echo "{$song['filename']} didn't convert correctly\n";
continue;
}
echo "Removing .wav file for $new_filename\n";
exec('rm '.$song['filename']);
}
$i++;
}
$time = time()-$start;
echo "Operation took ".floor($time/60)." minutes, ".floor($time%60)." seconds\n";
?>
|