summaryrefslogtreecommitdiff
path: root/youtube_oembed.py
diff options
context:
space:
mode:
authorPawky Languish2025-04-19 19:07:38 +0000
committerPawky Languish2025-04-19 19:07:38 +0000
commitf4fb34dde6b03fdb49f71476d587c5c7f986b565 (patch)
treeef8cc174c413dcd766754bc51c52b9a2fc328e5c /youtube_oembed.py
parent12062621d6d67adb8abee962f4201e2d5196f55b (diff)
idk some changes lol, formatting and stuff
Diffstat (limited to 'youtube_oembed.py')
-rwxr-xr-xyoutube_oembed.py38
1 files changed, 19 insertions, 19 deletions
diff --git a/youtube_oembed.py b/youtube_oembed.py
index 4a0ca20..4ed427c 100755
--- a/youtube_oembed.py
+++ b/youtube_oembed.py
@@ -3,6 +3,7 @@ from urllib.parse import urlencode, urlparse, parse_qs
from json import loads as json_loads
from URLget import urlget, URLgetException
+
class YouTube:
def __init__(self):
try:
@@ -14,6 +15,7 @@ class YouTube:
self.util.mesg(msg, t)
def match_urls(self, str):
+ str = str.replace("http://", "https://")
r = [
i
for i in str.split()
@@ -57,18 +59,14 @@ class YouTube:
str = self
else:
str = str[0]
- return str.startswith("https://youtube.com/shorts/") or str.startswith(
- "https://www.youtube.com/shorts/"
- )
+ return str.startswith("https://youtube.com/shorts/") or str.startswith("https://www.youtube.com/shorts/")
def is_clip(self, *str):
if type(self) == type("a"):
str = self
else:
str = str[0]
- return str.startswith("https://youtube.com/clip/") or str.startswith(
- "https://www.youtube.com/clip/"
- )
+ return str.startswith("https://youtube.com/clip/") or str.startswith("https://www.youtube.com/clip/")
def is_shorturl(self, *str):
if type(self) == type("a"):
@@ -78,8 +76,10 @@ class YouTube:
return str.startswith("https://youtu.be/")
def yt(self, url):
- irc_string = "[\x0304Youtube\x03] \x0307ERROR:\x0308 got no data from server! \x0315(check your URL for typos!)\x03"
- ansi_string = "[\x1b[31mYoutube\x1b[0m] \x1b[33;2mERROR:\x1b[33;1m got no data from server! \x1b[37;2m(check your URL for typos!)\x1b[0m"
+ irc_string = (
+ "[\x0304YouTube\x03] \x0307ERROR:\x0308 got no data from server! \x0315(check your URL for typos!)\x03"
+ )
+ ansi_string = "[\x1b[31mYouTube\x1b[0m] \x1b[33;2mERROR:\x1b[33;1m got no data from server! \x1b[37;2m(check your URL for typos!)\x1b[0m"
# self.util.mesg("dbg hello")
url = url.rstrip("\x01")
if self.is_embed(url):
@@ -116,23 +116,23 @@ class YouTube:
url = f"https://www.youtube.com/oembed?{urlencode([('url',url),('format','json')])}"
try:
# print(url, " and ", playlist_id)
- status,data = urlget(url)
+ status, data = urlget(url)
if status != 200:
- irc_string = f"[\x0304Youtube\x03] \x0307ERROR:\x0308 {status} \x0315\x03"
- ansi_string = f"[\x1b[31mYoutube\x1b[0m] \x1b[33;2mERROR:\x1b[33;1m {status} \x1b[37;2m\x1b[0m"
+ irc_string = f"[\x0304YouTube\x03] \x0307ERROR:\x0308 {status} \x0315\x03"
+ ansi_string = f"[\x1b[31mYouTube\x1b[0m] \x1b[33;2mERROR:\x1b[33;1m {status} \x1b[37;2m\x1b[0m"
data = json_loads(data)
title = data["title"]
channelName = data["author_name"]
except URLgetException as e:
- irc_string = f"[\x0304Youtube\x03] \x0307ERROR:\x0308 {e} \x0315\x03"
- ansi_string = f"[\x1b[31mYoutube\x1b[0m] \x1b[33;2mERROR:\x1b[33;1m {e} \x1b[37;2m\x1b[0m"
- print(ansi_string)
+ irc_string = f"[\x0304YouTube\x03] \x0307ERROR:\x0308 {e} \x0315\x03"
+ ansi_string = f"[\x1b[31mYouTube\x1b[0m] \x1b[33;2mERROR:\x1b[33;1m {e} \x1b[37;2m\x1b[0m"
+ if __import__("sys").stdout.isatty():
+ print(ansi_string)
return irc_string, True
- irc_string = (
- f"[\x0303Youtube\x03] \x02{title}\x02 uploaded by \x1d{channelName}\x1d"
- )
- ansi_string = f"[\x1b[32mYoutube\x1b[0m] \x1b[1m{title}\x1b[0m uploaded by \x1b[03m{channelName}\x1b[0m"
- if __import__("sys").stdout.isatty(): print(ansi_string)
+ irc_string = f"[\x0303YouTube\x03] \x02{title}\x02 uploaded by \x1d{channelName}\x1d"
+ ansi_string = f"[\x1b[32mYouTube\x1b[0m] \x1b[1m{title}\x1b[0m uploaded by \x1b[03m{channelName}\x1b[0m"
+ if __import__("sys").stdout.isatty():
+ print(ansi_string)
return irc_string, False