Checked in anndl.
[utils.git] / anndl
1 #!/usr/bin/perl -w
2
3 use Anime::ANN;
4 use Getopt::Long qw/:config gnu_getopt/;
5
6 if(!defined($ARGV[0])) {
7     print STDERR "usage: anndl SERIES\n";
8     exit 1;
9 }
10
11 unless($id = Anime::ANN::getid $ARGV[0]) {
12     print STDERR "anndl: could not find $ARGV[0]\n";
13     exit 1;
14 }
15
16 %info = %{Anime::ANN::getseries $id};
17
18 if(!defined $info{"eps"}) {
19     print "could not find number of eps\n";
20     print "accept? ";
21     if(!(<STDIN> =~ /^y/i)) {
22         exit 1;
23     }
24 }
25
26 $name = $info{"name"};
27 print "canonical name [$name]: ";
28 chomp($newname = <STDIN>);
29 $name = $newname if $newname ne "";
30 $dirname = $ENV{"HOME"} . "/dc/autodl/cur/" . $name;
31 mkdir $dirname || die "could not create $dirname: $!";
32 mkdir "$dirname/.autodl" || die "could not create $dirname/.autodl: $!";
33 open FH, ">$dirname/.autodl/disabled" || die "could not create $dirname/.autodl/disabled: $!";
34 close FH;
35 open FH, ">$dirname/nextep" || die "could not create nextep: $!";
36 print FH "1\n";
37 close FH;
38 open FH, ">$dirname/.autodl/uarg" || die "could not create $dirname/.autodl/uarg: $!";
39 if(defined $info{"eps"}) {
40     $melen = length $info{"eps"}
41 } else {
42     $melen = 2;
43 }
44 print FH ("rename:auto:$name:$melen:move:../autodl/cur/$name\n");
45 close FH;
46 $sexpr = lc $name;
47 $sexpr =~ s/ /.*/g;
48 $sexpr = "\"L~$sexpr\[^0-9]*0*%i([^0-9]*(\\[[^]]*\\]|\\([^\\)]*\\)|v2))*[^0-9]*\\.(avi|ogm|mkv|mp4)\$\"";
49 open FH, ">$dirname/.autodl/sexpr" || die "could not create $dirname/.autodl/sexpr: $!";
50 print FH "$sexpr\n";
51 close FH;
52 print "sexpr: $sexpr\n";
53 print "accept? ";
54 if(!(<STDIN> =~ /^y/i)) {
55     system $ENV{"EDITOR"}, "$dirname/.autodl/sexpr";
56 }
57 open FH, ">$dirname/.autodl/curep" || die "could not create $dirname/.autodl/curep: $!";
58 print FH "1\n";
59 close FH;
60 if(defined $info{"eps"}) {
61     open FH, ">$dirname/.autodl/maxep" || die "could not create $dirname/.autodl/maxep: $!";
62     print FH ($info{"eps"} . "\n");
63     close FH;
64 }
65 print "begin? ";
66 if(<STDIN> =~ /^y/i) {
67     unlink "$dirname/.autodl/disabled";
68 }