def nightcore(message): # Copyright (c) @kisekinopureya | 2021 reply = message.reply_to_message if not (reply and (reply.audio or reply.voice or (reply.document and 'audio' in reply.document.mime_type))): edit(message, f'`{get_translation("wrongMedia")}`') else: edit(message, f'`{get_translation("applyNightcore")}`') media = download_media_wc(reply) filename = f'{media}.mp3' if path.exists(filename): remove(filename) process = Popen([ 'ffmpeg', '-i', media, '-af', 'asetrate=44100*1.16,aresample=44100,atempo=1', filename, ]) process.communicate() edit(message, f'`{get_translation("uploadMedia")}`') reply_audio(reply or message, f'{media}.mp3', delete_file=True) remove(media) message.delete()
def youtubedl(message): args = extract_args(message).split(' ', 2) if len(args) != 2: edit(message, f'`{get_translation("wrongCommand")}`') return util = args[0].lower() url = args[1] try: video_info = YoutubeDL().extract_info(url, False) except DownloadError as e: return edit(message, get_translation('banError', ['`', '**', e])) title = video_info.get('title') uploader = video_info.get('uploader') if util == 'mp4': edit(message, get_translation('downloadYTVideo', ['**', title, '`'])) ydl_opts = { 'outtmpl': f'{title}.%(ext)s', 'format': 'bestvideo[ext=mp4][height<=?1080]+bestaudio[ext=mp3]/best', } with YoutubeDL(ydl_opts) as ydl: ydl.download([url]) edit(message, f'`{get_translation("uploadMedia")}`') reply_video( message, f'{title}.mp4', caption= f"**{get_translation('videoTitle')}** `{title}`\n**{get_translation('videoUploader')}** `{uploader}`", delete_orig=True, delete_file=True, ) elif util == 'mp3': edit(message, get_translation('downloadYTAudio', ['**', title, '`'])) ydl_opts = { 'outtmpl': f'{title}.%(ext)s', 'format': 'bestaudio/best', 'postprocessors': [{ 'key': 'FFmpegExtractAudio', 'preferredcodec': 'mp3', 'preferredquality': '320', }], } with YoutubeDL(ydl_opts) as ydl: ydl.download([url]) edit(message, f'`{get_translation("uploadMedia")}`') reply_audio( message, f'{title}.mp3', caption=f"**{get_translation('videoUploader')}** `{uploader}`", delete_orig=True, delete_file=True, )
def deezermusic(message): if not DEEZER_TOKEN: return edit(message, f'`{get_translation("deezerArlMissing")}`') args = extract_args(message) url = args edit(message, f'`{get_translation("processing")}`') if not url: return edit(message, f'`{get_translation("wrongCommand")}`') try: deezer = Session(DEEZER_TOKEN) except Exception as e: return edit(message, get_translation('banError', ['`', '**', e])) try: if 'deezer' in url: if 'track' in url: track = deezer.download(url, bitrate='MP3_320') edit(message, f'`{get_translation("uploadMedia")}`') reply_audio(message, track, delete_orig=True) elif 'album' in url: album = deezer.download(url, bitrate='MP3_320') edit(message, f'`{get_translation("uploadMedia")}`') for track in album: reply_audio(message, track, delete_orig=True) except Exception as e: return edit(message, get_translation('banError', ['`', '**', e]))
def earrape(message): args = extract_args(message).split(' ', 1) reply = message.reply_to_message util = args[0].lower() if util == 'mp4': if not (reply and (reply.video or reply.video_note or (reply.document and 'video' in reply.document.mime_type))): edit(message, f'`{get_translation("wrongMedia")}`') else: edit(message, f'`{get_translation("applyEarrape")}`') media = download_media_wc(reply) process = Popen([ 'ffmpeg', '-i', f'{media}', '-af', 'acrusher=.1:1:64:0:log', f'{media}.mp4', ]) process.communicate() edit(message, f'`{get_translation("uploadMedia")}`') reply_video(reply or message, f'{media}.mp4', delete_file=True) remove(media) message.delete() elif util == 'mp3': if not (reply and (reply.video or reply.video_note or (reply.audio or reply.voice or (reply.document and 'video' in reply.document.mime_type)))): edit(message, f'`{get_translation("wrongMedia")}`') else: edit(message, f'`{get_translation("applyEarrape")}`') media = download_media_wc(reply) process = Popen([ 'ffmpeg', '-i', f'{media}', '-af', 'acrusher=.1:1:64:0:log', f'{media}.mp3', ]) process.communicate() edit(message, f'`{get_translation("uploadMedia")}`') reply_audio(reply or message, f'{media}.mp3', delete_file=True) remove(media) message.delete() else: edit(message, f'`{get_translation("wrongCommand")}`') return
def download_track(self, message, song_list: list, is_zip): lock = Lock() with lock: with ThreadPoolExecutor(min(32, cpu_count() or 0) + 4) as executor: executor.map(self.search_track, song_list) if is_zip: zipfile = ZipFile('Spotify/playlist.zip', 'w') for song in glob('Spotify/*.mp3'): zipfile.write(song) remove(song) zipfile.close() edit(message, f'`{get_translation("uploadingZip")}`') reply_doc( message, 'Spotify/playlist.zip', delete_orig=True, delete_after_send=True, ) else: for song in glob('Spotify/*.mp3'): reply_audio(message, song, delete_orig=True, delete_file=True)
def youtubedl(message): args = extract_args(message).split(' ', 2) if len(args) != 2: edit(message, f'`{get_translation("wrongCommand")}`') return util = args[0].lower() url = args[1] if util == 'mp4': ydl_opts = { 'outtmpl': f'%(id)s.%(ext)s', 'format': 'bestvideo[ext=mp4][height<=?1080]+bestaudio[ext=m4a]/best', 'addmetadata': True, 'prefer_ffmpeg': True, 'geo_bypass': True, 'nocheckcertificate': True, 'postprocessors': [ {'key': 'FFmpegMetadata'}, {'key': 'FFmpegVideoConvertor', 'preferedformat': 'mp4'}, ], 'quiet': True, 'logtostderr': False, } thumb_path = None with YoutubeDL(ydl_opts) as ydl: try: video_info = ydl.extract_info(url, False) title = video_info['title'] uploader = video_info['uploader'] duration = video_info['duration'] except KeyError: uploader = get_translation('notFound') duration = None except BaseException as e: return edit(message, get_translation('banError', ['`', '**', e])) edit(message, get_translation('downloadYTVideo', ['**', title, '`'])) try: temp = BytesIO() with get(video_info['thumbnail']) as req: temp.name = 'file.webp' temp.write(req.content) temp.seek(0) im = Image.open(temp) imc = im.convert('RGB') imc.save(thumb_path := f'{get_download_dir()}/{video_info["id"]}.jpg') except BaseException: thumb_path = None ydl.download([url]) edit(message, f'`{get_translation("uploadMedia")}`') reply_video( message, f'{video_info["id"]}.mp4', thumb=thumb_path, caption=f"**{get_translation('videoTitle')}** `{title}`\n**{get_translation('videoUploader')}** `{uploader}`", duration=duration, delete_orig=True, delete_file=True, ) try: remove(thumb_path) except BaseException: pass elif util == 'mp3': ydl_opts = { 'outtmpl': f'%(title)s.%(ext)s', 'format': 'bestaudio/best', 'addmetadata': True, 'writethumbnail': True, 'prefer_ffmpeg': True, "extractaudio": True, 'geo_bypass': True, 'nocheckcertificate': True, 'postprocessors': [ { 'key': 'FFmpegExtractAudio', 'preferredcodec': 'mp3', 'preferredquality': '320', }, {'key': 'EmbedThumbnail'}, {'key': 'FFmpegMetadata'}, ], 'quiet': True, 'logtostderr': False, } with YoutubeDL(ydl_opts) as ydl: try: video_info = ydl.extract_info(url, False) title = video_info['title'] uploader = video_info['uploader'] duration = int(video_info['duration']) except KeyError: uploader = get_translation('notFound') duration = None except BaseException as e: return edit(message, get_translation('banError', ['`', '**', e])) edit(message, get_translation('downloadYTAudio', ['**', title, '`'])) ydl.download([url]) edit(message, f'`{get_translation("uploadMedia")}`') reply_audio( message, f'{title}.mp3', caption=f"**{get_translation('videoUploader')}** `{uploader}`", duration=duration, delete_orig=True, delete_file=True, )