mirror of
https://github.com/yasirarism/MissKatyPyro.git
synced 2026-01-05 03:34:51 +00:00
Change API and add justwatch
This commit is contained in:
parent
d6eb31432a
commit
f47c6c419d
3 changed files with 76 additions and 30 deletions
|
|
@ -2,7 +2,9 @@ import os
|
||||||
import random
|
import random
|
||||||
import string
|
import string
|
||||||
import time
|
import time
|
||||||
|
import json
|
||||||
from http.cookies import SimpleCookie
|
from http.cookies import SimpleCookie
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
import psutil
|
import psutil
|
||||||
|
|
||||||
|
|
@ -82,3 +84,37 @@ async def rentry(teks):
|
||||||
.json()
|
.json()
|
||||||
.get("url")
|
.get("url")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_provider(url):
|
||||||
|
|
||||||
|
def pretty(names):
|
||||||
|
name = names[1]
|
||||||
|
if names[0] == "play":
|
||||||
|
name = "Google Play Movies"
|
||||||
|
return name.title()
|
||||||
|
|
||||||
|
netloc = urlparse(url).netloc
|
||||||
|
return pretty(netloc.split('.'))
|
||||||
|
|
||||||
|
async def search_jw(movie_name: str, locale: str):
|
||||||
|
m_t_ = ""
|
||||||
|
response = await http.get(f"https://justwatch.imdbot.workers.dev/?q={movie_name}&L={locale}".format(
|
||||||
|
q=movie_name,
|
||||||
|
L=locale
|
||||||
|
))
|
||||||
|
soup = json.loads(response.text)
|
||||||
|
items = soup["items"]
|
||||||
|
for item in items:
|
||||||
|
if movie_name.lower() == item.get("title", "").lower():
|
||||||
|
offers = item.get("offers", [])
|
||||||
|
t_m_ = []
|
||||||
|
for offer in offers:
|
||||||
|
url = offer.get("urls").get("standard_web")
|
||||||
|
if url not in t_m_:
|
||||||
|
p_o = get_provider(url)
|
||||||
|
m_t_ += f"<a href='{url}'>{p_o}</a> | "
|
||||||
|
t_m_.append(url)
|
||||||
|
if m_t_ != "":
|
||||||
|
m_t_ = m_t_[:-2].strip()
|
||||||
|
break
|
||||||
|
return m_t_
|
||||||
|
|
@ -18,12 +18,12 @@ from database.imdb_db import *
|
||||||
from misskaty import BOT_USERNAME, app
|
from misskaty import BOT_USERNAME, app
|
||||||
from misskaty.core.decorator.errors import capture_err
|
from misskaty.core.decorator.errors import capture_err
|
||||||
from misskaty.helper.http import http
|
from misskaty.helper.http import http
|
||||||
from misskaty.helper.tools import GENRES_EMOJI, get_random_string
|
from misskaty.helper.tools import get_random_string, search_jw
|
||||||
from misskaty.vars import COMMAND_HANDLER
|
from misskaty.vars import COMMAND_HANDLER
|
||||||
from utils import demoji
|
|
||||||
|
|
||||||
LOGGER = logging.getLogger(__name__)
|
LOGGER = logging.getLogger(__name__)
|
||||||
LIST_CARI = {}
|
LIST_CARI = {}
|
||||||
|
IMDB_API = "https://imdb.yasirapi.eu.org/search"
|
||||||
|
|
||||||
|
|
||||||
# IMDB Choose Language
|
# IMDB Choose Language
|
||||||
|
|
@ -104,17 +104,18 @@ async def imdb_search_id(kueri, message):
|
||||||
msg = ""
|
msg = ""
|
||||||
buttons = InlineKeyboard(row_width=4)
|
buttons = InlineKeyboard(row_width=4)
|
||||||
try:
|
try:
|
||||||
r = await http.get(f"https://yasirapi.eu.org/imdb-search?q={kueri}")
|
# https://yasirapi.eu.org/imdb-search?q=doraemon # Second API
|
||||||
res = json.loads(r.text).get("result")
|
r = await http.get(f"{IMDB_API}?query={kueri}")
|
||||||
|
res = json.loads(r.text).get("results")
|
||||||
if not res:
|
if not res:
|
||||||
return await k.edit_caption(f"⛔️ Tidak ditemukan hasil untuk kueri: <code>{kueri}</code>")
|
return await k.edit_caption(f"⛔️ Tidak ditemukan hasil untuk kueri: <code>{kueri}</code>")
|
||||||
msg += f"🎬 Ditemukan ({len(res)}) hasil untuk kueri: <code>{kueri}</code>\n\n"
|
msg += f"🎬 Ditemukan ({len(res)}) hasil untuk kueri: <code>{kueri}</code>\n\n"
|
||||||
for num, movie in enumerate(res, start=1):
|
for num, movie in enumerate(res, start=1):
|
||||||
title = movie.get("l")
|
title = movie.get("title")
|
||||||
year = f"({movie.get('y')})" if movie.get("y") else ""
|
year = f"({movie.get('year', 'N/A')})"
|
||||||
type = movie.get("q").replace("feature", "movie").capitalize()
|
typee = movie.get("type", 'N/A').capitalize()
|
||||||
movieID = re.findall(r"tt(\d+)", movie.get("id"))[0]
|
movieID = re.findall(r"tt(\d+)", movie.get("id"))[0]
|
||||||
msg += f"{num}. {title} {year} - {type}\n"
|
msg += f"{num}. {title} {year} - {typee}\n"
|
||||||
BTN.append(
|
BTN.append(
|
||||||
InlineKeyboardButton(
|
InlineKeyboardButton(
|
||||||
text=num,
|
text=num,
|
||||||
|
|
@ -149,17 +150,17 @@ async def imdb_search_en(kueri, message):
|
||||||
msg = ""
|
msg = ""
|
||||||
buttons = InlineKeyboard(row_width=4)
|
buttons = InlineKeyboard(row_width=4)
|
||||||
try:
|
try:
|
||||||
r = await http.get(f"https://yasirapi.eu.org/imdb-search?q={kueri}")
|
r = await http.get(f"{IMDB_API}/search?query={kueri}")
|
||||||
res = json.loads(r.text).get("result")
|
res = json.loads(r.text).get("results")
|
||||||
if not res:
|
if not res:
|
||||||
return await k.edit_caption(f"⛔️ Result not found for keywords: <code>{kueri}</code>")
|
return await k.edit_caption(f"⛔️ Result not found for keywords: <code>{kueri}</code>")
|
||||||
msg += f"🎬 Found ({len(res)}) result for keywords: <code>{kueri}</code>\n\n"
|
msg += f"🎬 Found ({len(res)}) result for keywords: <code>{kueri}</code>\n\n"
|
||||||
for num, movie in enumerate(res, start=1):
|
for num, movie in enumerate(res, start=1):
|
||||||
title = movie.get("l")
|
title = movie.get("title")
|
||||||
year = f"({movie.get('y')})" if movie.get("y") else ""
|
year = f"({movie.get('year', 'N/A')})"
|
||||||
type = movie.get("q").replace("feature", "movie").capitalize()
|
typee = movie.get("type", "N/A").capitalize()
|
||||||
movieID = re.findall(r"tt(\d+)", movie.get("id"))[0]
|
movieID = re.findall(r"tt(\d+)", movie.get("id"))[0]
|
||||||
msg += f"{num}. {title} {year} - {type}\n"
|
msg += f"{num}. {title} {year} - {typee}\n"
|
||||||
BTN.append(
|
BTN.append(
|
||||||
InlineKeyboardButton(
|
InlineKeyboardButton(
|
||||||
text=num,
|
text=num,
|
||||||
|
|
@ -199,17 +200,17 @@ async def imdbcari_id(client, query):
|
||||||
msg = ""
|
msg = ""
|
||||||
buttons = InlineKeyboard(row_width=4)
|
buttons = InlineKeyboard(row_width=4)
|
||||||
try:
|
try:
|
||||||
r = await http.get(f"https://yasirapi.eu.org/imdb-search?q={kueri}")
|
r = await http.get(f"{IMDB_API}/search?query={kueri}")
|
||||||
res = json.loads(r.text).get("result")
|
res = json.loads(r.text).get("results")
|
||||||
if not res:
|
if not res:
|
||||||
return await query.message.edit_caption(f"⛔️ Tidak ditemukan hasil untuk kueri: <code>{kueri}</code>")
|
return await query.message.edit_caption(f"⛔️ Tidak ditemukan hasil untuk kueri: <code>{kueri}</code>")
|
||||||
msg += f"🎬 Ditemukan ({len(res)}) hasil dari: <code>{kueri}</code> ~ {query.from_user.mention}\n\n"
|
msg += f"🎬 Ditemukan ({len(res)}) hasil dari: <code>{kueri}</code> ~ {query.from_user.mention}\n\n"
|
||||||
for num, movie in enumerate(res, start=1):
|
for num, movie in enumerate(res, start=1):
|
||||||
title = movie.get("l")
|
title = movie.get("title")
|
||||||
year = f"({movie.get('y')})" if movie.get("y") else ""
|
year = f"({movie.get('year', 'N/A')})"
|
||||||
type = movie.get("q").replace("feature", "movie").capitalize()
|
typee = movie.get("type", "N/A").capitalize()
|
||||||
movieID = re.findall(r"tt(\d+)", movie.get("id"))[0]
|
movieID = re.findall(r"tt(\d+)", movie.get("id"))[0]
|
||||||
msg += f"{num}. {title} {year} - {type}\n"
|
msg += f"{num}. {title} {year} - {typee}\n"
|
||||||
BTN.append(InlineKeyboardButton(text=num, callback_data=f"imdbres_id#{uid}#{movieID}"))
|
BTN.append(InlineKeyboardButton(text=num, callback_data=f"imdbres_id#{uid}#{movieID}"))
|
||||||
BTN.extend(
|
BTN.extend(
|
||||||
(
|
(
|
||||||
|
|
@ -238,17 +239,17 @@ async def imdbcari_en(client, query):
|
||||||
msg = ""
|
msg = ""
|
||||||
buttons = InlineKeyboard(row_width=4)
|
buttons = InlineKeyboard(row_width=4)
|
||||||
try:
|
try:
|
||||||
r = await http.get(f"https://yasirapi.eu.org/imdb-search?q={kueri}")
|
r = await http.get(f"{IMDB_API}/search?query={kueri}")
|
||||||
res = json.loads(r.text).get("result")
|
res = json.loads(r.text).get("results")
|
||||||
if not res:
|
if not res:
|
||||||
return await query.message.edit_caption(f"⛔️ Result not found for keywords: <code>{kueri}</code>")
|
return await query.message.edit_caption(f"⛔️ Result not found for keywords: <code>{kueri}</code>")
|
||||||
msg += f"🎬 Found ({len(res)}) result for keywords: <code>{kueri}</code> ~ {query.from_user.mention}\n\n"
|
msg += f"🎬 Found ({len(res)}) result for keywords: <code>{kueri}</code> ~ {query.from_user.mention}\n\n"
|
||||||
for num, movie in enumerate(res, start=1):
|
for num, movie in enumerate(res, start=1):
|
||||||
title = movie.get("l")
|
title = movie.get("title")
|
||||||
year = f"({movie.get('y')})" if movie.get("y") else ""
|
year = f"({movie.get('year', 'N/A')})"
|
||||||
type = movie.get("q").replace("feature", "movie").capitalize()
|
typee = movie.get("type", "N/A").capitalize()
|
||||||
movieID = re.findall(r"tt(\d+)", movie.get("id"))[0]
|
movieID = re.findall(r"tt(\d+)", movie.get("id"))[0]
|
||||||
msg += f"{num}. {title} {year} - {type}\n"
|
msg += f"{num}. {title} {year} - {typee}\n"
|
||||||
BTN.append(InlineKeyboardButton(text=num, callback_data=f"imdbres_en#{uid}#{movieID}"))
|
BTN.append(InlineKeyboardButton(text=num, callback_data=f"imdbres_en#{uid}#{movieID}"))
|
||||||
BTN.extend(
|
BTN.extend(
|
||||||
(
|
(
|
||||||
|
|
@ -274,10 +275,11 @@ async def imdb_id_callback(_, query):
|
||||||
f"https://yasirapi.eu.org/imdb-page?url={url}",
|
f"https://yasirapi.eu.org/imdb-page?url={url}",
|
||||||
headers={"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/600.1.17 (KHTML, like Gecko) Version/7.1 Safari/537.85.10"},
|
headers={"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/600.1.17 (KHTML, like Gecko) Version/7.1 Safari/537.85.10"},
|
||||||
)
|
)
|
||||||
|
ott = await search_jw(r_json.get("title"), "en_ID")
|
||||||
r_json = resp.json().get("result")
|
r_json = resp.json().get("result")
|
||||||
res_str = ""
|
res_str = ""
|
||||||
if judul := r_json.get("title"):
|
if judul := r_json.get("title"):
|
||||||
res_str += f"<b>📹 Judul:</b> {judul}\n"
|
res_str += f"<b>📹 Judul:</b> <a href='{url}'>{judul} [{r_json.get('year')}]</a>\n"
|
||||||
if aka := r_json.get("aka"):
|
if aka := r_json.get("aka"):
|
||||||
res_str += f"<b>📢 AKA:</b> <code>{aka}</code>\n\n"
|
res_str += f"<b>📢 AKA:</b> <code>{aka}</code>\n\n"
|
||||||
else:
|
else:
|
||||||
|
|
@ -312,6 +314,8 @@ async def imdb_id_callback(_, query):
|
||||||
res_str += f"<b>🏆 Penghargaan:</b> <code>{GoogleTranslator('auto', 'id').translate(award)}</code>\n\n"
|
res_str += f"<b>🏆 Penghargaan:</b> <code>{GoogleTranslator('auto', 'id').translate(award)}</code>\n\n"
|
||||||
else:
|
else:
|
||||||
res_str += "\n"
|
res_str += "\n"
|
||||||
|
if ott != "":
|
||||||
|
res_str += f"\nAvailable On:\n{ott}\n"
|
||||||
res_str += f"<b>©️ IMDb by</b> @{BOT_USERNAME}"
|
res_str += f"<b>©️ IMDb by</b> @{BOT_USERNAME}"
|
||||||
if trailer := r_json.get("trailer_url"):
|
if trailer := r_json.get("trailer_url"):
|
||||||
markup = InlineKeyboardMarkup(
|
markup = InlineKeyboardMarkup(
|
||||||
|
|
@ -353,9 +357,10 @@ async def imdb_en_callback(bot, query):
|
||||||
headers={"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/600.1.17 (KHTML, like Gecko) Version/7.1 Safari/537.85.10"},
|
headers={"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/600.1.17 (KHTML, like Gecko) Version/7.1 Safari/537.85.10"},
|
||||||
)
|
)
|
||||||
r_json = resp.json().get("result")
|
r_json = resp.json().get("result")
|
||||||
|
ott = await search_jw(r_json.get("title"), "en_US")
|
||||||
res_str = ""
|
res_str = ""
|
||||||
if judul := r_json.get("title"):
|
if judul := r_json.get("title"):
|
||||||
res_str += f"<b>📹 Title:</b> {judul}\n"
|
res_str += f"<b>📹 Title:</b> <a href='{url}'>{judul} [{r_json.get('year')}]</a>\n"
|
||||||
if aka := r_json.get("aka"):
|
if aka := r_json.get("aka"):
|
||||||
res_str += f"<b>📢 AKA:</b> <code>{aka}</code>\n\n"
|
res_str += f"<b>📢 AKA:</b> <code>{aka}</code>\n\n"
|
||||||
else:
|
else:
|
||||||
|
|
@ -389,6 +394,8 @@ async def imdb_en_callback(bot, query):
|
||||||
res_str += f"<b>🏆 Awards:</b> <code>{award}</code>\n\n"
|
res_str += f"<b>🏆 Awards:</b> <code>{award}</code>\n\n"
|
||||||
else:
|
else:
|
||||||
res_str += "\n"
|
res_str += "\n"
|
||||||
|
if ott != "":
|
||||||
|
res_str += f"\nAvailable On:\n{ott}\n"
|
||||||
res_str += f"<b>©️ IMDb by</b> @{BOT_USERNAME}"
|
res_str += f"<b>©️ IMDb by</b> @{BOT_USERNAME}"
|
||||||
if trailer := r_json.get("trailer_url"):
|
if trailer := r_json.get("trailer_url"):
|
||||||
markup = InlineKeyboardMarkup(
|
markup = InlineKeyboardMarkup(
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ from pyrogram.types import (
|
||||||
|
|
||||||
from misskaty import BOT_USERNAME, app, user
|
from misskaty import BOT_USERNAME, app, user
|
||||||
from misskaty.helper.http import http
|
from misskaty.helper.http import http
|
||||||
from misskaty.helper.tools import GENRES_EMOJI
|
from misskaty.helper.tools import GENRES_EMOJI, search_jw
|
||||||
from misskaty.plugins.misc_tools import get_content
|
from misskaty.plugins.misc_tools import get_content
|
||||||
from utils import demoji
|
from utils import demoji
|
||||||
|
|
||||||
|
|
@ -360,7 +360,7 @@ async def inline_menu(_, inline_query: InlineQuery):
|
||||||
description = midb.get("q", "")
|
description = midb.get("q", "")
|
||||||
stars = midb.get("s", "")
|
stars = midb.get("s", "")
|
||||||
imdb_url = f"https://imdb.com/title/{midb.get('id')}"
|
imdb_url = f"https://imdb.com/title/{midb.get('id')}"
|
||||||
year = f"({midb.get('y')})" if midb.get("y") else ""
|
year = f"({midb.get('y', '')})"
|
||||||
image_url = midb.get("i").get("imageUrl").replace(".jpg", "._V1_UX360.jpg") if midb.get("i") else "https://te.legra.ph/file/e263d10ff4f4426a7c664.jpg"
|
image_url = midb.get("i").get("imageUrl").replace(".jpg", "._V1_UX360.jpg") if midb.get("i") else "https://te.legra.ph/file/e263d10ff4f4426a7c664.jpg"
|
||||||
caption = f"<a href='{image_url}'>🎬</a>"
|
caption = f"<a href='{image_url}'>🎬</a>"
|
||||||
caption += f"<a href='{imdb_url}'>{title} {year}</a>"
|
caption += f"<a href='{imdb_url}'>{title} {year}</a>"
|
||||||
|
|
@ -436,6 +436,7 @@ async def imdb_inl(_, query):
|
||||||
url = f"https://www.imdb.com/title/{movie}/"
|
url = f"https://www.imdb.com/title/{movie}/"
|
||||||
resp = await get_content(url)
|
resp = await get_content(url)
|
||||||
sop = BeautifulSoup(resp, "lxml")
|
sop = BeautifulSoup(resp, "lxml")
|
||||||
|
ott = await search_jw(r_json["name"], "en_ID")
|
||||||
r_json = json.loads(sop.find("script", attrs={"type": "application/ld+json"}).contents[0])
|
r_json = json.loads(sop.find("script", attrs={"type": "application/ld+json"}).contents[0])
|
||||||
res_str = ""
|
res_str = ""
|
||||||
type = f"<code>{r_json['@type']}</code>" if r_json.get("@type") else ""
|
type = f"<code>{r_json['@type']}</code>" if r_json.get("@type") else ""
|
||||||
|
|
@ -520,6 +521,8 @@ async def imdb_inl(_, query):
|
||||||
res_str += f"<b>🏆 Penghargaan:</b> <code>{GoogleTranslator('auto', 'id').translate(awards)}</code>\n\n"
|
res_str += f"<b>🏆 Penghargaan:</b> <code>{GoogleTranslator('auto', 'id').translate(awards)}</code>\n\n"
|
||||||
else:
|
else:
|
||||||
res_str += "\n"
|
res_str += "\n"
|
||||||
|
if ott != "":
|
||||||
|
res_str += f"\nAvailable On:\n{ott}\n"
|
||||||
res_str += "<b>©️ IMDb by</b> @MissKatyRoBot"
|
res_str += "<b>©️ IMDb by</b> @MissKatyRoBot"
|
||||||
if r_json.get("trailer"):
|
if r_json.get("trailer"):
|
||||||
trailer_url = r_json["trailer"]["url"]
|
trailer_url = r_json["trailer"]["url"]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue