I think this fixes youtube alternate urls, bonus: now embed links work also!
This commit is contained in:
parent
7c966381fe
commit
d5f6f0a7bc
26
commands.py
26
commands.py
|
@ -1,7 +1,8 @@
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from irctokens import build
|
from irctokens import build
|
||||||
|
|
||||||
from youtube import YouTube
|
import importlib
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
class Command:
|
class Command:
|
||||||
|
@ -9,8 +10,8 @@ class Command:
|
||||||
self.config = config
|
self.config = config
|
||||||
self.commands = []
|
self.commands = []
|
||||||
|
|
||||||
def mesg(self, msg):
|
def mesg(self, msg, t=None):
|
||||||
self.util.mesg(msg)
|
self.util.mesg(msg, t)
|
||||||
|
|
||||||
def notice(self, msg):
|
def notice(self, msg):
|
||||||
self.util.notice(msg)
|
self.util.notice(msg)
|
||||||
|
@ -94,6 +95,7 @@ class Command:
|
||||||
|
|
||||||
def preq_cmd(self): # command prequisites / triggers
|
def preq_cmd(self): # command prequisites / triggers
|
||||||
cmd = self.line
|
cmd = self.line
|
||||||
|
#self.mesg(f"attempting command: {cmd}")
|
||||||
if cmd == "help" or cmd.startswith("help "):
|
if cmd == "help" or cmd.startswith("help "):
|
||||||
command = "help"
|
command = "help"
|
||||||
elif cmd.startswith("echo "):
|
elif cmd.startswith("echo "):
|
||||||
|
@ -106,11 +108,7 @@ class Command:
|
||||||
command = "dbg"
|
command = "dbg"
|
||||||
elif cmd == "dbg2" or cmd.startswith("dbg2 "):
|
elif cmd == "dbg2" or cmd.startswith("dbg2 "):
|
||||||
command = "dbg2"
|
command = "dbg2"
|
||||||
elif (
|
elif cmd.startswith("yt ") or self.YouTube.match_urls(self.YouTube,cmd)!=[]:
|
||||||
"https://www.youtube.com/watch?v="
|
|
||||||
or "https://m.youtube.com/watch?v="
|
|
||||||
or "https://youtu.be/"
|
|
||||||
) in cmd or cmd.startswith("yt "):
|
|
||||||
command = "yt"
|
command = "yt"
|
||||||
elif cmd.startswith("\x01") or self.is_ctcp:
|
elif cmd.startswith("\x01") or self.is_ctcp:
|
||||||
command = "ctcp"
|
command = "ctcp"
|
||||||
|
@ -151,19 +149,11 @@ class Command:
|
||||||
@cmd
|
@cmd
|
||||||
def yt(self, prefix, cmd, pm, line, admin, mesg):
|
def yt(self, prefix, cmd, pm, line, admin, mesg):
|
||||||
"""youtube"""
|
"""youtube"""
|
||||||
|
YouTube = self.YouTube
|
||||||
if cmd.startswith("yt "):
|
if cmd.startswith("yt "):
|
||||||
cmd = cmd[3:]
|
cmd = cmd[3:]
|
||||||
# cmd=cmd.split()[0]
|
# cmd=cmd.split()[0]
|
||||||
urls = [
|
urls = YouTube.match_urls(YouTube,cmd)
|
||||||
i
|
|
||||||
for i in cmd.split()
|
|
||||||
if i.startswith(
|
|
||||||
"https://www.youtube.com/watch?v="
|
|
||||||
or "https://m.youtube.com/watch?v="
|
|
||||||
or "https://youtu.be/"
|
|
||||||
)
|
|
||||||
]
|
|
||||||
# mesg(urls)
|
|
||||||
for video in urls:
|
for video in urls:
|
||||||
try:
|
try:
|
||||||
a = YouTube.yt(YouTube, video)
|
a = YouTube.yt(YouTube, video)
|
||||||
|
|
|
@ -14,7 +14,7 @@ class config:
|
||||||
# get password from secret file
|
# get password from secret file
|
||||||
nickserv_pass = open("pass.txt", "r").read().strip()
|
nickserv_pass = open("pass.txt", "r").read().strip()
|
||||||
channel = "##jan6"
|
channel = "##jan6"
|
||||||
autojoin = ["##share", "#1337331", "#opsec"]
|
autojoin = ["##share", "#1337331"]
|
||||||
|
|
||||||
class admin:
|
class admin:
|
||||||
accounts = ["jan6"]
|
accounts = ["jan6"]
|
||||||
|
|
19
stuff.py
19
stuff.py
|
@ -2,6 +2,7 @@ import irctokens
|
||||||
from config import config as Config
|
from config import config as Config
|
||||||
from util import Util
|
from util import Util
|
||||||
from commands import Command
|
from commands import Command
|
||||||
|
from youtube import YouTube
|
||||||
import sys, importlib, time
|
import sys, importlib, time
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,7 +29,9 @@ def stuff(bot, sock):
|
||||||
config = importlib.reload(sys.modules["config"]).config
|
config = importlib.reload(sys.modules["config"]).config
|
||||||
util = Util(config, sock)
|
util = Util(config, sock)
|
||||||
command = importlib.reload(sys.modules["commands"]).Command(config)
|
command = importlib.reload(sys.modules["commands"]).Command(config)
|
||||||
|
command.YouTube = importlib.reload(sys.modules["youtube"]).YouTube
|
||||||
command.util = util
|
command.util = util
|
||||||
|
command.YouTube.util = util
|
||||||
prefixes = config.cmd.prefixes
|
prefixes = config.cmd.prefixes
|
||||||
admin_accounts = config.admin.accounts
|
admin_accounts = config.admin.accounts
|
||||||
admin_users = config.admin.hostmasks
|
admin_users = config.admin.hostmasks
|
||||||
|
@ -86,9 +89,11 @@ def stuff(bot, sock):
|
||||||
f"IDENTIFY {config.self.nick} {config.server.nickserv_pass}",
|
f"IDENTIFY {config.self.nick} {config.server.nickserv_pass}",
|
||||||
line.source.split("!")[0],
|
line.source.split("!")[0],
|
||||||
)
|
)
|
||||||
if line.command == "433": #433 is ERR_NICKNAMEINUSE
|
if line.command == "433": # 433 is ERR_NICKNAMEINUSE
|
||||||
util.nick(config.self.nick + "_")
|
util.nick(config.self.nick + "_")
|
||||||
if line.command == "376" or line.command == "422": #376 is RPL_ENDOFMOTD and 422 is ERR_NOMOTD
|
if (
|
||||||
|
line.command == "376" or line.command == "422"
|
||||||
|
): # 376 is RPL_ENDOFMOTD and 422 is ERR_NOMOTD
|
||||||
send(irctokens.build("CAP", ["LS", "302"]).format())
|
send(irctokens.build("CAP", ["LS", "302"]).format())
|
||||||
elif line.command == "CAP" and line.params[1] == "LS":
|
elif line.command == "CAP" and line.params[1] == "LS":
|
||||||
if server_caps == []:
|
if server_caps == []:
|
||||||
|
@ -134,13 +139,9 @@ def stuff(bot, sock):
|
||||||
is_pm
|
is_pm
|
||||||
or cmd.startswith(self_nick)
|
or cmd.startswith(self_nick)
|
||||||
or cmd[0] in prefixes
|
or cmd[0] in prefixes
|
||||||
or cmd.startswith("https://")
|
or "https://" in cmd
|
||||||
or (
|
or "http://" in cmd
|
||||||
"https://www.youtube.com/watch?v="
|
# or cmd.startswith("https://")
|
||||||
or "https://m.youtube.com/watch?v="
|
|
||||||
or "https://youtu.be/"
|
|
||||||
)
|
|
||||||
in cmd
|
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
# if message in a channel, remove prefixes
|
# if message in a channel, remove prefixes
|
||||||
|
|
26
youtube.py
26
youtube.py
|
@ -5,6 +5,28 @@ from urllib.request import urlopen
|
||||||
class YouTube:
|
class YouTube:
|
||||||
y, z = {}, {}
|
y, z = {}, {}
|
||||||
|
|
||||||
|
def mesg(self, msg, t=None):
|
||||||
|
self.util.mesg(msg, t)
|
||||||
|
|
||||||
|
def match_urls(self,str):
|
||||||
|
r = [
|
||||||
|
i
|
||||||
|
for i in str.split()
|
||||||
|
if "https://youtu.be/" in i
|
||||||
|
or "https://www.youtube.com/watch?v=" in i
|
||||||
|
or "https://m.youtube.com/watch?v=" in i
|
||||||
|
or "https://youtube.com/watch?v=" in i
|
||||||
|
or "https://www.youtube.com/embed/" in i
|
||||||
|
or "https://www.youtube-nocookie.com/embed/" in i
|
||||||
|
]
|
||||||
|
r=list(dict.fromkeys(r))
|
||||||
|
return r
|
||||||
|
|
||||||
|
def is_embed(str):
|
||||||
|
return str.startswith("https://www.youtube.com/embed/") or str.startswith(
|
||||||
|
"https://www.youtube-nocookie.com/embed/"
|
||||||
|
)
|
||||||
|
|
||||||
class parseprop(HTMLParser):
|
class parseprop(HTMLParser):
|
||||||
def handle_starttag(self, tag, attrs):
|
def handle_starttag(self, tag, attrs):
|
||||||
if tag != "meta" or [i for i in attrs if "itemprop" in i] == []:
|
if tag != "meta" or [i for i in attrs if "itemprop" in i] == []:
|
||||||
|
@ -37,7 +59,11 @@ class YouTube:
|
||||||
return f"{m}m {s}s"
|
return f"{m}m {s}s"
|
||||||
|
|
||||||
def yt(self, url):
|
def yt(self, url):
|
||||||
|
# self.util.mesg("hello")
|
||||||
url = url.rstrip("\x01")
|
url = url.rstrip("\x01")
|
||||||
|
if self.is_embed(url):
|
||||||
|
videoId = url.split("/")[4]
|
||||||
|
url = f"https://www.youtube.com/watch?v={videoId}"
|
||||||
global y, z
|
global y, z
|
||||||
y, z = {}, {}
|
y, z = {}, {}
|
||||||
p = self.parseprop()
|
p = self.parseprop()
|
||||||
|
|
Loading…
Reference in New Issue