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 _parse_post(self): """ Parse all available photos using the best image sizes available """ super()._parse_post() video_info = YoutubeDL().extract_info(self.url.as_string(), False) self.title = video_info.get('title') self.description = video_info.get('description') self.duration = int(video_info.get('duration', 0)) self.format = video_info.get('format', 'Unknown') self.files.append(TumblrVideo(video_info, self))
def retrive_songs_info(self, url: str) -> list[dict]: info = YoutubeDL({'quiet': True}).extract_info(url, download=False) if info.get('_type') == 'playlist': return info.get('entries') return [info, ]