This commit is contained in:
luk.lu
2021-06-07 10:03:42 +08:00
parent be14f64242
commit 7f0bf14e13
57 changed files with 1592 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
#!C:/Perl/bin/perl
if ($#ARGV==-1) {
printf "Usage: align.pl binary_alignment_filename\n";
exit (0);
};
system ("align_info -labels %SWISRSDK%/config/en.sg/models/SpeechPearl.hmmlabels $ARGV[0] > $ARGV[0].txt");
printf ("$ARGV[0] -> $ARGV[0].txt\n");
open(BINARY_ALIGN, "$ARGV[0].txt") or die "Cannot open file $ARGV[0].txt";
$count=1;
while(<BINARY_ALIGN>){
s/\s+$//;
if(/^uttname: $1/){
close FD;
$lola = sprintf("alignments_%d.txt", $count++);
print "$' => $lola\n";
open(FD, ">$lola") || die "cannot open $lola";
printf FD "$'\n";
printf FD "MillisecondsPerFrame: 10\nEND OF HEADER\n";
printf FD "start end phoneme score -sscore score/msec\n";
$total_score=0;
} elsif (/^ortho: /){
printf FD "$'\n";
} elsif(/^ label index (.*)/){
$label=$1;
} elsif (/^ model score (.*)/){
$score=$1;
$total_score += $score;
} elsif (/^ from time (.*)/){
$from_time=$1;
} elsif (/^ to time (.*)/){
$to_time=$1;
} elsif (/^ segment type (.*)/){
if (0){
next if $from_time == $to_time;
printf FD "%5.3f %5.3f %-20s %10.2f %10.2f %.2f\n", $from_time*100, $to_time*100, $label,$score, -$total_score, $score/($to_time -$from_time)/100;
} else {
$dscore = ($to_time==$from_time) ? 0 : $score/($to_time -$from_time)/1000;
printf FD "%5.3f %5.3f %-20s %10.2f %10.2f %.2f\n", $from_time, $to_time, $label,$score, -$total_score, $dscore;
}
}
}
exit 0;

View File

@@ -0,0 +1,22 @@
if ($ARGV[0] =~ m|^\s*$|)
{
print "Check existence of listed sound files.\n";
print "Usage: perl $0 FILE_LIST\n";
print "Example: perl $0 corpus.list\n";
exit 0;
}
open LIST, "$ARGV[0]" or die;
open REPORT, ">$ARGV[0].inexistent" or die;
while (<LIST>)
{
if (m|\s*([^\s]+\.(ulaw\|wav))\s*|)
{
if (not (-e $1))
{
print REPORT "$1\n";
}
}
}

View File

@@ -0,0 +1,21 @@
open(SUM, "$ARGV[0]");
open(EXCEL, ">". "$ARGV[0].excel");
if ($ARGV[0] eq '')
{
print "Converting summary file $ARGV[0] to excel format.\n";
print "Usage: perl $0 SUMMARY_FILE\n";
exit;
}
while(<SUM>)
{
chomp($_);
$_ =~ s/^ +//g;
$_ =~ s/ +$//g;
$_ =~ s/ +/ /g;
$_ =~ s/ /\t/g;
$_ =~ s/%//g;
print EXCEL $_."\n";
}

View File

@@ -0,0 +1,62 @@
$scriptfile = $ARGV[0];
open (SCR, $scriptfile);
while(<SCR>)
{
chomp($_);
$_ =~ s/ +$//;
$startwriting = 0;
if(($_ =~ /^recognize/)&&($_ =~ /\.wav/))
{
@parts = split(/ /, $_);
$soundFile = $parts[1];
open(WAV,$soundFile) || next;
# die "cannot open $soundFile: $1";
# open(WAV,$soundFile) || die;
binmode WAV;
# get first 4 Bytes
read WAV,$rawstring, 4;
$signature = unpack("a4",$rawstring);
if ($signature eq "NIST")
{
print "$soundFile has a sphere header and is converted to ulaw!\n";
$input = $soundFile;
$input_base = substr($input, 0 ,-4);
open (INPUT, $input);
binmode INPUT;
while ($line = <INPUT>)
{
if($startwriting == 1)
{
$line =~ s/^ +//; #remove rest of header (spaces)
$startwriting = 2;
$output = $input_base . ".". $ext;
open(OUTPUT, ">". $output) or die;
binmode OUTPUT;
}
elsif($startwriting == 2)
{
print OUTPUT $line;
}
elsif($line =~ /end_head/)
{
$startwriting = 1; #read lines until end_head statement is found.
}
else
{
if($line =~ /s4 alaw/)
{
$ext = "alaw";
print $ext."\n";
}
elsif($line =~ /s4 ulaw/)
{
$ext = "ulaw";
print $ext."\n";
}
}
}
}
}
}

