JamesBond531 commited on
Commit
8b47596
1 Parent(s): 9352d5b

Add second shortlink for file link

Browse files
Files changed (1) hide show
  1. utils.py +32 -4
utils.py CHANGED
@@ -578,8 +578,7 @@ async def get_shortlink(chat_id, link, second=False):
578
  try:
579
  link = await shortzy.convert(link)
580
  except:
581
- await get_shortlink(chat_id, link, second=True)
582
- return
583
  return link
584
 
585
  # async def get_shortlink(chat_id, link, second=False):
@@ -686,7 +685,36 @@ async def get_shortlink(chat_id, link, second=False):
686
 
687
  # # link = await shortzy.convert(link)
688
  # # return link
689
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
690
  async def get_tutorial(chat_id):
691
  settings = await get_settings(chat_id) #fetching settings for group
692
  if 'tutorial' in settings.keys():
@@ -871,7 +899,7 @@ def get_name(media_msg: Message) -> str:
871
 
872
  def get_hash(media_msg: Message) -> str:
873
  media = get_media_from_message(media_msg)
874
- return getattr(media, "file_unique_id", "")[:6]
875
 
876
  def addBracketInYear(name):
877
  year = []
 
578
  try:
579
  link = await shortzy.convert(link)
580
  except:
581
+ return await get_shortlink(chat_id, link, second=True)
 
582
  return link
583
 
584
  # async def get_shortlink(chat_id, link, second=False):
 
685
 
686
  # # link = await shortzy.convert(link)
687
  # # return link
688
+
689
+
690
+ async def second_shortlink(url, link):
691
+ if "shrs" in url:
692
+ URL = SECOND_SHORTLINK_URL
693
+ API = SECOND_SHORTLINK_API
694
+ else:
695
+ URL = SHORTLINK_URL
696
+ API = SHORTLINK_API
697
+ if URL == "api.shareus.io":
698
+ url = f'https://{URL}/easy_api'
699
+ params = {
700
+ "key": API,
701
+ "link": link,
702
+ }
703
+ try:
704
+ async with aiohttp.ClientSession() as session:
705
+ async with session.get(url, params=params, raise_for_status=True, ssl=False) as response:
706
+ data = await response.text()
707
+ return data
708
+ except Exception as e:
709
+ logger.error(e)
710
+ else:
711
+ shortzy = Shortzy(api_key=API, base_site=URL)
712
+ try:
713
+ link = await shortzy.convert(link)
714
+ except:
715
+ return await second_shortlink("mplaylink", link)
716
+ return link
717
+
718
  async def get_tutorial(chat_id):
719
  settings = await get_settings(chat_id) #fetching settings for group
720
  if 'tutorial' in settings.keys():
 
899
 
900
  def get_hash(media_msg: Message) -> str:
901
  media = get_media_from_message(media_msg)
902
+ return getattr(media, "file_unique_id", "")[:6]
903
 
904
  def addBracketInYear(name):
905
  year = []