From 3231cbf0870573c2719eda0777e789a85b8d281e Mon Sep 17 00:00:00 2001 From: Toni Gundogdu Date: Sun, 20 Oct 2013 19:46:20 +0300 Subject: [PATCH] media/metacafe.lua: Rewrite ident function Rewrite the `ident' function for the libquvi 0.9+ series. * Implement `Metacafe.can_parse_url' function * Remove any now obsolete code Signed-off-by: Toni Gundogdu --- share/media/metacafe.lua | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/share/media/metacafe.lua b/share/media/metacafe.lua index b114d57..e226239 100644 --- a/share/media/metacafe.lua +++ b/share/media/metacafe.lua @@ -21,18 +21,12 @@ local Metacafe = {} -- Utility functions unique to this script. --- Identify the script. -function ident(self) - package.path = self.script_dir .. '/?.lua' - local C = require 'quvi/const' - local r = {} - r.domain = "metacafe%.com" - r.formats = "default" - r.categories = C.proto_http - local U = require 'quvi/util' - r.handles = U.handles(self.page_url, {r.domain}, - {"/watch/%d+/", "/watch/yt-[^/]+/"}) - return r +-- Identify the media script. +function ident(qargs) + return { + can_parse_url = Metacafe.can_parse_url(qargs), + domains = table.concat({'metacafe.com'}, ',') + } end -- Query available formats. @@ -80,6 +74,20 @@ end -- Utility functions -- +function Metacafe.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('metacafe%.com$') + and t.path and (t.path:lower():match('^/watch/%d+/') + or t.path:lower():match('^/watch/yt-[^/]+/')) + then + return true + else + return false + end +end + function Metacafe.redirectp(self) local s = self.page_url:match('/watch/yt%-([^/]+)/') if s then -- Hand over to youtube.lua -- 2.11.4.GIT