View File

@@ -0,0 +1,27 @@
#!/bin/csh
if ("$1" == '') then
echo "Please enter the first absolute path with file prefix:"
set first=$<
else
set first=$1
endif
if ("$2" == '') then
echo "Please enter the second absolute path with file prefix:"
set second=$<
else
set second=$2
endif
if ("$3" == '') then
echo "Please enter the absolute path with file prefix of diff results:"
set diff=$<
else
set diff=$3
endif
perl /users/llu/scratch/OSR_accuracy/diff_osr_sum.pl $first.sum $second.sum >! $diff.sum
echo "$first.sum vs. $second.sum => $diff.sum"
perl /users/llu/scratch/OSR_accuracy/diff_osr_wer.pl $first.wer $second.wer >! $diff.wer
echo "$first.wer vs. $second.wer => $diff.wer"

View File

@@ -0,0 +1,31 @@
use File::Find;
use File::Copy;
@files = glob "$ARGV[0]/*";
open XML, ">Favorites.html" or die;
#print XML "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n<resource>\n";
foreach $file (@files)
{
if (-f $file)
{
open URL, "$file" or die;
$url = '';
while (<URL>)
{
if (m|URL=(.*)|)
{
$url = $1;
last;
}
}
$file =~ s|Favorites/||;
$file =~ s|\.url||;
$url =~ s|&|&amp;|g;
print XML "<a href=\"$url\">$file</a><br>\n";
close URL;
}
}
#print XML "</resource>\n</xml>\n";

View File

@@ -0,0 +1,25 @@
print "Usage: perl $0 transcription_file path_prefix output_file\n";
print "Example: perl $0 /direct/datadigest/en_sg/ives/000.txt /direct/datadigest/en_sg/ives/calls/ ~/ives.list\n";
open TRAN, $ARGV[0] or die "Cannot open transcription file $ARGV[0] for read.\n";
open CORPUS, ">>$ARGV[2]" or die "Cannot open corpus file $ARGV[1] for write.\n";
if ($ARGV[1] =~ m|/$|) # the parameter "path_prefix" is ended with /
{
$prefix = $ARGV[1];
}else
{
$prefix = "$ARGV[1]/";
}
while (<TRAN>)
{
chomp;
m|([^ ]+)\s+(.*)|;
if ($1 =~ m|\.info$|)
{
print CORPUS "new_speaker\n";
next;
}
print CORPUS "$prefix$1.ulaw\t$2\n";
}

View File

@@ -0,0 +1,35 @@
print "Usage: perl $0 transcription_dir path_prefix output_file\n";
print "Example: perl $0 /direct/datadigest/read_English_SG/gitm/transcription /direct/datadigest/read_English_SG/gitm/calls/ ~/gitm.list\n";
use File::Find;
use File::Copy;
open CORPUS, ">$ARGV[2]" or die "Cannot open corpus file $ARGV[1] for write.\n";
if ($ARGV[1] =~ m|/$|) # the parameter "path_prefix" is ended with /
{
$prefix = $ARGV[1];
}else
{
$prefix = "$ARGV[1]/";
}
@dirs = ($ARGV[0]);
find ( {wanted => \&wanted},
@dirs );
sub wanted
{
if (m|^([a-zA-Z0-9_]+)_(utt\d+)\.words$|)
{
$folder = $1;
$utt = $2;
$folder =~ m|^[A-Za-z]+(\d\d\d)|;
$group = $1; # usually it's 000, but not always. So $group need be extracted.
open WORDS, "$_" or die "Cannot open words file $_\n";
$words = <WORDS>;
chomp ($words);
print CORPUS "$prefix$group/$folder/${folder}_${utt}.ulaw\t$words\n";
}
}

View File

@@ -0,0 +1,2 @@
set TCLLIBPATH=C:/Programs/Lyre/tclpkg
C:/Programs/Lyre/bin/wish80.exe C:/Programs/Lyre/bin/lyre.tcl %1 %2 %3 %4 %5

View File

@@ -0,0 +1,3 @@
set TCLLIBPATH=C:/Programs/Lyre/tclpkg
C:/Programs/Lyre/bin/wish80.exe C:/Programs/Lyre/bin/lyrepipe.tcl

View File

@@ -0,0 +1,3 @@
set TCLLIBPATH=C:/Programs/Lyre/tclpkg
C:/Programs/Lyre/bin/wish80.exe C:/Programs/Lyre/bin/lyre.tcl C:/Programs/Lyre/examples/126-20040812084228.ulaw --l C:/Programs/Lyre/examples/126-20040812084228.1 --l C:/Programs/Lyre/examples/126-20040812084228.0

View File

@@ -0,0 +1,29 @@
#!/bin/csh
echo "Usage: source nacc_summary.csh lg.co 1st_result_set [2nd_result_set]"
setenv OSRACCDIR /scratch/res/work/Quantum/llu/nacc
setenv CFG $OSRACCDIR/$1/cfg/BASELINE.cfg
perl $OSRACCDIR/script/summarize_proton.pl -printinvocab -normalizeCpu -runtest proton -useGroup proton -meanByTestset -config $CFG -output $2/summary.proton proton $2 > /dev/null; perl ~/bin/tools/convert_summary_for_excel.pl $2/summary.proton
echo Generated $2/summary.proton
perl $OSRACCDIR/script/proton_wer.pl -printinvocab -normalizeCpu -runtest proton -useGroup proton -meanByTestset -config $CFG -output $2/summary.wer proton $2 > /dev/null; perl ~/bin/tools/convert_summary_for_excel.pl $2/summary.wer
echo Generated $2/summary.wer
# for variable $3, it doesn't work to use $?3 for test existence.
if ($3 != '') then
perl $OSRACCDIR/script/summarize_proton.pl -printinvocab -normalizeCpu -runtest proton -useGroup proton -meanByTestset -config $CFG -output $3/summary.proton proton $3 > /dev/null; perl ~/bin/tools/convert_summary_for_excel.pl $3/summary.proton
echo Generated $3/summary.proton
perl $OSRACCDIR/script/proton_wer.pl -printinvocab -normalizeCpu -runtest proton -useGroup proton -meanByTestset -config $CFG -output $3/summary.wer proton $3 > /dev/null; perl ~/bin/tools/convert_summary_for_excel.pl $3/summary.wer
echo Generated $3/summary.wer
perl $OSRACCDIR/script/summarize_proton.pl -printinvocab -normalizeCpu -runtest proton -useGroup proton -meanByTestset -config $CFG -output ./compare.summary.proton proton1 $2 proton2 $3 > /dev/null; perl ~/bin/tools/convert_summary_for_excel.pl ./compare.summary.proton
echo Generated ./compare.summary.proton
perl $OSRACCDIR/script/proton_wer.pl -printinvocab -normalizeCpu -runtest proton -useGroup proton -meanByTestset -config $CFG -output ./compare.summary.wer proton1 $2 proton2 $3 > /dev/null; perl ~/bin/tools/convert_summary_for_excel.pl ./compare.summary.wer
echo Generated ./compare.summary.wer
perl $OSRACCDIR/script/diff_osr_sum.pl $2/summary.proton $3/summary.proton >! ./diff.summary; perl ~/bin/tools/convert_summary_for_excel.pl ./diff.summary
echo "Generated ./diff.summary from $2 vs $3 /summary.proton"
perl $OSRACCDIR/script/diff_osr_wer.pl $2/summary.wer $3/summary.wer >! ./diff.wer; perl ~/bin/tools/convert_summary_for_excel.pl ./diff.wer
echo "Generated ./diff.wer from $2 vs $3 /summary.wer"
endif

