From 65b77ccf8ebe8876d39c6aea9b65158b1561e2c9 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Tue, 5 Jun 2012 04:49:27 +0200 Subject: [PATCH] Added 1channel external URL resolver --- __init__.py | 2 ++ resolvers/__init__.py | 1 + resolvers/onechannel.py | 15 +++++++++++++++ 3 files changed, 18 insertions(+) create mode 100644 resolvers/onechannel.py diff --git a/__init__.py b/__init__.py index ad72db8..dfa49d3 100644 --- a/__init__.py +++ b/__init__.py @@ -6,5 +6,7 @@ def resolve(url): return putlocker.resolve(url) elif re.match("https?:\/\/(www\.)?sockshare\.com", url) is not None: return sockshare.resolve(url) + elif re.match("https?:\/\/(www\.)?1channel\.ch\/external\.php", url) is not None: + return onechannel.resolve(url) else: return {} diff --git a/resolvers/__init__.py b/resolvers/__init__.py index 22aea7e..208f9cf 100644 --- a/resolvers/__init__.py +++ b/resolvers/__init__.py @@ -1,3 +1,4 @@ from dummy import * from putlocker import * from sockshare import * +from onechannel import * diff --git a/resolvers/onechannel.py b/resolvers/onechannel.py new file mode 100644 index 0000000..d94ed7d --- /dev/null +++ b/resolvers/onechannel.py @@ -0,0 +1,15 @@ +import re, base64 +from resolv.shared import ResolverError + +def resolve(url): + matches = re.search("https?:\/\/(www\.)?1channel\.ch\/external\.php\?.*url=([^&]+)", url) + + if matches is None: + raise ResolverError("The provided URL is not a valid external 1channel URL.") + + try: + real_url = base64.b64decode(matches.group(2)).strip() + except TypeError: + raise ResolverError("The provided URL is malformed.") + + return { 'url': real_url }