Home Page
  • October 03, 2024, 06:47:58 pm *
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

News:

Official site launch very soon, hurrah!


Author Topic: Download all of an author’s fictionpress stories  (Read 17891 times)

Dakusan

  • Programmer Person
  • Administrator
  • Hero Member
  • *****
  • Posts: 543
    • View Profile
    • Dakusan's Domain
Download all of an author’s fictionpress stories
« on: August 01, 2018, 10:01:31 pm »

Original post for Download all of an author’s fictionpress stories can be found at https://www.castledragmire.com/Posts/Download_all_of_an_author’s_fictionpress_stories.
Originally posted on: 08/02/18

I was surprised in my failure to find a script online to download all of an author’s stories from Fiction Press or Fan Fiction.Net, so I threw together the below.

If you go to an author’s page in a browser (only tested in Chrome) it should have all of their stories, and you can run the following script in the console (F12) to grab them all. Their save name format is STORY_NAME_LINK_FORMAT - CHAPTER_NUMBER.html. It works as follows:

  1. Gathers all of the names, chapter 1 links, and chapter counts for each story.
  2. Converts this information into a list of links it needs to download. The links are formed by using the chapter 1 link, and just replacing the chapter number.
  3. It then downloads all of the links to your current browser’s download folder.

Do note that chrome should prompt you to answer “This site is attempting to download multiple files”. So of course, say yes. The script is also designed to detect problems, which would happen if fictionpress changes their html formatting.


//Gather the story information
const Stories=[];
$('.mystories .stitle').each((Index, El) =>
   Stories[Index]={Link:$(El).attr('href'), Name:$(El).text()}
);
$('.mystories .xgray').each((Index, El) =>
   Stories[Index].NumChapters=/ - Chapters: (\d+) - /.exec($(El).text())[1]
);

//Get links to all stories
const LinkStart=document.location.protocol+'//'+document.location.host;
const AllLinks=[];
$.each(Stories, (_, Story) => {
   if(typeof(Story.NumChapters)!=='string' || !/^\d+$/.test(Story.NumChapters))
      return console.log('Bad number of chapters for: '+Story.Name);
   const StoryParts=/^\/s\/(\d+)\/1\/(.*)$/.exec(Story.Link);
   if(!StoryParts)
      return console.log('Bad link format for stories: '+Story.Name);
   for(let i=1; i<=Story.NumChapters; i++)
      AllLinks.push([LinkStart+'/s/'+StoryParts[1]+'/'+i+'/'+StoryParts[2], StoryParts[2]+' - '+i+'.html']);
});

//Download all the links
$.each(AllLinks, (_, LinkInfo) =>
   $('a').attr('download', LinkInfo[1]).attr('href', LinkInfo[0])[0].click()
);

jQuery('.blurb.group .heading a[href^="/works"]').map((_, El) => jQuery(El).text()).toArray().join('\n');
Logged