Skip to content

Commit bb4bc70

Browse files
committed
Make compatible with torrent py api
1 parent 955e2e4 commit bb4bc70

File tree

9 files changed

+33
-50
lines changed

9 files changed

+33
-50
lines changed

app.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "Torrenthunt",
3-
"description": "Torrenthunt",
2+
"name": "Torrenthunt Clone",
3+
"description": "Torrenthunt clone: https://github.com/hemantapkh/TorrentHunt",
44
"stack": "container",
55
"keywords": [
66
"auto-filter",
@@ -42,14 +42,14 @@
4242
"required": true
4343
},
4444
"TORRENTHUNT_API_URL": {
45-
"description": "URL of Torrent Hunt API",
46-
"value": "https://torrenthunt.p.rapidapi.com",
45+
"description": "URL of Torrents API, Deploy from https://github.com/Ryuk-me/Torrent-Api-py",
46+
"value": "https://torrent-api-py-nx0x.onrender.com",
4747
"required": true
4848
},
4949
"TORRENTHUNT_API_KEY": {
50-
"description": "Get your key from https://rapidapi.com/hemantapkh/api/torrenthunt",
50+
"description": "API key for Torrents api",
5151
"value": "",
52-
"required": true
52+
"required": false
5353
},
5454
"SENTRY_DSN": {
5555
"description": "Sentry.io token for error tracking",

app/apis/torrenthunt.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@ class TorrentHunt:
99
def __init__(self, api_key):
1010
url = (
1111
environ.get(
12-
"TORRENTHUNT_API_URL",
12+
"TORRENTHUNT_API_URL"
1313
)
14-
or "https://torrenthunt.p.rapidapi.com"
1514
)
1615
self.requests = Requests()
1716
self.url = url.strip("/")
1817
self.headers = {
19-
"X-RapidAPI-Key": api_key,
20-
"X-RapidAPI-Proxy-Secret": api_key,
21-
"X-RapidAPI-Host": "torrenthunt.p.rapidapi.com",
18+
"X-API-Key": environ.get("TORRENTHUNT_API_KEY"),
2219
}
2320

2421
async def request(self, route, method="GET", params=None, data=None):
@@ -27,5 +24,5 @@ async def request(self, route, method="GET", params=None, data=None):
2724
self.url + route,
2825
params=params,
2926
data=data,
30-
headers=self.headers,
27+
headers=self.headers
3128
)

app/database/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import datetime
44

5-
import sqlalchemy
65
from database.models import Session, Setting, User
76

87

app/database/models.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from uuid import uuid4
33

