Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tests/modules/test_adfly.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ def test_adfly_valid_link(adfly):
assert uri == 'https://microsoft.com'


def test_adfly_valid_link__redirection(adfly):
uri = adfly.unshorten('http://adf.ly/1ZpGSo')
assert uri == 'http://www.google.com/'


def test_adfly_invalid_link(adfly):
with pytest.raises(UnshortenFailed, message='No ysmm variable found.'):
adfly.unshorten('http://adf.ly/1icWR')
Expand Down
9 changes: 9 additions & 0 deletions unshortenit/modules/adfly.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
from unshortenit.module import UnshortenModule
from unshortenit.exceptions import UnshortenFailed

from six.moves import urllib_parse


class AdfLy(UnshortenModule):

name = 'adfly'
domains = set([
'adf.ly',
'clearload.bid',
'j.gs',
'q.gs',
'u.bb',
Expand All @@ -29,6 +32,12 @@ def unshorten(self, uri: str) -> str:
ysmm = re.findall(r'var ysmm =.*\;?', res.text)

if len(ysmm) == 0:

parsed_url = urllib_parse.urlparse(res.url)

if parsed_url.netloc not in self.domains:
return res.url

raise UnshortenFailed('No ysmm variable found.')

# Decode the ysmm variable and extract the actual link
Expand Down