Posts in category ruby

PAR2 file mover

This is my first Ruby script... please feel free to contact me with feedback.

It will read a PAR2 parity file and move all the files in it to a subdirectory. The original thing I asked for:


I know you can currently download into subdirectories based on ID3 tags. I would love to be able to have downloads go into subdirectories based on the PAR2 file that "covers" them.

Example, all files downloaded overnite into a huge directory:

AAA.PAR2
AAA 01-16.mp3
AAA 02-16.mp3
...
AAA 16-16.mp3
AAA.nfo
AnnoyinglyNamedNothingLikeAAAButInThePARFileAnyway.nfo
BBB.PAR2
BBB 01-92.mp3
BBB 02-92.mp3
...
BBB 92-92.mp3
BBB.nfo
...
XXY.PAR2
XXY.mp3
XXY.txt

So I would want them moved into the subdirectories "AAA", "BBB", "XXY", etc. It wouldn't be perfect but it would be a great start for what I do to process my inbound stuff.

If not, how about dumping some log file I can parse in perl or ruby that gives me "AAA.LOG" which lists the files that went with AAA.PAR2 ?


Of course, being a borderline OCD engineer, I didn't just solve the problem but also put together a full object-oriented infrastructure to parse and process PAR2 files. I've only handled one packet type defined in the PAR2 specifications, but put in place a Par2BasePacket with an interface that all the other packet types can be derived from.

Without further delay, see the attached code (sorry, my install doesn't support syntax highlighting of ruby and I don't have time now - but you can paste the code into this online highlighter).