44
from asyncpg import Connection as asyncpg_connection
5-
from dotenv import load_dotenv
65
from loguru import logger
76
from sqlalchemy import (
87
TIMESTAMP,
@@ -17,8 +16,6 @@
1716
from sqlalchemy.orm import declarative_base, relationship, sessionmaker
1817
from sqlalchemy.sql import func
1918

20-
logger.info("Loading variables from .env file")
21-
load_dotenv()
2219

2320
connection_string = (
2421
environ.get("DATABASE_URL", "")

app/plugins/functions/keyboards.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@ def main(self, lang, message=None):
2727
def sites(self, keyword):
2828
results = [
2929
types.InlineKeyboardButton(
30-
text=self.client.sites[key]["title"],
31-
switch_inline_query_current_chat=f"{self.client.sites[key]['code']} {keyword}",
30+
text=self.client.sites[key]["website"],
31+
switch_inline_query_current_chat=f"!{key} {keyword}",
3232
)
3333
for key in self.client.sites
34-
if not self.client.sites[key].get("deactivated")
3534
]
3635

3736
return (

app/plugins/functions/misc.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def __init__(self, Client):
1414
async def fetch_config(self):
1515
# Get available sites
1616
config = await self.Client.torrent_hunt_api.request(
17-
"/api/config",
17+
"/api/v1/sites/config",
1818
)
1919

2020
if "error" in config:
@@ -74,7 +74,3 @@ async def user_lang(self, message):
7474
def split_list(self, lst, size):
7575
return [lst[i : i + size] for i in range(0, len(lst), size)]
7676

77-
# Get the site by it's code
78-
def code_to_site(self, code):
79-
data = self.Client.sites
80-
return next((key for key, value in data.items() if value["code"] == code), None)

app/plugins/search/inline.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,44 @@
1-
from os import environ
2-
31
from loguru import logger
42
from plugins.functions.database import get_restricted_mode
5-
from pyrogram import Client, filters, types
3+
from pyrogram import Client, types
64

75

8-
@Client.on_inline_query(filters.regex("!"))
6+
@Client.on_inline_query()
97
async def query_search(Client, inline_query):
108
user_lang = await Client.misc.user_lang(inline_query)
119
restricted_mode = await get_restricted_mode(inline_query.from_user.id)
1210
query_list = inline_query.query.split()
1311
results = []
1412

1513
# If keyword is not empty
16-
if len(query_list) > 1:
14+
if len(query_list) >= 1:
1715
keyword = " ".join(query_list[1:])
18-
site = Client.misc.code_to_site(query_list[0])
16+
site = query_list[0]
17+
18+
if site.startswith("!"):
19+
site = site[1:]
20+
21+
else:
22+
site = "piratebay"
1923

2024
page = int(inline_query.offset) if inline_query.offset else 1
2125
logger.info(f"Inline searching {keyword} on {site} on page {page}")
2226

2327
response = await Client.torrent_hunt_api.request(
24-
route="/api/search",
28+
route="/api/v1/search",
2529
params={
2630
"query": keyword,
2731
"site": site,
2832
"page": str(page),
2933
},
3034
)
3135

32-
if response.get("items"):
36+
if response.get("data"):
3337
pm_text = Client.language.STR("resultsFor", user_lang).format(
3438
keyword,
3539
)
3640

37-
for res in response.get("items"):
41+
for res in response.get("data"):
3842
text, markup = Client.struct.content_message(
3943
res,
4044
language=user_lang,
@@ -43,13 +47,13 @@ async def query_search(Client, inline_query):
4347
results.append(
4448
types.InlineQueryResultArticle(
4549
title=res.get("name"),
46-
thumb_url=res.get("thumbnail")
50+
thumb_url=res.get("thumbnail") or res.get("poster")
4751
or f"https://raw.githubusercontent.com/hemantapkh/torrenthunt/main/images/{site}.jpg",
4852
description="💾 {}, 🟢 {}, 🔴 {}, 📅 {}".format(
4953
res.get("size"),
5054
res.get("seeders"),
5155
res.get("leechers"),
52-
res.get("uploadDate"),
56+
res.get("date"),
5357
),
5458
input_message_content=types.InputTextMessageContent(
5559
message_text=text,

app/torrenthunt.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66

77
import uvloop
88
import sentry_sdk
9+
from loguru import logger
10+
from pyrogram import Client, filters
11+
912
from apis.requests import Requests
1013
from apis.torrenthunt import TorrentHunt
1114
from database import DataBase
1215
from database.models import init_models
1316
from init import exec_dir
1417
from langs.lang import Lang
15-
from loguru import logger
1618
from models.explicit_detector.explicit_detector import ExplicitDetector
1719
from plugins.blueprint.schema import Schema
1820
from plugins.functions.filters import Filter
@@ -32,15 +34,6 @@
3234
logger.info("Installing uvloop")
3335
uvloop.install()
3436

35-
# Configure logger to write logs to file and console
36-
log_file = environ.get("LOGFILE")
37-
if log_file:
38-
logger.add(
39-
log_file,
40-
backtrace=True,
41-
rotation="10 MB",
42-
)
43-
4437
logger.info("Creating database instance")
4538
Client.DB = DataBase()
4639

sample.env

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Telegram configs
2-
BOT_NAME=Torrent Hunt
2+
BOT_NAME=Torrent Hunt Clone
33
BOT_TOKEN=
44
API_ID=
55
API_HASH=
@@ -8,7 +8,8 @@ BOT_ADMINS=
88
# Database connection string
99
DATABASE_URL=sqlite:///torrenthunt.db
1010

11-
# Torrent Hunt API
11+
# Torrent API (https://github.com/Ryuk-me/Torrent-Api-py)
12+
TORRENTHUNT_API_URL=https://torrent-api-py-nx0x.onrender.com
1213
TORRENTHUNT_API_KEY=
1314

1415
# Message to forward on start
@@ -19,7 +20,4 @@ START_ADS_MESSAGE=
1920
# Sentry.io for error tracing
2021
SENTRY_DSN=
2122

22-
# MISC
23-
WORKDIR=
24-
LOGFILE=
2523
ENVIRONMENT=local

0 commit comments

Comments
 (0)