Register
It is currently Tue Jul 22, 2014 1:29 pm

[solved]Download any fanfiction from fanfiction.net


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Thu Apr 29, 2010 12:39 pm   

Joined: Thu Apr 29, 2010 12:30 pm
Posts: 2
Hello all, I'm just getting into bash scripting, and I really need some help. I have initially picked something valuable to me, fanfics. They have a bad habit of disappearing, and having a local copy would be nice. Hence, I'm trying to write a script to do so. This is what I have right now:
Code:
#!/bin/bash
#This is the script I invoke to download FFs
_zenity="/usr/bin/zenity"
basename="/usr/bin/basename"
curr=1
#domain=$(${_zenity} --title  "Enter domain" \
#               --entry --text "Enter the domain you would download from" )
domain=http://www.fanfiction.net/s/2428341/40/
   
#chapter=$($basename $domain) #should result in integer
chapter=${domain:36:35} #should result in integer      
domain=${domain:0:${#domain} - 3} #should result in something like http://www.fanfiction.net/s/2428341/

while [ "$curr" != "$chapter"]
do
   echo -n "$domain""$curr" > list.txt
   $curr=$(( $curr + 1))
done
wget -p -k -input-file=./list.txt
echo Download Complete


It doesn't work. I've temporarily hard-coded a variable, but zenity is working. Could someone either fix it, or just write one for me, as I can then try to understand it and keep learning that way. Thanks.


Last edited by WearilyWandering on Sun May 02, 2010 11:01 am, edited 1 time in total.

Top
 Profile  
 PostPosted: Thu Apr 29, 2010 3:40 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 532
Hi,

how do you know "It doesn't work."? and how do we know?

I think echo -n "$domain""$curr" > list.txt , should be
Code:
echo "$domain""$curr" >> list.txt


Top
 Profile  
 PostPosted: Sun May 02, 2010 11:01 am   

Joined: Thu Apr 29, 2010 12:30 pm
Posts: 2
I have fixed my script, now, if anyone's curious.
Code:
#!/bin/bash
#This is the script I invoke to download FFs
_zenity="/usr/bin/zenity"
rm -f ./list.txt
  > ./list.txt

domain=$(${_zenity} --title  "Enter domain" \
               --entry --text "Enter the domain you would download from" )
#domain=http://www.fanfiction.net/s/2428341/40/  #when I am testing, hard-code
   
chapter=$(basename $domain) #should result in integer

#chapter=${domain:36:((#chapter + 1))} #should result in integer      
domain=${domain%$chapter/} #should result in something like http://www.fanfiction.net/s/2428341/
curr=1
while [ $curr != $(($chapter+1)) ] ;
do
   echo  ""$domain""$curr"/" >> ./list.txt  ;
   curr=$(($curr+1))

done
wget -H -r -l1 -A.js $(head -n1 ./list.txt )
wget -E -H -p -k --input-file=./list.txt

echo Download Complete



Unfortunately, besides downloading more than I want, the pages aren't even linked to each other. Massive waste of time; next time I'll just check the source code of the page. Perhaps I'll still find a way to put them into an epub, though, sometime.


Top
 Profile  
 PostPosted: Sun May 02, 2010 4:34 pm   

Joined: Mon Mar 02, 2009 3:03 am
Posts: 532
I'd rather use a C-style for loop:
Code:
#!/bin/bash
#This is the script I invoke to download FFs

_zenityForm1() {
   /usr/bin/zenity --title  "Enter domain" --entry  \
                   --text "Enter the domain you would download from:"
}
List=/tmp/list.txt
#rm -f ./list.txt
[ -f "$List" ] && >$List

domain=$(_zenityForm1)
chapter=$(basename $domain) #should result in integer
domain=${domain%$chapter/} #should result in something like http://www.fanfiction.net/s/2428341/

#curr=1
#while [ $curr != $(($chapter+1)) ] ;
for (( curr=1; curr<=chapter; curr++ ))
do
   echo  "${domain}$curr/ >>$List  ;
#   curr=$(($curr+1))
done

wget -H -r -l1 -A.js $(head -n1 $List)
wget -E -H -p -k --input-file=$List

echo Download Complete

rm -f $List


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP