Expand shortURL link to Original URL

Simple script to return or expand a shortURL link. It use Python.

It include more 20 different shortURL links provider.
If the link provider is not in the list set Force to True

set dialogText to "Paste the shortURL link:"
set theURLString to (display dialog dialogText default answer "https://apple.co/3oFQeDf")'s text returned

display alert (my expandShortURL:theURLString force:"False")

on expandShortURL:_theURL force:_bool
	set theScript to "
import requests
from urlparse import urlparse, urljoin


def resolve_short_url(url, force=False, depth=1):
    domain = urlparse(url).netloc

    if not force and len(domain) >= 7 and domain not in URL_SHORTENERS:
        return url
    count = 0

    while count < depth:
        count += 1

        r = requests.head(url, allow_redirects=False)

        if 'location' not in r.headers:
        url = r.headers['location']

        if url.startswith('//'):
            parsed_rurl = urlparse(r.url)
            url = '%s:%s' % (parsed_rurl.scheme, url)

        if not urlparse(url).netloc:
            url = urljoin(r.url, url)
    return url

print resolve_short_url('" & _theURL & "', '" & _bool & "',1)
	return (do shell script "python <<EOF" & theScript & "EOF") as text
end expandShortURL:force: