Skip to content

Commit

Permalink
feat: faster than ever, better results
Browse files Browse the repository at this point in the history
  • Loading branch information
g0ldyy committed Aug 31, 2024
1 parent e5cc425 commit 19f9cc4
Show file tree
Hide file tree
Showing 12 changed files with 238 additions and 188 deletions.
16 changes: 3 additions & 13 deletions comet/api/core.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import PTT
import RTN

from fastapi import APIRouter, Request
Expand Down Expand Up @@ -25,20 +26,9 @@ async def health():
web_config = {
"indexers": [indexer.replace(" ", "_").lower() for indexer in indexers],
"languages": [
language.replace(" ", "_")
for language in RTN.patterns.language_code_mapping.keys()
],
"resolutions": [
"360p",
"480p",
"576p",
"720p",
"1080p",
"1440p",
"2160p",
"4K",
"Unknown",
language for language in PTT.parse.LANGUAGES_TRANSLATION_TABLE.values()
],
"resolutions": [resolution.value for resolution in RTN.models.Resolution],
"resultFormat": ["Title", "Metadata", "Size", "Tracker", "Languages"],
}

Expand Down
45 changes: 22 additions & 23 deletions comet/api/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,12 @@ async def stream(request: Request, b64config: str, type: str, id: str):
)
metadata = await get_metadata.json()
element = metadata["d"][
0 if metadata["d"][0]["id"] not in ["/imdbpicks/summer-watch-guide", "/emmys"] else 1
0
if metadata["d"][0]["id"]
not in ["/imdbpicks/summer-watch-guide", "/emmys"]
else 1
]

