async def ssvideo(framecap): if not framecap.reply_to_msg_id: return await framecap.edit("`reply to video!`") reply_message = await framecap.get_reply_message() if not reply_message.media: return await framecap.edit("`reply to a video!`") try: frame = int(framecap.pattern_match.group(1)) if frame > 10: return await framecap.edit("`hey..dont put that much`") except BaseException: return await framecap.edit("`Please input number of frame!`") if ( reply_message.photo or ( DocumentAttributeFilename(file_name="AnimatedSticker.tgs") in reply_message.media.document.attributes ) or ( DocumentAttributeFilename(file_name="sticker.webp") in reply_message.media.document.attributes ) ): return await framecap.edit("`Unsupported files!`") c_time = time.time() await framecap.edit("`Downloading media...`") ss = await bot.download_media( reply_message, "anu.mp4", progress_callback=lambda d, t: asyncio.get_event_loop().create_task( progress(d, t, framecap, c_time, "[DOWNLOAD]") ), ) try: await framecap.edit("`Proccessing...`") command = f"vcsi -g {frame}x{frame} {ss} -o ss.png " os.system(command) await framecap.client.send_file( framecap.chat_id, "ss.png", reply_to=framecap.reply_to_msg_id, ) await framecap.delete() except BaseException as e: await framecap.edit(f"{e}") os.system("rm -rf *.png *.mp4")
async def download_video(v_url): pro = v_url sender = await pro.get_sender() me = await pro.client.get_me() pro1 = v_url.text if not sender.id == me.id: dc = await pro.reply("`processing, please wait...`") else: dc = await pro.edit("`processing, please wait...`") teamcobra = pro1[8:] if not teamcobra: return await dc.edit("`Error \nusage .ytvideo <song name>`") search = SearchVideos(teamcobra, offset=1, mode="json", max_results=1) test = search.result() p = json.loads(test) q = p.get('search_result') try: teamcobra = q[0]['link'] except: return await dc.edit("`failed to find your desired song`") type = "audio" await dc.edit("`Ok downloading your song 🤗`") if type == "audio": opts = { 'format': 'best', 'addmetadata': True, 'key': 'FFmpegMetadata', 'prefer_ffmpeg': True, 'geo_bypass': True, 'nocheckcertificate': True, 'postprocessors': [{ 'key': 'FFmpegVideoConvertor', 'preferedformat': 'mp4' }], 'outtmpl': '%(id)s.mp4', 'logtostderr': False, 'quiet': True } song = False video = True try: await dc.edit("`Fetching data, please wait...`") with YoutubeDL(opts) as darkcobra: darkcobra_data = darkcobra.extract_info(teamcobra) except DownloadError as error: await dc.edit(f"`{str(error)}`") return except ContentTooShortError: await dc.edit("`Oof the download content was too short 🤐`") return except GeoRestrictedError: await dc.edit( "`Video is not available from your geographic location due to geographic restrictions imposed by a website 🤔`" ) return except MaxDownloadsReached: await dc.edit("`Max-downloads limit has been reached 😶`") return except PostProcessingError: await dc.edit("`There was an error during post processing 😐`") return except UnavailableVideoError: await dc.edit( "`sorry, media is not available in the requested format.`") return except XAttrMetadataError as XAME: await dc.edit(f"`{XAME.code}: {XAME.msg}\n{XAME.reason}`") return except ExtractorError: await dc.edit("`There was an error while fetching your query...`") return except Exception as e: await dc.edit(f"{str(type(e)): {str(e)}}") return c_time = time.time() if song: await dc.edit(f"`Preparing to upload your video song 🤗`\ \n**{darkcobra_data['title']}**\ \nby *{darkcobra_data['uploader']}*") await v_url.client.send_file( v_url.chat_id, f"{darkcobra_data['id']}.mp3", supports_streaming=True, attributes=[ DocumentAttributeAudio( duration=int(darkcobra_data['duration']), title=str(darkcobra_data['title']), performer=str(darkcobra_data['uploader'])) ], progress_callback=lambda d, t: asyncio.get_event_loop( ).create_task( progress(d, t, v_url, c_time, "Uploading your video song 😍", f"{darkcobra_data['title']}.mp3"))) os.remove(f"{darkcobra_data['id']}.mp3") await v_url.delete() elif video: await dc.edit(f"`Preparing to upload your video song ❤`\ \n**{darkcobra_data['title']}**\ \nby *{darkcobra_data['uploader']}*") await v_url.client.send_file( v_url.chat_id, f"{darkcobra_data['id']}.mp4", supports_streaming=True, caption=darkcobra_data['title'], progress_callback=lambda d, t: asyncio.get_event_loop( ).create_task( progress(d, t, v_url, c_time, "Uploading...", f"{darkcobra_data['title']}.mp4"))) os.remove(f"{darkcobra_data['id']}.mp4") await dc.delete()
async def _(event): if event.fwd_from: return urlissed = event.pattern_match.group(1) myself_stark = await edit_or_reply( event, f"`Getting {urlissed} From Youtube Servers. Please Wait.`") search = SearchVideos(f"{urlissed}", offset=1, mode="dict", max_results=1) mi = search.result() mio = mi["search_result"] mo = mio[0]["link"] thum = mio[0]["title"] fridayz = mio[0]["id"] thums = mio[0]["channel"] kekme = f"https://img.youtube.com/vi/{fridayz}/hqdefault.jpg" await asyncio.sleep(0.6) if not os.path.isdir("./music/"): os.makedirs("./music/") path = Config.TMP_DOWNLOAD_DIRECTORY url = mo sedlyf = wget.download(kekme, out=path) opts = { "format": "bestaudio", "addmetadata": True, "key": "FFmpegMetadata", "writethumbnail": True, "prefer_ffmpeg": True, "geo_bypass": True, "nocheckcertificate": True, "postprocessors": [{ "key": "FFmpegExtractAudio", "preferredcodec": "mp3", "preferredquality": "480", }], "outtmpl": "%(title)s.mp3", "quiet": True, "logtostderr": False, } try: with YoutubeDL(opts) as ytdl: ytdl_data = ytdl.extract_info(url) except Exception as e: await event.edit(f"**Failed To Download** \n**Error :** `{str(e)}`") return await asyncio.sleep(20) c_time = time.time() file_stark = f"{ytdl_data['title']}.mp3" lol_m = await upload_file( file_name=file_stark, client=borg, file=open(file_stark, "rb"), progress_callback=lambda d, t: asyncio.get_event_loop().create_task( progress(d, t, event, c_time, "Uploading Your Song!", file_stark)), ) capy = f"**Song Name ➠** `{thum}` \n**Requested For ➠** `{urlissed}` \n**Channel ➠** `{thums}` \n**Link ➠** `{mo}`" await event.delete() await borg.send_file( event.chat_id, lol_m, force_document=False, allow_cache=False, caption=capy, thumb=sedlyf, attributes=[ DocumentAttributeAudio( duration=int(ytdl_data["duration"]), title=str(ytdl_data["title"]), performer=str(ytdl_data["uploader"]), ) ], supports_streaming=True, ) for files in (sedlyf, file_stark): if files and os.path.exists(files): os.remove(files)