From e71af14d94223a7d9b14c1b923b512aca7a3eb43 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Mon, 29 Oct 2012 15:23:20 +0100 Subject: [PATCH] Add support for MediaFire document viewer URLs --- resolv/__init__.py | 2 +- resolv/resolvers/mediafire.py | 11 +++++++++++ test.py | 3 ++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/resolv/__init__.py b/resolv/__init__.py index 90507c7..94fa4b6 100644 --- a/resolv/__init__.py +++ b/resolv/__init__.py @@ -31,7 +31,7 @@ def resolve(url): elif re.match("https?:\/\/(www\.)?pastebin\.com\/[a-zA-Z0-9]+", url) is not None: task = resolvers.PastebinTask(url) return task.run() - elif re.match("https?:\/\/(www\.)?mediafire\.com\/\?[a-z0-9]+", url) is not None: + elif re.match("https?:\/\/(www\.)?mediafire\.com\/(view\/)?\?[a-z0-9]+", url) is not None: task = resolvers.MediafireTask(url) return task.run() else: diff --git a/resolv/resolvers/mediafire.py b/resolv/resolvers/mediafire.py index a891ab1..c584cc2 100644 --- a/resolv/resolvers/mediafire.py +++ b/resolv/resolvers/mediafire.py @@ -9,6 +9,17 @@ class MediafireTask(Task): author_url = "http://cryto.net/~joepie91" def run(self): + url_match = re.match("(https?):\/\/(www\.)?mediafire\.com\/view\/\?([a-z0-9]+)", self.url) + + if url_match is not None: + self.url = "%s://%smediafire.com/?%s" % url_match.groups(1) + + url_match = re.match("(https?):\/\/(www\.)?mediafire\.com\/\?([a-z0-9]+)", self.url) + + if url_match is None: + self.state = "invalid" + raise ResolverError("The specified URL is not a valid MediaFire URL.") + try: contents = self.fetch_page(self.url) except urllib2.URLError, e: diff --git a/test.py b/test.py index 0055110..aa80d43 100644 --- a/test.py +++ b/test.py @@ -19,7 +19,8 @@ suites = { }, 'mediafire': { "MediaFire": "http://www.mediafire.com/?vxltbkr2l9ycmah", - "MediaFire with password (mfddl)": "http://www.mediafire.com/?traa1p0lki9611h" + "MediaFire with password (mfddl)": "http://www.mediafire.com/?traa1p0lki9611h", + 'MediaFire Document Viewer': "http://www.mediafire.com/view/?vxltbkr2l9ycmah" }, 'youtube': { "YouTube": "http://www.youtube.com/watch?v=XSGBVzeBUbk"