async def last_logged(message: Message): """get last traceback from main account""" limit_ = message.input_str if not limit_: limit_ = 5 elif not limit_.isdigit(): return await message.edit("`Provide a number as limit.`", del_in=5) if limit_ > 10: return await message.edit("`Can't search more than 10 messages.`", del_in=5) await message.edit("`Looking for last traceback...`") num = 0 me_ = (await userge.get_me()).first_name async for msg_ in userge.search_messages(Config.LOG_CHANNEL_ID): if msg_type(msg_) == "text": num += 1 if "-e" in message.flags: search_ = "#EXECUTOR" found_ = "eval traceback" else: search_ = "#TRACEBACK" found_ = "traceback" if search_ in msg_.text: text_ = msg_.text.html text_ = text_.replace("\n", "<br>") link_ = post_to_telegraph( f"{found_.capitalize()} from log channel of {me_}.", text_) return await message.edit( f"Last <b>{found_}</b> is [<b>HERE</b>]({link_}).", disable_web_page_preview=True, ) if num == limit_: return await message.edit( f"`Couldn't find {found_} in last {limit_} messages.`", del_in=5)
async def get_lyrics(search: str) -> Optional[str]: async with get_response.get_session() as session: async with session.post( "http://www.glyrics.xyz/search", json={"searchTerm": search}, headers={"content-type": "application/json"}, ) as resp: if not resp.status == 200: return result = await resp.json() if lyrics := result.get("lyrics"): nl = "\n" return post_to_telegraph(search, f'<pre>{lyrics.replace(nl, "<br>")}</pre>')
async def mediainfo(message: Message): """Get Media Info""" reply = message.reply_to_message if not reply: await message.err("reply to media first", del_in=5) return process = await message.edit("`Processing ...`") x_media = None available_media = ( "audio", "document", "photo", "sticker", "animation", "video", "voice", "video_note", "new_chat_photo", ) for kind in available_media: x_media = getattr(reply, kind, None) if x_media is not None: break if x_media is None: await message.err("Reply To a Vaild Media Format", del_in=3) return media_type = str(type(x_media)).split("'")[1] file_path = safe_filename(await reply.download()) output_ = await runcmd(f'mediainfo "{file_path}"') out = None if len(output_) != 0: out = output_[0] body_text = f""" <h2>JSON</h2> <pre>{x_media}</pre> <br> <h2>DETAILS</h2> <pre>{out or 'Not Supported'}</pre> """ text_ = media_type.split(".")[-1].upper() link = post_to_telegraph(media_type, body_text) if message.client.is_bot: markup = InlineKeyboardMarkup([[InlineKeyboardButton(text=text_, url=link)]]) await process.edit_text("ℹ️ <b>MEDIA INFO</b>", reply_markup=markup) else: await message.edit(f"ℹ️ <b>MEDIA INFO: [{text_}]({link})</b>") os.remove(file_path)
async def lyrics(message: Message): song = message.input_str if not song: await message.edit("Bruh WTF?") return await message.edit(f"Searching lyrics for **{song}**...") to_search = song + "genius lyrics" gen_surl = list(search(to_search, num=1, stop=1))[0] gen_page = requests.get(gen_surl) scp = BeautifulSoup(gen_page.text, "html.parser") lyrics = scp.find("div", class_="lyrics") if not lyrics: await message.edit(f"No Results Found for: `{song}`") return lyrics = lyrics.get_text() lyrics = re.sub(r"[\(\[].*?[\)\]]", "", lyrics) lyrics = os.linesep.join((s for s in lyrics.splitlines() if s)) title = scp.find("title").get_text().split("|") writers_box = [ writer for writer in scp.find_all("span", {"class": "metadata_unit-label"}) if writer.text == "Written By" ] if writers_box: target_node = writers_box[0].find_next_sibling( "span", {"class": "metadata_unit-info"}) writers = target_node.text.strip() else: writers = "UNKNOWN" lyr_format = "" lyr_format += "<b>" + title[0] + "</b>\n" lyr_format += "<i>" + lyrics + "</i>" lyr_format += "\n\n<b>Written By: </b>" + "<i>" + writers + "</i>" lyr_format += "\n<b>Source: </b>" + "`" + title[1] + "`" if lyr_format: if len(lyr_format) <= 4096: await message.edit(lyr_format) else: lyr_format = lyr_format.replace("\n", "<br>") link = post_to_telegraph(title[0], lyr_format) await message.edit( f"Posted the lyrics to telegraph...\n[Link]({link})") else: await message.edit(f"No Lyrics Found for **{song}**")
async def tele_text(message: Message): """Paste on Telegra.ph""" start = time.time() replied = message.reply_to_message if not replied: await message.err("Reply To Message First !", del_in=5) return if not (replied.text or replied.caption): await message.err("Replied Message Doesn't Contain Text. Ъце", del_in=5) return await message.edit("Pasting...") text = replied.text if replied.text else replied.caption if "-mono" in message.flags: text = "<code>{}</code>".format(text) else: text = text.html if "-m" in message.flags: if not (replied.photo or replied.video or replied.document or replied.animation): return await message.err("Media Type Not Supported", del_in=3) link = await upload_media_(message) if link == "error": return if link.endswith((".mp4", ".mkv")): media_link = f'<video controls src="https://telegra.ph{link}">Browser not supported</video>' else: media_link = f'<img src="https://telegra.ph{link}">' text = media_link + text user = await userge.get_me() user_n = f"@{user.username}" if user.username else user.first_name title = message.filtered_input_str if not title: title = f"By {user_n}" link = post_to_telegraph(title, text) msg = "**Pasted to -** " msg += f"<b><a href={link}>{link.replace('http://telegra.ph/', '')}</a></b>\n" end = time.time() msg += f"in <code>{time_formatter(end - start)}</code> sec" await message.edit(msg, disable_web_page_preview=True)
async def mediainfo(message: Message): """Get Media Info""" reply = message.reply_to_message if not reply: await message.err("reply to media first", del_in=5) return process = await message.edit("`Processing ...`") x_media = None for media_type in TYPES: if reply[media_type]: x_media = media_type break if not x_media: return await message.err("Reply To a Vaild Media Format", del_in=3) file_path = await reply.download() output_ = await runcmd(f"mediainfo {file_path}") out = output_[0] if len(output_) != 0 else None if not out: out = "Not Supported" body_text = f"""<br> <h2>JSON</h2> <code>{reply[x_media]}</code> <br> <br> <h2>DETAILS</h2> <code>{out}</code> """ link = post_to_telegraph(f"pyrogram.types.{x_media}", body_text) if message.client.is_bot: markup = InlineKeyboardMarkup( [[InlineKeyboardButton(text=x_media.upper(), url=link)]]) await process.edit_text("ℹ️ <b>MEDIA INFO</b>", reply_markup=markup) else: await message.edit( f"ℹ️ <b>MEDIA INFO: [{x_media.upper()}]({link})</b>") os.remove(file_path)
async def mediainfo(message: Message): """Get Media Info""" reply = message.reply_to_message if not reply: await message.err('reply to media first', del_in=5) return process = await message.edit('`Processing ...`') for media_type in TYPES: if reply[media_type]: X_MEDIA = media_type break if not X_MEDIA: return await message.err('Reply To a Vaild Media Format', del_in=5) file_path = await reply.download() out, err, ret, pid = await runcmd(f"mediainfo {file_path}") if not out: out = "Not Supported" body_text = f"""<br> <h2>JSON</h2> <code>{reply[X_MEDIA]}</code> <br> <br> <h2>DETAILS</h2> <code>{out}</code> """ link = post_to_telegraph(f'pyrogram.types.{X_MEDIA}', body_text) if message.client.is_bot: markup = InlineKeyboardMarkup( [[InlineKeyboardButton(text=X_MEDIA.upper(), url=link)]]) await process.edit_text("ℹ️ <b>MEDIA INFO</b>", reply_markup=markup) else: await message.edit( f'ℹ️ <b>MEDIA INFO: [{X_MEDIA.upper()}]({link})</b>') os.remove(file_path)
async def ytdl_callback(c_q: CallbackQuery): choosen_btn = c_q.matches[0].group(1) data_key = c_q.matches[0].group(2) page = c_q.matches[0].group(3) if os.path.exists(PATH): with open(PATH) as f: view_data = ujson.load(f) search_data = view_data.get(data_key) total = len(search_data) else: return await c_q.answer( "Search data doesn't exists anymore, please perform search again ...", show_alert=True, ) if choosen_btn == "back": index = int(page) - 1 del_back = index == 1 back_vid = search_data.get(str(index)) await xbot.edit_inline_media( c_q.inline_message_id, media=(await xmedia.InputMediaPhoto( file_id=back_vid.get("thumb"), caption=back_vid.get("message"), )), reply_markup=yt_search_btns( del_back=del_back, data_key=data_key, page=index, vid=back_vid.get("video_id"), total=total, ), ) elif choosen_btn == "next": index = int(page) + 1 if index > total: return await c_q.answer("that's all folks", show_alert=True) front_vid = search_data.get(str(index)) await xbot.edit_inline_media( c_q.inline_message_id, media=(await xmedia.InputMediaPhoto( file_id=front_vid.get("thumb"), caption=front_vid.get("message"), )), reply_markup=yt_search_btns( data_key=data_key, page=index, vid=front_vid.get("video_id"), total=total, ), ) elif choosen_btn == "listall": list_res = "" for vid_s in search_data: list_res += search_data.get(vid_s).get("list_view") telegraph = post_to_telegraph( a_title= f"Showing {total} youtube video results for the given query ...", content=list_res, ) await xbot.edit_inline_media( c_q.inline_message_id, media=(await xmedia.InputMediaPhoto( file_id=search_data.get("1").get("thumb"), caption=f"<b>[Click to view]({telegraph})</b>", )), reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton( "📰 Detailed View", callback_data=f"ytdl_detail_{data_key}_{page}", ) ]]), ) else: # Detailed index = 1 first = search_data.get(str(index)) await xbot.edit_inline_media( c_q.inline_message_id, media=(await xmedia.InputMediaPhoto( file_id=first.get("thumb"), caption=first.get("message"), )), reply_markup=yt_search_btns( del_back=True, data_key=data_key, page=index, vid=first.get("video_id"), total=total, ), )
async def lyrics(message: Message): song = message.filtered_input_str or message.reply_to_message.text flag = message.flags if not song: await message.err("Search song lyrics without song name?") return if Config.GENIUS is None: await message.err( "Provide 'Genius access token' as `GENIUS` to config vars...\nGet it from docs.genius.com" ) return to_search = song + "genius lyrics" gen_surl = list(search(to_search, num=1, stop=1))[0] gen_page = requests.get(gen_surl) scp = BeautifulSoup(gen_page.text, "html.parser") writers_box = [ writer for writer in scp.find_all("span", {"class": "metadata_unit-label"}) if writer.text == "Written By" ] if writers_box: target_node = writers_box[0].find_next_sibling( "span", {"class": "metadata_unit-info"}) writers = target_node.text.strip() else: writers = "Couldn't find writers..." artist = "" if " - " in song: artist, song = song.split("-", 1) artist = artist.strip() name_a = artist.split() artist_a = [] for a in name_a: a = a.capitalize() artist_a.append(a) artist = " ".join(artist_a) song = song.strip() name_s = song.split() song_s = [] for s in name_s: s = s.capitalize() song_s.append(s) song = " ".join(song_s) if artist == "": title = song else: title = f"{artist} - {song}" await message.edit(f"Searching lyrics for **{title}** on Genius...`") try: lyr = genius.search_song(song, artist) except Exception: name = f"{song} {artist}" data = {"searchTerm": name} async with aiohttp.request( "POST", "http://www.glyrics.xyz/search", headers={ "content-type": "application/json", }, data=json.dumps(data), ) as result: lyric = await result.text() lyr = json.loads(lyric) lyr = lyr["lyrics"] lyrics = f"\n{lyr}" lyrics += f"\n\n<b>Written by:</b> <code>{writers}</code>" lyrics += f"\n<b>Source:</b> <code>genius.com</code>" lyrics = lyrics.replace("[", "<b>[").replace("]", "]</b>") full_lyr = f"Lyrics for **{title}** by Genius.com...\n\n{lyrics}" if len(full_lyr) <= 4096 and "-t" not in flag: await message.edit(full_lyr) else: lyrics = lyrics.replace("\n", "<br>") link = post_to_telegraph(f"Lyrics for {title}...", lyrics) await message.edit( f"Lyrics for **{title}** by Genius.com...\n[Link]({link})", disable_web_page_preview=True, ) return if lyr is None: await message.edit(f"Couldn't find `{title}` on Genius...") return lyric = lyr.lyrics lyrics = f"\n{lyric}" lyrics += f"\n\n<b>Written by:</b> <code>{writers}</code>" lyrics += f"\n<b>Source:</b> <code>genius.com</code>" lyrics = lyrics.replace("[", "<b>[") lyrics = lyrics.replace("]", "]</b>") lyr_msg = f"Lyrics for <b>{title}</b>...\n\n{lyrics}" if len(lyr_msg) <= 4096 and "-t" not in flag: await message.edit(f"{lyr_msg}") else: lyrics = lyrics.replace("\n", "<br>") link = post_to_telegraph(f"Lyrics for {title}...", lyrics) await message.edit( f"Lyrics for **{title}** by Genius.com...\n[Link]({link})", disable_web_page_preview=True, )
async def lyrics(message: Message): """Lyrics from genius.com""" song = message.filtered_input_str or message.reply_to_message.text flag = message.flags if not song: await message.err("Search song lyrics without song name?", del_in=5) return if GENIUS is None: await message.err( "Provide 'Genius access token' as `GENIUS` to config vars...\nGet it from docs.genius.com...", del_in=5, ) return if len(flag) > 1: await message.edit("Only one flag at a time please...", del_in=5) return if "-s" in flag: songs = genius.search_songs(song) await message.edit(f"Searching songs matching <b>{song}</b>...") number = 0 s_list = [] hits = songs["hits"] for one in hits: s_list.append( f'• <code>{hits[number]["result"]["full_title"]}</code>') number += 1 s_list = "\n".join(s_list) await message.edit(f"Songs matching [<b>{song}</b>]:\n\n" f"{s_list}") return artist = "" if " - " in song: artist, song = song.split("-", 1) artist = artist.strip() artist = capitaled(artist) song = song.strip() song = capitaled(song) if artist == "": title = song else: title = f"{artist} - {song}" await message.edit(f"Searching lyrics for **{title}** on Genius...`") dis_pre = False try: lyr = genius.search_song(song, artist) except Exception: await message.edit(f"Couldn't find <code>{title}</code> on genius...", del_in=5) return if lyr is None: await message.edit(f"Couldn't find `{title}` on Genius...") return lyric = lyr.lyrics lyrics = f"\n{lyric}</i>" lyrics += f"\n\n<b>Source:</b> <code>genius.com</code>" lyrics = (lyrics.replace("[", "</i><b>[").replace("]", "]</b><i>").replace( "EmbedShare", "").replace("URLCopyEmbedCopy", "")) lyr_msg = f"Lyrics for <b>{title}</b>...\n\n<i>{lyrics}" if len(lyr_msg) <= 4096 and "-t" not in flag and "-pre" not in flag: await message.edit(f"{lyr_msg}") else: if "-no_p" in flag: dis_pre = True lyrics = lyrics.replace("\n", "<br>") link = post_to_telegraph(f"Lyrics for {title}...", f"<i>{lyrics}") await message.edit( f"Lyrics for [<b>{title}</b>]({link}) by genius.com...", disable_web_page_preview=dis_pre, )
async def lyrics(message: Message): song = message.input_str or message.reply_to_message.text if not song: await message.err("Search song lyrics without song name?") return if Config.GENIUS is None: await message.err( "Provide 'Genius access token' as `GENIUS` to config vars...\nGet it from docs.genius.com" ) return to_search = song + "genius lyrics" gen_surl = list(search(to_search, num=1, stop=1))[0] gen_page = requests.get(gen_surl) scp = BeautifulSoup(gen_page.text, "html.parser") writers_box = [ writer for writer in scp.find_all("span", {"class": "metadata_unit-label"}) if writer.text == "Written By" ] if writers_box: target_node = writers_box[0].find_next_sibling( "span", {"class": "metadata_unit-info"}) writers = target_node.text.strip() else: writers = "Couldn't find writers..." artist = "" if " - " in song: artist, song = song.split("-", 1) artist = artist.strip() name_a = artist.split() artist_a = [] for a in name_a: a = a.capitalize() artist_a.append(a) artist = " ".join(map(str, artist_a)) song = song.strip() name_s = song.split() song_s = [] for s in name_s: s = s.capitalize() song_s.append(s) song = " ".join(map(str, song_s)) title = f"{artist} - {song}" if artist == "": title = title.replace(" - ", "") await message.edit(f"Searching lyrics for **{title}** on Genius...`") lyr = genius.search_song(song, artist) if lyr is None: await message.edit(f"Couldn't find `{title}` on Genius...") return lyric = lyr.lyrics lyrics = f"\n{lyric}" lyrics += f"\n\n<b>Written by: </b><code>{writers}</code>" lyrics += f"\n<b>Source: </b><code>genius.com</code>" lyrics = lyrics.replace("[", "<b>[") lyrics = lyrics.replace("]", "]</b>") lyr_msg = f"Lyrics for <b>{title}</b>...\n\n{lyrics}" if len(lyr_msg) <= 4096: await message.edit(f"{lyr_msg}") else: lyrics = lyrics.replace("\n", "<br>") link = post_to_telegraph(f"Lyrics for {title}...", lyrics) await message.edit( f"Lyrics for **{title}** by Genius.com...\n[Link]({link})")