VT-PR/vinetrimmer/services/__init__.py
Aswin 05ed9d57df Changes
Add default device
Switch to requests to get manifest.
Import peacock service
2025-03-23 09:56:39 +05:30

51 lines
1.7 KiB
Python

import os
import re
from copy import copy
from vinetrimmer.services.BaseService import BaseService
SERVICE_MAP = {}
from vinetrimmer.services.amazon import Amazon
from vinetrimmer.services.appletvplus import AppleTVPlus
from vinetrimmer.services.max import Max
from vinetrimmer.services.netflix import Netflix
from vinetrimmer.services.peacock import Peacock
# Above is necessary since dynamic imports like below fuck up nuitak
# Below dynamic imports fuck with compiling when using Nuitka - exec() call is the problem
#for service in os.listdir(os.path.dirname(__file__)):
# if service.startswith("_") or not service.endswith(".py"):
# continue
# service = os.path.splitext(service)[0]
# if service in ("__init__", "BaseService"):
# continue
# with open(os.path.join(os.path.dirname(__file__), f"{service}.py"), encoding="utf-8") as fd:
# code = ""
# for line in fd.readlines():
# if re.match(r"\s*(?:import(?! click)|from)\s", line):
# continue
# code += line
# if re.match(r"\s*super\(\)\.__init__\(", line):
# break
# exec(code)
for x in copy(globals()).values():
if isinstance(x, type) and issubclass(x, BaseService) and x != BaseService:
SERVICE_MAP[x.__name__] = x.ALIASES
def get_service_key(value):
"""
Get the Service Key name (e.g. DisneyPlus, not dsnp, disney+, etc.) from the SERVICE_MAP.
Input value can be of any case-sensitivity and can be either the key itself or an alias.
"""
value = value.lower()
for key, aliases in SERVICE_MAP.items():
if value in map(str.lower, aliases) or value == key.lower():
return key