From bc01ae90bf556e243ac4522a9ba63d2d0c8715b5 Mon Sep 17 00:00:00 2001 From: Toni Gundogdu Date: Tue, 30 Apr 2013 12:24:09 +0300 Subject: [PATCH] media/liveleak.lua: Rewrite ident function Rewrite the `ident' function for the libquvi 0.9+ series. * Implement `LiveLeak.can_parse_url' function * Remove any now obsolete code Signed-off-by: Toni Gundogdu --- share/media/liveleak.lua | 45 ++++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/share/media/liveleak.lua b/share/media/liveleak.lua index cd99aab..1708795 100644 --- a/share/media/liveleak.lua +++ b/share/media/liveleak.lua @@ -20,19 +20,12 @@ local LiveLeak = {} -- Utility functions specific to this script --- Identify the script. -function ident(self) - package.path = self.script_dir .. '/?.lua' - local C = require 'quvi/const' - local r = {} - r.domain = "liveleak%.com" - r.formats = "default" - r.categories = C.proto_http - local U = require 'quvi/util' - LiveLeak.normalize(self) - r.handles = U.handles(self.page_url, - {r.domain}, {"view"}, {"i=[%w_]+"}) - return r +-- Identify the media script. +function ident(qargs) + return { + can_parse_url = LiveLeak.can_parse_url(qargs), + domains = table.concat({'liveleak.com'}, ',') + } end -- Query available formats. @@ -70,20 +63,18 @@ end -- Utility functions -- -function LiveLeak.normalize(self) - if not self.page_url then return self.page_url end - - local U = require 'quvi/url' - local t = U.parse(self.page_url) - - if not t.path then return self.page_url end - - local i = t.path:match('/e/([_%w]+)') - if i then - t.query = 'i=' .. i - t.path = '/view' - self.page_url = U.build(t) - end +function LiveLeak.can_parse_url(qargs) + local U = require 'socket.url' + local t = U.parse(qargs.input_url) + if t and t.scheme and t.scheme:lower():match('^http$') + and t.host and t.host:lower():match('liveleak%.com$') + and t.path and t.path:lower():match('^/view') + and t.query and t.query:lower():match('i=[_%w]+') + then + return true + else + return false + end end -- vim: set ts=4 sw=4 tw=72 expandtab: -- 2.11.4.GIT