Skip to content

Commit

Permalink
feat: language unknown support
Browse files Browse the repository at this point in the history
  • Loading branch information
g0ldyy committed Nov 17, 2024
1 parent 5ca4aa5 commit 6f7c79f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
3 changes: 2 additions & 1 deletion comet/api/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ async def health():

indexers = settings.INDEXER_MANAGER_INDEXERS
languages = [language for language in PTT.parse.LANGUAGES_TRANSLATION_TABLE.values()]
languages.insert(0, "Multi")
languages.insert(0, "Unknown")
languages.insert(1, "Multi")
web_config = {
"indexers": [indexer.replace(" ", "_").lower() for indexer in indexers],
"languages": languages,
Expand Down
19 changes: 10 additions & 9 deletions comet/api/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,16 @@

@streams.get("/stream/{type}/{id}.json")
async def stream_noconfig(request: Request, type: str, id: str):
return {
"streams": [
{
"name": "[⚠️] Comet",
"description": f"{request.url.scheme}://{request.url.netloc}/configure",
"url": "https://comet.fast",
}
]
}
return {
"streams": [
{
"name": "[⚠️] Comet",
"description": f"{request.url.scheme}://{request.url.netloc}/configure",
"url": "https://comet.fast",
}
]
}


@streams.get("/{b64config}/stream/{type}/{id}.json")
async def stream(request: Request, b64config: str, type: str, id: str):
Expand Down
1 change: 1 addition & 0 deletions comet/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@

<script type="module">
const languagesEmojis = {
"Unknown": "❓",
"Multi": "🌎",
"English": "🇬🇧",
"Japanese": "🇯🇵",
Expand Down
8 changes: 7 additions & 1 deletion comet/utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from comet.utils.models import settings, ConfigModel

languages_emojis = {
"unknown": "❓", # Unknown
"multi": "🌎", # Dubbed
"en": "🇬🇧", # English
"ja": "🇯🇵", # Japanese
Expand Down Expand Up @@ -554,6 +555,7 @@ def get_balanced_hashes(hashes: dict, config: dict):
not include_all_languages
and not any(lang in hash_info["languages"] for lang in config_languages)
and ("multi" not in languages if hash_info["dubbed"] else True)
and not (len(hash_info["languages"]) == 0 and "unknown" in languages)
):
continue

Expand All @@ -569,7 +571,11 @@ def get_balanced_hashes(hashes: dict, config: dict):
if max_results == 0 and max_results_per_resolution == 0 or total_resolutions == 0:
return hashes_by_resolution

hashes_per_resolution = max_results // total_resolutions if max_results > 0 else max_results_per_resolution
hashes_per_resolution = (
max_results // total_resolutions
if max_results > 0
else max_results_per_resolution
)
extra_hashes = max_results % total_resolutions

balanced_hashes = {}
Expand Down
2 changes: 1 addition & 1 deletion comet/utils/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def check_max_results(cls, v):
if v < 0:
v = 0
return v

@field_validator("maxResultsPerResolution")
def check_max_results_per_resolution(cls, v):
if v < 0:
Expand Down

0 comments on commit 6f7c79f

Please sign in to comment.