Webscript: Guidelines

Summary
Webscript: Guidelines
ident functionIdentifies the webscript to the library.
ident: Required fieldsMust set the following fields.
query_formats functionQueries the available formats to an URL.
query_formats: Required fieldsMust set the following fields.
query_formats: ErrorsParsing errors should raise an error.
parse functionParses the media details.
parse: Required fieldsMust set the following fields.
parse: Optional fieldsSet these if data is available or otherwise applicable.
parse: NotesImportant notes.
parse: ErrorsParsing (e.g.
General TipsUseful tips.
Additional modulesAdditional modules with functions.
IdiomsUseful lua idioms.
See alsoRelated pages.

ident function

Identifies the webscript to the library.

ident: Required fields

Must set the following fields.

  • self.domain (pattern, e.g.  “video.google.”)
  • self.formats (‘default’ or ‘default|best’ if >1 formats)
  • self.categories (protocol category of script)
  • self.handles (whether script can handle the URL)

query_formats function

Queries the available formats to an URL.

query_formats: Required fields

Must set the following fields.

  • self.formats (‘default’ or a dynamically created if >1 formats)

See youtube.lua, cbsnews.lua, dailymotion.lua and vimeo.lua for examples of >1 formats.

query_formats: Errors

Parsing errors should raise an error.

parse function

Parses the media details.

parse: Required fields

Must set the following fields.

  • self.host_id
  • self.title
  • self.id
  • self.url (NOTE: an array of URLs)

parse: Optional fields

Set these if data is available or otherwise applicable.

  • self.thumbnail_url (see youtube.lua)
  • self.redirect_url (academicearth.lua)
  • self.start_time (youtube.lua)
  • self.duration (soundcloud.lua)

parse: Notes

Important notes.

  • Fallback to ‘default’ if self.requested_format value is not recognized

parse: Errors

Parsing (e.g. no match) should call lua’s error function.  Note however that format parsing is exception to this rule:

  • Script must fallback to ‘default’ format and only if that fails too, exit with an error

General Tips

Useful tips.

quvi.fetch

  • Use sparingly
  • Set fetch_type only if fetching other than ‘page’ (default)
  • Set arbitrary_cookie only when absolutely necessary (dailymotion.lua)
  • Set user_agent only when absolutely necessary (globo.lua)

quvi.resolve

  • Use sparingly (see blip.lua)

Additional modules

Additional modules with functions.  These can be imported in your script.  Use them sparingly.

local U = require 'quvi/util'
local bar = U.unescape(foo)

See the quvi/ subdir in the website/ directory for the other modules.

Idioms

Useful lua idioms.

/* Consider the following in C */
b = (a == 1) 0:1;
-- Equivalent in lua:
b = (a == 1) and 0 or 1

Armed with this knowledge, consider the following.

local foo
if bar == 'baz' then
    foo = 'foo'
else
    foo = 'bar'
end

Could also be written like this.

local foo = (bar == 'baz') and 'foo' or 'bar'

See also

Related pages.

Close