Hi all,
ever wanted to download a huge number of files that have enumerated filnames
like foo1.pgn foo2.png foo3.png etc.
well most download managers come with a some feature to generate a list like
this right.
last week I needed to download a very big number of files (in the order of 8000)
but I needed a more complex series
for the filnames, since it would have taken me forever to do this manualy I sat
down and made a couple of tiny programs
to solve this problem.
series and nseries are coded in c++ (using awk would was the correct choice but
I'm crap at awk and I needed this quickly)
you can compile them by typing
g++ -o series series.cc
g++ -o nseries nseries.cc
to excute the files you type ./series or ./nseries (or put them in your /usr/bin
if you think they're that useful ;-)
now I'll show you how it works
series simply takes some string like foo then genereates a list like
foo01
foo02
foo03
......
foo13
then adds a string to each item in the list like .png so the end product would
be
foo01.png
foo02.png
foo03.png
..........
foo13.png
to get this you run
../series 1 13 2 '.png' 'foo'
1 is the begining of the list, 13 is its end, 2 is the minimum number of digits
to be used
so if the value to be added uses less digits leading zeros will be padded
otherwise it would have
looked like this
foo1.png
foo2.png
foo3.png
.........
foo13.png
notice they how foo12.png is a longer filename than foo3.png which usualy
confuses sorting
no we will call foo the prefix, .png the postfix 1 the start value 13 the end
value and 2 the pad value
thus the syntax for series is
../series start end pad postfix prefix
you can have blank prefix or postfix by putting '' in there place
no ./series can generate one list for many prefixes in one command the suntax
would become
../series start end pad postfix prefix1 prefix2 prefix3 etc
so for instanmce if I want to generate a list like that foo009 ... foo099 and
another list fubar009 ... fubar099
I would type this at my console
../series 9 99 3 '' 'foo' 'fubar'
the foo list would be generated first then the fubar one.
easy eh?
if you don't type in a prefix at all like this
../series 9 99 3 ''
it will ask wait for you to inoput a prefix, then it'll generate a list for this
prefix and ask wait for another one
until you press Ctrl-D (end of file)
this might not seem important, but no this is the most powerful thing about
series you can fully utilise redirection
and piping with it, for instance if you want a list of all 3 digit octal numbers
then you'd type
../series 0 7 1 '' '' | ./series 0 7 1 '' | ./series 0 7 1 ''
notice how the two last commands have no prefix (only one blank string while the
first one has two)
what happened here is that
../series 0 7 1 '' '' tells series to generate the list 0 1 2 3 4 5 6 7
the first pipe sends this output as input to ./series 0 7 1 '' which then takes
every item in the input and
generate a list for it so we get 00..07 10..17 20..27 .... 70..77
next we take all this output and pipe it through to the last command whihc
generrates
000..007...010..017...770..777
and voila you got all three digit octal numbers and in correct order too.
nseries is similar to using series with no prefix argument but it instead adds
an incrementing number to its input
so for instance if I want the list alaa1.au mena2.au dalia3.au manal4.au foo5.au
etc I'd type
../nseries 1 1 '.au'
and then enter input of alaa mena dalia manal foo Ctrl-D
the syntax here is a bit different, since there is no need for end and nseries
has to take input from stdin it look like this
../nseries start pad postfix
and it simply terminates when it reads Ctrl-D (eof).
it is useless this way, its real purpose is to be used with pipes and
redirections
so lets say I want to to generat all three digit octal numbers and their decimal
equivalent I'd type
../series 0 7 1 '' '' | ./series 0 7 1 '' | ./series 0 7 1 '=' | ./nseries 0 1
''
cool eh
this is a quick hack for one purpose so it still has many serious flaws,
the worst is when series and nseries work in input mode (no prefix given) they
will always generate an extra list
for a blank prefix, this could be a big problem when using pipes or redirection
(for instance the final output for the last
example will not be 777=511 as it should be but there will be lots of rubish)
this rubish gets bigger every time you pipe the output.
I get around this by redirecting output to a file and manualy removing rubish
from the file then redirecting corrected file
as input of next command
so the last example would be
../series 0 7 1 '' '' | ./series 0 7 1 '' > octtemp
first command does not produce rubsih.
now I would edit octtemp and remove last 8 lines then type
../series 0 7 1 '' <octtemp
remove last seven lines, etc.
its a nasty bug I know please help me to fix it.
other problems are when the input has spaces series and nseries would consider
it several inputs not one
for instance if I pipe the output of this
../series 13 55 2 '/' '~/fu bar'
to ./nseries 13 2 '.mpg'
instead of generating
~/fu bar13/13.mpg
~/fu bar14/14.mpg
~/fu bar15/15.mpg
etc.
it will produce
~/fu13.mpg
bar13/14.mpg
~/fu15.mpg
bar14/16.mpg
~/fu17.mpg
bar15/18.mpg
etc.
solving this should be easy, I just didn't get to do it, if someone fixes it
please send me the fix.
it wouls be nice also if it had support for steps (going 2 4 6 7 or 3 6 9 12
instead of 1 2 3 4)
and alphabetical sequences a b c d instead of 1 2 3 4, or even alphanumerical
sequences like hex numbers.
I used series and nseries to generate a download list for all Garfield comics
from Ucomics, as every Garfield
fan would know, the first one was on 19th of june 1978 and there is one
published every day till today
so this meant a download list of more than 8000 files in just a couple of minute
(the time it took me to
write the code and use it).
hope you'll find it useful
cheers,
Alaa