1111import aiohttp
1212import asyncio
1313import json
14- from .exceptions import (
14+ from .errors import (
1515 ShortlyError ,
1616 ShortlyInvalidLinkError ,
1717 ShortlyLinkNotFoundError ,
@@ -25,7 +25,7 @@ def __init__(self, api_key: str = None, base_site: str = None):
2525 self .api_key = api_key
2626 self .base_site = base_site
2727
28- async def adlinkfy_convert (self , link , alias = None , silently = False , timeout = 10 ):
28+ async def adlinkfy_convert (self , link , alias = None , silently = False , timeout = 30 ):
2929 """
3030 Shorten a URL using Link Shortly/All Adlinkfy API.
3131
@@ -35,7 +35,7 @@ async def adlinkfy_convert(self, link, alias=None, silently=False, timeout=10):
3535 link (str): The long URL you want to shorten.
3636 alias (str, optional): Custom alias for the short link. Default is None.
3737 silently (bool): If True, the function will directly return the original URL without raising errors.
38- timeout (int, optional): Maximum seconds to wait for API response. Default is 10 .
38+ timeout (int, optional): Maximum seconds to wait for API response. Default is 30 .
3939
4040 Returns:
4141 str: The shortened URL returned by the API.
@@ -48,11 +48,12 @@ async def adlinkfy_convert(self, link, alias=None, silently=False, timeout=10):
4848 ShortlyJsonDecodeError: If API response is not valid JSON.
4949 ShortlyError: For other API-related errors.
5050 """
51+ if silently :
52+ return link
53+
5154 api_url = f"https://{ self .base_site } /api"
5255 params = {"api" : self .api_key , "url" : link }
53-
54- if silently :
55- return link
56+
5657 if alias :
5758 params ["alias" ] = alias
5859
@@ -93,7 +94,7 @@ async def adlinkfy_convert(self, link, alias=None, silently=False, timeout=10):
9394 except Exception as e :
9495 raise ShortlyError (f"An unexpected error occurred: { e } " )
9596
96- async def ouo_convert (self , link , alias = None , silently = False , timeout = 10 ):
97+ async def ouo_convert (self , link , alias = None , silently = False , timeout = 30 ):
9798 """
9899 Shorten a URL using ouo.io API.
99100
@@ -107,7 +108,7 @@ async def ouo_convert(self, link, alias=None, silently=False, timeout=10):
107108 return link
108109
109110 # API endpoint
110- api_url = f"http ://{ self .base_site } /api/{ self .api_key } "
111+ api_url = f"https ://{ self .base_site } /api/{ self .api_key } "
111112 params = {"s" : link }
112113
113114 try :
@@ -127,7 +128,7 @@ async def ouo_convert(self, link, alias=None, silently=False, timeout=10):
127128 except Exception as e :
128129 raise ShortlyError (f"Ouo.io unexpected error: { e } " )
129130
130- async def shareus_convert (self , link , alias = None , silently = False , timeout = 10 ):
131+ async def shareus_convert (self , link , alias = None , silently = False , timeout = 30 ):
131132 """
132133 Shorten a URL using Shareus.io API.
133134
@@ -137,7 +138,7 @@ async def shareus_convert(self, link, alias=None, silently=False, timeout=10):
137138 link (str): The long URL you want to shorten.
138139 alias (str, optional): Custom alias for the short link. Default is None.
139140 silently (bool): If True, the function will directly return the original URL without raising errors.
140- timeout (int, optional): Maximum seconds to wait for API response. Default is 10 .
141+ timeout (int, optional): Maximum seconds to wait for API response. Default is 30 .
141142
142143 Returns:
143144 str: The shortened URL returned by the API.
@@ -201,7 +202,7 @@ async def shareus_convert(self, link, alias=None, silently=False, timeout=10):
201202 except Exception as e :
202203 raise ShortlyError (f"An unexpected error occurred: { e } " )
203204
204- async def tinyurl_convert (self , link , alias = None , silently = False , timeout = 10 ):
205+ async def tinyurl_convert (self , link , alias = None , silently = False , timeout = 30 ):
205206 """
206207 Shorten a URL using TinyURL API - supports both old (no token) and new (with token) APIs
207208 """
@@ -214,12 +215,12 @@ async def tinyurl_convert(self, link, alias=None, silently=False, timeout=10):
214215 else :
215216 return await self ._tinyurl_old_api (link , alias , timeout )
216217
217- async def _tinyurl_old_api (self , link , alias = None , timeout = 10 ):
218+ async def _tinyurl_old_api (self , link , alias = None , timeout = 30 ):
218219 """
219220 Old TinyURL API (no token required)
220- Docs: http ://tinyurl.com/api-create.php
221+ Docs: https ://tinyurl.com/api-create.php
221222 """
222- api_url = f"http ://{ self .base_site } /api-create.php"
223+ api_url = f"https ://{ self .base_site } /api-create.php"
223224 params = {"url" : link }
224225
225226 if alias :
@@ -245,7 +246,7 @@ async def _tinyurl_old_api(self, link, alias=None, timeout=10):
245246 except Exception as e :
246247 raise ShortlyError (f"TinyURL unexpected error: { e } " )
247248
248- async def _tinyurl_new_api (self , link , alias = None , timeout = 10 ):
249+ async def _tinyurl_new_api (self , link , alias = None , timeout = 30 ):
249250 """
250251 New TinyURL API (requires token)
251252 Docs: https://tinyurl.com/app/dev/api
@@ -322,7 +323,7 @@ async def _tinyurl_new_api(self, link, alias=None, timeout=10):
322323 except Exception as e :
323324 raise ShortlyError (f"TinyURL unexpected error: { e } " )
324325
325- async def bitly_convert (self , link , alias = None , silently = False , timeout = 10 ):
326+ async def bitly_convert (self , link , alias = None , silently = False , timeout = 30 ):
326327 """
327328 Bitly API का उपयोग करके URL को छोटा (shorten) करें।
328329 Docs: https://dev.bitly.com/api-reference
0 commit comments