Skip to content

Commit

Permalink
fix: useless repeated code
Browse files Browse the repository at this point in the history
  • Loading branch information
g0ldyy committed Jul 11, 2024
1 parent db1a003 commit fa8ce05
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 26 deletions.
12 changes: 2 additions & 10 deletions comet/api/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from fastapi.templating import Jinja2Templates

from comet.utils.models import settings
from comet.utils.general import config_check
from comet.utils.general import config_check, get_debrid_extension

templates = Jinja2Templates("comet/templates")
main = APIRouter()
Expand Down Expand Up @@ -65,15 +65,7 @@ async def manifest(b64config: str = None):
if not config:
config = {"debridService": None}

debrid_extension = None
if config["debridService"] == "realdebrid":
debrid_extension = "RD"
elif config["debridService"] == "alldebrid":
debrid_extension = "AD"
elif config["debridService"] == "premiumize":
debrid_extension = "PM"
elif config["debridService"] == "torbox":
debrid_extension = "TB"
debrid_extension = get_debrid_extension(config["debridService"])

return {
"id": settings.ADDON_ID,
Expand Down
19 changes: 3 additions & 16 deletions comet/api/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from comet.utils.general import (
bytes_to_size,
config_check,
get_debrid_extension,
get_indexer_manager,
get_zilean,
filter,
Expand Down Expand Up @@ -128,14 +129,7 @@ async def stream(request: Request, b64config: str, type: str, id: str):
)
sorted_ranked_files = json.loads(sorted_ranked_files[0])

if config["debridService"] == "realdebrid":
debrid_extension = "RD"
elif config["debridService"] == "alldebrid":
debrid_extension = "AD"
elif config["debridService"] == "premiumize":
debrid_extension = "PM"
elif config["debridService"] == "torbox":
debrid_extension = "TB"
debrid_extension = get_debrid_extension(config["debridService"])

balanced_hashes = await get_balanced_hashes(sorted_ranked_files, config)

Expand Down Expand Up @@ -278,14 +272,7 @@ async def stream(request: Request, b64config: str, type: str, id: str):
)
logger.info(f"Results have been cached for {log_name}")

if config["debridService"] == "realdebrid":
debrid_extension = "RD"
elif config["debridService"] == "alldebrid":
debrid_extension = "AD"
elif config["debridService"] == "premiumize":
debrid_extension = "PM"
elif config["debridService"] == "torbox":
debrid_extension = "TB"
debrid_extension = get_debrid_extension(config["debridService"])

balanced_hashes = await get_balanced_hashes(sorted_ranked_files, config)

Expand Down
14 changes: 14 additions & 0 deletions comet/utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,20 @@ def config_check(b64config: str):
return False


def get_debrid_extension(debridService: str):
debrid_extension = "?" # Unknown
if debridService == "realdebrid":
debrid_extension = "RD"
elif debridService == "alldebrid":
debrid_extension = "AD"
elif debridService == "premiumize":
debrid_extension = "PM"
elif debridService == "torbox":
debrid_extension = "TB"

return debrid_extension


async def get_indexer_manager(
session: aiohttp.ClientSession,
indexer_manager_type: str,
Expand Down

0 comments on commit fa8ce05

Please sign in to comment.