Use the proper decoding function for titles

develop
Sven Slootweg 12 years ago
parent c211e67635
commit f93f948574

@ -1,5 +1,5 @@
import re, urllib, urllib2
from resolv.shared import ResolverError
from resolv.shared import ResolverError, unescape
def resolve(url):
matches = re.search("https?:\/\/(www\.)?pastebin\.com\/([a-zA-Z0-9]+)", url)
@ -19,6 +19,6 @@ def resolve(url):
if matches is None:
raise ResolverError("The provided URL is not a valid paste.")
paste_title = urllib.unquote(matches.group(1))
paste_title = unescape(matches.group(1))
return { 'title': paste_title, 'files': { 'file': "http://pastebin.com/download.php?i=%s" % paste_id } }

@ -1,5 +1,5 @@
import re
from resolv.shared import ResolverError
from resolv.shared import ResolverError, unescape
def resolve(url):
try:
@ -48,7 +48,7 @@ def resolve(url):
video_file = matches.group(1)
try:
video_title = urllib.unquote(re.search('<a href="\/file\/[^"]+"[^>]*><strong>([^<]*)<\/strong><\/a>', page).group(1))
video_title = unescape(re.search('<a href="\/file\/[^"]+"[^>]*><strong>([^<]*)<\/strong><\/a>', page).group(1))
except:
raise ResolverError("Could not find the video title.")

@ -1,5 +1,5 @@
import re
from resolv.shared import ResolverError
from resolv.shared import ResolverError, unescape
def resolve(url):
try:
@ -48,7 +48,7 @@ def resolve(url):
video_file = matches.group(1)
try:
video_title = urllib.unquote(re.search('<a href="\/file\/[^"]+"[^>]*><strong>([^<]*)<\/strong><\/a>', page).group(1))
video_title = unescape(re.search('<a href="\/file\/[^"]+"[^>]*><strong>([^<]*)<\/strong><\/a>', page).group(1))
except:
raise ResolverError("Could not find the video title.")

@ -1,5 +1,5 @@
import re, urllib, urllib2
from resolv.shared import ResolverError
from resolv.shared import ResolverError, unescape
def resolve(url):
try:
@ -69,7 +69,7 @@ def resolve(url):
stream_pool['video_%s_%s' % (video_quality, video_format)] = video_url
try:
video_title = urllib.unquote(re.search('<meta property="og:title" content="([^"]*)">', contents).group(1))
video_title = unescape(re.search('<meta property="og:title" content="([^"]*)">', contents).group(1))
except:
raise ResolverError("Could not find the video title.")

@ -4,3 +4,11 @@ class ResolverError(Exception):
def __str__(self):
return repr(self.val)
def unescape(s):
s = s.replace("&lt;", "<")
s = s.replace("&gt;", ">")
s = s.replace("&quot;", '"')
s = s.replace("&apos;", "'")
s = s.replace("&amp;", "&")
return s

Loading…
Cancel
Save