From 7f855e365702b70c1634f68a7f206a537fbbe166 Mon Sep 17 00:00:00 2001 From: baldurk Date: Tue, 29 Mar 2011 20:34:41 +0100 Subject: [PATCH] Add hacky download-one-post mode --- fetch-thread.pl | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/fetch-thread.pl b/fetch-thread.pl index abb8634..bb960d5 100755 --- a/fetch-thread.pl +++ b/fetch-thread.pl @@ -12,6 +12,8 @@ # These following settings should be set to 1 to enable them, # or to 0 to disable them +$downloadOnePost = 0; + # Fetch images and videos # (you might want to temporarily disable this for faster testing) $downloadFiles = 1; @@ -63,11 +65,16 @@ # renum'ing? - ie, does index.html exist? -if(-s "index.html") { +if(!$downloadOnePost and -s "index.html") { &renumThread; exit; } +if($downloadOnePost and -s "Update XYZ/index.html") { + print "Already got a single post as XYZ! Move it out of the way before grabbing another.\n"; + exit; +} + # Ok, we're fetching # OS and cookie detection @@ -147,6 +154,10 @@ $numVids = 0; $vidSize = 0; $errors = ""; $skippedImgFile = ""; $skippedVidFile = ""; +if($downloadOnePost) { + $autoChapters = 0; +} + if($autoChapters) { # Start by running through to check how many valid posts have @@ -255,6 +266,10 @@ # Delete temporary file if we downloaded the thread ourselves if($threadURL) { unlink 'autoFetchedThread.txt'; } +if($downloadOnePost) { + exit; +} + # Need to delete the 'next' links from the final update # Read in the existing file @@ -640,6 +655,8 @@ sub getPost { if($upd == -1) { $keepPost = 1; } } + if($downloadOnePost) { $keepPost = 1; } + if(! $keepPost) { # Keeping requires: $minImage images or a video href (if videoPosts is on) # not contained inside a [quote] (a
) @@ -651,6 +668,8 @@ sub getPost { $gotUpdate = 1; $upd++; + if($downloadOnePost) { $upd = 50; } + # Fix definitely typo filter $postBody =~ s/\[NOTE: I AM TOO STUPID TO SPELL THE WORD "DEFINITELY" CORRECTLY\]/definitely/g; @@ -667,6 +686,9 @@ sub getPost { # Create a directory to put it all in $postDir = sprintf("Update %02d", $upd); + + if($downloadOnePost) { $postDir = "Update XYZ"; } + mkdir $postDir || die $!; # Generate the HTML file @@ -958,6 +980,8 @@ sub getThread { } close(FIRST); + if($downloadOnePost) { $pages = 1; $authorID = 0; $authorPosts = 1; } + # If got the author ID and there's more than one page, need to reget first page to get correct number of pages if($authorID && $pages > 1) { print "* Fetching thread from $threadURL with author ID $authorID...\n";