Skip to content

Commit

Permalink
speed goes brrrrr
Browse files Browse the repository at this point in the history
  • Loading branch information
g0ldyy committed Jun 29, 2024
1 parent 167c80e commit 68666be
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .env-sample
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ DEBRID_PROXY_URL=http://127.0.0.1:1080 # https://github.com/cmj2002/warp-docker
INDEXER_MANAGER_TYPE=jackett # or prowlarr
INDEXER_MANAGER_URL=http://127.0.0.1:9117
INDEXER_MANAGER_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
INDEXER_MANAGER_TIMEOUT=30 # maximum time to obtain search results from indexer manager in seconds
INDEXER_MANAGER_TIMEOUT=60 # maximum time to obtain search results from indexer manager in seconds
INDEXER_MANAGER_INDEXERS='["EXAMPLE1_CHANGETHIS", "EXAMPLE2_CHANGETHIS"]'
GET_TORRENT_TIMEOUT=5 # maximum time to obtain the torrent info hash in seconds
CUSTOM_HEADER_HTML=None # only set it if you know what it is
49 changes: 42 additions & 7 deletions comet/api/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,27 @@ async def stream(request: Request, b64config: str, type: str, id: str):
if len(torrentHashes) == 0:
return {"streams": []}

getAvailability = await session.get(f"https://api.real-debrid.com/rest/1.0/torrents/instantAvailability/{'/'.join(torrentHashes)}", headers={
"Authorization": f"Bearer {config['debridApiKey']}"
})
# hashChunks = [torrentHashes[i:i + 5] for i in range(0, len(torrentHashes), 5)]

files = {}
# tasks = []
# for chunk in hashChunks:
# tasks.append(session.get(f"https://api.real-debrid.com/rest/1.0/torrents/instantAvailability/{'/'.join(chunk)}", headers={
# "Authorization": f"Bearer {config['debridApiKey']}"
# }))

tasks = []
for hash in torrentHashes:
tasks.append(session.get(f"https://api.real-debrid.com/rest/1.0/torrents/instantAvailability/{hash}", headers={
"Authorization": f"Bearer {config['debridApiKey']}"
}))

availability = await getAvailability.json()
responses = await asyncio.gather(*tasks)

availability = {}
for response in responses:
availability.update(await response.json())

files = {}
for hash, details in availability.items():
if not "rd" in details:
continue
Expand Down Expand Up @@ -217,12 +231,33 @@ async def stream(request: Request, b64config: str, type: str, id: str):
"streams": results
}

@streams.route("/{b64config}/playback/{hash}/{index}", methods=["HEAD", "GET"])
async def stream(b64config: str, hash: str, index: str):
# @streams.route("/{b64config}/playback/{hash}/{index}", methods=["HEAD", "GET"])
# async def playback(b64config: str, hash: str, index: str):
# config = configChecking(b64config)
# if not config:
# return

# downloadLink = await generateDownloadLink(config["debridApiKey"], hash, index)

# return RedirectResponse(downloadLink, status_code=302)

@streams.head("/{b64config}/playback/{hash}/{index}")
async def playback(b64config: str, hash: str, index: str):
config = configChecking(b64config)
if not config:
return

downloadLink = await generateDownloadLink(config["debridApiKey"], hash, index)

return RedirectResponse(downloadLink, status_code=302)


@streams.get("/{b64config}/playback/{hash}/{index}")
async def playback(b64config: str, hash: str, index: str):
config = configChecking(b64config)
if not config:
return

downloadLink = await generateDownloadLink(config["debridApiKey"], hash, index)

return RedirectResponse(downloadLink, status_code=302)
5 changes: 2 additions & 3 deletions comet/utils/models.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import os
from typing import List, Optional

from typing import List, Optional
from databases import Database
from pydantic_settings import BaseSettings, SettingsConfigDict
from RTN import RTN, BaseRankingModel, SettingsModel


class AppSettings(BaseSettings):
model_config = SettingsConfigDict(
env_file=".env",
env_file_encoding="utf-8",
env_file_encoding="utf-8"
)

FASTAPI_HOST: str = "0.0.0.0"
Expand Down

0 comments on commit 68666be

Please sign in to comment.