parent
fd3011e96d
commit
195214649a
@ -1,15 +1,15 @@
|
||||
import re, base64
|
||||
import resolv
|
||||
from resolv.shared import ResolverError
|
||||
|
||||
def resolve(url):
|
||||
matches = re.search("https?:\/\/(www\.)?1channel\.ch\/external\.php\?.*url=([^&]+)", url)
|
||||
|
||||
if matches is None:
|
||||
raise resolv.ResolverError("The provided URL is not a valid external 1channel URL.")
|
||||
raise ResolverError("The provided URL is not a valid external 1channel URL.")
|
||||
|
||||
try:
|
||||
real_url = base64.b64decode(matches.group(2)).strip()
|
||||
except TypeError:
|
||||
raise resolv.ResolverError("The provided URL is malformed.")
|
||||
raise ResolverError("The provided URL is malformed.")
|
||||
|
||||
return { 'url': real_url }
|
||||
|
@ -0,0 +1,15 @@
|
||||
from HTMLParser import HTMLParser
|
||||
|
||||
import sys
|
||||
reload(sys)
|
||||
sys.setdefaultencoding("UTF-8")
|
||||
|
||||
class ResolverError(Exception):
|
||||
def __init__(self, value):
|
||||
self.val = value
|
||||
|
||||
def __str__(self):
|
||||
return repr(self.val)
|
||||
|
||||
def unescape(s):
|
||||
return HTMLParser.unescape.__func__(HTMLParser, s)
|
Loading…
Reference in New Issue