Using URL Macros

Portable Offline Browser supports URL macros. Macros are useful for scheduled automatic downloads when URL is changing every time.

For example, a weather site has an image that updates daily. Its URL has a day number inside. Thus,

http://www.weather.com/image5.png corresponds to the 5th day of the current month, while

http://www.weather.com/image12.png corresponds to the 12th day of the current month.

In such case, the following URL macros will be useful:

http://www.weather.com/image{:day}.png

When Portable Offline Browser starts downloading the Project, it substitutes macros with their values. Macro should start with {: symbols and end with }

The following macros are supported:

{:day} the current day number (1 - 31)

{:0day} the current day with a leading zero, when necessary (01 - 31)

{:shortday} the day as an abbreviation (Sun-Sat)

{:longday} the day as a full name (Sunday-Saturday)

{:month} the current month as a number without a leading zero (1-12)

{:0month} the month as a number with a leading zero (01-12)

{:shortmonth} the month as an abbreviation (Jan-Dec)

{:longmonth} the month as a full name (January-December)

{:year} the current year as a two-digit number (00-99)

{:longyear} the year as a four-digit number (0000-9999)

{:week} the current week number without a leading zero (1-51)

{:0week} the week number with a leading zero (00-51)

{:hour} the current hour without a leading zero (0-23)

{:0hour} the hour with a leading zero (00-23)

{:minute} the current minute without a leading zero (0-59)

{:0minute} the minute with a leading zero (00-59)

{:second} the second when download starts without a leading zero (0-59)

{:0second} the second with a leading zero (00-59)

{:5..12} this is a special macro which will load URLs with numbers from 5 to 12. You may also use leading zeros in the first number.

{:0..100|25} the | separator defines enumeration step. In this example numbers 0, 25, 50, 75, 100 will be generated.

{:a..z} to load URLs with letters from a to z. You may use single letters from A to Z and a to z here.

{:roman:XIX..XXX} to load URLs with roman numbers from XIX (19) to XXX (30). You may also use lower-cased numbers here. You can specify normal numbers as well that will be converted to romans - {:roman:19..30}.

{:Value1,Value2,…,ValueN} This macro will load URLs with values from the comma-separated list. For example, you can use it to enumerate states - {:AL,WA,CA,IL}

{:file=c:\values.txt} This macro be replaced with values loaded from the specified text file. One value should be specified on a line. If the text file contains URL Macros, they will be ignored.

{:FileURLEncode=c:\post.txt} The same as above but the text will be in URL-Encoded form. It is good for POST requests. For example, all space symbols from the text file will be replaced with + and so on.

{:setdate=...} This is a special macro that allows you to change date and time used in the above macros.

For example, if you want to download an image that was created yesterday, you can specify the following URL:

http://www.weather.com/{:setdate=date-1}image{:day}.png

The above URL will use yesterday date for the {:day} macro. The same way you can set tomorrow date:

http://www.weather.com/{:setdate=date+1}image{:day}.png

You can set any number of days to change the current date. You can also change months this way:

http://www.weather.com/{:setdate=date-5M}image{:day}.png

To change the current time, use {:setdate=time+17} or {:setdate=time-80} format, where the number specifies minutes.

{:julian} Inserts Julian day number - Julian dates (abbreviated JD) are simply a continuous count of days and fractions since noon Universal Time on January 1, 4713 BCE (on the Julian calendar). This macro is useful if a URL uses a continuous counter and each new day increases it. You can use {:julian+1000} or {:julian-500} forms of the macro to offset the resulting number.

{:JavaScriptTime} Inserts the current date/time as a number in JavaScript format.

To redefine the standard names of months, you can use the following macros:

{:#longmonths:January,February,...,November,December} and {:#shortmonths:J,F,M,A,M,J,J,A,S,O,N,D}. They are especially good if you are downloading sites that use month names in another language or your system default month names are different from what a site uses.

When a date or a sequence repeats in a URL, the following macro will help:

http://www.srv.com/dir{:5..7#1}/file{:#1}.htm

This will generate the following three URLs:

http://www.srv.com/dir5/file5.htm

http://www.srv.com/dir6/file6.htm

http://www.srv.com/dir7/file7.htm

A more complex format allows you to increment or decrement the second part: http://www.srv.com/dir{:5..7#1}/file{:#1+10}.htm

http://www.srv.com/dir5/file15.htm

http://www.srv.com/dir6/file16.htm

http://www.srv.com/dir7/file17.htm

You can also use ...{:#1-10}...

You can use URL Macros in POST request, AutoExport= and other lines - every line in the URLs field that contains URL Macros will be processed. The following macros could be useful in addition to the auto export feature:

{:MapFile} inserts the full path to the Project Map (.map) file with the list of all files that were downloaded by the Project.

{:IID} inserts the Project ID number.

{:DD}inserts the full path to the Download directory where Project stores downloaded files.

{:ProjectName}inserts the project name. Can be useful in macros that call executables and pass command-line parameters to them.

URL Macros can be also used in URL Filters (Included/Excluded keywords lists in Server, Directory and Filename sections) and in URL Substitutes.

The support of URL Macros in URL Filters allows you to create universal templates for certain Web sites. A new set of macros is introduced for this purpose:

{:server} inserts the starting server name from the URLs field. For example, www.site.com

{:domain} inserts the domain of the server from the URLs field. For example, if the URL is http://www.site.com, its domain will be site.com

{:dir} inserts the starting directory name from the URLs field. For example, /directory/sub/

{:filename} inserts the starting filename from the URLs field. For example, file.asp?param

Variables

You may define your own variables:

{:myserv=metaproducts}

http://www.{:myserv}.com/

They help to make a universal Project that can be easily copied for downloading other sites. The macro variable can be used in URL Filters keywords and URL Substitutes rules.

If you have several URLs in the URLs field, Portable Offline Browser creates several URL Filters keywords - one per each of the specified URLs.