new version !
This commit is contained in:
parent
6a64b221b3
commit
7d5f8fc778
@ -34,6 +34,9 @@ volume = 0.1
|
|||||||
# playback mode should be one of "one-shot", "loop", "random"
|
# playback mode should be one of "one-shot", "loop", "random"
|
||||||
playback_mode = one-shot
|
playback_mode = one-shot
|
||||||
|
|
||||||
|
# target version, stable or testing (testing need to bot installed with git)
|
||||||
|
target_version = stable
|
||||||
|
|
||||||
# Users allowed to kill the bot, or ban URLs.
|
# Users allowed to kill the bot, or ban URLs.
|
||||||
admin = User1;User2;
|
admin = User1;User2;
|
||||||
# Folder that stores your local songs.
|
# Folder that stores your local songs.
|
||||||
|
@ -34,6 +34,10 @@ port = 64738
|
|||||||
# This option will be overridden by value in the database.
|
# This option will be overridden by value in the database.
|
||||||
#playback_mode = one-shot
|
#playback_mode = one-shot
|
||||||
|
|
||||||
|
# target version, stable or testing (testing need to bot installed with git)
|
||||||
|
# stable will use simple bash with curl command to get releases, testing will follow github master branch with git commands
|
||||||
|
#target_version = stable
|
||||||
|
|
||||||
# 'admin': Users allowed to kill the bot, or ban URLs. Separated by ';'
|
# 'admin': Users allowed to kill the bot, or ban URLs. Separated by ';'
|
||||||
#admin = User1;User2;
|
#admin = User1;User2;
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ import youtube_dl
|
|||||||
import logging
|
import logging
|
||||||
import logging.handlers
|
import logging.handlers
|
||||||
import traceback
|
import traceback
|
||||||
|
from packaging import version
|
||||||
|
|
||||||
import util
|
import util
|
||||||
import command
|
import command
|
||||||
@ -33,6 +34,7 @@ import media.system
|
|||||||
from librb import radiobrowser
|
from librb import radiobrowser
|
||||||
from media.playlist import PlayList
|
from media.playlist import PlayList
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
FORMAT OF A MUSIC INTO THE PLAYLIST
|
FORMAT OF A MUSIC INTO THE PLAYLIST
|
||||||
type : url
|
type : url
|
||||||
@ -65,7 +67,7 @@ type : file
|
|||||||
|
|
||||||
|
|
||||||
class MumbleBot:
|
class MumbleBot:
|
||||||
version = 5
|
version = 5.1
|
||||||
|
|
||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
self.log = logging.getLogger("bot")
|
self.log = logging.getLogger("bot")
|
||||||
@ -196,7 +198,7 @@ class MumbleBot:
|
|||||||
def check_update(self):
|
def check_update(self):
|
||||||
self.log.debug("update: checking for updates...")
|
self.log.debug("update: checking for updates...")
|
||||||
new_version = util.new_release_version()
|
new_version = util.new_release_version()
|
||||||
if new_version > self.version:
|
if version.parse(new_version) > version.parse(self.version):
|
||||||
self.log.info("update: new version %d found, current installed version %d." % (new_version, self.version))
|
self.log.info("update: new version %d found, current installed version %d." % (new_version, self.version))
|
||||||
self.send_msg(constants.strings('new_version_found'))
|
self.send_msg(constants.strings('new_version_found'))
|
||||||
else:
|
else:
|
||||||
|
@ -6,3 +6,4 @@ python-magic
|
|||||||
Pillow
|
Pillow
|
||||||
mutagen
|
mutagen
|
||||||
requests
|
requests
|
||||||
|
packaging
|
||||||
|
25
update.sh
25
update.sh
@ -1,5 +1,20 @@
|
|||||||
curl -Lo /tmp/botamusique.tar.gz https://azlux.fr/botamusique/sources.tar.gz
|
#!/usr/bin/env bash
|
||||||
tar -xzf /tmp/botamusique.tar.gz -C /tmp/
|
|
||||||
cp -r /tmp/botamusique/* .
|
case "$1" in
|
||||||
rm -r /tmp/botamusique
|
stable)
|
||||||
rm -r /tmp/botamusique.tar.gz
|
curl -Lo /tmp/botamusique.tar.gz https://azlux.fr/botamusique/sources.tar.gz
|
||||||
|
tar -xzf /tmp/botamusique.tar.gz -C /tmp/
|
||||||
|
cp -r /tmp/botamusique/* .
|
||||||
|
rm -r /tmp/botamusique
|
||||||
|
rm -r /tmp/botamusique.tar.gz
|
||||||
|
;;
|
||||||
|
testing)
|
||||||
|
git fetch
|
||||||
|
git pull --all
|
||||||
|
git submodule update
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
exit 0
|
||||||
|
37
util.py
37
util.py
@ -21,9 +21,11 @@ from sys import platform
|
|||||||
import base64
|
import base64
|
||||||
import media
|
import media
|
||||||
import media.radio
|
import media.radio
|
||||||
|
from packaging import version
|
||||||
|
|
||||||
log = logging.getLogger("bot")
|
log = logging.getLogger("bot")
|
||||||
|
|
||||||
|
|
||||||
def solve_filepath(path):
|
def solve_filepath(path):
|
||||||
if not path:
|
if not path:
|
||||||
return ''
|
return ''
|
||||||
@ -34,7 +36,8 @@ def solve_filepath(path):
|
|||||||
mydir = os.path.dirname(os.path.realpath(__file__))
|
mydir = os.path.dirname(os.path.realpath(__file__))
|
||||||
return mydir + '/' + path
|
return mydir + '/' + path
|
||||||
|
|
||||||
def get_recursive_filelist_sorted(path):
|
|
||||||
|
def get_recursive_file_list_sorted(path):
|
||||||
filelist = []
|
filelist = []
|
||||||
for root, dirs, files in os.walk(path):
|
for root, dirs, files in os.walk(path):
|
||||||
relroot = root.replace(path, '', 1)
|
relroot = root.replace(path, '', 1)
|
||||||
@ -57,6 +60,7 @@ def get_recursive_filelist_sorted(path):
|
|||||||
filelist.sort()
|
filelist.sort()
|
||||||
return filelist
|
return filelist
|
||||||
|
|
||||||
|
|
||||||
def get_music_path(music):
|
def get_music_path(music):
|
||||||
uri = ''
|
uri = ''
|
||||||
if music["type"] == "url":
|
if music["type"] == "url":
|
||||||
@ -95,7 +99,7 @@ def get_music_tag_info(music):
|
|||||||
tags = mutagen.File(uri)
|
tags = mutagen.File(uri)
|
||||||
if 'TIT2' in tags:
|
if 'TIT2' in tags:
|
||||||
music['title'] = tags['TIT2'].text[0]
|
music['title'] = tags['TIT2'].text[0]
|
||||||
if 'TPE1' in tags: # artist
|
if 'TPE1' in tags: # artist
|
||||||
music['artist'] = tags['TPE1'].text[0]
|
music['artist'] = tags['TPE1'].text[0]
|
||||||
|
|
||||||
if im is None:
|
if im is None:
|
||||||
@ -110,7 +114,7 @@ def get_music_tag_info(music):
|
|||||||
tags = mutagen.File(uri)
|
tags = mutagen.File(uri)
|
||||||
if '©nam' in tags:
|
if '©nam' in tags:
|
||||||
music['title'] = tags['©nam'][0]
|
music['title'] = tags['©nam'][0]
|
||||||
if '©ART' in tags: # artist
|
if '©ART' in tags: # artist
|
||||||
music['artist'] = tags['©ART'][0]
|
music['artist'] = tags['©ART'][0]
|
||||||
|
|
||||||
if im is None:
|
if im is None:
|
||||||
@ -135,6 +139,7 @@ def get_music_tag_info(music):
|
|||||||
|
|
||||||
return music
|
return music
|
||||||
|
|
||||||
|
|
||||||
def format_song_string(music):
|
def format_song_string(music):
|
||||||
display = ''
|
display = ''
|
||||||
source = music["type"]
|
source = music["type"]
|
||||||
@ -169,6 +174,7 @@ def format_song_string(music):
|
|||||||
|
|
||||||
return display
|
return display
|
||||||
|
|
||||||
|
|
||||||
def format_debug_song_string(music):
|
def format_debug_song_string(music):
|
||||||
display = ''
|
display = ''
|
||||||
source = music["type"]
|
source = music["type"]
|
||||||
@ -203,6 +209,7 @@ def format_debug_song_string(music):
|
|||||||
|
|
||||||
return display
|
return display
|
||||||
|
|
||||||
|
|
||||||
def format_current_playing():
|
def format_current_playing():
|
||||||
music = var.playlist.current_item()
|
music = var.playlist.current_item()
|
||||||
display = format_song_string(music)
|
display = format_song_string(music)
|
||||||
@ -229,7 +236,7 @@ def zipdir(zippath, zipname_prefix=None):
|
|||||||
if zipname_prefix and '../' not in zipname_prefix:
|
if zipname_prefix and '../' not in zipname_prefix:
|
||||||
zipname += zipname_prefix.strip().replace('/', '_') + '_'
|
zipname += zipname_prefix.strip().replace('/', '_') + '_'
|
||||||
|
|
||||||
files = get_recursive_filelist_sorted(zippath)
|
files = get_recursive_file_list_sorted(zippath)
|
||||||
hash = hashlib.sha1((str(files).encode())).hexdigest()
|
hash = hashlib.sha1((str(files).encode())).hexdigest()
|
||||||
zipname += hash + '.zip'
|
zipname += hash + '.zip'
|
||||||
|
|
||||||
@ -258,22 +265,25 @@ def get_user_ban():
|
|||||||
res += "<br/>" + i[0]
|
res += "<br/>" + i[0]
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
def new_release_version():
|
def new_release_version():
|
||||||
v = int(urllib.request.urlopen(urllib.request.Request("https://azlux.fr/botamusique/version")).read())
|
v = urllib.request.urlopen(urllib.request.Request("https://packages.azlux.fr/botamusique/version")).read()
|
||||||
return v
|
return v.rstrip().decode()
|
||||||
|
|
||||||
|
|
||||||
def update(version):
|
def update(version):
|
||||||
global log
|
global log
|
||||||
|
|
||||||
v = new_release_version()
|
new_version = new_release_version()
|
||||||
if v > version:
|
if version.parse(new_version) > version.parse(version):
|
||||||
log.info('update: new version, start updating...')
|
log.info('update: new version, start updating...')
|
||||||
tp = sp.check_output(['/usr/bin/env', 'bash', 'update.sh']).decode()
|
target = var.config.get('bot','target_version')
|
||||||
|
tp = sp.check_output(['/usr/bin/env', 'bash', 'update.sh', target]).decode()
|
||||||
log.debug(tp)
|
log.debug(tp)
|
||||||
log.info('update: update pip librairies dependancies')
|
log.info('update: update pip librairies dependancies')
|
||||||
tp = sp.check_output([var.config.get('bot', 'pip3_path'), 'install', '--upgrade', '-r', 'requirements.txt']).decode()
|
tp = 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."
|
||||||
|
|
||||||
else:
|
else:
|
||||||
log.info('update: starting update youtube-dl via pip3')
|
log.info('update: starting update youtube-dl 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', 'youtube-dl']).decode()
|
||||||
@ -286,6 +296,7 @@ def update(version):
|
|||||||
msg += "<br/> Youtube-dl reloaded"
|
msg += "<br/> Youtube-dl reloaded"
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
|
|
||||||
def user_ban(user):
|
def user_ban(user):
|
||||||
var.db.set("user_ban", user, None)
|
var.db.set("user_ban", user, None)
|
||||||
res = "User " + user + " banned"
|
res = "User " + user + " banned"
|
||||||
@ -316,6 +327,7 @@ def url_unban(url):
|
|||||||
res = "Done"
|
res = "Done"
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
def pipe_no_wait(pipefd):
|
def pipe_no_wait(pipefd):
|
||||||
''' Used to fetch the STDERR of ffmpeg. pipefd is the file descriptor returned from os.pipe()'''
|
''' Used to fetch the STDERR of ffmpeg. pipefd is the file descriptor returned from os.pipe()'''
|
||||||
if platform == "linux" or platform == "linux2" or platform == "darwin":
|
if platform == "linux" or platform == "linux2" or platform == "darwin":
|
||||||
@ -355,7 +367,6 @@ def pipe_no_wait(pipefd):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Dir(object):
|
class Dir(object):
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
self.name = os.path.basename(path.strip('/'))
|
self.name = os.path.basename(path.strip('/'))
|
||||||
@ -432,7 +443,7 @@ class Dir(object):
|
|||||||
|
|
||||||
for key, val in self.subdirs.items():
|
for key, val in self.subdirs.items():
|
||||||
files.extend(map(lambda file: key + '/' + file, val.get_files_recursively()))
|
files.extend(map(lambda file: key + '/' + file, val.get_files_recursively()))
|
||||||
|
|
||||||
return files
|
return files
|
||||||
|
|
||||||
def render_text(self, ident=0):
|
def render_text(self, ident=0):
|
||||||
@ -453,4 +464,4 @@ def get_url_from_input(string):
|
|||||||
if res:
|
if res:
|
||||||
return res.group(1)
|
return res.group(1)
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user