summaryrefslogtreecommitdiffstats
path: root/irc-bot2.py
diff options
context:
space:
mode:
Diffstat (limited to 'irc-bot2.py')
-rw-r--r--irc-bot2.py18
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(" ")