Skip to content

Commit a11a65e

Browse files
committed
feat: add comet scraper
1 parent b3aec55 commit a11a65e

File tree

7 files changed

+78
-4
lines changed

7 files changed

+78
-4
lines changed

.env-sample

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ INDEXER_MANAGER_TIMEOUT=60 # maximum time to obtain search results from indexer
1919
INDEXER_MANAGER_INDEXERS='["EXAMPLE1_CHANGETHIS", "EXAMPLE2_CHANGETHIS"]' # for jackett, get the names from https://github.com/Jackett/Jackett/tree/master/src/Jackett.Common/Definitions - for prowlarr you can write them like on the web dashboard
2020
GET_TORRENT_TIMEOUT=5 # maximum time to obtain the torrent info hash in seconds
2121
DOWNLOAD_TORRENT_FILES=False # set to True to enable torrent file retrieval instead of using only magnet link info (infohash and sources, ensuring file index is included in results for Jackett and Prowlarr torrents)
22+
SCRAPE_COMET=False # scrape another Comet instance
23+
COMET_URL=https://comet.elfhosted.com # Allows you to scrape custom instances of Comet
2224
SCRAPE_ZILEAN=False # scrape Zilean/DMM
2325
ZILEAN_URL=https://zilean.elfhosted.com # for DMM search - https://github.com/iPromKnight/zilean - ex: http://127.0.0.1:8181
2426
SCRAPE_TORRENTIO=False # scrape Torrentio

comet/api/stream.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,9 @@ async def stream(
304304
return {"streams": cached_results + non_cached_results}
305305

306306

307-
@streams.get("/{b64config}/playback/{hash}/{index}/{name}/{season}/{episode}/{torrent_name}")
307+
@streams.get(
308+
"/{b64config}/playback/{hash}/{index}/{name}/{season}/{episode}/{torrent_name}"
309+
)
308310
async def playback(
309311
request: Request,
310312
b64config: str,
@@ -313,7 +315,7 @@ async def playback(
313315
name: str,
314316
season: str,
315317
episode: str,
316-
torrent_name: str
318+
torrent_name: str,
317319
):
318320
config = config_check(b64config)
319321

comet/debrid/stremthru.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,13 @@ async def get_availability(
169169
return files
170170

171171
async def generate_download_link(
172-
self, hash: str, index: str, name: str, torrent_name: str, season: int, episode: int
172+
self,
173+
hash: str,
174+
index: str,
175+
name: str,
176+
torrent_name: str,
177+
season: int,
178+
episode: int,
173179
):
174180
try:
175181
magnet = await self.session.post(

comet/main.py

+6
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ def start_log():
131131
else:
132132
logger.log("COMET", "Indexer Manager: False")
133133

134+
comet_url = f" - {settings.COMET_URL}"
135+
logger.log(
136+
"COMET",
137+
f"Comet Scraper: {bool(settings.SCRAPE_COMET)}{comet_url if settings.SCRAPE_COMET else ''}",
138+
)
139+
134140
zilean_url = f" - {settings.ZILEAN_URL}"
135141
logger.log(
136142
"COMET",

comet/scrapers/comet.py

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from curl_cffi import requests
2+
3+
from comet.utils.models import settings
4+
from comet.utils.logger import logger
5+
6+
7+
async def get_comet(manager, media_type: str, media_id: str):
8+
torrents = []
9+
try:
10+
try:
11+
get_comet = requests.get(
12+
f"{settings.COMET_URL}/stream/{media_type}/{media_id}.json"
13+
).json()
14+
except Exception as e:
15+
logger.warning(
16+
f"Failed to get Comet results without proxy for {media_id}: {e}"
17+
)
18+
19+
get_comet = requests.get(
20+
f"{settings.COMET_URL}/stream/{media_type}/{media_id}.json",
21+
proxies={
22+
"http": settings.DEBRID_PROXY_URL,
23+
"https": settings.DEBRID_PROXY_URL,
24+
},
25+
).json()
26+
27+
for torrent in get_comet["streams"]:
28+
title_full = torrent["description"]
29+
title = title_full.split("\n")[0]
30+
31+
seeders = (
32+
title_full.split("👤 ")[1].split(" ")[0] if "👤" in title_full else None
33+
)
34+
tracker = title_full.split("🔎 ")[1].split("\n")[0]
35+
36+
torrents.append(
37+
{
38+
"title": title,
39+
"infoHash": torrent["infoHash"].lower(),
40+
"fileIndex": torrent["fileIdx"] if "fileIdx" in torrent else None,
41+
"seeders": seeders,
42+
"size": torrent["behaviorHints"]["videoSize"],
43+
"tracker": f"Comet|{tracker}",
44+
"sources": torrent["sources"] if "sources" in torrent else [],
45+
}
46+
)
47+
except Exception as e:
48+
logger.warning(
49+
f"Exception while getting torrents for {media_id} with Comet, your IP is most likely blacklisted (you should try proxying Comet): {e}"
50+
)
51+
pass
52+
53+
await manager.filter_manager(torrents)

comet/scrapers/manager.py

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from .mediafusion import get_mediafusion
2424
from .jackett import get_jackett
2525
from .prowlarr import get_prowlarr
26+
from .comet import get_comet
2627

2728

2829
class TorrentManager:
@@ -66,6 +67,8 @@ async def scrape_torrents(
6667
session: aiohttp.ClientSession,
6768
):
6869
tasks = []
70+
if settings.SCRAPE_COMET:
71+
tasks.append(get_comet(self, self.media_type, self.media_id))
6972
if settings.SCRAPE_TORRENTIO:
7073
tasks.append(get_torrentio(self, self.media_type, self.media_id))
7174
if settings.SCRAPE_MEDIAFUSION:

comet/utils/models.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ class AppSettings(BaseSettings):
4949
INDEXER_MANAGER_INDEXERS: List[str] = []
5050
GET_TORRENT_TIMEOUT: Optional[int] = 5
5151
DOWNLOAD_TORRENT_FILES: Optional[bool] = False
52-
SCRAPE_MEDIAFUSION: Optional[bool] = False
52+
SCRAPE_COMET: Optional[bool] = False
53+
COMET_URL: Optional[str] = "https://comet.elfhosted.com"
5354
SCRAPE_ZILEAN: Optional[bool] = False
5455
ZILEAN_URL: Optional[str] = "https://zilean.elfhosted.com"
5556
SCRAPE_TORRENTIO: Optional[bool] = False
@@ -72,6 +73,7 @@ class AppSettings(BaseSettings):
7273
"ZILEAN_URL",
7374
"TORRENTIO_URL",
7475
"MEDIAFUSION_URL",
76+
"COMET_URL",
7577
"STREMTHRU_URL",
7678
)
7779
def remove_trailing_slash(cls, v):

0 commit comments

Comments
 (0)