1
0
mirror of https://github.com/azlux/botamusique synced 2024-11-23 22:06:09 +00:00

Compare commits

...

3 Commits

Author SHA1 Message Date
9f032c3a57
Merge pull request #366 from Eswcvlad/master
Fix YouTube package update logic
2023-07-03 11:06:55 +02:00
XenonPK
bb179ebc23
Add bots option to exclude other bot users from autoplay logic (#301)
* Add bots option to exclude other bot users from autoplay logic
* Refactor get_user_count_in_channel to make it more readable
* Remove commandline option and rename config key for "bots"
* Remove --bots from argparse
* Correct when_nobody_in_channel_ignore config read typo
* Fix when_nobody_in_channel_ignore configuration read order
2023-07-03 10:42:40 +02:00
Vlad Lipskiy
8c9bfd03f4 Fix YouTube package update logic
As of now, the update command fails with an IndexError using current
versions of pip. If a package is already of the latest version, there is
no "Requirement already up-to-date" line present anymore. And since
nothing is installed, there is no "Successfully installed" string
either, so it fails later. So now it checks, that "Collecting yt-dlp"
line is missing instead. This works in older versions of pip as well.

Another issue is that since botamusique uses yt-dlp now instead of
youtube-dl, it was trying to update the wrong package. So the package
name was extracted as a constant and was changed to yt-dlp.

Additional minor fix in the output message. Before there was no spacing
between the botamusique version message and the YouTube package one. Now
it starts on a separate line.
2023-06-25 03:00:05 +03:00
4 changed files with 31 additions and 10 deletions

View File

@ -65,6 +65,7 @@ tmp_folder_max_size = 10
username = botamusique username = botamusique
volume = 0.8 volume = 0.8
when_nobody_in_channel = nothing when_nobody_in_channel = nothing
when_nobody_in_channel_ignore =
[webinterface] [webinterface]
access_address = http://127.0.0.1:8181 access_address = http://127.0.0.1:8181

View File

@ -134,6 +134,10 @@ port = 64738
# - leave empty (do nothing) # - leave empty (do nothing)
#when_nobody_in_channel = #when_nobody_in_channel =
# 'when_nobody_in_channel_ignore': Specify the list of users that should be ignored, from the list of active users.
# This is typically used when other bots are present in the channel.
#when_nobody_in_channel_ignore =
# 'youtube_query_cookie': Sometimes youtube will block the request of our bot and # 'youtube_query_cookie': Sometimes youtube will block the request of our bot and
# request the bot to complete a captcha to verify the request is not made by a # request the bot to complete a captcha to verify the request is not made by a
# bot. # bot.

View File

@ -103,6 +103,7 @@ class MumbleBot:
tokens = var.config.get("server", "tokens") tokens = var.config.get("server", "tokens")
tokens = tokens.split(',') tokens = tokens.split(',')
if args.user: if args.user:
self.username = args.user self.username = args.user
else: else:
@ -132,8 +133,11 @@ class MumbleBot:
self.join_channel() self.join_channel()
self.mumble.set_bandwidth(self.bandwidth) self.mumble.set_bandwidth(self.bandwidth)
bots = var.config.get("bot", "when_nobody_in_channel_ignore",fallback="")
self.bots = set(bots.split(','))
self._user_in_channel = self.get_user_count_in_channel() self._user_in_channel = self.get_user_count_in_channel()
# ====== Volume ====== # ====== Volume ======
self.volume_helper = util.VolumeHelper() self.volume_helper = util.VolumeHelper()
@ -374,8 +378,18 @@ class MumbleBot:
# ======================= # =======================
def get_user_count_in_channel(self): def get_user_count_in_channel(self):
# Get the channel, based on the channel id
own_channel = self.mumble.channels[self.mumble.users.myself['channel_id']] own_channel = self.mumble.channels[self.mumble.users.myself['channel_id']]
return len(own_channel.get_users())
# Build set of unique usernames
users = set([user.get_property("name") for user in own_channel.get_users()])
# Exclude all bots from the set of usernames
users = users.difference(self.bots)
# Return the number of elements in the set, as the final user count
return len(users)
def users_changed(self, user, message): def users_changed(self, user, message):
# only check if there is one more user currently in the channel # only check if there is one more user currently in the channel

20
util.py
View File

@ -12,13 +12,15 @@ import zipfile
import re import re
import subprocess as sp import subprocess as sp
import logging import logging
import yt_dlp as youtube_dl
from importlib import reload from importlib import reload
from sys import platform from sys import platform
import traceback import traceback
import requests import requests
from packaging import version from packaging import version
import yt_dlp as youtube_dl
YT_PKG_NAME = 'yt-dlp'
log = logging.getLogger("bot") log = logging.getLogger("bot")
@ -137,7 +139,7 @@ def update(current_version):
new_version = new_release_version(target) new_version = new_release_version(target)
msg = "" msg = ""
if target == "git": if target == "git":
msg = "git install, I do nothing" msg = "git install, I do nothing<br/>"
elif (target == "stable" and version.parse(new_version) > version.parse(current_version)) or \ elif (target == "stable" and version.parse(new_version) > version.parse(current_version)) or \
(target == "testing" and version.parse(new_version) != version.parse(current_version)): (target == "testing" and version.parse(new_version) != version.parse(current_version)):
@ -146,17 +148,17 @@ def update(current_version):
log.debug(tp) log.debug(tp)
log.info('update: update pip libraries dependencies') log.info('update: update pip libraries dependencies')
sp.check_output([var.config.get('bot', 'pip3_path'), 'install', '--upgrade', '-r', 'requirements.txt']).decode() sp.check_output([var.config.get('bot', 'pip3_path'), 'install', '--upgrade', '-r', 'requirements.txt']).decode()
msg = "New version installed, please restart the bot." msg = "New version installed, please restart the bot.<br/>"
log.info('update: starting update youtube-dl via pip3') log.info(f'update: starting update {YT_PKG_NAME} via pip3')
tp = sp.check_output([var.config.get('bot', 'pip3_path'), 'install', '--upgrade', 'youtube-dl']).decode() tp = sp.check_output([var.config.get('bot', 'pip3_path'), 'install', '--upgrade', YT_PKG_NAME]).decode()
if "Requirement already up-to-date" in tp: if f"Collecting {YT_PKG_NAME}" in tp.splitlines():
msg += "Youtube-dl is up-to-date"
else:
msg += "Update done: " + tp.split('Successfully installed')[1] msg += "Update done: " + tp.split('Successfully installed')[1]
else:
msg += YT_PKG_NAME.capitalize() + " is up-to-date"
reload(youtube_dl) reload(youtube_dl)
msg += "<br/> Youtube-dl reloaded" msg += "<br/>" + YT_PKG_NAME.capitalize() + " reloaded"
return msg return msg