1
0
Fork 0

[framalink] Fix ycc shortner

This commit is contained in:
Max 2015-10-25 12:23:46 +01:00 committed by nemunaire
parent 04d5be04fa
commit 1e36846265
1 changed files with 11 additions and 4 deletions

View File

@ -19,9 +19,13 @@ def default_reducer(url, data):
snd_url = url + quote(data, "/:%@&=?")
return web.getURLContent(snd_url)
def ycc_reducer(url, data):
snd_url = url + quote(data, "/:%@&=?")
return "http://ycc.fr/%s" % web.getURLContent(snd_url)
def framalink_reducer(url, data):
json_data = json.loads(web.getURLContent(url, "lsturl="
+ quote(data),
json_data = json.loads(web.getURLContent(url, "lsturl=" + quote(data),
header={"Content-Type": "application/x-www-form-urlencoded"}))
if 'short' in json_data:
return json_data['short']
@ -34,7 +38,7 @@ def framalink_reducer(url, data):
PROVIDERS = {
"tinyurl": (default_reducer, "http://tinyurl.com/api-create.php?url="),
"ycc": (default_reducer, "http://ycc.fr/redirection/create/"),
"ycc": (ycc_reducer, "http://ycc.fr/redirection/create/"),
"framalink": (framalink_reducer, "https://frama.link/a?format=json")
}
DEFAULT_PROVIDER = "framalink"
@ -43,6 +47,7 @@ PROVIDERS_NETLOC = [urlparse(web.getNormalizedURL(url), "http").netloc for f, ur
# LOADING #############################################################
def load(context):
global DEFAULT_PROVIDER
@ -62,6 +67,7 @@ def reduce(url, provider=DEFAULT_PROVIDER):
"""
return PROVIDERS[provider][0](PROVIDERS[provider][1], url)
def gen_response(res, msg, srv):
if res is None:
raise IRCException("bad URL : %s" % srv)
@ -90,7 +96,8 @@ def parseresponse(msg):
o = urlparse(web._getNormalizedURL(url), "http")
# Skip short URLs
if o.netloc == "" or o.netloc in PROVIDERS or len(o.netloc) + len(o.path) < 17:
if (o.netloc == "" or o.netloc in PROVIDERS or
len(o.netloc) + len(o.path) < 17):
continue
for recv in msg.receivers: