#! /usr/bin/env pike
string dest = getenv("HOME") +"/Movies/Dance";
string flat = "All"; // subdirectory where the index of all movies goes
int verbose = 0; // writes actions to stderr; turned on with -v, for instance
int get_all = 0; // overrides the next setting: 1 to simply fetch *everything*
// You especially want this if you want to get future categories automatically
// What categories to download; erase or //-comment out anything unwanted:
multiset get = (<
"20s Partner Charleston",
"30s Partner Charleston",
"Bal Swing",
"Balboa",
"Cake Walk",
"Collegiate Shag",
"Jitterbug",
"Lindy Hop",
"Music",
"Salsa",
"Street",
"Tap",
"Vernacular Jazz",
"West Coast"
>);
string base = "http://www.idance.net/";
mapping url = ([ "index":base + "previews.php",
"thumb":base + "getthumbnail.php?id=",
"movie":base + "getfreebie.php?id=",
"about":base + "movedetail.php?clip_id=" ]);
mixed opts = ([ "user-agent":"Mozilla/5.0 (Macintosh; U; Intel Mac OS X; "
"en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0" ]);
int main( int argc )
{
if( argc > 1 )
verbose = 1;
Stdio.mkdirhier( dest );
cd( dest );
Stdio.mkdirhier( flat );
string html = Protocols.HTTP.get_url_data( url->index, 0, opts ), type;
while( sscanf( html,
"%*sa>
%s%s",
int id, string name, html ) >= 3 )
{
if( file_stat( combine_path( flat, id +"-"+ name +".mov") ) )
{
if( verbose )
werror( "Already got %s; skipping.\n", name );
continue;
}
if( type = symlink( id, name ) )
{
if( verbose )
werror( "%s; ignoring.\n", type );
continue; // returns true for dance types we ignore
}
if( verbose )
werror( "Downloading %s...\n", name );
save( url->thumb + id, id +"-"+ name +".gif" );
save( url->movie + id, id +"-"+ name +".mov" );
}
}
// Saves url in dest/flat/filename
void save( string url, string filename )
{
string file = Protocols.HTTP.get_url_data( url, 0, opts );
Stdio.write_file( combine_path( flat, filename ), file );
}
// find categories, symlink movies and hardlink images there
// returns non-zero (the category name) for categories we don't want
string symlink( int id, string name )
{
string file = id +"-"+ name;
string html = Protocols.HTTP.get_url_data( url->about + id, 0, opts );
while( sscanf( html, "%*s