Removed URL Shorteners

This commit is contained in:
Manuel Cortez 2021-11-08 15:29:23 -06:00
parent 076761b9dd
commit 1c8ee1a64f
12 changed files with 0 additions and 282 deletions

View File

@ -1,3 +0,0 @@
from __future__ import unicode_literals
from . import shorteners
from . __main__ import *

View File

@ -1,46 +0,0 @@
from __future__ import unicode_literals
from functools import wraps
from . import shorteners
def service_selecter (func):
@wraps(func)
def wrapper (*args, **kwargs):
tmp = dict(kwargs)
if 'service' in tmp:
del(tmp['service'])
kwargs['service'] = find_service(kwargs['service'], **tmp) or default_service()
else:
kwargs['service'] = default_service()
return func(*args, **kwargs)
return wrapper
@service_selecter
def shorten (url, service=None, **kwargs):
return service(**kwargs).shorten(url)
@service_selecter
def unshorten (url, service=None, **kwargs):
return service(**kwargs).unshorten(url)
def default_service ():
return shorteners.AcortameShortener
def find_service (service, **kwargs):
for i in shorteners.__all__:
obj = getattr(shorteners, i)(**kwargs)
if obj.name.lower() == service.lower():
return getattr(shorteners, i)
def list_services ():
return [getattr(shorteners, i)().name for i in shorteners.__all__]
def unshorten_any (url):
"""Unshortens an URL using any available unshortener. Check to see if unshortened URL was created by a shortener (nested) and unshorten if so."""
unshortened_url = shorteners.URLShortener().unshorten(url)
# None is returned if URL not unshortened
if unshortened_url:
return unshorten_any(unshortened_url)
return url

View File

@ -1,11 +0,0 @@
from __future__ import unicode_literals
from .url_shortener import URLShortener
from .hkcim import HKCShortener
from . isgd import IsgdShortener
from . onjme import OnjmeShortener
from . tinyarrows import TinyArrowsShortener
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"]

View File

@ -1,30 +0,0 @@
from __future__ import unicode_literals
from future import standard_library
standard_library.install_aliases()
from . url_shortener import URLShortener
import requests
import urllib.request, urllib.parse, urllib.error
class AcortameShortener (URLShortener):
def __init__(self, *args, **kwargs):
self.name = "acorta.me"
super(AcortameShortener, self).__init__(*args, **kwargs)
def _shorten (self, url):
answer = url
api = requests.get ("https://acorta.me/api.php?action=shorturl&format=simple&url=" + urllib.parse.quote(url))
if api.status_code == 200:
answer = api.text
return answer
def created_url (self, url):
return 'acorta.me' in url
def unshorten (self, url):
if not 'acorta.me' in url:
#use generic expand method
return super(AcortameShortener, self).unshorten(url)
answer = url
api = requests.get ("https://acorta.me/api.php?action=expand&format=simple&shorturl=" + urllib.parse.quote(url))
if api.status_code == 200:
answer = api.text
return answer

View File

@ -1,22 +0,0 @@
from __future__ import unicode_literals
from future import standard_library
standard_library.install_aliases()
import urllib.request, urllib.parse, urllib.error
import requests
from . url_shortener import URLShortener
class ClckruShortener (URLShortener):
def __init__ (self, *args, **kwargs):
self.name = "clck.ru"
super(ClckruShortener, self).__init__(*args, **kwargs)
def _shorten (self, url):
answer = url
api = requests.get ("http://clck.ru/--?url=" + urllib.parse.quote(url))
if api.status_code == 200:
answer = api.text
return answer
def created_url (self, url):
return 'clck.ru' in url

View File

@ -1,21 +0,0 @@
from __future__ import unicode_literals
from future import standard_library
standard_library.install_aliases()
import urllib.request, urllib.parse, urllib.error
import requests
from . url_shortener import URLShortener
class HKCShortener (URLShortener):
def __init__ (self, *args, **kwargs):
self.name = "HKC.im"
super(HKCShortener, self).__init__(*args, **kwargs)
def _shorten (self, url):
answer = url
api = requests.get ("http://hkc.im/yourls-api.php?action=shorturl&format=simple&url=" + urllib.parse.quote(url))
if api.status_code == 200:
answer = api.text
return answer
def created_url (self, url):
return 'hkc.im' in url.lower()

View File

