import logging import time import re from collections import Counter from collections import defaultdict import telebot from telebot.types import InlineKeyboardMarkup, InlineKeyboardButton from telebot import types from EyeTube_you_a import extract_youtube_audio_link from EyeTube_Ig_a import extract_instagram_audio_link from EyeTube_Face_a import extract_facebook_audio_link from EyeTube_X_a import extract_twitter_audio_link from EyeTube_Lin_a import extract_linkedin_audio_link from EyeTube_Snap_a import extract_snapchat_audio_link from EyeTube_am import extract_audiomack_audio_link from EyeTube_you import download_youtube_video from EyeTube_Ig import download_instagram_content from EyeTube_X import download_twitter_video from EyeTube_Snap import download_snapchat_video from EyeTube_Face import download_facebook_video from EyeTube_Lin import download_linkedin_video import pw import support import subprocess import requests from bs4 import BeautifulSoup import logging import whois from update_checker import UpdateChecker logging.basicConfig(level=logging.INFO) pw.auto() print("\033[93mLets start EyeTubeBot 2 0 1...\n\033[0m") support.check_support() admin = input("\033[92mPlease enter your name ๐Ÿ‘‰ : \033[0m") TOKEN = input("\n\033[92mPlease enter your Telegram API token ๐Ÿ‘‰ : \033[0m") if not TOKEN: print("\033[91mโ“You provided No API token.\n\n Shuting down/Exiting...\033[0m") exit(1) try: bot = telebot.TeleBot(TOKEN) print("\033[92mBot initialized successfully!\033[0m") bot_info = bot.get_me() print(f"\033[92mBot Username: {bot_info.username}\033[0m") print("\033[92mReady to receive commands.\033[0m") except Exception as e: print(f"\033[91mError: Failed to initialize bot. {e}\033[0m") #============================================================================== # Retry Error Handling def retry_on_failure(func): def wrapper(*args, **kwargs): while True: try: return func(*args, **kwargs) except Exception as e: print(f"Error: {e}. Retrying in 5 seconds...") time.sleep(20) return wrapper # UPDATE METHODS #============================================================================== update_checker = UpdateChecker("https://raw.githubusercontent.com/Mickekofi/EyeTubeBot") @bot.message_handler(commands=['check_update']) def check_updates(message): """Check for updates and notify the user.""" chat_id = message.chat.id try: latest_version = update_checker.get_latest_version() local_version = update_checker.get_local_version() if latest_version is None: bot.send_message(chat_id, "Failed to fetch the latest version. Please try again later.") elif local_version != latest_version: bot.send_message(chat_id, f"๐Ÿ“Œ A new version ({latest_version}) is available!") bot.send_message(chat_id, "โฌ†๏ธ Please update your bot by typing /update.") else: bot.send_message(chat_id, "โœ… Your bot is up to date.") except Exception as e: bot.send_message(chat_id, f"An error occurred while checking for updates: {e}") @bot.message_handler(commands=['update']) def update_bot(message): """Handle the bot update process.""" chat_id = message.chat.id bot.send_message(chat_id, "Starting the update process...") try: subprocess.run(["git", "pull", "origin", "master"], check=True) latest_version = update_checker.get_latest_version() if latest_version: update_checker.update_local_version(latest_version) markup = InlineKeyboardMarkup() update_button = InlineKeyboardButton("๐ŸŽ ๐—–๐—ต๐—ฒ๐—ฐ๐—ธ ๐—ช๐—ต๐—ฎ๐˜ ๐—ถ๐˜€ ๐—ก๐—ฒ๐˜„๐—น๐˜† ๐—ฃ๐—ฎ๐—ฐ๐—ธ๐—ฒ๐—ฑ ๐—ณ๐—ผ๐—ฟ ๐˜†๐—ผ๐˜‚", url="https://github.com/Mickekofi/EyeTubeBot/blob/master/update.md") markup.add(update_button) bot.send_message(chat_id, f"โœ… Bot updated successfully! Version: {latest_version}\n\nPlease Retart it to take effect", reply_markup=markup) else: bot.send_message(chat_id, "Update completed, but failed to fetch the latest version. Please check manually.") except subprocess.CalledProcessError as e: bot.send_message(chat_id, f"Failed to update the bot: {e}") except Exception as e: bot.send_message(chat_id, f"An unexpected error occurred: {e}") #STEP 1 #============================================================================== # Function to check if the these Platform URL are valid links using the regex module to find sequences of user's input string link that match a pattern in the official platform URL string # Function to check if it's a valid AudioMack link def is_valid_audiomack_url(url): audiomack_regex = re.compile(r'(https?://)?(www\.)?audiomack\.com/.+/song/.+') return audiomack_regex.match(url) def is_valid_youtube_url(url): youtube_regex = re.compile(r'(https?://)?(www\.)?(youtube|youtu|youtube-nocookie)\.(com|be)/.+') return youtube_regex.match(url) def is_valid_instagram_url(url): instagram_regex = re.compile(r'(https?://)?(www\.)?instagram\.com/.+') return instagram_regex.match(url) def is_valid_twitter_url(url): twitter_regex = re.compile(r'(https?://)?(www\.)?(twitter|x)\.com/.+/status/.+') return twitter_regex.match(url) def is_valid_facebook_url(url): facebook_regex = re.compile(r'(https?://)?(www\.)?(facebook|fb)\.com/.+') return facebook_regex.match(url) def is_valid_linkedin_url(url): linkedin_regex = re.compile(r'(https?://)?(www\.)?linkedin\.com/(posts|feed|in/.+/detail/recent-activity)/.+') return linkedin_regex.match(url) def is_valid_snapchat_url(url): snapchat_regex = re.compile(r'(https?://)?(www\.)?(snapchat\.com/t/.+|snapchat\.com/add/.+|snapchat\.com/discover/.+|snapchat\.com/spotlight/.+)') return bool(snapchat_regex.match(url)) def is_valid_url(url): # This regex will match a wide variety of valid URLs including subdomains, paths, and query strings url_regex = re.compile( r'^(https?://)?' # Optional scheme (http or https) r'([a-zA-Z0-9-]+\.)+' # Subdomains (optional) and main domain r'[a-zA-Z]{2,}' # Top-level domain (e.g., .com, .org, etc.) r'(:[0-9]{1,5})?' # Optional port number r'(/[^\s]*)?$' # Optional path and query string ) return bool(url_regex.match(url)) # WELCOME START #============================================================================== @bot.message_handler(commands=['start']) def send_welcome(message): markup = telebot.types.ReplyKeyboardMarkup(row_width=2) itembtn1 = telebot.types.KeyboardButton('/Help') itembtn2 = telebot.types.KeyboardButton('/Engineer') itembtn3 = telebot.types.KeyboardButton('/check_update') itembtn4 = telebot.types.KeyboardButton('/update') markup.add(itembtn1, itembtn2, itembtn3, itembtn4) bot.reply_to(message, f"๐Ÿ•น {bot_info.username} is Operated by {admin}.\n\n๐™‹๐™–๐™จ๐™ฉ๐™š ๐™ฎ๐™ค๐™ช๐™ง ๐™Ž๐™ค๐™˜๐™ž๐™–๐™ก ๐™ˆ๐™š๐™™๐™ž๐™– ๐ŸŽฌ ๐™‘๐™ž๐™™๐™š๐™ค ๐™‡๐™ž๐™ฃ๐™  ๐™๐™š๐™ง๐™š ๐™ค๐™ง ๐™–๐™ฃ๐™ฎ ๐™ฌ๐™š๐™— ๐™ก๐™ž๐™ฃ๐™  ๐Ÿ“Ž?", reply_markup=markup) #============================================================================================ #About @bot.message_handler(commands=['Help']) def open_about_command(message): keyboard = types.InlineKeyboardMarkup() button6 = types.InlineKeyboardButton(text="Visit Our Page", url="https://github.com/Mickekofi/EyeTubeBot") button1 = types.InlineKeyboardButton(text="๐Ÿ“š Learn about EyeTubeBot Version(2.0.1)", url="https://github.com/Mickekofi/EyeTubeBot/blob/master/Documentation_For_Dev/Documentation.md") button4 = types.InlineKeyboardButton(text="๐Ÿ‘ฅ Who are We", url="https://github.com/Mickekofi/EyeTubeBot/tree/master/Documentation_For_End_User_/Who_are_we.md") button5 = types.InlineKeyboardButton(text="What is in for this Update", url="https://github.com/Mickekofi/EyeTubeBot/tree/master/Documentation_For_Dev/update.md") keyboard.add(button6) keyboard.add(button1) keyboard.add(button4) keyboard.add(button5) bot.send_message(message.chat.id, "About Info", reply_markup=keyboard) bot.send_message(message.chat.id,'''โ“๐’๐ฎ๐ ๐ ๐ž๐ฌ๐ญ ๐š๐ง ๐ˆ๐ฌ๐ฌ๐ฎ๐ž ๐š ๐๐ฎ๐  ๐จ๐ซ ๐š ๐…๐ž๐š๐ญ๐ฎ๐ซ๐ž ๐‘๐ž๐ช๐ฎ๐ž๐ฌ๐ญ?๐Ÿ“ฌ; ๐™๐™š๐™ฅ๐™ค๐™ง๐™ฉ ๐™ฉ๐™ค ๐™‚๐™ž๐™ฉ๐™๐™ช๐™— ๐™ค๐™ง ๐œ๐จ๐ฉ๐ฒ ๐š๐ง๐ ๐ฉ๐š๐ฌ๐ญ๐ž ๐™ฉ๐™๐™š ๐™Ž๐™ฉ๐™ง๐™ž๐™ฃ๐™œ๐™จ ๐™—๐™š๐™ก๐™ค๐™ฌ ๐ข๐ง ๐ฒ๐จ๐ฎ๐ซ ๐›๐ซ๐จ๐ฐ๐ฌ๐ž๐ซ ๐Ÿ‘‡๐Ÿ‘‡๐Ÿ‘‡''') bot.send_message(message.chat.id, f'''mailto:eyetubebot@gmail.com?subject=๐Ÿ“ฌID_{message.from_user.id}%20[Issue]%20Report%20&body=(๐Ÿ–‡Please_Attach_your_Issue_screenshot)%0A%0A-[Country]:%0A%0A%0A%0A-%5BPlease%20describe%20your%20Issue%20here%5D%20: ''') @bot.message_handler(commands=['Engineer']) def send_engineer(message): bot.send_photo(message.chat.id, open('Michael.jpg', 'rb'), caption="๐Ÿ’ฌ \"๐Ÿ…ฐ๐Ÿ…ฝ๐Ÿ†ˆ๐Ÿ…พ๐Ÿ…ฝ๐Ÿ…ด ๐Ÿ…ฒ๐Ÿ…ฐ๐Ÿ…ฝ ๐Ÿ…ฒ๐Ÿ…พ๐Ÿ…พ๐Ÿ…บ\" - ๐— ๐—ถ๐—ฐ๐—ต๐—ฎ๐—ฒ๐—น ๐—”๐—ฝ๐—ฝ๐—ถ๐—ฎ๐—ต") bot.reply_to(message, """ ๐˜๐ž๐ฅ๐ฅ๐จ , ๐ˆ'๐ฆ ๐Œ๐ข๐œ๐ก๐š๐ž๐ฅ ๐€๐ฉ๐ฉ๐ข๐š๐ก, ๐š๐ง ๐š๐ฌ๐ฉ๐ข๐ซ๐ข๐ง๐  ๐€๐ซ๐ญ๐ข๐Ÿ๐ข๐œ๐ข๐š๐ฅ ๐ˆ๐ง๐ญ๐ž๐ฅ๐ฅ๐ข๐ ๐ž๐ง๐œ๐ž ๐„๐ง๐ ๐ข๐ง๐ž๐ž๐ซ ๐š๐ง๐ ๐ญ๐ก๐ž ๐ฅ๐ž๐š๐๐ž๐ซ ๐จ๐Ÿ ๐๐จ๐ฌ๐ฌ๐ข๐›๐ข๐ฅ๐ข๐ญ๐ฒ ๐€๐ข ๐š๐ง๐ ๐‚๐ฎ๐ซ๐ซ๐ž๐ง๐ญ๐ฅ๐ฒ ๐š ๐’๐ญ๐ฎ๐๐ž๐ง๐ญ ๐จ๐Ÿ ๐ญ๐ก๐ž ๐”๐ง๐ข๐ฏ๐ž๐ซ๐ฌ๐ข๐ญ๐ฒ ๐จ๐Ÿ ๐„๐๐ฎ๐œ๐š๐ญ๐ข๐จ๐ง, ๐–๐ข๐ง๐ง๐ž๐›๐š. ๐ˆ ๐ฌ๐ฉ๐ž๐œ๐ข๐š๐ฅ๐ข๐ณ๐ž ๐ข๐ง ๐๐ฎ๐ข๐ฅ๐๐ข๐ง๐  ๐€๐ข ๐€๐ฎ๐ญ๐จ๐ฆ๐š๐ญ๐ž๐ ๐‚๐ก๐š๐ญ๐๐จ๐ญ๐ฌ, ๐’๐ฒ๐ฌ๐ญ๐ž๐ฆ๐ฌ ๐€๐ฎ๐ญ๐จ๐ฆ๐š๐ญ๐ข๐จ๐ง ๐š๐ง๐ ๐’๐จ๐Ÿ๐ญ๐ฐ๐š๐ซ๐ž ๐ƒ๐ž๐ฏ๐ž๐ฅ๐จ๐ฉ๐ฆ๐ž๐ง๐ญ ๐ฎ๐ฌ๐ข๐ง๐  ๐๐ฒ๐ญ๐ก๐จ๐ง ๐š๐ง๐ ๐‚++. ๐‚๐จ๐ง๐ง๐ž๐œ๐ญ ๐ฐ๐ข๐ญ๐ก ๐ฆ๐ž: โ€ข ๐™‡๐™ž๐™ฃ๐™ ๐™š๐™™๐™„๐™ฃ: [๐™ˆ๐™ž๐™˜๐™๐™–๐™š๐™ก ๐˜ผ๐™ฅ๐™ฅ๐™ž๐™–๐™]( https://www.linkedin.com/in/michael-appiah-9b6919255 ) ๐Ÿ’ผ โ€ข ๐™‚๐™ž๐™ฉ๐™ƒ๐™ช๐™—: [๐™ˆ๐™ž๐™˜๐™ ๐™š๐™ ๐™ค๐™›๐™ž] ( https://github.com/Mickekofi ) ๐Ÿง‘โ€๐Ÿ’ป ยฉ๏ธ Possibility AI `24 """) #STAGE 2 #============================================================================== # bot to handle the user's message and check if the user's message is a valid link and then send the user a message to wait while the bot is processing the link using the created handle platform function @bot.message_handler(func=lambda message: True) def handle_message(message): url = message.text.strip() if is_valid_youtube_url(url): handle_youtube_url(message, url) elif is_valid_instagram_url(url): handle_instagram_url(message, url) elif is_valid_twitter_url(url): handle_twitter_url(message, url) elif is_valid_facebook_url(url): handle_facebook_url(message, url) elif is_valid_linkedin_url(url): handle_linkedin_url(message, url) elif is_valid_snapchat_url(url): handle_snapchat_url(message, url) elif is_valid_audiomack_url(url): handle_audiomack_url(message, url) elif is_valid_url(url): process_link(message, url) else: bot.reply_to(message, "Sorry, this link is not valid๐Ÿ˜ข") #open the start command automatically withot the user typing it or clicking on the start button send_welcome(message) #STAGE 4b #============================================================================== #This is Where the platform handle functions is defined with two conditions or Roads and checks the string link again if the user wants to download the audio(-a) or video(default) of the link. It then sends the users choice on the right path to the respective "send_audio_link" or "send_video_link" function for further processing and extraction of the download link # Handle the AudioMack URL # Handle AudioMack URL def handle_audiomack_url(message, url): bot.reply_to(message, "AudioMack only supports audio downloads. Please wait while I fetch the link...") try: send_audiomack_audio(message, url) except Exception as e: bot.reply_to(message, f"Error: {e}. Retrying in 5 seconds...") logging.error(f"Error in handling AudioMack URL: {e}") # Handle YouTube URL def handle_youtube_url(message, url): try: if ' -info' in url: bot.reply_to(message, "๐Ÿ“บ Fetching YouTube video information. Please wait...") process_media(message, url.replace('-info', '').strip()) return # Determine audio or video download request if ' -a' in url: bot.reply_to(message, "๐ŸŽค Generating YouTube audio download link...") send_youtube_audio(message, url.replace('-a', '').strip()) return # Exit the function after handling audio download # Set default quality quality = 'best' # Check for quality options in the URL if '-l' in url: quality = 'worst' url = url.replace('-l', '').strip() elif '-h' in url: quality = 'best' # This line is actually redundant as quality is already set to 'best' # Notify the user that the download is in progress bot.reply_to(message, "Generating YouTube video download link. Please wait...") # Call the download function cookies_file = 'you1cookies.txt' # Define the path to your cookies file download_url = download_youtube_video(url) # Check the download URL and respond accordingly if download_url: bot.reply_to(message, f"โœ… Here is your download link: {download_url}\n\n๐Ÿš“check : [ /status ]") else: send_error_message(message, "Youtube") except Exception as e: logging.error(f"Error in handling YouTube URL: {e}") send_error_message(message, "Youtube") # Optional: You could implement a retry mechanism here if desired def handle_instagram_url(message, url): try: if ' -info' in url: bot.reply_to(message, "๐Ÿงฒ Fetching Instagram video information. Please wait...") process_media(message, url.replace('-info', '').strip()) return if ' -a' in url: bot.reply_to(message, "๐ŸŽต Generating Instagram audio download link...") send_instagram_audio(message, url.replace(' -a', '').strip()) return bot.reply_to(message, "๐Ÿ“บ Downloading Instagram video. Please wait...") download_url = download_instagram_content(url.strip()) if download_url: bot.reply_to(message, f"โœ… Here is your download link: {download_url}\n\n๐Ÿš“ Check: [ /status ]") else: send_error_message(message, "Instagram") except Exception as e: logging.error(f"Error handling Instagram URL: {e}") send_error_message(message, "Instagram") def handle_twitter_url(message, url): try: if ' -info' in url: bot.reply_to(message, "๐Ÿงฒ Fetching Twitter video information. Please wait...") process_media(message, url.replace('-info', '').strip()) return if ' -a' in url: bot.reply_to(message, "๐ŸŽค Generating Twitter audio download link...") send_twitter_audio(message, url.replace(' -a', '').strip()) return bot.reply_to(message, "๐Ÿ“บ Generating Twitter video download link. Please wait...") download_url = download_twitter_video(url.strip()) if download_url: bot.reply_to(message, f"โœ… Here is your download link: {download_url}\n\n๐Ÿš“ Check: [ /status ]") else: send_error_message(message, "Twitter") except Exception as e: logging.error(f"Error handling Twitter URL: {e}") send_error_message(message, "Twitter") def handle_facebook_url(message, url): try: if ' -info' in url: bot.reply_to(message, "๐Ÿงฒ Fetching Facebook video information. Please wait...") process_media(message, url.replace('-info', '').strip()) return if ' -a' in url: bot.reply_to(message, "๐ŸŽค Generating Facebook audio download link...") send_facebook_audio(message, url.replace(' -a', '').strip()) return bot.reply_to(message, "๐Ÿ“บ Downloading Facebook video. Please wait...") video_url = download_facebook_video(url.strip()) if video_url: bot.reply_to(message, f"โœ… Here is your download link: {video_url}\n\n๐Ÿš“ Check: [ /status ]") else: send_error_message(message, "Facebook") except Exception as e: logging.error(f"Error handling Facebook URL: {e}") send_error_message(message, "Facebook") def handle_linkedin_url(message, url): try: if ' -info' in url: bot.reply_to(message, "๐Ÿงฒ Fetching LinkedIn video information. Please wait...") process_media(message, url.replace('-info', '').strip()) return if ' -a' in url: bot.reply_to(message, "๐ŸŽค Generating LinkedIn audio download link...") send_linkedin_audio(message, url.replace(' -a', '').strip()) return bot.reply_to(message, "๐Ÿ“บ Downloading LinkedIn video. Please wait...") video_url = download_linkedin_video(url.strip()) if video_url: bot.reply_to(message, f"โœ… Here is your download link: {video_url}\n\n๐Ÿš“ Check: [ /status ]") else: send_error_message(message, "LinkedIn") except Exception as e: logging.error(f"Error handling LinkedIn URL: {e}") send_error_message(message, "LinkedIn") def handle_snapchat_url(message, url): try: if ' -info' in url: bot.reply_to(message, "๐Ÿงฒ Fetching Snapchat video information. Please wait...") process_media(message, url.replace('-info', '').strip()) return if ' -a' in url: bot.reply_to(message, "๐ŸŽค Generating Snapchat audio download link...") send_snapchat_audio(message, url.replace(' -a', '').strip()) return bot.reply_to(message, "๐Ÿ“บ Downloading Snapchat video. Please wait...") video_url = download_snapchat_video(url.strip()) if video_url: bot.reply_to(message, f"โœ… Here is your download link: {video_url}\n\n๐Ÿš“ Check: [ /status ]") else: send_error_message(message, "Snapchat") except Exception as e: logging.error(f"Error handling Snapchat URL: {e}") send_error_message(message, "Snapchat") def send_error_message(message, platform): """Send a generic error message with platform-specific details.""" # First block of the message error_message = ( f"โ“ ERROR: Unable to process your {platform} request.\n\n" "๐™๐™š๐™ฅ๐™ค๐™ง๐™ฉ ๐™ฉ๐™๐™ž๐™จ ๐™„๐™จ๐™จ๐™ช๐™š ๐™ค๐™ฃ ๐™‚๐™ž๐™ฉ๐™ƒ๐™ช๐™— ๐™ค๐™ง ๐œ๐จ๐ฉ๐ฒ ๐š๐ง๐ ๐ฉ๐š๐ฌ๐ญ๐ž ๐™ฉ๐™๐™š ๐™Ž๐™ฉ๐™ง๐™ž๐™ฃ๐™œ๐™จ ๐™—๐™š๐™ก๐™ค๐™ฌ ๐™ž๐™ฃ ๐™ฎ๐™ค๐™ช๐™ง ๐™—๐™ง๐™ค๐™ฌ๐™จ๐™š๐™ง\n ๐Ÿ‘‡ ๐Ÿ‘‡ ๐Ÿ‘‡.\n\n" ) bot.send_message(message.chat.id, error_message) # Second block of the message email_template = ( f"mailto:eyetubebot@gmail.com?subject=๐Ÿ“ฌID_{message.from_user.id}%20[Issue]%20Report%20&" "body=(๐Ÿ–‡Please_Attach_your_Issue_screenshot)%0A%0A-[Country]:%0A%0A%0A%0A-" "[Please describe your Issue here]:" ) bot.send_message(message.chat.id, email_template) #STAGE 4a #============================================================================== #This is where the send_audio_link function is defined to send the user the download link for the audio based on the hard work of the Audio extraction functions called the "extract_platform_audio_link" function which are in their independent files def send_audiomack_audio(message, url): audio_url = extract_audiomack_audio_link(url) if audio_url: bot.reply_to(message, f"Here is your AudioMack download link: {audio_url}\n\n") else: send_error_message(message, "AudioMack") def send_youtube_audio(message, url): audio_url = extract_youtube_audio_link(url) if audio_url: bot.reply_to(message, f"Here is your YouTube download link: {audio_url}\n\n.") else: send_error_message(message, "YouTube") def send_instagram_audio(message, url): audio_url = extract_instagram_audio_link(url) if audio_url: bot.reply_to(message, f"Here is your Instagram download link: {audio_url}\n\n.") def send_facebook_audio(message, url): audio_url = extract_facebook_audio_link(url) if audio_url: bot.reply_to(message, f"Here is your Facebook download link: {audio_url}\n\n.") def send_twitter_audio(message, url): audio_url = extract_twitter_audio_link(url) if audio_url: bot.reply_to(message, f"Here is your Twitter download link: {audio_url}\n\n.") def send_linkedin_audio(message, url): audio_url = extract_linkedin_audio_link(url) if audio_url: bot.reply_to(message, f"Here is your LinkedIn download link: {audio_url}\n\n.") def send_snapchat_audio(message, url): audio_url = extract_snapchat_audio_link(url) if audio_url: bot.reply_to(message, f"Here is your Snapchat download link: {audio_url}\n\n.") #WEBSITE INFO #============================================================================== # Process Links Based on Platform def process_media(message, url): if is_valid_url(url): try: if "youtube.com" in url or "youtu.be" in url: metadata = fetch_youtube_metadata(url) platform = "YouTube ๐ŸŽฅ" elif "twitter.com" in url: metadata = fetch_twitter_metadata(url) platform = "Twitter ๐Ÿฆ" elif "facebook.com" in url: metadata = fetch_facebook_metadata(url) platform = "Facebook ๐Ÿ“˜" elif "instagram.com" in url: metadata = fetch_instagram_metadata(url) platform = "Instagram ๐Ÿ“ธ" elif "linkedin.com" in url: metadata = fetch_linkedin_metadata(url) platform = "LinkedIn ๐Ÿ’ผ" else: bot.reply_to(message, "Platform not supported ๐Ÿ˜ข") return # Send metadata to user with emojis bot.reply_to(message, ( f"โœ… Platform: {platform}\n\n" f"๐ŸŒ Title: {metadata.get('title', 'No title found')}\n\n" f"๐Ÿ“ Description: {metadata.get('description', 'No description found')}\n\n" f"๐Ÿ”— URL: {metadata.get('url', 'No URL found')}\n\n" f"๐Ÿ“ธ Image/Thumbnail: {metadata.get('image', metadata.get('thumbnail', 'No image found'))}\n\n\n๐Ÿš“check : [ /status ]" )) except Exception as e: bot.reply_to(message, f"Oops! Something went wrong while fetching the data ๐Ÿ˜“\nError: {str(e)}") else: bot.reply_to(message, "Invalid URL. Please check the link and try again. ๐Ÿšจ") # YouTube Metadata Scraper def fetch_youtube_metadata(url): try: response = requests.get(url) response.raise_for_status() soup = BeautifulSoup(response.text, 'html.parser') metadata = { 'title': soup.find('meta', attrs={'property': 'og:title'})['content'] if soup.find('meta', attrs={'property': 'og:title'}) else 'No title found', 'description': soup.find('meta', attrs={'property': 'og:description'})['content'] if soup.find('meta', attrs={'property': 'og:description'}) else 'No description found', 'thumbnail': soup.find('meta', attrs={'property': 'og:image'})['content'] if soup.find('meta', attrs={'property': 'og:image'}) else 'No thumbnail found', 'url': soup.find('meta', attrs={'property': 'og:url'})['content'] if soup.find('meta', attrs={'property': 'og:url'}) else 'No URL found' } return metadata except Exception as e: return {"error": str(e)} # Twitter Metadata Scraper def fetch_twitter_metadata(url): try: response = requests.get(url) response.raise_for_status() soup = BeautifulSoup(response.text, 'html.parser') metadata = { 'title': soup.find('meta', attrs={'property': 'og:title'})['content'] if soup.find('meta', attrs={'property': 'og:title'}) else 'No title found', 'description': soup.find('meta', attrs={'property': 'og:description'})['content'] if soup.find('meta', attrs={'property': 'og:description'}) else 'No description found', 'image': soup.find('meta', attrs={'property': 'og:image'})['content'] if soup.find('meta', attrs={'property': 'og:image'}) else 'No image found', 'url': soup.find('meta', attrs={'property': 'og:url'})['content'] if soup.find('meta', attrs={'property': 'og:url'}) else 'No URL found' } return metadata except Exception as e: return {"error": str(e)} # Facebook Metadata Scraper def fetch_facebook_metadata(url): try: response = requests.get(url) response.raise_for_status() soup = BeautifulSoup(response.text, 'html.parser') metadata = { 'title': soup.find('meta', attrs={'property': 'og:title'})['content'] if soup.find('meta', attrs={'property': 'og:title'}) else 'No title found', 'description': soup.find('meta', attrs={'property': 'og:description'})['content'] if soup.find('meta', attrs={'property': 'og:description'}) else 'No description found', 'image': soup.find('meta', attrs={'property': 'og:image'})['content'] if soup.find('meta', attrs={'property': 'og:image'}) else 'No image found', 'url': soup.find('meta', attrs={'property': 'og:url'})['content'] if soup.find('meta', attrs={'property': 'og:url'}) else 'No URL found' } return metadata except Exception as e: return {"error": str(e)} # Instagram Metadata Scraper def fetch_instagram_metadata(url): try: response = requests.get(url) response.raise_for_status() soup = BeautifulSoup(response.text, 'html.parser') metadata = { 'title': soup.find('meta', attrs={'property': 'og:title'})['content'] if soup.find('meta', attrs={'property': 'og:title'}) else 'No title found', 'description': soup.find('meta', attrs={'property': 'og:description'})['content'] if soup.find('meta', attrs={'property': 'og:description'}) else 'No description found', 'image': soup.find('meta', attrs={'property': 'og:image'})['content'] if soup.find('meta', attrs={'property': 'og:image'}) else 'No image found', 'url': soup.find('meta', attrs={'property': 'og:url'})['content'] if soup.find('meta', attrs={'property': 'og:url'}) else 'No URL found' } return metadata except Exception as e: return {"error": str(e)} # LinkedIn Metadata Scraper def fetch_linkedin_metadata(url): try: response = requests.get(url) response.raise_for_status() soup = BeautifulSoup(response.text, 'html.parser') metadata = { 'title': soup.find('meta', attrs={'property': 'og:title'})['content'] if soup.find('meta', attrs={'property': 'og:title'}) else 'No title found', 'description': soup.find('meta', attrs={'property': 'og:description'})['content'] if soup.find('meta', attrs={'property': 'og:description'}) else 'No description found', 'image': soup.find('meta', attrs={'property': 'og:image'})['content'] if soup.find('meta', attrs={'property': 'og:image'}) else 'No image found', 'url': soup.find('meta', attrs={'property': 'og:url'})['content'] if soup.find('meta', attrs={'property': 'og:url'}) else 'No URL found' } return metadata except Exception as e: return {"error": str(e)} # Bot Message Handler @bot.message_handler(func=lambda message: True) def handle_message(message): url = message.text.strip() # Expect a URL in the message process_media(message, url) # Process the URL and fetch metadata #WEBSITE INFO FOR ANY LINK #============================================================================== def extract_metadata(url): try: # Fetch the main URL response = requests.get(url) response.raise_for_status() # Handle bad responses (like 404) # HTTP Status Code http_status = response.status_code # Parse the page content soup = BeautifulSoup(response.text, 'html.parser') # Extract title title = soup.title.string if soup.title else 'No title found ๐Ÿง' # Extract description description = soup.find('meta', attrs={'name': 'description'}) description_content = description['content'] if description else 'No description found ๐Ÿคทโ€โ™‚๏ธ' # Extract canonical URL canonical = soup.find('link', attrs={'rel': 'canonical'}) canonical_url = canonical['href'] if canonical else 'No canonical URL found ๐Ÿ”—' # Extract author owner = soup.find('meta', attrs={'name': 'author'}) owner_content = owner['content'] if owner else 'No author information found ๐Ÿค”' # Extract keywords keywords = soup.find('meta', attrs={'name': 'keywords'}) keywords_content = keywords['content'] if keywords else 'No keywords found ๐Ÿ”‘' # Extract OpenGraph metadata (if available) og_title = soup.find('meta', attrs={'property': 'og:title'}) og_title_content = og_title['content'] if og_title else 'No OpenGraph title found ๐Ÿ“ฑ' # Check for basic safety (simple heuristic) is_safe = "โœ… Safe and sound!" if "phishing" not in response.text.lower() else "โš ๏ธ Potentially unsafe website!" # WHOIS information whois_info = whois.whois(url) creation_date = whois_info.creation_date if whois_info.creation_date else 'No creation date found ๐Ÿ“…' # Check for robots.txt file (gracefully handle 404) robots_url = url.rstrip('/') + "/robots.txt" try: robots_response = requests.get(robots_url) if robots_response.status_code == 200: robots_content = robots_response.text else: robots_content = 'No robots.txt file found ๐Ÿค–' except requests.exceptions.HTTPError: robots_content = 'No robots.txt file found ๐Ÿค–' # Gather social media links (optional) social_links = [] for anchor in soup.find_all('a', href=True): href = anchor['href'] if "facebook.com" in href: social_links.append("๐Ÿ“˜ Facebook") elif "twitter.com" in href: social_links.append("๐Ÿฆ Twitter") elif "linkedin.com" in href: social_links.append("๐Ÿ”— LinkedIn") social_links = social_links if social_links else ['No social media links found ๐Ÿšซ'] # Return all extracted information with emojis for fun output return { 'title': title, 'description': description_content, 'owner': owner_content, 'canonical_url': canonical_url, 'keywords': keywords_content, 'http_status': f"HTTP Status: {http_status} ๐Ÿ–ฅ๏ธ", 'is_safe': is_safe, 'creation_date': creation_date, 'robots_content': robots_content, 'open_graph_title': og_title_content, 'social_links': ', '.join(social_links) } # Handle errors for specific HTTP issues except requests.exceptions.HTTPError as http_err: return {"error": f"\nno data: We managed to ๐Ÿ”‘get this for you ๐Ÿ›‘: {http_err}"} # Handle request errors except requests.exceptions.RequestException as req_err: return {"error": f"Request error occurred โ—: {req_err}"} # Handle any other exceptions except Exception as e: return {"error": f"Unexpected error occurred ๐Ÿคฏ: {str(e)}"} # Step 3: Process Links Function def process_link(message, url): try: if is_valid_url(url): bot.reply_to(message, "๐Ÿ› ๏ธ Digging Information from the provided Site... ๐ŸŒ") metadata = extract_metadata(url) # Send metadata to user if "error" in metadata: bot.reply_to(message, f"โš ๏ธ This page/site is โ›“protected : {metadata['error']},\n\n please click this๐Ÿ‘† link then copy & paste to me") else: bot.reply_to(message, ( f"๐ŸŽฏ Title: {metadata['title']}\n\n" f"๐Ÿ“ Description: {metadata['description']}\n\n" f"๐Ÿ‘ค Owner: {metadata['owner']}\n\n" f"๐Ÿ”— Canonical URL: {metadata['canonical_url']}\n\n" f"๐Ÿ”‘ Keywords: {metadata['keywords']}\n\n" f"๐Ÿ“ก OpenGraph Title: {metadata['open_graph_title']}\n\n" f"๐Ÿ›ก๏ธ Safety Status: {metadata['is_safe']}\n\n" f"๐Ÿ“… Creation Date: {metadata['creation_date']}\n\n" f"๐Ÿค– robots.txt Content: {metadata['robots_content']}\n\n" f"๐ŸŒ Social Media Links: {metadata['social_links']}\n\n" f"๐Ÿ–ฅ๏ธ HTTP Status Code: {metadata['http_status']}\n\n\n๐Ÿš“check : [ /status ]" )) else: bot.reply_to(message, "โŒ Invalid URL. Please check the link and try again.") except Exception as e: bot.reply_to(message, f"๐Ÿ˜ž We're sorry, This page/site has an Advanced โ›“protection. We are working 24/7 to break into links like these") #============================================================================== @retry_on_failure def bot_polling(): bot.polling(none_stop=True, timeout=60) bot_polling()