Scripting System Overview (2.0)

HDoujin Downloader supports the use of custom scripts, so that you can you can add any site you want, or edit functionality for sites that are already supported by default. Of course, you can always ask me to do that for you, too.

This page will help you get started with writing your own scripts. I recommend using the HDD Script Editor, as it will allow you to test your scripts before using them. It also comes with a couple of example scripts to give you an idea of how they work.

The new scripting system functions a lot more like a legitimate scripting language than the previous iteration, and allows you to set your own variables, use if statements and loops, and modify results with a bunch of built-in functions.

Getting Started

Scripts are divided into three sections: info, where you fetch information about a manga and add it to the list; pages, where you fetch a list of pages to download; and chapters, where you fetch a list of chapter URLs/titles. These sections are specified using #info, #pages, and #chapters headings. Any code after these lines will be executed at the applicable time, up until the next heading (or the end of the script).

Functions

The main functions to be aware of are list_add, page_add, and chapter_add. They are used for adding an item to the download queue, adding a page to the page list, and adding a chapter to the chapter list, respectively. They are generally used at the end of a section (or repeatedly through loops in the case of the last two). They are used like so, where each parameter is a variable declared/assigned to before calling the function:

list_add(faviconURL, title, pages, chapters, site, tags, desc, author, artist)
page_add(pageURL)
chapter_add(chapterTitle, chapterURL)

A complete list of available functions is below:

between
(a, b, c) // returns substring in ‘a’ between substrings ‘b’ and ‘c’
after(a, b) // returns substring in ‘a’ after ‘b’
before(a, b) // returns substring in ‘a’ before ‘b’
count(a, b) // returns number of substring ‘b’ present in ‘a’
contains(a, b) // returns true if ‘a’ contains substring ‘b’; false otherwise
replace(a, b, c) // returns ‘a’ with all instances of substring ‘b’ replaced with substring ‘c’
mtags(a, b, c) // creates a comma-delimited list of tags present in ‘a’, between bounds ‘b’ and ‘c’
trim(a) // removes excess white-space surrounding ‘a’
repair(a) // returns ‘a’ with HTML character encoding repaired
substring(a, b, c) // returns a substring of ‘a’ from index ‘b’ to length ‘c’
last_index_of(a, b) // returns the index of the last instance of substring ‘b’ in ‘a’
index_of(a, b) // returns the first index of substring ‘b’ in ‘a’
length(a) // returns the length of string ‘a’

pad(a, b) // pads number ‘a’ with zeroes until it is length ‘b’
ceil(a) // returns ceiling of number ‘a’
floor(a) // returns floor of number ‘a’
rnd(a) // returns rounded of number ‘a’

simplify(a) // simplifies a URL (i.e., eliminates “http” and directories)
filename(a) // returns the file name of URL
extension(a) // returns the extension of file name
get(a) // returns source code of webpage at address ‘a’

page_reverse() // reverses page order
chapter_reverse() // reverses chapter order

log(a) // (editor-only) writes value ‘a’ to the script processing log

Variables

You can declare variables using the var keyword, followed by the names of the variables you would like to use, separated by commas. For example:

var favicon, title, pages, chapters, site = “FAKKU!”, tags, desc, author, artist

You can also assign values to variables when declaring them, as seen above with the ‘site’ variable. Note that you don’t necessarily need to declare variables in this way (they’ll be created automatically if you assign a value to a non-existent variable), but it’s safer to do it this way.

The following “constants” also exist: url, src, true, false, newline

I put “constants” in quotation marks because you can change the values of url and src, which refer to the URL of the manga being downloaded and the source code retrieved from the page it’s found on, respectively. In a lot of cases, you’ll need to modify these values. Of course, you could also assign them to a new variable if you want to.

If, While, and Loop

if statements will allow you to test a condition before running code that is encapsulated in curly braces. If the condition is false, the code won’t be run.

while loops will continue to run as long as the condition is true, and loop will run a specified number of iterations.

Note that all statements require that the condition be in parentheses directly following the keyword, along with an opening curly brace either on the next line, or following the condition.

Operators

The following operators are supported:
For numeric values: +, -, /, \, *, <, >, %, mod, ^
For Boolean values: &&, ||, ==, !=, !, <>, not, or, and
For strings: &
Assignment: = (can be combined with some other operators)

Be sure to check out the example scripts that come with the editor! Some of them have comments to help you understand each line (if you need it).

One thought on “Scripting System Overview (2.0)

  1. Pingback: Updated Scripting System & Other News | HDoujin Downloader

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s