Skip to content

Commit fbbdac4

Browse files
committed
Add support to nyaa.si
1 parent af44349 commit fbbdac4

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

torrenthunt.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json, ssl
33
from pathlib import Path
44
from os import path, remove
5+
from ast import literal_eval
56
from time import sleep, time
67

78
import pyshorteners
@@ -213,7 +214,7 @@ def result(response, userLanguage, torrentType, page, category=None, week=None,
213214
markup.add(telebot.types.InlineKeyboardButton(language['previousBtn'][userLanguage], callback_data=cb))
214215

215216
if query:
216-
markup.add(telebot.types.InlineKeyboardButton(text='Pirate Bay 🔎', switch_inline_query_current_chat=f"!pb {query}"))
217+
markup.add(telebot.types.InlineKeyboardButton(text='Pirate Bay 🔎', switch_inline_query_current_chat=f"!pb {query}"), telebot.types.InlineKeyboardButton(text='Nyaa 🔎', switch_inline_query_current_chat=f"!nyaa {query}"))
217218
elif torrentType == 'top':
218219
markup.add(telebot.types.InlineKeyboardButton(text='Pirate Bay 🔎', switch_inline_query_current_chat=f"!pb --top"))
219220

@@ -807,6 +808,21 @@ def query_text(inline_query):
807808
else:
808809
bot.answer_inline_query(inline_query.id, [telebot.types.InlineQueryResultArticle(id=0, title=language['noResults'][userLanguage], url='https://t.me/h9youtube', hide_url=True, thumb_url='https://image.freepik.com/free-vector/error-404-found-glitch-effect_8024-4.jpg', input_message_content=telebot.types.InputTextMessageContent(language['noResults'][userLanguage], parse_mode='HTML'))], is_personal=True)
809810

811+
elif inline_query.query[:5] == '!nyaa':
812+
page = int(inline_query.offset) if inline_query.offset else 0
813+
results = literal_eval(requests.get('https://api.api-zero.workers.dev/nyaasi/'+inline_query.query[6:]).text)
814+
815+
if 'error' not in results:
816+
results = results[page*50:(page+1)*50]
817+
queryResult = []
818+
for count, item in enumerate(results):
819+
queryResult.append(telebot.types.InlineQueryResultArticle(id=count, title=item['Name'], url=item['Url'], hide_url=True, thumb_url='https://i.pinimg.com/736x/2d/8d/5c/2d8d5c5e953fd50493e388da2759ac41.jpg', thumb_width='123', thumb_height='182', description=f"{item['Size']} size {item['Seeder']} seeders {item['Leecher']} leechers", input_message_content=telebot.types.InputTextMessageContent(queryMessageContent(userId=inline_query.from_user.id, torrentz=item, source='nyaa'), parse_mode='HTML')))
820+
821+
bot.answer_inline_query(inline_query.id, queryResult, next_offset=page+1 if len(results) else None, is_personal=True, cache_time=0)
822+
823+
else:
824+
bot.answer_inline_query(inline_query.id, [telebot.types.InlineQueryResultArticle(id=0, title=language['noResults'][userLanguage], url='https://t.me/h9youtube', hide_url=True, thumb_url='https://image.freepik.com/free-vector/error-404-found-glitch-effect_8024-4.jpg', input_message_content=telebot.types.InputTextMessageContent(language['noResults'][userLanguage], parse_mode='HTML'))], is_personal=True)
825+
810826
else:
811827
offset = int(inline_query.offset.split(':')[0]) if inline_query.offset else 0
812828
page = int(inline_query.offset.split(':')[1]) if inline_query.offset else 1
@@ -849,6 +865,9 @@ def queryMessageContent(userId, torrentz, source):
849865
elif source == 'tpb':
850866
msg = f"<b>✨ {torrentz.title}</b>\n\n{language['size'][userLanguage]}{torrentz.filesize}\n{language['seeders'][userLanguage]}{torrentz.seeds}\n{language['leechers'][userLanguage]}{torrentz.leeches}\n{language['uploadedBy'][userLanguage]}{torrentz.uploader}\n{language['uploadedOn'][userLanguage]}{torrentz.upload_date}\n\n<b>Magnet Link: </b><code>{torrentz.magnetlink}</code>"
851867

868+
elif source == 'nyaa':
869+
msg = f"<b>✨ {torrentz['Name']}</b>\n\n{language['size'][userLanguage]}{torrentz['Size']}\n{language['seeders'][userLanguage]}{torrentz['Seeder']}\n{language['leechers'][userLanguage]}{torrentz['Leecher']}\n{language['uploadedOn'][userLanguage]}{torrentz['Date']}\n\n<b>Magnet Link: </b><code>{torrentz['Magnet']}</code>"
870+
852871
return msg
853872

854873
# Polling Bot

0 commit comments

Comments
 (0)