[framalink] some refactor
This commit is contained in:
parent
2cd8f70cdc
commit
aa4050f6cd
@ -34,6 +34,7 @@ PROVIDERS = {
|
||||
}
|
||||
DEFAULT_PROVIDER = "framalink"
|
||||
|
||||
PROVIDERS_NETLOC = [urlparse(url, "http").netloc for f, url in PROVIDERS.values()]
|
||||
|
||||
# LOADING #############################################################
|
||||
|
||||
@ -81,11 +82,12 @@ def parseresponse(msg):
|
||||
try:
|
||||
urls = re.findall("([a-zA-Z0-9+.-]+:(?://)?[^ :]+)", msg.text)
|
||||
for url in urls:
|
||||
o = urlparse(url)
|
||||
if o.scheme != "":
|
||||
if o.netloc == "ycc.fr" or o.netloc == "tinyurl.com" or o.netloc == "frama.link" or (
|
||||
o.netloc == "" and len(o.path) < 10):
|
||||
o = urlparse(url, "http")
|
||||
|
||||
# Skip short URLs
|
||||
if o.netloc == "" or o.netloc in PROVIDERS or len(o.netloc) + len(o.path) < 17:
|
||||
continue
|
||||
|
||||
for recv in msg.receivers:
|
||||
if recv not in LAST_URLS:
|
||||
LAST_URLS[recv] = list()
|
||||
@ -119,12 +121,9 @@ def cmd_reduceurl(msg):
|
||||
res = list()
|
||||
for url in minify:
|
||||
o = urlparse(url, "http")
|
||||
if o.scheme != "":
|
||||
minief_url = reduce(url)
|
||||
if o.netloc == "":
|
||||
res.append(gen_response(minief_url, msg, o.scheme))
|
||||
else:
|
||||
res.append(gen_response(minief_url, msg, o.netloc))
|
||||
else:
|
||||
res.append(gen_response(None, msg, url))
|
||||
return res
|
||||
|
Loading…
Reference in New Issue
Block a user