Added Pastebin resolver

develop
Sven Slootweg 13 years ago
parent 19887d0184
commit 0754f110c4

@ -12,6 +12,8 @@ def resolve(url):
return youtube.resolve(url) return youtube.resolve(url)
elif re.match("https?:\/\/(www\.)?filebox\.com\/[a-zA-Z0-9]+", url) is not None: elif re.match("https?:\/\/(www\.)?filebox\.com\/[a-zA-Z0-9]+", url) is not None:
return filebox.resolve(url) return filebox.resolve(url)
elif re.match("https?:\/\/(www\.)?pastebin\.com\/[a-zA-Z0-9]+", url) is not None:
return pastebin.resolve(url)
else: else:
return {} return {}

@ -4,3 +4,4 @@ from sockshare import *
from onechannel import * from onechannel import *
from youtube import * from youtube import *
from filebox import * from filebox import *
from pastebin import *

@ -0,0 +1,24 @@
import re, urllib, urllib2
from resolv.shared import ResolverError
def resolve(url):
matches = re.search("https?:\/\/(www\.)?pastebin\.com\/([a-zA-Z0-9]+)", url)
if matches is None:
raise ResolverError("The provided URL is not a valid Pastebin URL.")
paste_id = matches.group(2)
try:
contents = urllib2.urlopen(url).read()
except:
raise ResolverError("Could not retrieve the specified URL. The specified paste may not exist.")
matches = re.search("<h1>([^<]+)</h1>", contents)
if matches is None:
raise ResolverError("The provided URL is not a valid paste.")
paste_title = urllib.unquote(matches.group(1))
return { 'title': paste_title, 'files': { 'file': "http://pastebin.com/download.php?i=%s" % paste_id } }
Loading…
Cancel
Save