View File

@@ -0,0 +1,29 @@
#!/bin/bash
echo "Usage: source nacc_summary.csh 1st_result_set [2nd_result_set]"
export LLUNACCDIR=/scratch/res/work/Quantum/llu/nacc
export LLUCFG=/scratch/res/work/Quantum/llu/nacc/zh.tw/cfg/BASELINE.cfg
perl $LLUNACCDIR/script/summarize_proton.pl -printinvocab -normalizeCpu -runtest proton -useGroup proton -meanByTestset -config $LLUCFG -output $1/summary.proton proton $1 > /dev/null; perl ~/bin/tools/convert_summary_for_excel.pl $1/summary.proton
echo Generated $1/summary.proton
perl $LLUNACCDIR/script/proton_wer.pl -printinvocab -normalizeCpu -runtest proton -useGroup proton -meanByTestset -config $LLUCFG -output $1/summary.wer proton $1 > /dev/null; perl ~/bin/tools/convert_summary_for_excel.pl $1/summary.wer
echo Generated $1/summary.wer
if [ ! -z "$2" ]
then
perl $LLUNACCDIR/script/summarize_proton.pl -printinvocab -normalizeCpu -runtest proton -useGroup proton -meanByTestset -config $LLUCFG -output $2/summary.proton proton $2 > /dev/null; perl ~/bin/tools/convert_summary_for_excel.pl $2/summary.proton
echo Generated $2/summary.proton
perl $LLUNACCDIR/script/proton_wer.pl -printinvocab -normalizeCpu -runtest proton -useGroup proton -meanByTestset -config $LLUCFG -output $2/summary.wer proton $2 > /dev/null; perl ~/bin/tools/convert_summary_for_excel.pl $2/summary.wer
echo Generated $2/summary.wer
perl $LLUNACCDIR/script/summarize_proton.pl -printinvocab -normalizeCpu -runtest proton -useGroup proton -meanByTestset -config $LLUCFG -output ./compare.summary.proton proton1 $1 proton2 $2 > /dev/null; perl ~/bin/tools/convert_summary_for_excel.pl ./compare.summary.proton
echo Generated ./compare.summary.proton
perl $LLUNACCDIR/script/proton_wer.pl -printinvocab -normalizeCpu -runtest proton -useGroup proton -meanByTestset -config $LLUCFG -output ./compare.summary.wer proton1 $1 proton2 $2 >/dev/null; perl ~/bin/tools/convert_summary_for_excel.pl ./compare.summary.wer
echo Generated ./compare.summary.wer
perl $LLUNACCDIR/script/diff_osr_sum.pl $1/summary.proton $2/summary.proton >! ./diff.summary; perl ~/bin/tools/convert_summary_for_excel.pl ./diff.summary
echo "Generated ./diff.summary from $1 vs $2 /summary.proton"
perl $LLUNACCDIR/script/diff_osr_wer.pl $1/summary.wer $2/summary.wer >! ./diff.wer; perl ~/bin/tools/convert_summary_for_excel.pl ./diff.wer
echo "Generated ./diff.wer from $1 vs $2 /summary.wer"
fi

View File

