Change API and add justwatch

This commit is contained in:
yasir 2023-01-17 15:01:40 +07:00
parent d6eb31432a
commit f47c6c419d
3 changed files with 76 additions and 30 deletions

View file

@ -2,7 +2,9 @@ import os
import random
import string
import time
import json
from http.cookies import SimpleCookie
from urllib.parse import urlparse
import psutil
@ -82,3 +84,37 @@ async def rentry(teks):
.json()
.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_

View file

@ -18,12 +18,12 @@ from database.imdb_db import *
from misskaty import BOT_USERNAME, app
from misskaty.core.decorator.errors import capture_err
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 utils import demoji
LOGGER = logging.getLogger(__name__)
LIST_CARI = {}
IMDB_API = "https://imdb.yasirapi.eu.org/search"
# IMDB Choose Language
@ -104,17 +104,18 @@ async def imdb_search_id(kueri, message):
msg = ""
buttons = InlineKeyboard(row_width=4)
try:
r = await http.get(f"https://yasirapi.eu.org/imdb-search?q={kueri}")
res = json.loads(r.text).get("result")
# https://yasirapi.eu.org/imdb-search?q=doraemon # Second API
r = await http.get(f"{IMDB_API}?query={kueri}")
res = json.loads(r.text).get("results")
if not res:
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"
for num, movie in enumerate(res, start=1):
title = movie.get("l")
year = f"({movie.get('y')})" if movie.get("y") else ""
type = movie.get("q").replace("feature", "movie").capitalize()
title = movie.get("title")
year = f"({movie.get('year', 'N/A')})"
typee = movie.get("type", 'N/A').capitalize()
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,
@ -149,17 +150,17 @@ async def imdb_search_en(kueri, message):
msg = ""
buttons = InlineKeyboard(row_width=4)
try:
r = await http.get(f"https://yasirapi.eu.org/imdb-search?q={kueri}")
res = json.loads(r.text).get("result")
r = await http.get(f"{IMDB_API}/search?query={kueri}")
res = json.loads(r.text).get("results")
if not res:
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"
for num, movie in enumerate(res, start=1):
title = movie.get("l")
year = f"({movie.get('y')})" if movie.get("y") else ""
type = movie.get("q").replace("feature", "movie").capitalize()
title = movie.get("title")
year = f"({movie.get('year', 'N/A')})"
typee = movie.get("type", "N/A").capitalize()
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,
@ -199,17 +200,17 @@ async def imdbcari_id(client, query):
msg = ""
buttons = InlineKeyboard(row_width=4)
try:
r = await http.get(f"https://yasirapi.eu.org/imdb-search?q={kueri}")
res = json.loads(r.text).get("result")
r = await http.get(f"{IMDB_API}/search?query={kueri}")
res = json.loads(r.text).get("results")
if not res:
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"
for num, movie in enumerate(res, start=1):
title = movie.get("l")
year = f"({movie.get('y')})" if movie.get("y") else ""
type = movie.get("q").replace("feature", "movie").capitalize()
title = movie.get("title")
year = f"({movie.get('year', 'N/A')})"
typee = movie.get("type", "N/A").capitalize()
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.extend(
(
@ -238,17 +239,17 @@ async def imdbcari_en(client, query):
msg = ""
buttons = InlineKeyboard(row_width=4)
try:
r = await http.get(f"https://yasirapi.eu.org/imdb-search?q={kueri}")
res = json.loads(r.text).get("result")
r = await http.get(f"{IMDB_API}/search?query={kueri}")
res = json.loads(r.text).get("results")
if not res:
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"
for num, movie in enumerate(res, start=1):
title = movie.get("l")
year = f"({movie.get('y')})" if movie.get("y") else ""
type = movie.get("q").replace("feature", "movie").capitalize()
title = movie.get("title")
year = f"({movie.get('year', 'N/A')})"
typee = movie.get("type", "N/A").capitalize()
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.extend(
(
@ -274,10 +275,11 @@ async def imdb_id_callback(_, query):
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"},
)
ott = await search_jw(r_json.get("title"), "en_ID")
r_json = resp.json().get("result")
res_str = ""
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"):
res_str += f"<b>📢 AKA:</b> <code>{aka}</code>\n\n"
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"
else:
res_str += "\n"
if ott != "":
res_str += f"\nAvailable On:\n{ott}\n"
res_str += f"<b>©️ IMDb by</b> @{BOT_USERNAME}"
if trailer := r_json.get("trailer_url"):
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"},
)
r_json = resp.json().get("result")
ott = await search_jw(r_json.get("title"), "en_US")
res_str = ""
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"):
res_str += f"<b>📢 AKA:</b> <code>{aka}</code>\n\n"
else:
@ -389,6 +394,8 @@ async def imdb_en_callback(bot, query):
res_str += f"<b>🏆 Awards:</b> <code>{award}</code>\n\n"
else:
res_str += "\n"
if ott != "":
res_str += f"\nAvailable On:\n{ott}\n"
res_str += f"<b>©️ IMDb by</b> @{BOT_USERNAME}"
if trailer := r_json.get("trailer_url"):
markup = InlineKeyboardMarkup(

View file

@ -20,7 +20,7 @@ from pyrogram.types import (
from misskaty import BOT_USERNAME, app, user
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 utils import demoji
@ -360,7 +360,7 @@ async def inline_menu(_, inline_query: InlineQuery):
description = midb.get("q", "")
stars = midb.get("s", "")
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"
caption = f"<a href='{image_url}'>🎬</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}/"
resp = await get_content(url)
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])
res_str = ""
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"
else:
res_str += "\n"
if ott != "":
res_str += f"\nAvailable On:\n{ott}\n"
res_str += "<b>©️ IMDb by</b> @MissKatyRoBot"
if r_json.get("trailer"):
trailer_url = r_json["trailer"]["url"]