for element in metadata["d"]:
if element["id"] == id:
break
Expand Down Expand Up @@ -166,7 +169,7 @@ async def stream(request: Request, b64config: str, type: str, id: str):
data = hash_data["data"]
results.append(
{
"name": f"[{debrid_extension}โšก] Comet {data['resolution'][0] if data['resolution'] != [] else 'Unknown'}",
"name": f"[{debrid_extension}โšก] Comet {data['resolution']}",
"title": format_title(data, config),
"torrentTitle": (
data["torrent_title"]
Expand Down Expand Up @@ -241,7 +244,7 @@ async def stream(request: Request, b64config: str, type: str, id: str):
)
else:
logger.info(
f"No indexer {'manager ' if not indexer_manager_type else ' '}{'selected by user' if indexer_manager_type else 'defined'} for {log_name}"
f"No indexer {'manager ' if not indexer_manager_type else ''}{'selected by user' if indexer_manager_type else 'defined'} for {log_name}"
)

if settings.ZILEAN_URL:
Expand Down Expand Up @@ -339,23 +342,24 @@ async def stream(request: Request, b64config: str, type: str, id: str):

ranked_files = set()
for hash in files:
# try:
ranked_file = rtn.rank(
files[hash]["title"],
hash, # , correct_title=name, remove_trash=True
)
# except:
# continue
try:
ranked_file = rtn.rank(
files[hash]["title"],
hash, # , correct_title=name, remove_trash=True
)
except:
pass

ranked_files.add(ranked_file)

sorted_ranked_files = sort_torrents(ranked_files)

len_sorted_ranked_files = len(sorted_ranked_files)
logger.info(
f"{len(sorted_ranked_files)} cached files found on {config['debridService']} for {log_name}"
f"{len_sorted_ranked_files} cached files found on {config['debridService']} for {log_name}"
)

if len(sorted_ranked_files) == 0:
if len_sorted_ranked_files == 0:
return {"streams": []}

sorted_ranked_files = {
Expand Down Expand Up @@ -409,7 +413,7 @@ async def stream(request: Request, b64config: str, type: str, id: str):
data = hash_data["data"]
results.append(
{
"name": f"[{debrid_extension}โšก] Comet {data['resolution'][0] if data['resolution'] != [] else 'Unknown'}",
"name": f"[{debrid_extension}โšก] Comet {data['resolution']}",
"title": format_title(data, config),
"torrentTitle": data["torrent_title"],
"torrentSize": data["torrent_size"],
Expand Down Expand Up @@ -453,19 +457,14 @@ async def playback(request: Request, b64config: str, hash: str, index: str):
config = config_check(b64config)
if not config:
return FileResponse("comet/assets/invalidconfig.mp4")

if (
settings.PROXY_DEBRID_STREAM
and settings.PROXY_DEBRID_STREAM_PASSWORD
== config["debridStreamProxyPassword"]
and settings.PROXY_DEBRID_STREAM_PASSWORD == config["debridStreamProxyPassword"]
and config["debridApiKey"] == ""
):
config["debridService"] = (
settings.PROXY_DEBRID_STREAM_DEBRID_DEFAULT_SERVICE
)
config["debridApiKey"] = (
settings.PROXY_DEBRID_STREAM_DEBRID_DEFAULT_APIKEY
)
config["debridService"] = settings.PROXY_DEBRID_STREAM_DEBRID_DEFAULT_SERVICE
config["debridApiKey"] = settings.PROXY_DEBRID_STREAM_DEBRID_DEFAULT_APIKEY

async with aiohttp.ClientSession() as session:
# Check for cached download link
Expand Down
6 changes: 3 additions & 3 deletions comet/debrid/alldebrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,14 @@ async def get_files(
continue

filename_parsed = parse(filename)
if episode not in filename_parsed.episode:
if episode not in filename_parsed.episodes:
continue

if kitsu:
if filename_parsed.season:
if filename_parsed.seasons:
continue
else:
if season not in filename_parsed.season:
if season not in filename_parsed.seasons:
continue

files[magnet["hash"]] = {
Expand Down
6 changes: 3 additions & 3 deletions comet/debrid/debridlink.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ async def get_files(
continue

filename_parsed = parse(filename)
if episode not in filename_parsed.episode:
if episode not in filename_parsed.episodes:
continue

if kitsu:
if filename_parsed.season:
if filename_parsed.seasons:
continue
else:
if season not in filename_parsed.season:
if season not in filename_parsed.seasons:
continue

files[hash] = {
Expand Down
10 changes: 5 additions & 5 deletions comet/debrid/premiumize.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ async def get_files(

filename = filenames[index]
filename_parsed = parse(filename)
if episode not in filename_parsed.episode:
if episode not in filename_parsed.episodes:
continue

if kitsu:
if filename_parsed.season:
if filename_parsed.seasons:
continue
else:
if season not in filename_parsed.season:
if season not in filename_parsed.seasons:
continue

files[hashes[index]] = {
Expand Down Expand Up @@ -156,8 +156,8 @@ async def generate_download_link(self, hash: str, index: str):
if season is not None:
filename_parsed = parse(filename)
if (
season in filename_parsed.season
and episode in filename_parsed.episode
season in filename_parsed.seasons
and episode in filename_parsed.episodes
):
return file["link"]

Expand Down
6 changes: 3 additions & 3 deletions comet/debrid/realdebrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ async def get_files(
continue

filename_parsed = parse(filename)
if episode not in filename_parsed.episode:
if episode not in filename_parsed.episodes:
continue

if kitsu:
if filename_parsed.season:
if filename_parsed.seasons:
continue
else:
if season not in filename_parsed.season:
if season not in filename_parsed.seasons:
continue

files[hash] = {
Expand Down
6 changes: 3 additions & 3 deletions comet/debrid/torbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ async def get_files(
continue

filename_parsed = parse(filename)
if episode not in filename_parsed.episode:
if episode not in filename_parsed.episodes:
continue

if kitsu:
if filename_parsed.season:
if filename_parsed.seasons:
continue
else:
if season not in filename_parsed.season:
if season not in filename_parsed.seasons:
continue

files[torrent["hash"]] = {
Expand Down
5 changes: 2 additions & 3 deletions comet/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,11 @@ def start_log():
"COMET",
f"Indexer Manager: {settings.INDEXER_MANAGER_TYPE}|{settings.INDEXER_MANAGER_URL} - Timeout: {settings.INDEXER_MANAGER_TIMEOUT}s",
)
logger.log("COMET", f"Indexers: {', '.join(settings.INDEXER_MANAGER_INDEXERS)}")
logger.log("COMET", f"Get Torrent Timeout: {settings.GET_TORRENT_TIMEOUT}s")
else:
logger.log("COMET", "Indexer Manager: False")

logger.log("COMET", f"Indexers: {', '.join(settings.INDEXER_MANAGER_INDEXERS)}")
logger.log("COMET", f"Get Torrent Timeout: {settings.GET_TORRENT_TIMEOUT}s")

if settings.ZILEAN_URL:
logger.log(
"COMET",
Expand Down
64 changes: 62 additions & 2 deletions comet/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,55 @@
</sl-alert>

<script type="module">
const languagesEmojis = {
"English": "๐Ÿ‡ฌ๐Ÿ‡ง",
"Japanese": "๐Ÿ‡ฏ๐Ÿ‡ต",
"Chinese": "๐Ÿ‡จ๐Ÿ‡ณ",
"Russian": "๐Ÿ‡ท๐Ÿ‡บ",
"Arabic": "๐Ÿ‡ธ๐Ÿ‡ฆ",
"Portuguese": "๐Ÿ‡ต๐Ÿ‡น",
"Spanish": "๐Ÿ‡ช๐Ÿ‡ธ",
"French": "๐Ÿ‡ซ๐Ÿ‡ท",
"German": "๐Ÿ‡ฉ๐Ÿ‡ช",
"Italian": "๐Ÿ‡ฎ๐Ÿ‡น",
"Korean": "๐Ÿ‡ฐ๐Ÿ‡ท",
"Hindi": "๐Ÿ‡ฎ๐Ÿ‡ณ",
"Bengali": "๐Ÿ‡ง๐Ÿ‡ฉ",
"Punjabi": "๐Ÿ‡ต๐Ÿ‡ฐ",
"Marathi": "๐Ÿ‡ฎ๐Ÿ‡ณ",
"Gujarati": "๐Ÿ‡ฎ๐Ÿ‡ณ",
"Tamil": "๐Ÿ‡ฎ๐Ÿ‡ณ",
"Telugu": "๐Ÿ‡ฎ๐Ÿ‡ณ",
"Kannada": "๐Ÿ‡ฎ๐Ÿ‡ณ",
"Malayalam": "๐Ÿ‡ฎ๐Ÿ‡ณ",
"Thai": "๐Ÿ‡น๐Ÿ‡ญ",
"Vietnamese": "๐Ÿ‡ป๐Ÿ‡ณ",
"Indonesian": "๐Ÿ‡ฎ๐Ÿ‡ฉ",
"Turkish": "๐Ÿ‡น๐Ÿ‡ท",
"Hebrew": "๐Ÿ‡ฎ๐Ÿ‡ฑ",
"Persian": "๐Ÿ‡ฎ๐Ÿ‡ท",
"Ukrainian": "๐Ÿ‡บ๐Ÿ‡ฆ",
"Greek": "๐Ÿ‡ฌ๐Ÿ‡ท",
"Lithuanian": "๐Ÿ‡ฑ๐Ÿ‡น",
"Latvian": "๐Ÿ‡ฑ๐Ÿ‡ป",
"Estonian": "๐Ÿ‡ช๐Ÿ‡ช",
"Polish": "๐Ÿ‡ต๐Ÿ‡ฑ",
"Czech": "๐Ÿ‡จ๐Ÿ‡ฟ",
"Slovak": "๐Ÿ‡ธ๐Ÿ‡ฐ",
"Hungarian": "๐Ÿ‡ญ๐Ÿ‡บ",
"Romanian": "๐Ÿ‡ท๐Ÿ‡ด",
"Bulgarian": "๐Ÿ‡ง๐Ÿ‡ฌ",
"Serbian": "๐Ÿ‡ท๐Ÿ‡ธ",
"Croatian": "๐Ÿ‡ญ๐Ÿ‡ท",
"Slovenian": "๐Ÿ‡ธ๐Ÿ‡ฎ",
"Dutch": "๐Ÿ‡ณ๐Ÿ‡ฑ",
"Danish": "๐Ÿ‡ฉ๐Ÿ‡ฐ",
"Finnish": "๐Ÿ‡ซ๐Ÿ‡ฎ",
"Swedish": "๐Ÿ‡ธ๐Ÿ‡ช",
"Norwegian": "๐Ÿ‡ณ๐Ÿ‡ด",
"Malay": "๐Ÿ‡ฒ๐Ÿ‡พ",
};

let defaultLanguages = [];
let defaultResolutions = [];
let defaultResultFormat = [];
Expand Down Expand Up @@ -632,10 +681,21 @@
options.forEach(option => {
const optionElement = document.createElement("sl-option");
optionElement.value = option;
optionElement.textContent = option;

if (selectId === "languages") {
// For languages, prepend the flag emoji if it exists
const flag = languagesEmojis[option] || '';
optionElement.textContent = `${flag} ${option}`;
} else {
// For other selects, just use the option text as is
optionElement.textContent = option;
}

selectElement.appendChild(optionElement);
});
selectElement.value = options;

// Set the default value
selectElement.value = options; // Assuming first option as default
}

const installButton = document.querySelector("#install");
Expand Down
Loading

0 comments on commit 19f9cc4

Please sign in to comment.