@@ -0,0 +1,84 @@
#####################################################################################################################################
# Script to remove DM-related tokens that cause log not to load into OSI due to max nested levels.
# The SWIdmst and SWIphnd tokens will be replaced with SWIprst to print the relevant information
#####################################################################################################################################
#!/usr/bin/perl -w
use strict;
use Getopt::Long;
my ($help, $inputfile, $outputfile);
GetOptions ('-help' => \$help,
'-h' => \$help,
'-input=s' => \$inputfile,
'-output=s' => \$outputfile
);
if ($help) {
die("\nUsage: perl $0 [-help] -input <i/p file> -output <o/p file> \n"); }
if ($inputfile eq "" || $outputfile eq "" ) {
die("\nUsage: perl $0 [-help] -input <i/p file> -output <o/p file> \n"); }
open( INPUT_FILE, "< $inputfile" ) #open input file for reading;
or die( "Cannot open input file \"$inputfile\" : $!" );
open( OUTPUT_FILE, ">$outputfile" ) #open output file for writing;
or die( "Cannot open output file \"$outputfile\" : $!");
#my $type = "APNM";
#my $channum = "";
#my $orgchantext = "phone.-1.mps.-1.chan";
while ( my $string = <INPUT_FILE> ) {
chomp($string);
# my $outputstring = $string;
# Replace the Problematic SWIdmst and SWIdmnd with SWIprst to print the relevant information
if ( $string =~ m/SWIdmst/ || $string =~ m/SWIdmnd/
|| $string =~ m/SWIphst/ || $string =~ m/SWIphnd/
|| $string =~ m/SWIstst/ || $string =~ m/SWIstnd/) {
# print ("$string\n" );
# SWIdmst
if ( $string =~ m/SWIdmst/ ) {
$string =~ s/SWIdmst/SWIprst/;
$string =~ s/DMTP=/PRNM=<DMTP>/;
$string =~ s/DMNM=/PRTX=<DMNM>/;
print (OUTPUT_FILE "$string\n" );
}
# SWIphnd - use this instead of SWIdmnd since it has HYPO of DTMF
if ( $string =~ m/SWIphnd/ ) {
$string =~ s/SWIphnd/SWIprst/;
$string =~ s/TSTT=/PRNM=<TSTT>/;
$string =~ s/MODE=/PRTX=<MODE=/;
my ($pre, $mid) = split( /\|UCPU/ , $string);
my ($pre1, $pre2) = split( /MODE/ , $pre);
$pre2 =~ s/\|/\!/g;
my $newstring = $pre1."MODE".$pre2.">|UCPU".$mid;
# my $newstring = $pre.">|UCPU".$mid;
print (OUTPUT_FILE "$newstring\n" );
}
# SWIdmnd
# if ( $string =~ m/SWIdmnd/ ) {
# $string =~ s/SWIdmnd/SWIprst/;
# $string =~ s/TSTT=/PRNM=<TSTT>/;
# $string =~ s/TRTT=/PRTX=<TRTT>/;
# print (OUTPUT_FILE "$string\n" );
# }
}
else {
print (OUTPUT_FILE "$string\n" );
}
#endif
} #end of WHILE;
#close the Input and Output files;
close( INPUT_FILE )
or die( "Cannot close \"$inputfile\" : $!" );
close( OUTPUT_FILE )
or die( "Cannot close \"$outputfile\" : $!" );
print "COMPLETE\n\n\n\n";
#####################################################################################################################################

View File

@@ -0,0 +1,32 @@
open SCRIPT, "$ARGV[0]" or die;
open XML, ">$ARGV[0].xml" or die;
print XML <<xmlhead;
<?xml version="1.0" encoding='UTF-8'?>
<grammar xml:lang="de-DE" version="1.0" root="_ROOT" xmlns="http://www.w3.org/2001/06/grammar">
<rule id="_ROOT" scope="public">
<ruleref uri="#ITEMS"/>
<tag>SWI_meaning = ITEMS.V;</tag>
</rule>
<rule id="ITEMS">
<one-of>
xmlhead
while (<SCRIPT>)
{
if (m|^transcription\s+(.*)\s*$|)
{
$items{$1} ++;
}
}
foreach $item (keys %items)
{
print XML " <item>$item<tag>V=\"$item\"</tag></item>\n";
}
print XML <<xmltail;
</one-of>
</rule>
</grammar>
xmltail

View File

@@ -0,0 +1,6 @@
#!/cygdrive/c/perl/bin/perl
# lyrepipe hangs if started by .bat file or without "start"
system ("start lyrepipe.bat");
system ("start C:/Programs/SpeechDebug/speechdebug.exe");

View File

@@ -0,0 +1,25 @@
open UTD, "$ARGV[0]" or die;
$nr_utt = 0;
$nr_block = 0;
$head = "";
while (<UTD>)
{
if (not m|/datadigest/|)
{
$head = $head."$_";
}else
{
if ($nr_utt % 500 == 0)
{
$nr_block ++;
open FH, ">$ARGV[0].$nr_block" or die;
print FH $head;
}
print FH;
$nr_utt ++;
}
}

