Checked in anndl.
[utils.git] / anndl
CommitLineData
29c59b44
FT
1#!/usr/bin/perl -w
2
3use Anime::ANN;
4use Getopt::Long qw/:config gnu_getopt/;
5
6if(!defined($ARGV[0])) {
7 print STDERR "usage: anndl SERIES\n";
8 exit 1;
9}
10
11unless($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
18if(!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"};
27print "canonical name [$name]: ";
28chomp($newname = <STDIN>);
29$name = $newname if $newname ne "";
30$dirname = $ENV{"HOME"} . "/dc/autodl/cur/" . $name;
31mkdir $dirname || die "could not create $dirname: $!";
32mkdir "$dirname/.autodl" || die "could not create $dirname/.autodl: $!";
33open FH, ">$dirname/.autodl/disabled" || die "could not create $dirname/.autodl/disabled: $!";
34close FH;
35open FH, ">$dirname/nextep" || die "could not create nextep: $!";
36print FH "1\n";
37close FH;
38open FH, ">$dirname/.autodl/uarg" || die "could not create $dirname/.autodl/uarg: $!";
39if(defined $info{"eps"}) {
40 $melen = length $info{"eps"}
41} else {
42 $melen = 2;
43}
44print FH ("rename:auto:$name:$melen:move:../autodl/cur/$name\n");
45close 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)\$\"";
49open FH, ">$dirname/.autodl/sexpr" || die "could not create $dirname/.autodl/sexpr: $!";
50print FH "$sexpr\n";
51close FH;
52print "sexpr: $sexpr\n";
53print "accept? ";
54if(!(<STDIN> =~ /^y/i)) {
55 system $ENV{"EDITOR"}, "$dirname/.autodl/sexpr";
56}
57open FH, ">$dirname/.autodl/curep" || die "could not create $dirname/.autodl/curep: $!";
58print FH "1\n";
59close FH;
60if(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}
65print "begin? ";
66if(<STDIN> =~ /^y/i) {
67 unlink "$dirname/.autodl/disabled";
68}