diff --git a/misskaty/helper/kuso_utils.py b/misskaty/helper/kuso_utils.py
index d2d2bff7..9aa23caf 100644
--- a/misskaty/helper/kuso_utils.py
+++ b/misskaty/helper/kuso_utils.py
@@ -8,111 +8,56 @@ from telegraph.aio import Telegraph
from misskaty import BOT_USERNAME
from misskaty.helper.http import fetch
+from misskaty.helper.media_helper import post_to_telegraph
LOGGER = logging.getLogger("MissKaty")
-headers = {
- "Accept": "*/*",
- "User-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.19582",
-}
-
-async def kusonimeBypass(url: str, slug=None):
+async def kusonimeBypass(url: str):
result = {}
- _url = url
- if slug:
- noslug_url = "https://kusonime.com/{slug}"
- _url = noslug_url.format({"slug": slug})
+ page = await fetch.get(url)
+ if page.status_code != 200:
+ raise Exception(f"ERROR: Hostname might be blocked by server!")
try:
- page = await fetch.get(_url, headers=headers)
soup = BeautifulSoup(page.text, "lxml")
thumb = soup.find("div", {"class": "post-thumb"}).find("img").get("src")
data = []
+ # title = soup.select("#venkonten > div.vezone > div.venser > div.venutama > div.lexot > p:nth-child(3) > strong")[0].text.strip()
try:
title = soup.find("h1", {"class": "jdlz"}).text # fix title njing haha
- season = (
- soup.select(
- "#venkonten > div.vezone > div.venser > div.venutama > div.lexot > div.info > p:nth-child(3)"
- )[0]
- .text.split(":")
- .pop()
- .strip()
- )
- tipe = (
- soup.select(
- "#venkonten > div.vezone > div.venser > div.venutama > div.lexot > div.info > p:nth-child(5)"
- )[0]
- .text.split(":")
- .pop()
- .strip()
- )
- status_anime = (
- soup.select(
- "#venkonten > div.vezone > div.venser > div.venutama > div.lexot > div.info > p:nth-child(6)"
- )[0]
- .text.split(":")
- .pop()
- .strip()
- )
- ep = (
- soup.select(
- "#venkonten > div.vezone > div.venser > div.venutama > div.lexot > div.info > p:nth-child(7)"
- )[0]
- .text.split(":")
- .pop()
- .strip()
- )
- score = (
- soup.select(
- "#venkonten > div.vezone > div.venser > div.venutama > div.lexot > div.info > p:nth-child(8)"
- )[0]
- .text.split(":")
- .pop()
- .strip()
- )
- duration = (
- soup.select(
- "#venkonten > div.vezone > div.venser > div.venutama > div.lexot > div.info > p:nth-child(9)"
- )[0]
- .text.split(":")
- .pop()
- .strip()
- )
- rilis = (
- soup.select(
- "#venkonten > div.vezone > div.venser > div.venutama > div.lexot > div.info > p:nth-child(10)"
- )[0]
- .text.split(":")
- .pop()
- .strip()
- )
+ season = soup.select("#venkonten > div.vezone > div.venser > div.venutama > div.lexot > div.info > p:nth-child(3)")[0].text.split(":").pop().strip()
+ tipe = soup.select("#venkonten > div.vezone > div.venser > div.venutama > div.lexot > div.info > p:nth-child(5)")[0].text.split(":").pop().strip()
+ status_anime = soup.select("#venkonten > div.vezone > div.venser > div.venutama > div.lexot > div.info > p:nth-child(6)")[0].text.split(":").pop().strip()
+ ep = soup.select("#venkonten > div.vezone > div.venser > div.venutama > div.lexot > div.info > p:nth-child(7)")[0].text.split(":").pop().strip()
+ score = soup.select("#venkonten > div.vezone > div.venser > div.venutama > div.lexot > div.info > p:nth-child(8)")[0].text.split(":").pop().strip()
+ duration = soup.select("#venkonten > div.vezone > div.venser > div.venutama > div.lexot > div.info > p:nth-child(9)")[0].text.split(":").pop().strip()
+ rilis = soup.select("#venkonten > div.vezone > div.venser > div.venutama > div.lexot > div.info > p:nth-child(10)")[0].text.split(":").pop().strip()
except Exception:
e = traceback.format_exc()
LOGGER.error(e)
- title, season, tipe, status_anime, ep, score, duration, rilis = (
- "None",
- "None",
- "None",
- "None",
- 0,
- 0,
- 0,
- "None",
- )
+ title, season, tipe, status_anime, ep, score, duration, rilis = "None", "None", "None", "None", 0, 0, 0, "None"
+ num = 1
genre = []
- for _genre in soup.select(
- "#venkonten > div.vezone > div.venser > div.venutama > div.lexot > div.info > p:nth-child(2)"
- ):
+ for _genre in soup.select("#venkonten > div.vezone > div.venser > div.venutama > div.lexot > div.info > p:nth-child(2)"):
gen = _genre.text.split(":").pop().strip().split(", ")
genre = gen
- for _, smokedl in enumerate(
- soup.find("div", {"class": "dlbodz"}).find_all(
- "div", {"class": "smokeddlrh"}
- ),
- start=1,
- ):
+ for smokedl in soup.find("div", {"class": "dlbodz"}).find_all("div", {"class": "smokeddlrh"}):
+ if not smokedl:
+ continue
mendata = {"name": title, "links": []}
+ for smokeurl in smokedl.find_all("div", {"class": "smokeurl"}):
+ if not smokeurl:
+ continue
+ quality = smokeurl.find("strong").text
+ links = []
+ for link in smokeurl.find_all("a"):
+ url = link.get("href")
+ client = link.text
+ links.append({"client": client, "url": url})
+ mendata["links"].append({"quality": quality, "link_download": links})
for smokeurl in smokedl.find_all("div", {"class": "smokeurlrh"}):
+ if not smokeurl:
+ continue
quality = smokeurl.find("strong").text
links = []
for link in smokeurl.find_all("a"):
@@ -121,45 +66,62 @@ async def kusonimeBypass(url: str, slug=None):
links.append({"client": client, "url": url})
mendata["links"].append({"quality": quality, "link_download": links})
data.append(mendata)
- result |= {
- "error": False,
- "title": title,
- "thumb": thumb,
- "genre": genre,
- "genre_string": ", ".join(genre),
- "status_anime": status_anime,
- "season": season,
- "tipe": tipe,
- "ep": ep,
- "score": score,
- "duration": duration,
- "rilis": rilis,
- "data": data,
- }
- except Exception:
+ num += 1
+ for smokedl in soup.find("div", {"class": "dlbodz"}).find_all("div", {"class": "smokeddl"}):
+ if not smokedl:
+ continue
+ mendata = {"name": title, "links": []}
+ for smokeurl in smokedl.find_all("div", {"class": "smokeurl"}):
+ if not smokeurl:
+ continue
+ quality = smokeurl.find("strong").text
+ links = []
+ for link in smokeurl.find_all("a"):
+ url = link.get("href")
+ client = link.text
+ links.append({"client": client, "url": url})
+ mendata["links"].append({"quality": quality, "link_download": links})
+ for smokeurl in smokedl.find_all("div", {"class": "smokeurlrh"}):
+ if not smokeurl:
+ continue
+ quality = smokeurl.find("strong").text
+ links = []
+ for link in smokeurl.find_all("a"):
+ url = link.get("href")
+ client = link.text
+ links.append({"client": client, "url": url})
+ mendata["links"].append({"quality": quality, "link_download": links})
+ data.append(mendata)
+ num += 1
+ result.update({"title": title, "thumb": thumb, "genre": genre, "genre_string": ", ".join(genre), "status_anime": status_anime, "season": season, "tipe": tipe, "ep": ep, "score": score, "duration": duration, "rilis": rilis, "data": data})
+ except Exception as e:
+ if len(result) != 0:
+ result.clear()
err = traceback.format_exc()
- LOGGER.error(err)
- result |= {"error": True, "error_message": err}
- await http.delete(_url)
- return result
+ page.close()
+ LOGGER.error(f"class: {e.__class__.__name_}, {err}")
+ raise Exception(f"ERROR: {err}")
+ finally:
+ page.close()
+ return result
-async def byPassPh(url: str, name: str):
+async def byPassPh(url: str, name: str) -> Optional[str]:
kusonime = await kusonimeBypass(url)
- results = {"error": True, "error_message": kusonime}
- if not kusonime["error"]:
- template = """
+ if not isinstance(kusonime, dict):
+ return kusonime
+ template = """
Title : {{title}}
Genre : {{genre_string}}
Season : {{season}}
Type : {{tipe}}
Status : {{status_anime}}
Total Episode : {{ep}}
Score : {{score}}
Duration : {{duration}}
Released on : {{rilis}}
Season : {{season}}
Type : {{tipe}}
Status : {{status_anime}}
Total Episode : {{ep}}
Score : {{score}}
Duration : {{duration}}
Released on : {{rilis}}