View File

@@ -0,0 +1,32 @@
#!/bin/csh
# Example: ~/bin/tools/summaryize_accuracy.csh ~/OSR_accuracy/en.sg/results/20060418_osr309 ~/mysum309
if ("$1" == '') then
echo "Where is the evaluation results directory?"
echo -n "Please enter an absolute directory: "
set resdir=$<
else
set resdir=$1
endif
# You can enter a path with file name prefix,
# or just enter and the $resdir will be used by default.
if ("$2" == '') then
echo "Where to save summary files?"
echo -n "Please enter a absolute path with summary file prefix: "
set summary=$<
if ("$summary" == '') then
set summary=$resdir/summary
endif
else
set summary=$2
endif
# overall summary
cd /users/llu/scratch/OSR_accuracy/en.sg; perl ../summarize_proton.pl -normalizeCpu -printinvocab -useGroup proton -meanByWords -meanByTestset -geomMean test $resdir >! $summary.sum; echo Generated $summary.sum
# wer summary
cd /users/llu/scratch/OSR_accuracy/en.sg; perl ../proton_wer.pl -normalizeCpu -printinvocab -useGroup proton -meanByWords -geomMean test $resdir >! $summary.wer; echo Generated $summary.wer
perl ~/bin/tools/convert_summary_for_excel.pl $summary.sum; echo Generated $summary.sum.excel

View File

@@ -0,0 +1,27 @@
use File::Find;
use File::Copy;
if ($ARGV[0] =~ m|^\s*$|)
{
print "Traverse a directory recursively and list ulaw files.\n";
print "Usage: perl $0 TOP_DIR\n";
print "Example: perl $0 /bin\n";
exit 0;
}
@dirs = ($ARGV[0]);
open LIST, ">$ARGV[0].ulawlist" or die;
find ( {wanted => \&wanted},
@dirs );
sub wanted
{
if (m|^ulaw$|)
{
$file = $_;
# do something here.
print LIST "$file\n";
}
}

View File

@@ -0,0 +1,39 @@
use File::Find;
use File::Copy;
if ($ARGV[0] =~ m|^\s*$|)
{
print "Template to traverse a directory recursively.\n";
print "Usage: perl $0 TOP_DIR\n";
print "Example: perl $0 /bin\n";
exit 0;
}
@dirs = ($ARGV[0]);
open LOG, ">$ARGV[0]/SWIevent.log" or die;
$time='20060101000000000';
$defaultdm='Digits';
$grammar='digits.xml';
$language='en-GB';
$meaning='0';
$ortho='';
find ( {wanted => \&wanted},
@dirs );
sub wanted
{
if (/\.(ulaw|wav)$/)
{
$file = $_;
print LOG "TIME=$time|CHAN=0|EVNT=SWIclst|UCPU=0|SCPU=0\n";
print LOG "TIME=$time|CHAN=0|EVNT=SWIdmst|DMTP=CUST|DMNM=$defaultdm|UCPU=0|SCPU=0\n";
print LOG "TIME=$time|CHAN=0|EVNT=SWIrcst|GURI0=$grammar|GRNM=$grammar|LANG=$language|GRMT=application/srgs+xml|UCPU=0|SCPU=0\n";
print LOG "TIME=$time|CHAN=0|EVNT=SWIrcnd|RSTT=ok|RSLT=$meaning|RAWT=$ortho|SPOK=$ortho|GRMR=GURI0|CONF=999|WVNM=$file|UCPU=0|SCPU=0\n";
print LOG "TIME=$time|CHAN=0|EVNT=SWIdmnd|TSTT=Success|UCPU=0|SCPU=0\n";
print LOG "TIME=$time|CHAN=0|EVNT=SWIclnd|UCPU=0|SCPU=0\n";
}
}

View File

