1 | # decode all the files in the directory uusrc/ and copy |
1 | #!/usr/bin/perl |
2 | # the resulting files to uudst/ |
|
|
3 | |
2 | |
4 | use Convert::UUlib ':all'; |
3 | # decode all the files in the directory uusrc/ and copy |
|
|
4 | # the resulting files to uudst/ |
5 | |
5 | |
6 | sub namefilter { |
6 | #use Coro::Multicore; |
7 | my($path)=@_; |
|
|
8 | $path=~s/^.*[\/\\]//; |
|
|
9 | $path; |
|
|
10 | } |
|
|
11 | |
7 | |
12 | sub busycb { |
8 | use strict; |
13 | my ($action, $curfile, $partno, $numparts, $percent, $fsize) = @_; |
|
|
14 | $_[0]=straction($action); |
|
|
15 | print "busy_callback(", (join ",",@_), ")\n"; |
|
|
16 | 0; |
|
|
17 | } |
|
|
18 | |
9 | |
19 | SetOption OPT_IGNMODE, 1; |
10 | use Convert::UUlib ':all'; |
20 | SetOption OPT_VERBOSE, 1; |
|
|
21 | |
11 | |
22 | # show the three ways you can set callback functions. I normally |
12 | sub namefilter { |
23 | # prefer the one with the sub inplace. |
13 | my ($path) = @_; |
24 | SetFNameFilter \&namefilter; |
|
|
25 | |
14 | |
26 | SetBusyCallback "busycb", 333; |
15 | $path=~s/^.*[\/\\]//; |
27 | |
16 | |
28 | SetMsgCallback sub { |
17 | $path |
29 | my ($msg, $level) = @_; |
18 | } |
30 | print uc strmsglevel $_[1], ": $msg\n"; |
|
|
31 | }; |
|
|
32 | |
19 | |
33 | # the following non-trivial FileNameCallback takes care |
20 | sub busycb { |
34 | # of some subject lines not detected properly by uulib: |
21 | my ($action, $curfile, $partno, $numparts, $percent, $fsize) = @_; |
35 | SetFileNameCallback sub { |
22 | $_[0]=straction($action); |
36 | return unless $_[1]; # skip "Re:"-plies et al. |
23 | print "busy_callback(", (join ",",@_), ")\n"; |
37 | local $_ = $_[0]; |
24 | 0 |
|
|
25 | } |
38 | |
26 | |
39 | # the following rules are rather effective on some newsgroups, |
27 | SetOption OPT_RBUF, 128*1024; |
40 | # like alt.binaries.games.anime, where non-mime, uuencoded data |
28 | SetOption OPT_WBUF, 1024*1024; |
41 | # is very common |
29 | SetOption OPT_IGNMODE, 1; |
|
|
30 | SetOption OPT_VERBOSE, 1; |
|
|
31 | SetOption OPT_DOTDOT, 1; |
|
|
32 | SetOption OPT_AUTOCHECK, 0; |
42 | |
33 | |
43 | # if we find some *.rar, take it as the filename |
34 | # show the three ways you can set callback functions. I normally |
44 | return $1 if /(\S{3,}\.(?:[rstuvwxyz]\d\d|rar))\s/i; |
35 | # prefer the one with the sub inplace. |
|
|
36 | SetFNameFilter \&namefilter; |
45 | |
37 | |
46 | # one common subject format |
38 | SetBusyCallback "busycb", 333; |
47 | return $1 if /- "(.{2,}?\..+?)" (?:yenc )?\(\d+\/\d+\)/i; |
|
|
48 | |
39 | |
49 | # - filename.par (04/55) |
40 | SetMsgCallback sub { |
50 | return $1 if /- "?(\S{3,}\.\S+?)"? (?:yenc )?\(\d+\/\d+\)/i; |
41 | my ($msg, $level) = @_; |
|
|
42 | print uc strmsglevel $_[1], ": $msg\n"; |
|
|
43 | }; |
51 | |
44 | |
52 | # - (xxx) No. 1 sayuri81.jpg 756565 bytes |
45 | # the following non-trivial FileNameCallback takes care |
53 | # - (20 files) No.17 Roseanne.jpg [2/2] |
46 | # of some subject lines not detected properly by uulib: |
54 | return $1 if /No\.[ 0-9]+ (\S+\....) (?:\d+ bytes )?\[/; |
47 | SetFileNameCallback sub { |
|
|
48 | return unless $_[1]; # skip "Re:"-plies et al. |
|
|
49 | local $_ = $_[0]; |
55 | |
50 | |
56 | # otherwise just pass what we have |
51 | if ($_[1] =~ /^(img_?\d+|\d+\w?)\./) { |
57 | return (); |
52 | return "$1 $_[1]" |
58 | }; |
53 | if /^\s*\(([^)]+)\) \[\d+/; |
|
|
54 | } |
59 | |
55 | |
60 | # now read all files in the directory uusrc/* |
56 | # the following rules are rather effective on some newsgroups, |
61 | for(<uusrc/*>) { |
57 | # like alt.binaries.games.anime, where non-mime, uuencoded data |
62 | my($retval,$count)=LoadFile ($_, $_, 1); |
58 | # is very common |
63 | print "file($_), status(", strerror $retval, ") parts($count)\n"; |
|
|
64 | } |
|
|
65 | |
59 | |
66 | SetOption OPT_SAVEPATH, "uudst/"; |
60 | # File 06 of 33 - Kendo - Final - 0001.jpg (2/3) |
|
|
61 | return $1 if /File \d+ of \d+ - (.*) \(\d+\/\d+\)/i; |
67 | |
62 | |
68 | # now wade through all files and their source parts |
63 | # if we find some *.rar, take it as the filename |
69 | $i = 0; |
64 | return $1 if /(\S{3,}\.(?:[rstuvwxyz]\d\d|rar))\s/i; |
70 | while ($uu = GetFileListItem($i)) { |
|
|
71 | $i++; |
|
|
72 | print "file nr. $i"; |
|
|
73 | print " state ", $uu->state; |
|
|
74 | print " mode ", $uu->mode; |
|
|
75 | print " uudet ", strencoding $uu->uudet; |
|
|
76 | print " size ", $uu->size; |
|
|
77 | print " filename ", $uu->filename; |
|
|
78 | print " subfname ", $uu->subfname; |
|
|
79 | print " mimeid ", $uu->mimeid; |
|
|
80 | print " mimetype ", $uu->mimetype; |
|
|
81 | print "\n"; |
|
|
82 | |
65 | |
83 | # print additional info about all parts |
66 | # one common subject format |
84 | for ($uu->parts) { |
67 | return $1 if /- "(.{2,}?\..+?)" (?:yenc )?\(\d+\/\d+\)/i; |
85 | while (my ($k, $v) = each %$_) { |
|
|
86 | print "$k > $v, "; |
|
|
87 | } |
|
|
88 | print "\n"; |
|
|
89 | } |
|
|
90 | |
68 | |
91 | $uu->decode_temp; |
69 | # - filename.par (04/55) |
92 | print " temporarily decoded to ", $uu->binfile, "\n"; |
70 | return $1 if /- "?(\S{3,}\.\S+?)"? (?:yenc )?\(\d+\/\d+\)/i; |
93 | $uu->remove_temp; |
|
|
94 | |
71 | |
95 | print strerror $uu->decode; |
72 | # - (xxx) No. 1 sayuri81.jpg 756565 bytes |
96 | print " saved as uudst/", $uu->filename, "\n"; |
73 | # - (20 files) No.17 Roseanne.jpg [2/2] |
97 | } |
74 | return $1 if /No\.[ 0-9]+ (\S+\....) (?:\d+ bytes )?\[/; |
98 | |
75 | |
99 | print "cleanup...\n"; |
76 | # try to detect some common forms of filenames |
|
|
77 | return $1 if /([a-z0-9_\-+.]{3,}\.[a-z]{3,4}(?:.\d+))/i; |
100 | |
78 | |
|
|
79 | # otherwise just pass what we have |
|
|
80 | () |
|
|
81 | }; |
|
|
82 | |
|
|
83 | # now read all files in the directory uusrc/* |
|
|
84 | for(<uusrc/*>) { |
|
|
85 | my ($retval, $count) = LoadFile ($_, $_, 1); |
|
|
86 | print "file($_), status(", strerror $retval, ") parts($count)\n"; |
|
|
87 | } |
|
|
88 | |
|
|
89 | Smerge -1; |
|
|
90 | |
|
|
91 | SetOption OPT_SAVEPATH, "uudst/"; |
|
|
92 | |
|
|
93 | # now wade through all files and their source parts |
|
|
94 | for my $uu (GetFileList) { |
|
|
95 | print "file ", $uu->filename, "\n"; |
|
|
96 | print " state ", $uu->state, "\n"; |
|
|
97 | print " mode ", $uu->mode, "\n"; |
|
|
98 | print " uudet ", strencoding $uu->uudet, "\n"; |
|
|
99 | print " size ", $uu->size, "\n"; |
|
|
100 | print " subfname ", $uu->subfname, "\n"; |
|
|
101 | print " mimeid ", $uu->mimeid, "\n"; |
|
|
102 | print " mimetype ", $uu->mimetype, "\n"; |
|
|
103 | |
|
|
104 | # print additional info about all parts |
|
|
105 | print " parts"; |
|
|
106 | for ($uu->parts) { |
|
|
107 | for my $k (sort keys %$_) { |
|
|
108 | print " $k=$_->{$k}"; |
|
|
109 | } |
|
|
110 | print "\n"; |
|
|
111 | } |
|
|
112 | |
|
|
113 | $uu->remove_temp; |
|
|
114 | |
|
|
115 | if (my $err = $uu->decode) { |
|
|
116 | print " ERROR ", strerror $err, "\n"; |
|
|
117 | } else { |
|
|
118 | print " successfully saved as uudst/", $uu->filename, "\n"; |
|
|
119 | } |
|
|
120 | } |
|
|
121 | |
|
|
122 | print "cleanup...\n"; |
|
|
123 | |
101 | CleanUp(); |
124 | CleanUp; |