#! /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
  • %{" "%s" "%*[ >]%}
  • %s", array categories, html ) ) { categories = map( Array.flatten( categories ), String.trim_all_whites ); categories -= ({ ".." }); // safety precaution :-) if( !get_all && !get[ categories[0] ] ) return categories[0]; // shouldn't download or symlink this one string dir = categories * "/", up = "../" * sizeof( categories ); if( verbose ) werror( "%s: %s\n", name, dir ); Stdio.mkdirhier( dir ); catch( System.symlink( combine_path( up + flat, file +".mov" ), combine_path( dir, file +".mov" ) ) ); catch( System.hardlink( combine_path( flat, file +".gif" ), combine_path( dir, file +".gif" ) ) ); } }