@@ -0,0 +1,25 @@
use File::Find;
use File::Copy;
if ($ARGV[0] =~ m|^\s*$|)
{
print "Template to traverse a directory recursively.\n";
print "Usage: perl $0 TOP_DIR\n";
print "Example: perl $0 /bin\n";
exit 0;
}
@dirs = ($ARGV[0]);
find ( {wanted => \&wanted},
@dirs );
sub wanted
{
if (m|^ulaw$|) # check the current file name, if it contains ulaw then dome something on it.
{
$file = $_;
# do something here.
}
}

View File

@@ -0,0 +1,62 @@
# bug 1. final results as *.zip files are deleted by wrong
# bug 2. folders containing space cannot be correctly parsed.
use File::Find;
use File::Copy;
use Cwd;
if ($ARGV[0] =~ m|^\s*$|)
{
print "Extract warez directories recursively.\n";
print "Usage: perl $0 TOP_DIR\n";
print "Example: perl $0 /temp/my0day\n";
exit 0;
}
@dirs = ($ARGV[0]);
find ( {wanted => \&wanted},
@dirs );
sub wanted
{
if (-d $_)
{
# We are in the containing folder of $_
$folder = $_;
$folder =~ s| |_|g; # folders containing space in names cannot be extracted.
rename $_, $folder;
@zipfiles = glob "$folder/*.zip";
foreach $zipfile (@zipfiles)
{
print "$zipfile\n";
system "unzip -n $zipfile -d $folder";
}
@rarfiles = glob "$folder/*.rar";
if (scalar @rarfiles > 0)
{
$rarfile = $rarfiles[0]; # Only the first rar (which is the sole *.rar or *.part1.rar) is to be extracted.
print "$rarfile\n";
system "\"s:/Program Files/WinRAR/RAR.exe\" x -o- $rarfile $folder > $folder/unrar.info";
}
#############################
##### WARNING ###############
# sometime a file extracted from *.rar is another *.zip! In this case it will be deleted by wrong!
open INFO, "$folder/unrar.info" or next;
while (<INFO>)
{
if (m|All OK|)
{
unlink glob "$folder/*.zip";
unlink glob "$folder/*.r??";
unlink glob "$folder/*.DIZ";
unlink glob "$folder/*.diz";
unlink glob "$folder/unrar.info";
}
}
close INFO;
}
}

View File

@@ -0,0 +1,15 @@
#!/bin/bash
# Usage: this_script target_dir
for zipfile in $1/*.zip; do
unzip -n $zipfile -d $1;
done
for rarfile in $1/*.rar; do
/cygdrive/s/Program\ Files/WinRAR/RAR.exe x -o- $rarfile $1;
done
rm -f *.DIZ
rm -f *.diz

View File

@@ -0,0 +1,34 @@
# bug 1. final results as *.zip files are deleted by wrong
# bug 2. folders containing space cannot be correctly parsed.
use File::Find;
use File::Copy;
use Cwd;
if ($ARGV[0] =~ m|^\s*$|)
{
print "Rename warez directories.\n";
print "Usage: perl $0 TOP_DIR\n";
print "Example: perl $0 /temp/my0day\n";
exit 0;
}
@dirs = glob "$ARGV[0]/*";
foreach $dir (@dirs)
{
$org = $dir;
$dir =~ s|\.| |g;
$dir =~ s|_| |g;
$dir =~ s|/||g;
$dir =~ s|Wiley (Interscience)?||g;
$dir =~ s|Wiley (IEEE Press)?||g;
$dir =~ s|eBook-.*$||g;
$dir =~ s|ebook-.*$||g;
$dir =~ s|(Jan\|Feb\|Mar\|Apr\|May\|Jun\|Jul\|Aug\|Sep\|Oct\|Nov\|Dec) 200\d||g;
$dir =~ s|^\s+||;
$dir =~ s|\s+$||;
print "$dir\n";
rename $org, "p{Wiley} t{$dir}";
}

View File

@@ -0,0 +1,2 @@
set TCLLIBPATH=C:/Programs/Lyre/tclpkg
C:/Programs/Lyre/bin/wish80.exe C:/Programs/Lyre/bin/wedit.tcl %1 %2 %3 %4 %5