updated wait syntax because it was not supported any longer in asyncClient, replaced youtube-dl with yt-dlp in Commands

This commit is contained in:
jenz
2023-09-24 14:16:02 +02:00
parent cc56169ff9
commit bc5f212265
4 changed files with 26 additions and 27 deletions
@@ -79,7 +79,7 @@ class AsyncClient():
Data = json.dumps(obj, ensure_ascii = False, separators = (',', ':')).encode("UTF-8")
with (await self.SendLock):
async with self.SendLock:
if not self.Protocol:
return None
@@ -49,7 +49,7 @@ class URLFilter(BaseCommand):
def __init__(self, torchlight):
super().__init__(torchlight)
self.Triggers = [self.re.compile(r'''(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))''', self.re.IGNORECASE)]
self.Level = 10
self.Level = -1
self.re_youtube = self.re.compile(r'.*?(?:youtube\.com\/\S*(?:(?:\/e(?:mbed))?\/|watch\?(?:\S*?&?v\=))|youtu\.be\/)([a-zA-Z0-9_-]{6,11}).*?')
async def URLInfo(self, url, yt = False):
@@ -65,7 +65,7 @@ class URLFilter(BaseCommand):
if TimeStr:
Time = Utils.ParseTime(TimeStr)
Proc = await asyncio.create_subprocess_exec("youtube-dl", "--dump-json", "-g", url,
Proc = await asyncio.create_subprocess_exec("yt-dlp", "--dump-json", "-g", url,
stdout = asyncio.subprocess.PIPE)
Out, _ = await Proc.communicate()
@@ -79,8 +79,8 @@ class URLFilter(BaseCommand):
Info = self.json.loads(Info)
if Info["extractor_key"] == "Youtube":
self.Torchlight().SayChat("\x07E52D27[YouTube]\x01 {0} | {1} | {2}/5.00 | {3:,}".format(
Info["title"], str(self.datetime.timedelta(seconds = Info["duration"])), round(Info["average_rating"], 2), int(Info["view_count"])))
self.Torchlight().SayChat("\x07E52D27[YouTube]\x01 {0} | {1} | {2:,}".format(
Info["title"], str(self.datetime.timedelta(seconds = Info["duration"])), int(Info["view_count"])))
else:
match = None
@@ -331,7 +331,7 @@ class OpenWeather(BaseCommand):
import geoip2.database
def __init__(self, torchlight):
super().__init__(torchlight)
self.GeoIP = self.geoip2.database.Reader("/usr/share/GeoIP/GeoLite2-City.mmdb")
self.GeoIP = self.geoip2.database.Reader("/var/lib/GeoIP/GeoLite2-City.mmdb")
self.Triggers = ["!w", "!vv"]
self.Level = 10
@@ -645,7 +645,7 @@ class YouTubeSearch(BaseCommand):
Time = Utils.ParseTime(TimeStr)
message[1] = message[1][:Temp.value]
Proc = await asyncio.create_subprocess_exec("youtube-dl", "--dump-json", "-xg", "ytsearch:" + message[1],
Proc = await asyncio.create_subprocess_exec("yt-dlp", "--dump-json", "-xg", "ytsearch:" + message[1],
stdout = asyncio.subprocess.PIPE)
Out, _ = await Proc.communicate()
@@ -655,8 +655,8 @@ class YouTubeSearch(BaseCommand):
Info = self.json.loads(Info)
if Info["extractor_key"] == "Youtube":
self.Torchlight().SayChat("\x07E52D27[YouTube]\x01 {0} | {1} | {2}/5.00 | {3:,}".format(
Info["title"], str(self.datetime.timedelta(seconds = Info["duration"])), round(Info["average_rating"] or 0, 2), int(Info["view_count"])))
self.Torchlight().SayChat("\x07E52D27[YouTube]\x01 {0} | {1} | {2:,}".format(
Info["title"], str(self.datetime.timedelta(seconds = Info["duration"])), int(Info["view_count"])))
AudioClip = self.Torchlight().AudioManager.AudioClip(player, url)
if not AudioClip:
return 1
@@ -711,13 +711,13 @@ class Say(BaseCommand):
asyncio.ensure_future(self.Say(player, Language, message[1]))
return 0
'''
class DECTalk(BaseCommand):
import tempfile
def __init__(self, torchlight):
super().__init__(torchlight)
self.Triggers = ["!dec"]
self.Level = 0
self.Level = 2
async def Say(self, player, message):
message = "[:phoneme on]" + message
@@ -751,7 +751,7 @@ class DECTalk(BaseCommand):
asyncio.ensure_future(self.Say(player, message[1]))
return 0
'''
class Stop(BaseCommand):
def __init__(self, torchlight):
@@ -49,7 +49,7 @@ class URLFilter(BaseCommand):
def __init__(self, torchlight):
super().__init__(torchlight)
self.Triggers = [self.re.compile(r'''(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))''', self.re.IGNORECASE)]
self.Level = 10
self.Level = -1
self.re_youtube = self.re.compile(r'.*?(?:youtube\.com\/\S*(?:(?:\/e(?:mbed))?\/|watch\?(?:\S*?&?v\=))|youtu\.be\/)([a-zA-Z0-9_-]{6,11}).*?')
async def URLInfo(self, url, yt = False):
@@ -65,7 +65,7 @@ class URLFilter(BaseCommand):
if TimeStr:
Time = Utils.ParseTime(TimeStr)
Proc = await asyncio.create_subprocess_exec("youtube-dl", "--dump-json", "-g", url,
Proc = await asyncio.create_subprocess_exec("yt-dlp", "--dump-json", "-g", url,
stdout = asyncio.subprocess.PIPE)
Out, _ = await Proc.communicate()
@@ -79,8 +79,8 @@ class URLFilter(BaseCommand):
Info = self.json.loads(Info)
if Info["extractor_key"] == "Youtube":
self.Torchlight().SayChat("\x07E52D27[YouTube]\x01 {0} | {1} | {2}/5.00 | {3:,}".format(
Info["title"], str(self.datetime.timedelta(seconds = Info["duration"])), round(Info["average_rating"], 2), int(Info["view_count"])))
self.Torchlight().SayChat("\x07E52D27[YouTube]\x01 {0} | {1} | {2:,}".format(
Info["title"], str(self.datetime.timedelta(seconds = Info["duration"])), int(Info["view_count"])))
else:
match = None
@@ -129,9 +129,8 @@ class URLFilter(BaseCommand):
Url = "http://" + Url
if line.startswith("!yt "):
return
#URL, _ = await self.URLInfo(Url, True)
#return "!yt " + URL
URL, _ = await self.URLInfo(Url, True)
return "!yt " + URL
if line.startswith("!dec "):
_, text = await self.URLInfo(Url, False)
@@ -332,7 +331,7 @@ class OpenWeather(BaseCommand):
import geoip2.database
def __init__(self, torchlight):
super().__init__(torchlight)
self.GeoIP = self.geoip2.database.Reader("/usr/share/GeoIP/GeoLite2-City.mmdb")
self.GeoIP = self.geoip2.database.Reader("/var/lib/GeoIP/GeoLite2-City.mmdb")
self.Triggers = ["!w", "!vv"]
self.Level = 10
@@ -632,7 +631,6 @@ class YouTubeSearch(BaseCommand):
self.Level = 3
async def _func(self, message, player):
return -1
self.Logger.debug(sys._getframe().f_code.co_name + ' ' + str(message))
if self.check_disabled(player):
@@ -647,7 +645,7 @@ class YouTubeSearch(BaseCommand):
Time = Utils.ParseTime(TimeStr)
message[1] = message[1][:Temp.value]
Proc = await asyncio.create_subprocess_exec("youtube-dl", "--dump-json", "-xg", "ytsearch:" + message[1],
Proc = await asyncio.create_subprocess_exec("yt-dlp", "--dump-json", "-xg", "ytsearch:" + message[1],
stdout = asyncio.subprocess.PIPE)
Out, _ = await Proc.communicate()
@@ -657,8 +655,8 @@ class YouTubeSearch(BaseCommand):
Info = self.json.loads(Info)
if Info["extractor_key"] == "Youtube":
self.Torchlight().SayChat("\x07E52D27[YouTube]\x01 {0} | {1} | {2}/5.00 | {3:,}".format(
Info["title"], str(self.datetime.timedelta(seconds = Info["duration"])), round(Info["average_rating"] or 0, 2), int(Info["view_count"])))
self.Torchlight().SayChat("\x07E52D27[YouTube]\x01 {0} | {1} | {2:,}".format(
Info["title"], str(self.datetime.timedelta(seconds = Info["duration"])), int(Info["view_count"])))
AudioClip = self.Torchlight().AudioManager.AudioClip(player, url)
if not AudioClip:
return 1
@@ -713,13 +711,13 @@ class Say(BaseCommand):
asyncio.ensure_future(self.Say(player, Language, message[1]))
return 0
'''
class DECTalk(BaseCommand):
import tempfile
def __init__(self, torchlight):
super().__init__(torchlight)
self.Triggers = ["!dec"]
self.Level = 0
self.Level = 2
async def Say(self, player, message):
message = "[:phoneme on]" + message
@@ -753,7 +751,7 @@ class DECTalk(BaseCommand):
asyncio.ensure_future(self.Say(player, message[1]))
return 0
'''
class Stop(BaseCommand):
def __init__(self, torchlight):
@@ -21,3 +21,4 @@ urllib3
yarl
cython
geoip2
yt-dlp @ git+https://github.com/yt-dlp/yt-dlp@master