Spaces:
Sleeping
Sleeping
File size: 11,638 Bytes
aef1161 89a7a7a c26bbaf 89a7a7a 6cef7ec 89a7a7a aef1161 89a7a7a 6cef7ec 89a7a7a aef1161 b48df3a aef1161 b48df3a aef1161 b48df3a aef1161 b48df3a aef1161 b48df3a aef1161 89a7a7a 89ad488 89a7a7a 6cef7ec 89a7a7a d5a4401 aef1161 6cef7ec 89ad488 aef1161 d5a4401 89a7a7a 6cef7ec 89a7a7a d5a4401 89a7a7a 6cef7ec 89a7a7a 89ad488 d5a4401 89ad488 d5a4401 89a7a7a 6cef7ec d5a4401 89a7a7a 6cef7ec 89a7a7a 6cef7ec 89a7a7a 6cef7ec 89a7a7a 6cef7ec d5a4401 89ad488 d5a4401 89ad488 d5a4401 6cef7ec d5a4401 89ad488 d5a4401 6cef7ec d5a4401 6cef7ec d5a4401 6cef7ec 89a7a7a 89ad488 89a7a7a aef1161 89a7a7a aef1161 89a7a7a b48df3a 89a7a7a aef1161 6cef7ec b48df3a aef1161 89a7a7a aef1161 89a7a7a aef1161 89ad488 6cef7ec 89a7a7a aef1161 89a7a7a 6cef7ec 89a7a7a 3d6e111 6cef7ec 3d6e111 c26bbaf 89ad488 b48df3a 89a7a7a 6cef7ec b48df3a 89a7a7a 1c016d9 89ad488 1c016d9 89a7a7a b48df3a aef1161 89a7a7a 6cef7ec 89a7a7a 3d6e111 6cef7ec 3d6e111 c26bbaf 89ad488 b48df3a 89a7a7a 6cef7ec b48df3a 89a7a7a 1c016d9 89ad488 1c016d9 89a7a7a b48df3a aef1161 89a7a7a 6cef7ec 461b15e c26bbaf 461b15e 6cef7ec c26bbaf 6dcea66 c26bbaf 461b15e c26bbaf 6dcea66 c26bbaf 6dcea66 948742f 6dcea66 6cef7ec 6dcea66 c26bbaf 6dcea66 c26bbaf 6dcea66 6cef7ec 6dcea66 c26bbaf 6dcea66 6cef7ec 6dcea66 6cef7ec 461b15e 89a7a7a 461b15e 89a7a7a aef1161 1fc1023 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
import asyncio
from pyrogram import filters
from pyrogram.types import CallbackQuery
from pyrogram.types import InlineKeyboardButton as IKB
from pyrogram.types import InputMediaPhoto, InputMediaVideo, Message
from Powers import RMBG, genius_lyrics, is_rmbg
from Powers.utils.custom_filters import command
from Powers.utils.http_helper import *
from Powers.utils.sticker_help import toimage
from Powers.utils.web_helpers import *
from Powers.utils.web_scrapper import INSTAGRAM
# @Gojo.on_message(command(["songname","insong","songinfo","whichsong","rsong","reversesong"]))
# • /whichsong (/songname, /songinfo, /insong, /rsong, /reversesong) : Reply to file to get the song playing in it.
# async def get_song_info(c: Gojo, m: Message):
# if not is_audd:
# await m.reply_text("Audd api is missing add it to use this command")
# return
# reply = m.reply_to_message
# if not reply:
# await m.reply_text("Reply to a video or audio file")
# return
# elif reply.text:
# await m.reply_text("Reply to a video or audio file")
# return
# elif not (reply.video or reply.audio or reply.video_note or reply.document and (reply.document.mime_type.split("/")[0] in ["video","audio"])):
# await m.reply_text("Reply to a video or audio file")
# return
# try:
# to_edit = await m.reply_text("⏳")
# URL = "https://api.audd.io/"
# sizee = (await get_file_size(reply)).split()
# if (int(sizee[0]) <= 30 and sizee[1] == "mb") or sizee[1] == "kb":
# fpath = await reply.download()
# files = {
# "file" : open(fpath,"rb")
# }
# BASE_AUDD = {
# "api_token":Audd,
# "return": "spotify"
# }
# result = resp_post(URL,data=BASE_AUDD, files=files)
# # elif int(sizee[0]) > 15 or int(sizee[0]) <= 30 and sizee[1] == "mb":
# # BASE_AUDD = {
# # "api_token":Audd,
# # "url": f'{reply.link}',
# # "return": "spotify"
# # }
# # result = resp_post(URL,data=BASE_AUDD)
# else:
# await to_edit.edit_text("File size too big\nI can only fetch file of size upto 30 mbs for now")
# return
# if result.status_code != 200:
# await to_edit.edit_text(f"{result.status_code}:{result.text}")
# return
# result = result.json()
# data = result["result"]
# Artist = data["artist"]
# Title = data["title"]
# Release_date = data["release_date"]
# web_slink = data["song_link"]
# SPOTIFY = data["spotify"]
# spotify_url = SPOTIFY["external_urls"]
# album_url = SPOTIFY["album"]["external_urls"]
# Album = SPOTIFY["album"]["name"]
# photo = SPOTIFY["images"][0]["url"]
# artist_url = SPOTIFY["artists"]["external_urls"]
# cap = f"""
# Song name: {Title}
# Artist: {Artist}
# Album: {Album}
# Release data: {Release_date}
# """
# youtube_link = (await song_search(Title))[1]["link"]
# kb = [
# [
# IKB("🗂 Album", url=album_url),
# IKB("🎨 Artist",url=artist_url)
# ],
# [
# IKB("🎵 Spotify song link",url=spotify_url),
# IKB("▶️ Youtube",url=youtube_link)
# ],
# [IKB("♾ More links", url=web_slink)]
# ]
# if is_genius_lyrics:
# g_k = [IKB("📝 Lyrics",f"lyrics_{Title}:{Artist}")]
# kb.append(g_k)
# await to_edit.delete()
# os.remove(fpath)
# await m.reply_photo(photo,caption=cap,reply_markup=IKM(kb))
# except Exception as e:
# await to_edit.delete()
# await m.reply_text(f"Error\n{e}")
# try:
# os.remove(fpath)
# except Exception:
# pass
# return
songs = {}
@Gojo.on_callback_query(filters.regex("^lyrics_"))
async def lyrics_for_song(c: Gojo, q: CallbackQuery):
data = q.data.split("_")[1].split(":")
song = songe = data[0]
try:
artist = data[1]
except IndexError:
artist = None
if artist:
song = genius_lyrics.search_song(song, artist)
else:
song = genius_lyrics.search_song(song)
artist = song.artist
if not song.lyrics:
await q.answer("‼️ No lyrics found ‼️", True)
return
header = f"{songe.capitalize()} by {artist}"
if song.lyrics:
await q.answer("Fetching lyrics")
reply = song.lyrics.split("\n", 1)[1]
if len(reply) >= 4096:
cap = f"{header}\n{reply[:4080]}..."
if artist:
songs[f"{songe}"][f"{artist}"] = reply
art = f'_{artist}'
else:
songs[f"{songe}"] = reply
art = ''
new_kb = [
[
IKB("Next", f"lyrics_next_{songe}{art}")
]
[
IKB("Close", "f_close")
]
]
else:
cap = f"{header}\n{reply}"
new_kb = [
[
IKB("Close", "f_close")
]
]
await q.message.reply_to_message.reply_text(cap, reply_markup=new_kb)
await q.message.delete()
return
@Gojo.on_callback_query(filters.regex("^lyrics_next_") | filters.regex("^lyrics_prev_"))
async def lyrics_for_song_next(c: Gojo, q: CallbackQuery):
split = q.data.split("_")
song = split[2]
todo = split[1]
try:
artist = split[3]
header = f"{song.capitalize()} by {artist}"
art = f'_{artist}'
except IndexError:
artist = False
header = f"{song.capitalize()}"
art = ''
try:
songe = songs[song][artist] if artist else songs[song]
except KeyError:
if artist:
songe = genius_lyrics.search_song(song, artist)
else:
songe = genius_lyrics.search_song(song)
next_part = songe[4080:] if todo == "next" else songe[:4080]
next_part = f"{header}\n{next_part}"
new_kb = [
[
IKB("Next", f"lyrics_prev_{song}{art}")
]
[
IKB("Close", "f_close")
]
]
await q.edit_message_text(next_part, reply_markup=new_kb)
@Gojo.on_message(command(["removebackground", "removebg", "rmbg"]))
async def remove_background(c: Gojo, m: Message):
if not is_rmbg:
await m.reply_text("Add rmbg api to use this command")
return
reply = m.reply_to_message
if not reply:
await m.reply_text("Reply to image/sticker to remove it's background")
return
elif not (reply.photo or (reply.document and reply.document.mime_type.split("/")[0] == "image") or reply.sticker):
await m.reply_text("Reply to image/sticker to remove it's background")
return
elif reply.sticker and (reply.sticker.is_video or reply.sticker.is_animated):
await m.reply_text("Reply to normal sticker to remove it's background")
return
to_edit = await m.reply_text("⏳")
URL = "https://api.remove.bg/v1.0/removebg"
if reply.sticker:
filee = await reply.download()
file = toimage(filee)
else:
file = await reply.download()
finfo = {'image_file': open(file, 'rb')}
Data = {'size': 'auto'}
Headers = {'X-Api-Key': RMBG}
result = resp_post(URL, files=finfo, data=Data, headers=Headers)
await to_edit.delete()
contentType = result.headers.get("content-type")
if result.status_code != 200:
await m.reply_text(f"{result.status_code}:{result.text}")
os.remove(file)
return
elif "image" not in contentType:
await m.reply_text(f"Error\n{result.content.decode('UTF-8')}")
os.remove(file)
return
to_path = "./downloads"
to_path = f'{to_path}/no-bg.webp' if reply.sticker else f'{to_path}/no-bg.png'
with open(to_path, 'wb') as out:
out.write(result.content)
if reply.sticker:
await m.reply_sticker(to_path)
else:
await m.reply_photo(to_path)
try:
os.remove(file)
os.remove(to_path)
except PermissionError:
await asyncio.sleep(5)
return
@Gojo.on_message(command(["song", "yta"]))
async def song_down_up(c: Gojo, m: Message):
try:
splited = m.text.split(None, 1)[1].strip()
except IndexError:
await m.reply_text("**USAGE**\n /song [song name | link]")
return
_id = get_video_id(splited)
query = _id or splited
to_edit = await m.reply_text("⏳")
try:
await youtube_downloader(c, m, query, "a")
await to_edit.delete()
return
except KeyError:
await to_edit.edit_text("Failed to find any result")
return
except Exception as e:
await to_edit.edit_text(f"Got an error\n{e}")
LOGGER.error(e)
LOGGER.error(format_exc())
return
@Gojo.on_message(command(["vsong", "ytv"]))
async def video_down_up(c: Gojo, m: Message):
try:
splited = m.text.split(None, 1)[1].strip()
except IndexError:
await m.reply_text("**USAGE**\n /vsong [song name | link]")
return
_id = get_video_id(splited)
query = _id or splited
to_edit = await m.reply_text("⏳")
try:
await youtube_downloader(c, m, query, "v")
await to_edit.delete()
return
except KeyError:
await to_edit.edit_text("Failed to find any result")
return
except Exception as e:
await to_edit.edit_text(f"Got an error\n{e}")
LOGGER.error(e)
LOGGER.error(format_exc())
return
@Gojo.on_message(command(["ig", "instagram", "insta"]))
async def download_instareels(c: Gojo, m: Message):
try:
reel_ = m.command[1]
except IndexError:
await m.reply_text("Give me an instagram link to download it...")
return
insta = INSTAGRAM(reel_)
if not insta.is_correct_url():
await m.reply_text("The link you have provided is not of instagram")
return
to_edit = await m.reply_text("Trying to fetch data from the link")
content = insta.get_media()
if content["code"] == 69 or content["message"] != "success":
await to_edit.delete()
return await m.reply_text(content["message"])
try:
medias = content["content"]["mediaUrls"]
to_delete = await to_edit.edit_text("Found media in the link trying to download and upload them please wait")
to_send = []
for media in medias:
if media["type"] == "image":
to_send.append(InputMediaPhoto(media["url"]))
else:
to_send.append(InputMediaVideo(media["url"]))
await m.reply_media_group(to_send)
await to_delete.delete()
# shutil.rmtree("./scrapped/")
except KeyError:
await to_edit.delete()
await m.reply_text("Failed to fetch any media from given url")
return
__PLUGIN__ = "web support"
__HELP__ = """
**Available commands**
• /rmbg (/removebg, /removebackground) : Reply to image file or sticker of which you want to remove background
• /song (/yta) <songname or youtube link> : Download audio only from provided youtube url
• /vsong (/ytv) <songname or youtube link> : Download video from provided youtube url
• /ig (/instagram , /insta) <reel's url> : Download reel from it's url
**Bot will not download any song or video having duration greater than 10 minutes (to reduce the load on bot's server)**
"""
|