A little work on my previous Anime CRC32 checksum program resulted in this:

A standalone version (no extra python modules needed) to check your favorite Amine CRC32 sums
#!/usr/bin/python # Version 0.2 2009.01.25 # Copyright (c) 2009, Taoufik El Aoumari # Released under the GPL license http://www.gnu.org/licenses/gpl-3.0.txt import sys, re, zlib, os c_null = "\x1b[00;00m" c_red = "\x1b[31;01m" c_green = "\x1b[32;01m" p_reset = "\x08"*8 def crc32_checksum(filename): crc = 0 file = open(filename, "rb") buff_size = 65536 size = os.path.getsize(filename) done = 0 try: while True: data = file.read(buff_size) done += buff_size sys.stdout.write("%7d"%(done*100/size) + "%" + p_reset) if not data: break crc = zlib.crc32(data, crc) except KeyboardInterrupt: sys.stdout.write(p_reset) file.close() sys.exit(1) sys.stdout.write(p_reset) file.close() if crc < 0: crc &= 2**32-1 return "%.8X" %(crc) for file in sys.argv[1:]: try: crc = crc32_checksum(file) dest_sum = re.split("([a-fA-F0-9]{8})", file)[-2] if crc == dest_sum.upper(): c_in = c_green else: c_in = c_red sfile = file.split(dest_sum) print("%s%s%s %s%s%s%s%s" % (c_in, crc, c_null, sfile[0], c_in, dest_sum, c_null, sfile[1])) except(IndexError, ValueError): print(crc+" "+file) except IOError, e: print(e) continue
Note: This code was only tested under Python 2.5 and 2.6. I haven’t tested it (yet) with version 3.0.
Edit 2009.01.05: Corrected the regular expression thanks to Redditor Ademan suggestion.
Edit 2009.01.15: Added percentage progress per file and clean exit on keyboard interruption (Ctrl+C).
Edit 2009.01.25: Split using the checksum itself and ignore case in checksums. thanks to Arfy suggestions.
Edit 2009.05.13: Added GPL license.

























January 5th, 2009
at 23:33
Nice but if you have a directory in folder, you script return this
“[Errno 21] Is a directory” its not a big problem but just looks ugly
January 5th, 2009
at 23:36
And useful to have any exceptions. Like subtitles (ass, srt)
58D5C278 [gg-BSS]_Gundam_00_S2_-_01_[44C8CD36].ass
January 25th, 2009
at 15:05
Folks, it’s easy enough to simply specify what you DO want to check.
arfy@geass:/mymedia/anime/Nodame Cantible$ animecheck *.mkv
Taoufix: THANK YOU for this very useful code! I have not found anything else out there that does this! And nice thinking using zlib’s CRC routine btw.
Suggestion: I think would be useful to perhaps integrate this filename checking as a module or option for cfv (http://cfv.sourceforge.net/) which incidentally is also written in python.
January 25th, 2009
at 19:38
OK feel free to delete my THREE previous posts, cause here I offer solutions.
Line 38, to allow for not only [CRC] but also {CRC} (CRC) _CRC_ or spaces:
dest_sum = re.split(”([\[\{\(_ ][A-Fa-f0-9]{8}[\]\}\)_ ])”, file)[-2][1:9]
Line 38, to not check for delimiters at all (assumes sane filenames otherwise) note the range 1:9 has been changed to 0:8 .. I don’t know python I’m just guessing right :o)
dest_sum = re.split(”([A-Fa-f0-9]{8})”, file)[-2][0:8]
Line 39, to allow for lower-case a-f in crc as included in the regexes above:
if crc == str.upper(dest_sum):
Hopefully others will find this edit useful.
January 25th, 2009
at 20:21
@Arfy: Thanks a lot for your comments. I think it’s better to split the filename using the checksum itself, this way we avoid testing for every separator out there ;). Anyway, I updated the script to solve the issues you had.
January 27th, 2009
at 00:43
It is not probably as great an idea as it seems to get rid of the delimiters altogether, especially if you allow for lowercase. Filenames can be split at the wrong points if they contain any 8 chars in a row that match [a-fA-F0-9] For example, “decafbad” and part of “deadbeefcafe” etc will match erroneously and throw off the checking. Of course theses cases will generally be infrequent, but I choose to use the delimiters {} [] () __ to avoid unexpected results. It really comes down to the dataset you wind up working with. I don’t think I’ve seen lowercase checksums in my anime.
February 15th, 2009
at 21:39
Ooh, nice! This is super-useful to me.
I’m thinking you might want to apply a filter (filter, is that the right term for Python?) on the file list, to remove things that don’t have a dot in the filename (I suppose you could make an exception for dots at the beginning, but do you really want to check hidden files?). It should be fairly simple, but I can’t do it off the top of my head.
BTW, 2nd sentence s/Amine/anime/. Also, your captcha doesn’t work w/o javascript, which you might want to mention somewhere.
March 4th, 2009
at 13:17
June 11th, 2009
at 09:35
First of all thanks for your awsome program.
Today I’ve passed form Arch Linux to Ubuntu and I get this error when I try to execute animecheck:
[batousay@Batu ~]$ ./animecheck \[NTF\]Naruto\ Shippuden\ 111\ \[\].mp4
File “./animecheck”, line 34
if crc < 0:
^
SyntaxError: invalid syntax
[batousay@Batu ~]$ python –version
Python 2.6.2
Thanks for your atention.
June 11th, 2009
at 09:52
It seemed to be HTML codification…
if it can help someone like me…
< == <
& == &
[bye]
June 11th, 2009
at 10:10
@Batousay: Thanks for your feed back, it fixed now.