diff options
author | cqst <cqst@cqstia.com> | 2025-09-10 13:12:48 -0700 |
---|---|---|
committer | cqst <cqst@cqstia.com> | 2025-09-10 13:12:48 -0700 |
commit | bb63c1edc8878f6a44cfcde5d22f6b518477fc17 (patch) | |
tree | 9cd30d4e8d68e3ce3389463f7a47bc8cefed5742 /irc-bot2.py | |
parent | 821d9d73c829d9c56fb8b06bd143a706362ecac1 (diff) | |
download | irc-bot-bb63c1edc8878f6a44cfcde5d22f6b518477fc17.tar.gz |
working youtube previews
Diffstat (limited to 'irc-bot2.py')
-rw-r--r-- | irc-bot2.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/irc-bot2.py b/irc-bot2.py index 9e9390b..57c5ad3 100644 --- a/irc-bot2.py +++ b/irc-bot2.py @@ -1,7 +1,7 @@ import socket import ssl import random - +from yt_dlp import YoutubeDL def connect(): context = ssl.create_default_context() @@ -30,6 +30,7 @@ def command_loop(irc, IrcDetails): match parse_text(text_str): case "ping": ping(irc, text_str) case "command": bot_command(irc, text_str, IrcDetails) + case "youtube": youtube(irc, text_str, IrcDetails) def parse_text(text_str): @@ -38,6 +39,9 @@ def parse_text(text_str): if ":n!" in text_str: print("DEBUG, COMMAND") return "command" + if "http://youtube.com" in text_str or "https://youtube.com" in text_str: + print("DEBUG, YOUTUBE") + return "youtube" def ping(irc, text_str): @@ -46,6 +50,18 @@ def ping(irc, text_str): irc.send((bytes("PONG :" + split_str[1] + "\r\n", 'utf-8'))) +def youtube(irc, text_str, IrcDetails): + split_str_foo = text_str.split('https://') + vid_url_www = split_str_foo[1].strip() + vid_url = ''.join(("https://", vid_url_www)) + with YoutubeDL() as ydl: + info_dict = ydl.extract_info(vid_url, download=False) + video_title = info_dict.get('title', None) + channel_name = info_dict.get('channel', None) + irc.send((bytes("PRIVMSG " + IrcDetails.channel + " :" + channel_name + ": " + video_title + "\r\n", 'utf-8'))) + + + def bot_command(irc, text_str, IrcDetails): text_str_clean = text_str.rstrip() text_str_split = text_str_clean.split(" ") |