summaryrefslogtreecommitdiffstats
path: root/notcqst.py
diff options
context:
space:
mode:
authorcqst <cqst@cqstia.com>2025-08-22 13:24:32 -0700
committercqst <cqst@cqstia.com>2025-08-22 13:24:32 -0700
commit4903c5ecccebd7187736dd69b3256225df12b7a0 (patch)
tree217b281a6e511ec68ddd34db75acc0866cd11801 /notcqst.py
parent7fd250aff7d12d3712d06e87073ec1a3320047ad (diff)
downloadirc-bot-4903c5ecccebd7187736dd69b3256225df12b7a0.tar.gz
working video url parser
Diffstat (limited to 'notcqst.py')
-rw-r--r--notcqst.py40
1 files changed, 38 insertions, 2 deletions
diff --git a/notcqst.py b/notcqst.py
index 9d7cdef..9fb41f8 100644
--- a/notcqst.py
+++ b/notcqst.py
@@ -1,4 +1,27 @@
import socket
+from yt_dlp import YoutubeDL
+
+
+def check_youtube():
+ print("Hello World!\n")
+ if "https://youtube.com" in text_str or "https://www.youtube.com" in text_str:
+ split_str = text_str.split('##tech-tangents :')
+ vid_url = split_str[1].strip()
+ with YoutubeDL() as ydl:
+ info_dict = ydl.extract_info(vid_url, download=False)
+ video_url = info_dict.get("url", None)
+ video_id = info_dict.get("id", None)
+ video_title = info_dict.get('title', None)
+ channel_name = info_dict.get('channel', None)
+ irc.send((bytes("PRIVMSG " + channel + " :" + channel_name + ": " + video_title + "\r\n", 'utf-8')))
+ return 1
+ else:
+ return 0
+
+
+def parse_cmd():
+ check_youtube()
+
server = "irc.libera.chat"
channel = "##tech-tangents"
@@ -6,12 +29,25 @@ botnick = "notcqst"
irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+user_str = ("USER " + botnick + " " + botnick + " " + botnick + " :" + botnick + "\n")
+nick_str = ("NICK " + botnick + "\n")
+channel_string = ("JOIN " + channel + "\n")
+send_to_channel_str = ("PRIVMSG " + channel + " :Hello " + "\r\n")
+
print("connecting to: " + server)
irc.connect((server, 6667))
-irc.send(b'this should fail')
+irc.send(bytes(user_str, 'utf-8'))
+irc.send(bytes(nick_str, 'utf-8'))
+irc.send(bytes(channel_string, 'utf-8'))
+irc.send(bytes(send_to_channel_str, 'utf-8'))
+
while 1:
- text = irc.rec(2040)
+ text = irc.recv(2040)
print(text)
+ text_str = text.decode("utf-8")
+ parse_cmd()
+
+