Skip to content

Commit

Permalink
Further CRC32 and source enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
Terry Callan committed Nov 19, 2020
1 parent 68a9925 commit e57e07e
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions adbren.pl
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@
my $ed2k = AniDB::UDPClient::ed2k_hash($file);
my $size = -s $file;
print "ed2k://|file|" . $file . "|" . $size . "|" . $ed2k . "|\n";
my $crc32 = calculate_crc($file);
my $verified = "Unverified";
if (index(lc($file), lc($crc32)) != -1) {
$verified = "Verified";
}
print $verified . " " . $crc32 . "\n";
}
exit;
}
Expand Down Expand Up @@ -212,20 +218,15 @@ sub CLEANUP {
# Manually calculate crc if anidb doesn't return one
if ( $fileinfo->{'crc32'} eq "" ) {
print "Calculating manual crc32 for $filename\n";
my $crc = Digest::CRC->new(type=>"crc32");
open(my $handle, $filepath);
$crc->addfile(*$handle);
close($handle);
my $hash = $crc->hexdigest;
$hash =~ tr/a-z/A-Z/;
my $hash = calculate_crc($filepath);
$fileinfo->{'crc32'} = $hash;
print "Calculated $hash\n";
}
# Annotate files with non-standard sources
my $src = $fileinfo->{'source'};
if ( $src eq "HDTV" or $src eq "www" or $src eq "" ) {
$src = "";
} else {
} elsif ($src !~ /^\[/) {
$src = "[" . $src . "]";
}
$fileinfo->{'source'} = $src;
Expand Down Expand Up @@ -298,6 +299,17 @@ sub CLEANUP {
}
$a->logout();

sub calculate_crc {
my $filepath = shift(@_);
my $crc = Digest::CRC->new(type=>"crc32");
open(my $handle, $filepath);
$crc->addfile(*$handle);
close($handle);
my $hash = $crc->hexdigest;
$hash =~ tr/a-z/A-Z/;
return $hash
}

sub print_help {
print <<EOF;
adbren.pl [options] <file1\/dir1> [file2\/dir2] ...
Expand Down

0 comments on commit e57e07e

Please sign in to comment.