@ -1,22 +0,0 @@
from __future__ import unicode_literals
from future import standard_library
standard_library.install_aliases()
import urllib.request, urllib.parse, urllib.error
import requests
from . url_shortener import URLShortener
class IsgdShortener (URLShortener):
def __init__ (self, *args, **kwargs):
self.name = "Is.gd"
super(IsgdShortener, self).__init__(*args, **kwargs)
def _shorten (self, url):
answer = url
api = requests.get ("http://is.gd/api.php?longurl=" + urllib.parse.quote(url))
if api.status_code == 200:
answer = api.text
return answer
def created_url (self, url):
return 'is.gd' in url

View File

@ -1,21 +0,0 @@
from __future__ import unicode_literals
from future import standard_library
standard_library.install_aliases()
import urllib.request, urllib.parse, urllib.error
import requests
from . url_shortener import URLShortener
class OnjmeShortener (URLShortener):
def __init__ (self, *args, **kwargs):
self.name = "Onj.me"
super(OnjmeShortener, self).__init__(*args, **kwargs)
def _shorten (self, url):
answer = url
api = requests.get ("http://onj.me/yourls-api.php?action=shorturl&format=simple&url=" + urllib.parse.quote(url))
if api.status_code == 200:
answer = api.text
return answer
def created_url (self, url):
return 'onj.me' in url.lower()

View File

@ -1,21 +0,0 @@
from __future__ import unicode_literals
from future import standard_library
standard_library.install_aliases()
import urllib.request, urllib.parse, urllib.error
import requests
from . url_shortener import URLShortener
class TinyArrowsShortener (URLShortener):
def __init__ (self, *args, **kwargs):
self.name = "TinyArro.ws"
super(TinyArrowsShortener, self).__init__(*args, **kwargs)
def _shorten (self, url):
answer = url
api = requests.get("http://tinyarro.ws/api-create.php?utfpure=1&url=%s" % urllib.parse.quote(url))
if api.status_code == 200:
answer = api.text
return answer.decode('UTF-8')
def created_url(self, url):
return "tinyarro.ws" in url

View File

@ -1,20 +0,0 @@
from __future__ import unicode_literals
from future import standard_library
standard_library.install_aliases()
from .url_shortener import URLShortener
import requests
import urllib.request, urllib.parse, urllib.error
class TinyurlShortener (URLShortener):
def __init__(self, *args, **kwargs):
self.name = "TinyURL.com"
super(TinyurlShortener, self).__init__(*args, **kwargs)
def _shorten (self, url):
answer = url
api = requests.get ("http://tinyurl.com/api-create.php?url=" + urllib.parse.quote(url))
if api.status_code == 200:
answer = api.text
return answer
def created_url (self, url):
return 'tinyurl.com' in url

View File

@ -1,44 +0,0 @@
from __future__ import unicode_literals
from builtins import object
import requests
class URLShortener (object):
def __init__ (self, *args, **kwargs):
#Stub out arguments, silly object. :(
return super(URLShortener, self).__init__()
def shorten (self, url):
if self.created_url(url):
return url
else:
return self._shorten(url)
def _shorten (self, url):
raise NotImplementedError
def created_url (self, url):
"""Returns a boolean indicating whether or not this shortener created a provided url"""
raise NotImplementedError
def unshorten(self, url):
try:
r=requests.head(url)
if 'location' in list(r.headers.keys()):
if 'dropbox.com' in r.headers['location']:
return handle_dropbox(r.headers['location'])
else:
return r.headers['location']
else: # if the head method does not work, use get instead. Performance may decrease
r=requests.get(url, allow_redirects=False, stream=True)
# release the connection without downloading the content, we only need the response headers
r.close()
return r.headers['location']
except:
return url #we cannot expand
def handle_dropbox(url):
if url.endswith("dl=1"):
return url
else:
return url.replace("dl=0", "dl=1")

View File

@ -1,21 +0,0 @@
from __future__ import unicode_literals
from future import standard_library
standard_library.install_aliases()
import urllib.request, urllib.parse, urllib.error
import requests
from . url_shortener import URLShortener
class XedccShortener (URLShortener):
def __init__ (self, *args, **kwargs):
self.name = "Xed.cc"
super(XedccShortener, self).__init__(*args, **kwargs)
def _shorten (self, url):
answer = url
api = requests.get ("http://xed.cc/yourls-api.php?action=shorturl&format=simple&url=" + urllib.parse.quote(url))
if api.status_code == 200:
answer = api.text
return answer
def created_url (self, url):
return 'xed.cc' in url.lower()