| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 |
- # Part of Pull Req #2 by @MaskedVirus | github.com/swatv3nub
- import time
- from datetime import timedelta
- import requests
- from pyrogram import filters
- from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
- from wbb import app
- from wbb.core.decorators.errors import capture_err
- __MODULE__ = "Anime"
- __HELP__ = """
- /anime - search anime on AniList
- /manga - search manga on Anilist
- /char - search character on Anilist
- """
- def shorten(description, info="anilist.co"):
- ms_g = ""
- if len(description) > 700:
- description = description[0:500] + "...."
- ms_g += f"\n**Description**: __{description}__[More here]({info})"
- else:
- ms_g += f"\n**Description**: __{description}__"
- return (
- ms_g.replace("<br>", "")
- .replace("</br>", "")
- .replace("<i>", "")
- .replace("</i>", "")
- )
- def t(milliseconds: int) -> str:
- """Inputs time in milliseconds, to get beautified time,
- as string"""
- seconds, milliseconds = divmod(int(milliseconds), 1000)
- minutes, seconds = divmod(seconds, 60)
- hours, minutes = divmod(minutes, 60)
- days, hours = divmod(hours, 24)
- tmp = (
- ((str(days) + " Days, ") if days else "")
- + ((str(hours) + " Hours, ") if hours else "")
- + ((str(minutes) + " Minutes, ") if minutes else "")
- + ((str(seconds) + " Seconds, ") if seconds else "")
- + ((str(milliseconds) + " ms, ") if milliseconds else "")
- )
- return tmp[:-2]
- airing_query = """
- query ($id: Int,$search: String) {
- Media (id: $id, type: ANIME,search: $search) {
- id
- episodes
- title {
- romaji
- english
- native
- }
- siteUrl
- nextAiringEpisode {
- airingAt
- timeUntilAiring
- episode
- }
- }
- }
- """
- fav_query = """
- query ($id: Int) {
- Media (id: $id, type: ANIME) {
- id
- title {
- romaji
- english
- native
- }
- }
- }
- """
- anime_query = """
- query ($id: Int,$search: String) {
- Media (id: $id, type: ANIME,search: $search) {
- id
- idMal
- title {
- romaji
- english
- native
- }
- description (asHtml: false)
- startDate{
- year
- }
- episodes
- season
- type
- format
- status
- duration
- siteUrl
- studios{
- nodes{
- name
- }
- }
- trailer{
- id
- site
- thumbnail
- }
- averageScore
- genres
- bannerImage
- }
- }
- """
- character_query = """
- query ($query: String) {
- Character (search: $query) {
- id
- name {
- first
- last
- full
- }
- siteUrl
- favourites
- image {
- large
- }
- description
- }
- }
- """
- manga_query = """
- query ($id: Int,$search: String) {
- Media (id: $id, type: MANGA,search: $search) {
- id
- title {
- romaji
- english
- native
- }
- description (asHtml: false)
- startDate{
- year
- }
- type
- format
- status
- siteUrl
- averageScore
- genres
- bannerImage
- }
- }
- """
- def format_bytes(size):
- size = int(size)
- power = 1024
- n = 0
- power_labels = {0: "", 1: "K", 2: "M", 3: "G", 4: "T"}
- while size > power:
- size /= power
- n += 1
- return f"{size:.2f} {power_labels[n]+'B'}"
- def return_progress_string(current, total):
- filled_length = int(30 * current // total)
- return "[" + "=" * filled_length + " " * (30 - filled_length) + "]"
- def calculate_eta(current, total, start_time):
- if not current:
- return "00:00:00"
- end_time = time.time()
- elapsed_time = end_time - start_time
- seconds = (elapsed_time * (total / current)) - elapsed_time
- thing = "".join(str(timedelta(seconds=seconds)).split(".")[:-1]).split(
- ", "
- )
- thing[-1] = thing[-1].rjust(8, "0")
- return ", ".join(thing)
- url = "https://graphql.anilist.co"
- @app.on_message(filters.command("anime"))
- @capture_err
- async def anime_search(_, message):
- if len(message.command) < 2:
- await message.delete()
- return
- search = message.text.split(None, 1)[1]
- variables = {"search": search}
- json = (
- requests.post(
- url, json={"query": anime_query, "variables": variables}
- )
- .json()["data"]
- .get("Media", None)
- )
- if json:
- msg = f"**{json['title']['romaji']}**(`{json['title']['native']}`)\n**Type**: {json['format']}\n**Status**: {json['status']}\n**Episodes**: {json.get('episodes', 'N/A')}\n**Duration**: {json.get('duration', 'N/A')} Per Ep.\n**Score**: {json['averageScore']}\n**Genres**: `"
- for x in json["genres"]:
- msg += f"{x}, "
- msg = msg[:-2] + "`\n"
- msg += "**Studios**: `"
- for x in json["studios"]["nodes"]:
- msg += f"{x['name']}, "
- msg = msg[:-2] + "`\n"
- info = json.get("siteUrl")
- trailer = json.get("trailer", None)
- if trailer:
- trailer_id = trailer.get("id", None)
- site = trailer.get("site", None)
- if site == "youtube":
- trailer = "https://youtu.be/" + trailer_id
- description = (
- json.get("description", "N/A")
- .replace("<i>", "")
- .replace("</i>", "")
- .replace("<br>", "")
- )
- msg += shorten(description, info)
- image = info.replace("anilist.co/anime/", "img.anili.st/media/")
- if trailer:
- buttons = [
- [
- InlineKeyboardButton("More Info", url=info),
- InlineKeyboardButton("Trailer", url=trailer),
- ]
- ]
- else:
- buttons = [[InlineKeyboardButton("More Info", url=info)]]
- if image:
- try:
- await message.reply_photo(
- image,
- caption=msg,
- reply_markup=InlineKeyboardMarkup(buttons),
- )
- except Exception:
- msg += f" [✔️️]({image})"
- await message.edit(msg)
- else:
- await message.edit(msg)
- @app.on_message(filters.command("manga"))
- @capture_err
- async def manga_search(_, message):
- if len(message.command) < 2:
- await message.delete()
- return
- search = message.text.split(None, 1)[1]
- variables = {"search": search}
- json = (
- requests.post(
- url, json={"query": manga_query, "variables": variables}
- )
- .json()["data"]
- .get("Media", None)
- )
- ms_g = ""
- if json:
- title, title_native = json["title"].get("romaji", False), json[
- "title"
- ].get("native", False)
- start_date, status, score = (
- json["startDate"].get("year", False),
- json.get("status", False),
- json.get("averageScore", False),
- )
- if title:
- ms_g += f"**{title}**"
- if title_native:
- ms_g += f"(`{title_native}`)"
- if start_date:
- ms_g += f"\n**Start Date** - `{start_date}`"
- if status:
- ms_g += f"\n**Status** - `{status}`"
- if score:
- ms_g += f"\n**Score** - `{score}`"
- ms_g += "\n**Genres** - "
- for x in json.get("genres", []):
- ms_g += f"{x}, "
- ms_g = ms_g[:-2]
- image = json.get("bannerImage", False)
- ms_g += f"_{json.get('description', None)}_"
- if image:
- try:
- await message.reply_photo(image, caption=ms_g)
- except Exception:
- ms_g += f" [✔️️]({image})"
- await message.reply(ms_g)
- else:
- await message.reply(ms_g)
- @app.on_message(filters.command("char"))
- @capture_err
- async def character_search(_, message):
- if len(message.command) < 2:
- await message.delete()
- return
- search = message.text.split(None, 1)[1]
- variables = {"query": search}
- json = (
- requests.post(
- url, json={"query": character_query, "variables": variables}
- )
- .json()["data"]
- .get("Character", None)
- )
- if json:
- ms_g = f"**{json.get('name').get('full')}**(`{json.get('name').get('native')}`)\n"
- description = f"{json['description']}"
- site_url = json.get("siteUrl")
- ms_g += shorten(description, site_url)
- image = json.get("image", None)
- if image:
- image = image.get("large")
- await message.reply_photo(image, caption=ms_g)
- else:
- await message.reply(ms_g)
|