# Path: tools/shorturl.py
# class ShortUrl:
#     def googl(url, api_key=None, logger=None):
#     def isgd(url, api_key=None, logger=None):
#     def scenesat(url, api_key=None, alias=None, password=None, logger=None):
# 
# Path: tools/urlparse.py
# RE_PROTOCOL = r"(?:([\w\-_]+?)(?::\/\/))?"  # (1) match the protocol, strip :// e.g. https or ssh
# RE_DOMAIN = r"([\w\-_\.]+)"  # (2) match the domain, and any subdomains. e.g. www.google, google, or maps.google
# RE_TLD = r"\.([a-z]{2,16})"  # (3) The top level domain, does not account for unicode. e.g. com, info, org
# RE_PORT = r"(?::(\+?[1-9]\d{1,4}))?"  # (4) The port. e.g. google.com:100 extracts 100
# RE_PATH = r"(\/[^ ]+)?"  # (5) Get everything after the top level domain / port starting with a slash. e.g. /hi.html
# URL_REGEX = re.compile(RE_PROTOCOL + RE_DOMAIN + RE_TLD + RE_PORT + RE_PATH, re.I)
#     CERTAINTY_CAP = 100
# class Url:
#     def __init__(self, url, min_certainty=50):
#     def getCertainty(self):
#     def getMinCertainty(self):
#     def getUrl(self):
#     def getProtocol(self):
#     def getSubdomains(self):
#     def getDomain(self):
#     def getPort(self):
#     def getTld(self):
#     def getPath(self):
#     def getFactors(self):
#     def getAsDict(self):
#     def find(string):
#     def findAll(string):
#     def isUrl(self):
#     def encode(self):
#     def decode(self):
#     def _parse(self):
#     def _calculateCertainty(self):
#     def _addCertainty(self, amount, factor):


import html
import bs4
import urllib.request
from tools import shorturl
from tools import urlparse
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

UrlTools: Interact and manipulate URLs
"""




class UrlTools:
    SHORTEN_SERVICES = ["isgd", "googl", "scenesat"]

    def isUrl(url):
        return urlparse.Url(url).isUrl()

    def shorten(url, service, api_key=None, logger=None, ret_false=False):
        if service not in UrlTools.SHORTEN_SERVICES:
            return False if ret_false else "Service was not in available services."

        if not UrlTools.isUrl(url):
            return False if ret_false else "Url provided was not an URL."

        if api_key and service in api_key:
            api_key = api_key[service]
        else:
            api_key = None


# Path: tools/shorturl.py
# class ShortUrl:
#     def googl(url, api_key=None, logger=None):
#     def isgd(url, api_key=None, logger=None):
#     def scenesat(url, api_key=None, alias=None, password=None, logger=None):
# 
# Path: tools/urlparse.py
# RE_PROTOCOL = r"(?:([\w\-_]+?)(?::\/\/))?"  # (1) match the protocol, strip :// e.g. https or ssh
# RE_DOMAIN = r"([\w\-_\.]+)"  # (2) match the domain, and any subdomains. e.g. www.google, google, or maps.google
# RE_TLD = r"\.([a-z]{2,16})"  # (3) The top level domain, does not account for unicode. e.g. com, info, org
# RE_PORT = r"(?::(\+?[1-9]\d{1,4}))?"  # (4) The port. e.g. google.com:100 extracts 100
# RE_PATH = r"(\/[^ ]+)?"  # (5) Get everything after the top level domain / port starting with a slash. e.g. /hi.html
# URL_REGEX = re.compile(RE_PROTOCOL + RE_DOMAIN + RE_TLD + RE_PORT + RE_PATH, re.I)
#     CERTAINTY_CAP = 100
# class Url:
#     def __init__(self, url, min_certainty=50):
#     def getCertainty(self):
#     def getMinCertainty(self):
#     def getUrl(self):
#     def getProtocol(self):
#     def getSubdomains(self):
#     def getDomain(self):
#     def getPort(self):
#     def getTld(self):
#     def getPath(self):
#     def getFactors(self):
#     def getAsDict(self):
#     def find(string):
#     def findAll(string):
#     def isUrl(self):
#     def encode(self):
#     def decode(self):
#     def _parse(self):
#     def _calculateCertainty(self):
#     def _addCertainty(self, amount, factor):


# Path: tools/urltools.py
import html
import bs4
import urllib.request
from tools import shorturl
from tools import urlparse

FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

UrlTools: Interact and manipulate URLs
"""




class UrlTools:
    SHORTEN_SERVICES = ["isgd", "googl", "scenesat"]

    def isUrl(url):
        return urlparse.Url(url).isUrl()

    def shorten(url, service, api_key=None, logger=None, ret_false=False):
        if service not in UrlTools.SHORTEN_SERVICES:
            return False if ret_false else "Service was not in available services."

        if not UrlTools.isUrl(url):
            return False if ret_false else "Url provided was not an URL."

        if api_key and service in api_key:
            api_key = api_key[service]
        else:
            api_key = None


        return getattr(shorturl.ShortUrl, service)(url=url, api_key=api_key, logger=logger)