diff --git a/pbincli/__init__.py b/pbincli/__init__.py index 048a81b..a31e423 100644 --- a/pbincli/__init__.py +++ b/pbincli/__init__.py @@ -2,6 +2,6 @@ # -*- coding: utf-8 -*- __author__ = "R4SAS " -__version__ = "0.3.1" +__version__ = "0.3.2b1" __copyright__ = "Copyright (c) R4SAS" __license__ = "MIT" diff --git a/pbincli/api.py b/pbincli/api.py index 92841a5..9a6b62a 100644 --- a/pbincli/api.py +++ b/pbincli/api.py @@ -95,6 +95,8 @@ class Shortener: self._yourls_init(settings) elif self.api == 'isgd' or self.api == 'vgd': self._gd_init() + elif self.api == 'custom': + self.apiurl == settings['short_url'] self.session, self.proxy = _config_requests(settings) @@ -142,6 +144,7 @@ class Shortener: 'isgd': self._gd, 'vgd': self._gd, 'cuttly': self._cuttly + 'custom': self._custom } # run function selected by choosen API servicesList[self.api](url) @@ -250,3 +253,17 @@ class Shortener: print("Short Link:\t{}".format(result.text)) except Exception as ex: PBinCLIError("cutt.ly: unexcepted behavior: {}".format(ex)) + + + def _custom(self, url): + from urllib.parse import quote + qUrl = quote(url, safe="") # urlencoded paste url + rUrl = self.apiurl.replace("{{url}}", qUrl) + + try: + result = self.session.get( + url = rUrl, + proxies = self.proxy) + print("Short Link:\t{}".format(result.text)) + except Exception as ex: + PBinCLIError("Shorter: unexcepted behavior: {}".format(ex)) diff --git a/pbincli/cli.py b/pbincli/cli.py index b8a141f..763d39c 100755 --- a/pbincli/cli.py +++ b/pbincli/cli.py @@ -47,7 +47,7 @@ def main(): ## URL shortener send_parser.add_argument("-S", "--short", default=False, action="store_true", help="use URL shortener") send_parser.add_argument("--short-api", default=argparse.SUPPRESS, action="store", - choices=["tinyurl", "clckru", "isgd", "vgd", "cuttly", "yourls"], help="API used by shortener service") + choices=["tinyurl", "clckru", "isgd", "vgd", "cuttly", "yourls", "custom"], help="API used by shortener service") send_parser.add_argument("--short-url", default=argparse.SUPPRESS, help="URL of shortener service API") send_parser.add_argument("--short-user", default=argparse.SUPPRESS, help="Shortener username") send_parser.add_argument("--short-pass", default=argparse.SUPPRESS, help="Shortener password")