From f5cbd0dd90a6afaa4ef67b4414df602ce8bf6ec9 Mon Sep 17 00:00:00 2001 From: Toni Gundogdu Date: Tue, 6 Dec 2011 14:00:02 +0200 Subject: [PATCH] tcmag.lua: Make query_formats work with external content Additional changes * Check for liveleak content * Fix self.id pattern --- share/lua/website/tcmag.lua | 51 ++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/share/lua/website/tcmag.lua b/share/lua/website/tcmag.lua index 32bb90d..d897eed 100644 --- a/share/lua/website/tcmag.lua +++ b/share/lua/website/tcmag.lua @@ -20,8 +20,10 @@ -- 02110-1301 USA -- +local TCMag = {} -- Utility functions specific to this script + -- Identify the script. -function ident (self) +function ident(self) package.path = self.script_dir .. '/?.lua' local C = require 'quvi/const' local r = {} @@ -36,40 +38,51 @@ end -- Query available formats. function query_formats(self) self.formats = 'default' - return self + return TCMag.check_external_content(self) end -- Parse media URL. -function parse (self) +function parse(self) self.host_id = "tcmag" - local page = quvi.fetch(self.page_url) + return TCMag.check_external_content(self) +end + +-- +-- Utility functions +-- + +function TCMag.check_external_content(self) + local page = quvi.fetch(self.page_url) - local _,_,s = page:find('
(.-)
') - local article = s or error ("no match: article") + local article = page:match('
(.-)
') + or error("no match: article") - local _,_,s = article:find('http://.*youtube.com/embed/([^/]-)"') - if s then - -- Hand over to youtube.lua + local s = article:match('http://.*youtube.com/embed/([^/]-)"') + if s then -- Hand over to youtube.lua self.redirect_url = 'http://youtube.com/watch?v=' .. s return self end - local _,_,s = article:find('http://.*vimeo.com/video/([0-9]+)') - if s then - -- Hand over to vimeo.lua + local s = article:match('http://.*vimeo.com/video/([0-9]+)') + if s then -- Hand over to vimeo.lua self.redirect_url = 'http://vimeo.com/video/' .. s return self end - local _,_,s = article:find("'file': '(.-)',") - self.url = {s or error ("no match: media url")} - local url = s + local s = article:match('http://.*liveleak.com/e/([%w_]+)') + if s then -- Hand over to liveleak.lua + self.redirect_url = 'http://liveleak.com/e/' .. s + return self + end + + self.title = article:match('

(.-)

') + or error ("no match: media title") - local _,_,s = article:find('

(.-)

') - self.title = s or error ("no match: media title") + self.url = {article:match("'file': '(.-)',") + or error("no match: media url")} - local _,_,s = url:find("/(.-)/sizes/") - self.id = s or error ("no match: media id") + self.id = self.url[1]:match("/%d+/%d+/(.-)/sizes/") + or error ("no match: media id") return self end -- 2.11.4.GIT