Added support for the i.gal shortener. This is a very basical implementation as i.gal requires an API key to work

This commit is contained in:
Iván Novegil Cancelas 2017-11-29 18:03:37 +01:00
parent 8928a64a12
commit de0af09a33
3 changed files with 21 additions and 2 deletions

View File

@ -25,7 +25,7 @@ def unshorten (url, service=None, **kwargs):
def default_service ():
return shorteners.AcortameShortener
return shorteners.IgalShortener
def find_service (service, **kwargs):
for i in shorteners.__all__:

View File

@ -7,4 +7,5 @@ from tinyurl import TinyurlShortener
from xedcc import XedccShortener
from clckru import ClckruShortener
from acortame import AcortameShortener
__all__ = ["HKCShortener", "IsgdShortener", "OnjmeShortener", "TinyArrowsShortener", "TinyurlShortener", "XedccShortener", "ClckruShortener", "AcortameShortener"]
from igal import IgalShortener
__all__ = ["HKCShortener", "IsgdShortener", "OnjmeShortener", "TinyArrowsShortener", "TinyurlShortener", "XedccShortener", "ClckruShortener", "AcortameShortener", "IgalShortener"]

View File

@ -0,0 +1,18 @@
from url_shortener import URLShortener
import requests
import urllib
class IgalShortener (URLShortener):
def __init__(self, *args, **kwargs):
self.name = "i.gal"
super(IgalShortener, self).__init__(*args, **kwargs)
def _shorten (self, url):
answer = url
api = requests.get ("https://i.gal/api/v2/action/shorten?key=apikey&url=" + urllib.quote(url))
if api.status_code == 200:
answer = api.text
return answer
def created_url (self, url):
return 'i.gal' in url