mirror of
https://github.com/g0ldyy/comet.git
synced 2026-01-12 01:16:12 +01:00
feat: premiumize support
This commit is contained in:
+3
-1
@@ -68,8 +68,10 @@ async def manifest(b64config: str = None):
|
||||
debrid_extension = None
|
||||
if config["debridService"] == "realdebrid":
|
||||
debrid_extension = "RD"
|
||||
if config["debridService"] == "alldebrid":
|
||||
elif config["debridService"] == "alldebrid":
|
||||
debrid_extension = "AD"
|
||||
elif config["debridService"] == "premiumize":
|
||||
debrid_extension = "PM"
|
||||
|
||||
return {
|
||||
"id": settings.ADDON_ID,
|
||||
|
||||
+6
-4
@@ -126,11 +126,12 @@ async def stream(request: Request, b64config: str, type: str, id: str):
|
||||
)
|
||||
sorted_ranked_files = json.loads(sorted_ranked_files[0])
|
||||
|
||||
debrid_extension = "EZ"
|
||||
if config["debridService"] == "realdebrid":
|
||||
debrid_extension = "RD"
|
||||
if config["debridService"] == "alldebrid":
|
||||
elif config["debridService"] == "alldebrid":
|
||||
debrid_extension = "AD"
|
||||
elif config["debridService"] == "premiumize":
|
||||
debrid_extension = "PM"
|
||||
|
||||
balanced_hashes = await get_balanced_hashes(sorted_ranked_files, config)
|
||||
results = []
|
||||
@@ -273,11 +274,12 @@ async def stream(request: Request, b64config: str, type: str, id: str):
|
||||
)
|
||||
logger.info(f"Results have been cached for {logName}")
|
||||
|
||||
debrid_extension = "EZ"
|
||||
if config["debridService"] == "realdebrid":
|
||||
debrid_extension = "RD"
|
||||
if config["debridService"] == "alldebrid":
|
||||
elif config["debridService"] == "alldebrid":
|
||||
debrid_extension = "AD"
|
||||
elif config["debridService"] == "premiumize":
|
||||
debrid_extension = "PM"
|
||||
|
||||
balanced_hashes = await get_balanced_hashes(sorted_ranked_files, config)
|
||||
results = []
|
||||
|
||||
@@ -27,7 +27,7 @@ class AllDebrid:
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
f"Exception while checking premium status on All Debrid: {e}"
|
||||
f"Exception while checking premium status on All-Debrid: {e}"
|
||||
)
|
||||
|
||||
return False
|
||||
@@ -40,7 +40,7 @@ class AllDebrid:
|
||||
return await get_instant.json()
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
f"Exception while checking hashes instant availability on All Debrid: {e}"
|
||||
f"Exception while checking hashes instant availability on All-Debrid: {e}"
|
||||
)
|
||||
return
|
||||
|
||||
@@ -146,6 +146,6 @@ class AllDebrid:
|
||||
return unlock_link["data"]["link"]
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
f"Exception while getting download link from All Debrid for {hash}|{index}: {e}"
|
||||
f"Exception while getting download link from All-Debrid for {hash}|{index}: {e}"
|
||||
)
|
||||
return
|
||||
|
||||
@@ -2,6 +2,7 @@ import aiohttp
|
||||
|
||||
from .realdebrid import RealDebrid
|
||||
from .alldebrid import AllDebrid
|
||||
from .premiumize import Premiumize
|
||||
|
||||
|
||||
def getDebrid(session: aiohttp.ClientSession, config: dict):
|
||||
@@ -11,3 +12,5 @@ def getDebrid(session: aiohttp.ClientSession, config: dict):
|
||||
return RealDebrid(session, debrid_api_key)
|
||||
if debrid_service == "alldebrid":
|
||||
return AllDebrid(session, debrid_api_key)
|
||||
if debrid_service == "premiumize":
|
||||
return Premiumize(session, debrid_api_key)
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
import aiohttp
|
||||
import asyncio
|
||||
|
||||
from RTN import parse
|
||||
|
||||
from comet.utils.general import is_video
|
||||
from comet.utils.logger import logger
|
||||
|
||||
|
||||
class Premiumize:
|
||||
def __init__(self, session: aiohttp.ClientSession, debrid_api_key: str):
|
||||
self.session = session
|
||||
self.proxy = None
|
||||
self.debrid_api_key = debrid_api_key
|
||||
|
||||
self.api_url = "https://premiumize.me/api"
|
||||
|
||||
async def check_premium(self):
|
||||
try:
|
||||
check_premium = await self.session.get(
|
||||
f"{self.api_url}/account/info?apikey={self.debrid_api_key}"
|
||||
)
|
||||
check_premium = await check_premium.text()
|
||||
if (
|
||||
'"status":"success"' in check_premium
|
||||
and '"premium_until":null' not in check_premium
|
||||
):
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
f"Exception while checking premium status on Premiumize: {e}"
|
||||
)
|
||||
|
||||
return False
|
||||
|
||||
async def get_instant(self, chunk: list):
|
||||
try:
|
||||
response = await self.session.get(
|
||||
f"{self.api_url}/cache/check?apikey={self.debrid_api_key}&items[]={'&items[]='.join(hash for hash in chunk)}"
|
||||
)
|
||||
|
||||
response = await response.json()
|
||||
response["hashes"] = chunk
|
||||
|
||||
return response
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
f"Exception while checking hash instant availability on Premiumize: {e}"
|
||||
)
|
||||
return
|
||||
|
||||
async def get_files(
|
||||
self, torrent_hashes: list, type: str, season: str, episode: str
|
||||
):
|
||||
chunk_size = 100
|
||||
chunks = [
|
||||
torrent_hashes[i : i + chunk_size]
|
||||
for i in range(0, len(torrent_hashes), chunk_size)
|
||||
]
|
||||
|
||||
tasks = []
|
||||
for chunk in chunks:
|
||||
tasks.append(self.get_instant(chunk))
|
||||
|
||||
responses = await asyncio.gather(*tasks)
|
||||
|
||||
availability = []
|
||||
for response in responses:
|
||||
if response is None:
|
||||
continue
|
||||
|
||||
availability.append(response)
|
||||
|
||||
files = {}
|
||||
for result in availability:
|
||||
if result["status"] != "success":
|
||||
continue
|
||||
|
||||
responses = result["response"]
|
||||
filenames = result["filename"]
|
||||
filesizes = result["filesize"]
|
||||
hashes = result["hashes"]
|
||||
for index, response in enumerate(responses):
|
||||
if response is False:
|
||||
continue
|
||||
|
||||
if filesizes[index] is None:
|
||||
continue
|
||||
|
||||
filename = filenames[index]
|
||||
if type == "series":
|
||||
filename_parsed = parse(filename)
|
||||
if (
|
||||
season in filename_parsed.season
|
||||
and episode in filename_parsed.episode
|
||||
):
|
||||
files[hashes[index]] = {
|
||||
"index": f"{season}|{episode}",
|
||||
"title": filename,
|
||||
"size": int(filesizes[index]),
|
||||
}
|
||||
|
||||
continue
|
||||
|
||||
files[hashes[index]] = {
|
||||
"index": 0,
|
||||
"title": filename,
|
||||
"size": int(filesizes[index]),
|
||||
}
|
||||
|
||||
return files
|
||||
|
||||
async def generate_download_link(self, hash: str, index: str):
|
||||
try:
|
||||
add_magnet = await self.session.post(
|
||||
f"{self.api_url}/transfer/directdl?apikey={self.debrid_api_key}&src=magnet:?xt=urn:btih:{hash}",
|
||||
proxy=self.proxy,
|
||||
)
|
||||
add_magnet = await add_magnet.json()
|
||||
|
||||
season = None
|
||||
if "|" in index:
|
||||
index = index.split("|")
|
||||
season = int(index[0])
|
||||
episode = int(index[1])
|
||||
|
||||
content = add_magnet["content"]
|
||||
for file in content:
|
||||
filename = file["path"]
|
||||
if "/" in filename:
|
||||
filename = filename.split("/")[1]
|
||||
|
||||
if not is_video(filename):
|
||||
content.remove(file)
|
||||
continue
|
||||
|
||||
if season is not None:
|
||||
filename_parsed = parse(filename)
|
||||
if (
|
||||
season in filename_parsed.season
|
||||
and episode in filename_parsed.episode
|
||||
):
|
||||
return file["link"]
|
||||
|
||||
max_size_item = max(content, key=lambda x: x["size"])
|
||||
return max_size_item["link"]
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
f"Exception while getting download link from Premiumize for {hash}|{index}: {e}"
|
||||
)
|
||||
return
|
||||
@@ -24,7 +24,7 @@ class RealDebrid:
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
f"Exception while checking premium status on Real Debrid: {e}"
|
||||
f"Exception while checking premium status on Real-Debrid: {e}"
|
||||
)
|
||||
|
||||
return False
|
||||
@@ -37,7 +37,7 @@ class RealDebrid:
|
||||
return await response.json()
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
f"Exception while checking hash instant availability on Real Debrid: {e}"
|
||||
f"Exception while checking hash instant availability on Real-Debrid: {e}"
|
||||
)
|
||||
return
|
||||
|
||||
@@ -155,6 +155,6 @@ class RealDebrid:
|
||||
return unrestrict_link["download"]
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
f"Exception while getting download link from Real Debrid for {hash}|{index}: {e}"
|
||||
f"Exception while getting download link from Real-Debrid for {hash}|{index}: {e}"
|
||||
)
|
||||
return
|
||||
|
||||
@@ -535,6 +535,7 @@
|
||||
<sl-select id="debridService" value="realdebrid" label="Debrid Service" placeholder="Select debrid service">
|
||||
<sl-option value="realdebrid">Real-Debrid</sl-option>
|
||||
<sl-option value="alldebrid">All-Debrid</sl-option>
|
||||
<sl-option value="premiumize">Premiumize</sl-option>
|
||||
</sl-select>
|
||||
</div>
|
||||
|
||||
@@ -555,6 +556,8 @@
|
||||
apiKeyLink.href = "https://real-debrid.com/apitoken";
|
||||
} else if (selectedService === "alldebrid") {
|
||||
apiKeyLink.href = "https://alldebrid.fr/apikeys";
|
||||
} else if (selectedService === "premiumize") {
|
||||
apiKeyLink.href = "https://premiumize.me/account";
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -246,10 +246,10 @@ async def get_torrent_hash(
|
||||
session: aiohttp.ClientSession, indexer_manager_type: str, torrent: dict
|
||||
):
|
||||
if "InfoHash" in torrent and torrent["InfoHash"] is not None:
|
||||
return torrent["InfoHash"]
|
||||
return torrent["InfoHash"].lower()
|
||||
|
||||
if "infoHash" in torrent:
|
||||
return torrent["infoHash"]
|
||||
return torrent["infoHash"].lower()
|
||||
|
||||
url = (
|
||||
torrent["Link"] if indexer_manager_type == "jackett" else torrent["downloadUrl"]
|
||||
@@ -274,7 +274,7 @@ async def get_torrent_hash(
|
||||
|
||||
hash = match.group(1).upper()
|
||||
|
||||
return hash
|
||||
return hash.lower()
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
f"Exception while getting torrent info hash for {torrent['indexer'] if 'indexer' in torrent else (torrent['Tracker'] if 'Tracker' in torrent else '')}|{url}: {e}"
|
||||
|
||||
@@ -62,7 +62,7 @@ class ConfigModel(BaseModel):
|
||||
|
||||
@field_validator("debridService")
|
||||
def check_debrid_service(cls, v):
|
||||
if v not in ["realdebrid", "alldebrid"]:
|
||||
if v not in ["realdebrid", "alldebrid", "premiumize"]:
|
||||
raise ValueError("Invalid debridService")
|
||||
return v
|
||||
|
||||
|
||||
Reference in New Issue
Block a user