Advertisement
Guest User

Fimfiction - Favorite Stories Archiving Script

a guest
Aug 28th, 2014
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.23 KB | None | 0 0
  1. #! /bin/bash
  2.  
  3.  
  4. #   Put Username & Pass into variables that we can use in our POST-data request in curl,
  5. #       so we can authenticate & create a session with fimfiction.net
  6. echo -n -e "Please enter your username:\t";
  7. read username;
  8. echo -n -e "Please enter your password:\t";
  9. read -s password;
  10. echo "";
  11.  
  12.  
  13. #   User & Pass variables inserted & formated to POST-data variable
  14. POSTDATA_ONE="referrer=http%3A%2F%2Fwww.fimfiction.net%2F&username=$username&password=$password&keep_logged_in=1";
  15.  
  16.  
  17. #   Login to fimfiction.net to authenticate (using our POST-data variable)
  18. #       and create the cookie file that will hold our session information
  19. curl -c "./cookiejar.txt" -d "$POSTDATA_ONE" "http://www.fimfiction.net/ajax/login.php" 2>/dev/null 1>./ajax_return.txt;
  20.  
  21.  
  22. #   Edit session information so fimfiction will show us the "mature" stories too
  23. #       To-do: Create a conditional that prompts for user input, to make this step optional
  24. tail -n 1 "./cookiejar.txt"  | sed -r -e 's/session_token.*/view_mature\ttrue/g' >> "./cookiejar.txt";
  25.  
  26.  
  27. #   Get the first page that lists your favorite stories
  28. curl -b "./cookiejar.txt" "http://www.fimfiction.net/index.php?view=category&tracking=1&order=updated" 2>/dev/null 1>./Favorites-001.html;
  29.  
  30.  
  31. #   use a sequence of commands to extrapolate how many pages are used to
  32. #       list all your favorite stories. Then set this value to a variable.
  33. MAX=$(cat Favorites-001.html | grep -E -o "&page=[0-9]+" | sed -r -e 's/&page=(.*)/\1/g' | sort -n | tail -n 1);
  34.  
  35.  
  36. #   Prepare Loop Variable
  37. let iteration=1;
  38.  
  39.  
  40. #   Prepare First script by adding the 'shebang     interpreter' line
  41. echo -e "#!\t/bin/bash" >> gen_story_script.sh;
  42.  
  43.  
  44. #   This loop creates the gen_story_script, which itself creates the story_script,
  45. #       which downloads all the stories
  46. while [ "$iteration" -le  "$MAX" ]; do
  47.     echo "curl -b \"./cookiejar.txt\" \"http://www.fimfiction.net/stories/updated?tracking=1&page=$iteration\" 2>/dev/null | grep -E -o \"story_[0-9]+\" | sed -r -e 's/story_(.*)/cd txt \&\& wget --content-disposition \"http:\/\/www.fimfiction.net\/download_story.php?story=\1\" \&\& cd ..\/\ncd html \&\& wget --content-disposition \"http:\/\/www.fimfiction.net\/download_story.php?story=\1\&html\" \&\& cd ..\/\ncd epub \&\& wget --content-disposition \"http:\/\/www.fimfiction.net\/download_epub.php?story=\1\" \&\& cd ..\//g' >> story_script.sh" >> gen_story_script.sh;
  48.     let iteration=$iteration+1;
  49. done
  50.  
  51.  
  52. #   Prepare Second script by adding the 'shebang    interpreter' line
  53. echo -e "#!\t/bin/bash" >> story_script.sh;
  54.  
  55.  
  56. #   Make First script executable
  57. chmod 755 gen_story_script.sh;
  58.  
  59.  
  60. #   Execute it
  61. ./gen_story_script.sh;
  62.  
  63.  
  64. #   Make Second script executable
  65. chmod 755 story_script.sh;
  66.  
  67.  
  68. #   Make and change directory so we don't litter the current working directory
  69. #       with stories
  70. mkdir stories;
  71. mkdir stories/html;
  72. mkdir stories/epub;
  73. mkdir stories/txt;
  74. cd stories;
  75.  
  76.  
  77. #   Execute the final script
  78. ../story_script.sh;
  79.  
  80.  
  81. #   I always put the "wait" at the end of all my scripts, because it forces bash
  82. #       to execute the steps of this script in order. If you don't put the "wait"
  83. #       then bash may try to do things in parallel to be more efficient, which can
  84. #       really fuck shit up if your script has steps that need to be run IN ORDER
  85. wait;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement