diff --git a/configuration.default.ini b/configuration.default.ini
index 14867d6..5e0eec3 100644
--- a/configuration.default.ini
+++ b/configuration.default.ini
@@ -34,6 +34,9 @@ volume = 0.1
# playback mode should be one of "one-shot", "loop", "random"
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.
admin = User1;User2;
# Folder that stores your local songs.
diff --git a/configuration.example.ini b/configuration.example.ini
index b337313..608ce2b 100644
--- a/configuration.example.ini
+++ b/configuration.example.ini
@@ -34,6 +34,10 @@ port = 64738
# This option will be overridden by value in the database.
#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 = User1;User2;
diff --git a/mumbleBot.py b/mumbleBot.py
index c7f2c85..c5d7330 100644
--- a/mumbleBot.py
+++ b/mumbleBot.py
@@ -20,6 +20,7 @@ import youtube_dl
import logging
import logging.handlers
import traceback
+from packaging import version
import util
import command
@@ -33,6 +34,7 @@ import media.system
from librb import radiobrowser
from media.playlist import PlayList
+
"""
FORMAT OF A MUSIC INTO THE PLAYLIST
type : url
@@ -65,7 +67,7 @@ type : file
class MumbleBot:
- version = 5
+ version = 5.1
def __init__(self, args):
self.log = logging.getLogger("bot")
@@ -196,7 +198,7 @@ class MumbleBot:
def check_update(self):
self.log.debug("update: checking for updates...")
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.send_msg(constants.strings('new_version_found'))
else:
diff --git a/requirements.txt b/requirements.txt
index 878d03e..1ad1752 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -6,3 +6,4 @@ python-magic
Pillow
mutagen
requests
+packaging
diff --git a/update.sh b/update.sh
index a06e1b3..4f5c375 100644
--- a/update.sh
+++ b/update.sh
@@ -1,5 +1,20 @@
-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
+#!/usr/bin/env bash
+
+case "$1" in
+ stable)
+ 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
diff --git a/util.py b/util.py
index 7841dd8..be4b79c 100644
--- a/util.py
+++ b/util.py
@@ -21,9 +21,11 @@ from sys import platform
import base64
import media
import media.radio
+from packaging import version
log = logging.getLogger("bot")
+
def solve_filepath(path):
if not path:
return ''
@@ -34,7 +36,8 @@ def solve_filepath(path):
mydir = os.path.dirname(os.path.realpath(__file__))
return mydir + '/' + path
-def get_recursive_filelist_sorted(path):
+
+def get_recursive_file_list_sorted(path):
filelist = []
for root, dirs, files in os.walk(path):
relroot = root.replace(path, '', 1)
@@ -57,6 +60,7 @@ def get_recursive_filelist_sorted(path):
filelist.sort()
return filelist
+
def get_music_path(music):
uri = ''
if music["type"] == "url":
@@ -95,7 +99,7 @@ def get_music_tag_info(music):
tags = mutagen.File(uri)
if 'TIT2' in tags:
music['title'] = tags['TIT2'].text[0]
- if 'TPE1' in tags: # artist
+ if 'TPE1' in tags: # artist
music['artist'] = tags['TPE1'].text[0]
if im is None:
@@ -110,7 +114,7 @@ def get_music_tag_info(music):
tags = mutagen.File(uri)
if '©nam' in tags:
music['title'] = tags['©nam'][0]
- if '©ART' in tags: # artist
+ if '©ART' in tags: # artist
music['artist'] = tags['©ART'][0]
if im is None:
@@ -135,6 +139,7 @@ def get_music_tag_info(music):
return music
+
def format_song_string(music):
display = ''
source = music["type"]
@@ -169,6 +174,7 @@ def format_song_string(music):
return display
+
def format_debug_song_string(music):
display = ''
source = music["type"]
@@ -203,6 +209,7 @@ def format_debug_song_string(music):
return display
+
def format_current_playing():
music = var.playlist.current_item()
display = format_song_string(music)
@@ -229,7 +236,7 @@ def zipdir(zippath, zipname_prefix=None):
if zipname_prefix and '../' not in zipname_prefix:
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()
zipname += hash + '.zip'
@@ -258,22 +265,25 @@ def get_user_ban():
res += "
" + i[0]
return res
+
def new_release_version():
- v = int(urllib.request.urlopen(urllib.request.Request("https://azlux.fr/botamusique/version")).read())
- return v
+ v = urllib.request.urlopen(urllib.request.Request("https://packages.azlux.fr/botamusique/version")).read()
+ return v.rstrip().decode()
+
def update(version):
global log
- v = new_release_version()
- if v > version:
+ new_version = new_release_version()
+ if version.parse(new_version) > version.parse(version):
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.info('update: update pip librairies dependancies')
tp = sp.check_output([var.config.get('bot', 'pip3_path'), 'install', '--upgrade', '-r', 'requirements.txt']).decode()
msg = "New version installed, please restart the bot."
-
+
else:
log.info('update: starting update youtube-dl via pip3')
tp = sp.check_output([var.config.get('bot', 'pip3_path'), 'install', '--upgrade', 'youtube-dl']).decode()
@@ -286,6 +296,7 @@ def update(version):
msg += "
Youtube-dl reloaded"
return msg
+
def user_ban(user):
var.db.set("user_ban", user, None)
res = "User " + user + " banned"
@@ -316,6 +327,7 @@ def url_unban(url):
res = "Done"
return res
+
def pipe_no_wait(pipefd):
''' 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":
@@ -355,7 +367,6 @@ def pipe_no_wait(pipefd):
return True
-
class Dir(object):
def __init__(self, path):
self.name = os.path.basename(path.strip('/'))
@@ -432,7 +443,7 @@ class Dir(object):
for key, val in self.subdirs.items():
files.extend(map(lambda file: key + '/' + file, val.get_files_recursively()))
-
+
return files
def render_text(self, ident=0):
@@ -453,4 +464,4 @@ def get_url_from_input(string):
if res:
return res.group(1)
else:
- return False
\ No newline at end of file
+ return False