Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

can it be perl teim?

Name: Anonymous 2010-04-15 22:18

Hey, /prog/. Here's a script to autosort your anime into folders. You can thank me later.

#!/usr/bin/perl

use strict;
use warnings;

use File::Copy;

my @files = glob "*.mkv *.avi *.mp4";

foreach (@files) {
    my $file = $_;
    $_ =~ s/\ /_/g;

    print "$file\n";

    my @data = ($_ =~ m/^[([^[\]]+)\]([^[\]]+).+$/);
    next unless($data[1]);

    my $anime = ($data[1] =~ m/^((.*?)\d{2,3})/)[1];
   
    unless($anime) {
        $anime = ($data[1] =~ m/^(.+)$/)[0];
    }

    $anime =~ s/\./_/g;

    if ($anime =~ m/\-_$/) {
        $anime =~ s/\-_//g;
        $anime =~ s/_/\ /g;
        $anime =~ s/^\s+//;
        $anime =~ s/\s+$//;
    } else {
        $anime =~ s/_/\ /g;
        $anime =~ s/^\s+//;
        $anime =~ s/\s+$//;
    }

    unless (-d $anime) {
        next unless(mkdir $anime);
    }

    move("$file", "$anime/$file");
}

exit 0;

Name: Anonymous 2010-04-16 1:06

>>18
If you can write something cleaner that can match all of these examples, I'll give you an ecookie:

[SFW]_11eyes_-_06_[490871D2].mkv
[Ayako] A Certain Scientific Railgun - 10 [HQ][H264][CAFB8EE3].mkv
[Eclipse]_Claymore_-_22_(XviD)_[14E4C7B3].avi
[AonE_-_Conclave]_Devil_May_Cry_-_10_[9A4B4DAB].avi
[Ecliptic-BSS] Durarara!! - 12 [191E1603].mkv
[DB-gg]_Eden_of_the_East_the_Movie_I_King_of_Eden_[0747D19A].avi
[SRN]iDOLM@STER_XENOGLOSSIA_07_[53B65992].avi
[DB]_Bleach_264_[012073FE].avi
[A-E_&_Saizen]_Shigurui_01_[270652D1].mkv

There are several different test cases where it makes it difficult to simplify.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List