reformat logging
This commit is contained in:
parent
66bf4d94a1
commit
eb95fdcb58
17
interface.py
17
interface.py
@ -141,7 +141,8 @@ def index():
|
|||||||
|
|
||||||
files = list(map(lambda file: var.botamusique.get_music_tag_info({'type':'file','path': os.path.join(folder, file), 'user':'Web'}, \
|
files = list(map(lambda file: var.botamusique.get_music_tag_info({'type':'file','path': os.path.join(folder, file), 'user':'Web'}, \
|
||||||
var.config.get('bot', 'music_folder') + os.path.join(folder, file)), files))
|
var.config.get('bot', 'music_folder') + os.path.join(folder, file)), files))
|
||||||
print('Adding to playlist: ', files)
|
|
||||||
|
logging.info("adding to play list: " + " ,".join([file['path'] for file in files]))
|
||||||
var.playlist.extend(files)
|
var.playlist.extend(files)
|
||||||
|
|
||||||
elif 'add_url' in request.form:
|
elif 'add_url' in request.form:
|
||||||
@ -198,13 +199,13 @@ def index():
|
|||||||
var.botamusique.volume = var.botamusique.volume + 0.03
|
var.botamusique.volume = var.botamusique.volume + 0.03
|
||||||
else:
|
else:
|
||||||
var.botamusique.volume = 1.0
|
var.botamusique.volume = 1.0
|
||||||
logging.debug("web interface volume up to %.2f" % var.botamusique.volume)
|
logging.info("web interface volume up to %.2f" % var.botamusique.volume)
|
||||||
elif action == "volume_down":
|
elif action == "volume_down":
|
||||||
if var.botamusique.volume - 0.03 > 0:
|
if var.botamusique.volume - 0.03 > 0:
|
||||||
var.botamusique.volume = var.botamusique.volume - 0.03
|
var.botamusique.volume = var.botamusique.volume - 0.03
|
||||||
else:
|
else:
|
||||||
var.botamusique.volume = 0
|
var.botamusique.volume = 0
|
||||||
logging.debug("web interface volume down to %.2f" % var.botamusique.volume)
|
logging.info("web interface volume down to %.2f" % var.botamusique.volume)
|
||||||
|
|
||||||
return render_template('index.html',
|
return render_template('index.html',
|
||||||
all_files=files,
|
all_files=files,
|
||||||
@ -232,10 +233,10 @@ def upload():
|
|||||||
elif '../' in targetdir:
|
elif '../' in targetdir:
|
||||||
return redirect("./", code=406)
|
return redirect("./", code=406)
|
||||||
|
|
||||||
print('Uploading file:')
|
logging.info('Uploading file:')
|
||||||
print('filename:', filename)
|
logging.info(' - filename:', filename)
|
||||||
print('targetdir:', targetdir)
|
logging.info(' - targetdir:', targetdir)
|
||||||
print('mimetype:', file.mimetype)
|
logging.info(' - mimetype:', file.mimetype)
|
||||||
|
|
||||||
if "audio" in file.mimetype:
|
if "audio" in file.mimetype:
|
||||||
storagepath = os.path.abspath(os.path.join(var.music_folder, targetdir))
|
storagepath = os.path.abspath(os.path.join(var.music_folder, targetdir))
|
||||||
@ -250,7 +251,7 @@ def upload():
|
|||||||
return redirect("./", code=500)
|
return redirect("./", code=500)
|
||||||
|
|
||||||
filepath = os.path.join(storagepath, filename)
|
filepath = os.path.join(storagepath, filename)
|
||||||
print('filepath:',filepath)
|
logging.info(' - filepath: ', filepath)
|
||||||
if os.path.exists(filepath):
|
if os.path.exists(filepath):
|
||||||
return redirect("./", code=406)
|
return redirect("./", code=406)
|
||||||
|
|
||||||
|
49
mumbleBot.py
49
mumbleBot.py
@ -195,7 +195,7 @@ class MumbleBot:
|
|||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
logging.info(command + ' - ' + parameter + ' by ' + user)
|
logging.info('bot: received command ' + command + ' - ' + parameter + ' by ' + user)
|
||||||
|
|
||||||
if command == var.config.get('command', 'joinme'):
|
if command == var.config.get('command', 'joinme'):
|
||||||
self.mumble.users.myself.move_in(
|
self.mumble.users.myself.move_in(
|
||||||
@ -288,6 +288,7 @@ class MumbleBot:
|
|||||||
music = {'type': 'file',
|
music = {'type': 'file',
|
||||||
'path': filename,
|
'path': filename,
|
||||||
'user': user}
|
'user': user}
|
||||||
|
logging.info("bot: add to playlist: " + filename)
|
||||||
var.playlist.append(music)
|
var.playlist.append(music)
|
||||||
else:
|
else:
|
||||||
# try to do a partial match
|
# try to do a partial match
|
||||||
@ -300,6 +301,7 @@ class MumbleBot:
|
|||||||
music = {'type': 'file',
|
music = {'type': 'file',
|
||||||
'path': matches[0],
|
'path': matches[0],
|
||||||
'user': user}
|
'user': user}
|
||||||
|
logging.info("bot: add to playlist: " + matches[0])
|
||||||
var.playlist.append(music)
|
var.playlist.append(music)
|
||||||
else:
|
else:
|
||||||
msg = var.config.get(
|
msg = var.config.get(
|
||||||
@ -329,6 +331,7 @@ class MumbleBot:
|
|||||||
return
|
return
|
||||||
music['ready'] = "no"
|
music['ready'] = "no"
|
||||||
var.playlist.append(music)
|
var.playlist.append(music)
|
||||||
|
logging.info("bot: add to playlist: " + music['url'])
|
||||||
self.async_download_next()
|
self.async_download_next()
|
||||||
else:
|
else:
|
||||||
self.send_msg(var.config.get(
|
self.send_msg(var.config.get(
|
||||||
@ -365,24 +368,25 @@ class MumbleBot:
|
|||||||
'url': url,
|
'url': url,
|
||||||
'user': user}
|
'user': user}
|
||||||
var.playlist.append(music)
|
var.playlist.append(music)
|
||||||
|
logging.info("bot: add to playlist: " + music['url'])
|
||||||
self.async_download_next()
|
self.async_download_next()
|
||||||
else:
|
else:
|
||||||
self.send_msg(var.config.get('strings', 'bad_url'))
|
self.send_msg(var.config.get('strings', 'bad_url'))
|
||||||
# query http://www.radio-browser.info API for a radio station
|
# query http://www.radio-browser.info API for a radio station
|
||||||
elif command == var.config.get('command', 'rb_query'):
|
elif command == var.config.get('command', 'rb_query'):
|
||||||
logging.info('Querying radio stations')
|
logging.info('bot: Querying radio stations')
|
||||||
if not parameter:
|
if not parameter:
|
||||||
logging.debug('rbquery without parameter')
|
logging.debug('rbquery without parameter')
|
||||||
msg += 'You have to add a query text to search for a matching radio stations.'
|
msg += 'You have to add a query text to search for a matching radio stations.'
|
||||||
self.send_msg(msg, text)
|
self.send_msg(msg, text)
|
||||||
else:
|
else:
|
||||||
logging.debug('Found query parameter: ' + parameter)
|
logging.debug('bot: Found query parameter: ' + parameter)
|
||||||
# self.send_msg('Searching for stations - this may take some seconds...', text)
|
# self.send_msg('Searching for stations - this may take some seconds...', text)
|
||||||
rb_stations = radiobrowser.getstations_byname(parameter)
|
rb_stations = radiobrowser.getstations_byname(parameter)
|
||||||
msg = var.config.get('strings', 'rbqueryresult') + " :"
|
msg = var.config.get('strings', 'rbqueryresult') + " :"
|
||||||
msg += '\n<table><tr><th>!rbplay ID</th><th>Station Name</th><th>Genre</th><th>Codec/Bitrate</th><th>Country</th></tr>'
|
msg += '\n<table><tr><th>!rbplay ID</th><th>Station Name</th><th>Genre</th><th>Codec/Bitrate</th><th>Country</th></tr>'
|
||||||
if not rb_stations:
|
if not rb_stations:
|
||||||
logging.debug('No matches found for rbquery ' + parameter)
|
logging.debug('bot: No matches found for rbquery ' + parameter)
|
||||||
self.send_msg('Radio-Browser found no matches for ' + parameter, text)
|
self.send_msg('Radio-Browser found no matches for ' + parameter, text)
|
||||||
else:
|
else:
|
||||||
for s in rb_stations:
|
for s in rb_stations:
|
||||||
@ -400,7 +404,7 @@ class MumbleBot:
|
|||||||
self.send_msg(msg, text)
|
self.send_msg(msg, text)
|
||||||
# Shorten message if message too long (stage I)
|
# Shorten message if message too long (stage I)
|
||||||
else:
|
else:
|
||||||
logging.debug('Result too long stage I')
|
logging.debug('bot: Result too long stage I')
|
||||||
msg = var.config.get('strings', 'rbqueryresult') + " :" + ' (shortened L1)'
|
msg = var.config.get('strings', 'rbqueryresult') + " :" + ' (shortened L1)'
|
||||||
msg += '\n<table><tr><th>!rbplay ID</th><th>Station Name</th></tr>'
|
msg += '\n<table><tr><th>!rbplay ID</th><th>Station Name</th></tr>'
|
||||||
for s in rb_stations:
|
for s in rb_stations:
|
||||||
@ -413,7 +417,7 @@ class MumbleBot:
|
|||||||
self.send_msg(msg, text)
|
self.send_msg(msg, text)
|
||||||
# Shorten message if message too long (stage II)
|
# Shorten message if message too long (stage II)
|
||||||
else:
|
else:
|
||||||
logging.debug('Result too long stage II')
|
logging.debug('bot: Result too long stage II')
|
||||||
msg = var.config.get('strings', 'rbqueryresult') + " :" + ' (shortened L2)'
|
msg = var.config.get('strings', 'rbqueryresult') + " :" + ' (shortened L2)'
|
||||||
msg += '!rbplay ID - Station Name'
|
msg += '!rbplay ID - Station Name'
|
||||||
for s in rb_stations:
|
for s in rb_stations:
|
||||||
@ -428,13 +432,13 @@ class MumbleBot:
|
|||||||
self.send_msg('Query result too long to post (> 5000 characters), please try another query.', text)
|
self.send_msg('Query result too long to post (> 5000 characters), please try another query.', text)
|
||||||
# Play a secific station (by id) from http://www.radio-browser.info API
|
# Play a secific station (by id) from http://www.radio-browser.info API
|
||||||
elif command == var.config.get('command', 'rb_play'):
|
elif command == var.config.get('command', 'rb_play'):
|
||||||
logging.debug('Play a station by ID')
|
logging.debug('bot: Play a station by ID')
|
||||||
if not parameter:
|
if not parameter:
|
||||||
logging.debug('rbplay without parameter')
|
logging.debug('bot: rbplay without parameter')
|
||||||
msg += 'Please enter a station ID from rbquery. Example: !rbplay 96748'
|
msg += 'Please enter a station ID from rbquery. Example: !rbplay 96748'
|
||||||
self.send_msg(msg, text)
|
self.send_msg(msg, text)
|
||||||
else:
|
else:
|
||||||
logging.debug('Retreiving url for station ID ' + parameter)
|
logging.debug('bot: Retreiving url for station ID ' + parameter)
|
||||||
rstation = radiobrowser.getstationname_byid(parameter)
|
rstation = radiobrowser.getstationname_byid(parameter)
|
||||||
stationname = rstation[0]['name']
|
stationname = rstation[0]['name']
|
||||||
country = rstation[0]['country']
|
country = rstation[0]['country']
|
||||||
@ -448,18 +452,19 @@ class MumbleBot:
|
|||||||
msg += '<table><tr><th>ID</th><th>Station Name</th><th>Genre</th><th>Codec/Bitrate</th><th>Country</th><th>Homepage</th></tr>' + \
|
msg += '<table><tr><th>ID</th><th>Station Name</th><th>Genre</th><th>Codec/Bitrate</th><th>Country</th><th>Homepage</th></tr>' + \
|
||||||
'<tr><td>%s</td><td>%s</td><td>%s</td><td>%s/%s</td><td>%s</td><td>%s</td></tr></table>' \
|
'<tr><td>%s</td><td>%s</td><td>%s</td><td>%s/%s</td><td>%s</td><td>%s</td></tr></table>' \
|
||||||
% (parameter, stationname, genre, codec, bitrate, country, homepage)
|
% (parameter, stationname, genre, codec, bitrate, country, homepage)
|
||||||
logging.debug('Added station to playlist %s' % stationname)
|
logging.debug('bot: Added station to playlist %s' % stationname)
|
||||||
self.send_msg(msg, text)
|
self.send_msg(msg, text)
|
||||||
url = radiobrowser.geturl_byid(parameter)
|
url = radiobrowser.geturl_byid(parameter)
|
||||||
if url != "-1":
|
if url != "-1":
|
||||||
logging.info('Found url: ' + url)
|
logging.info('bot: Found url: ' + url)
|
||||||
music = {'type': 'radio',
|
music = {'type': 'radio',
|
||||||
'url': url,
|
'url': url,
|
||||||
'user': user}
|
'user': user}
|
||||||
var.playlist.append(music)
|
var.playlist.append(music)
|
||||||
|
logging.info("bot: add to playlist: " + music['url'])
|
||||||
self.async_download_next()
|
self.async_download_next()
|
||||||
else:
|
else:
|
||||||
logging.info('No playable url found.')
|
logging.info('bot: No playable url found.')
|
||||||
msg += "No playable url found for this station, please try another station."
|
msg += "No playable url found for this station, please try another station."
|
||||||
self.send_msg(msg, text)
|
self.send_msg(msg, text)
|
||||||
|
|
||||||
@ -587,6 +592,10 @@ class MumbleBot:
|
|||||||
|
|
||||||
elif command == var.config.get('command', 'repeat'):
|
elif command == var.config.get('command', 'repeat'):
|
||||||
var.playlist.append(var.playlist.current_item())
|
var.playlist.append(var.playlist.current_item())
|
||||||
|
if var.playlist.current_item()['type'] == 'file':
|
||||||
|
logging.info("bot: add to playlist: " + music['path'])
|
||||||
|
else:
|
||||||
|
logging.info("bot: add to playlist: " + music['url'])
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.mumble.users[text.actor].send_text_message(
|
self.mumble.users[text.actor].send_text_message(
|
||||||
@ -602,7 +611,7 @@ class MumbleBot:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def next():
|
def next():
|
||||||
logging.debug("Next into the queue")
|
logging.debug("bot: Next into the queue")
|
||||||
return var.playlist.next()
|
return var.playlist.next()
|
||||||
|
|
||||||
def launch_music(self, index=-1):
|
def launch_music(self, index=-1):
|
||||||
@ -616,7 +625,7 @@ class MumbleBot:
|
|||||||
else:
|
else:
|
||||||
music = var.playlist.jump(index)
|
music = var.playlist.jump(index)
|
||||||
|
|
||||||
logging.debug("launch_music asked" + str(music['path']))
|
logging.info("bot: play music " + str(music['path']))
|
||||||
if music["type"] == "url":
|
if music["type"] == "url":
|
||||||
# Delete older music is the tmp folder is too big
|
# Delete older music is the tmp folder is too big
|
||||||
media.system.clear_tmp_folder(var.config.get(
|
media.system.clear_tmp_folder(var.config.get(
|
||||||
@ -704,7 +713,7 @@ class MumbleBot:
|
|||||||
url = music['url']
|
url = music['url']
|
||||||
url_hash = hashlib.md5(url.encode()).hexdigest()
|
url_hash = hashlib.md5(url.encode()).hexdigest()
|
||||||
|
|
||||||
logging.debug("Download url:" + url)
|
logging.info("bot: Download url:" + url)
|
||||||
logging.debug(music)
|
logging.debug(music)
|
||||||
|
|
||||||
path = var.config.get('bot', 'tmp_folder') + url_hash + ".%(ext)s"
|
path = var.config.get('bot', 'tmp_folder') + url_hash + ".%(ext)s"
|
||||||
@ -731,8 +740,8 @@ class MumbleBot:
|
|||||||
self.send_msg(var.config.get(
|
self.send_msg(var.config.get(
|
||||||
'strings', "download_in_progress") % music['title'])
|
'strings', "download_in_progress") % music['title'])
|
||||||
|
|
||||||
logging.info("Information before start downloading :" +
|
logging.info("Information before start downloading: " +
|
||||||
str(music))
|
str(music['title']))
|
||||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||||
for i in range(2): # Always try 2 times
|
for i in range(2): # Always try 2 times
|
||||||
try:
|
try:
|
||||||
@ -799,13 +808,13 @@ class MumbleBot:
|
|||||||
def async_download_next(self):
|
def async_download_next(self):
|
||||||
# Function start if the next music isn't ready
|
# Function start if the next music isn't ready
|
||||||
# Do nothing in case the next music is already downloaded
|
# Do nothing in case the next music is already downloaded
|
||||||
logging.info("Async download next asked ")
|
logging.info("bot: Async download next asked ")
|
||||||
if len(var.playlist.playlist) > 1 and var.playlist.next_item()['type'] == 'url' and var.playlist.next_item()['ready'] in ["no", "validation"]:
|
if len(var.playlist.playlist) > 1 and var.playlist.next_item()['type'] == 'url' and var.playlist.next_item()['ready'] in ["no", "validation"]:
|
||||||
th = threading.Thread(
|
th = threading.Thread(
|
||||||
target=self.download_music, kwargs={'index': var.playlist.next_index()})
|
target=self.download_music, kwargs={'index': var.playlist.next_index()})
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
logging.info("Start downloading next in thread")
|
logging.info("bot: Start downloading next in thread")
|
||||||
th.daemon = True
|
th.daemon = True
|
||||||
th.start()
|
th.start()
|
||||||
|
|
||||||
@ -870,6 +879,7 @@ class MumbleBot:
|
|||||||
self.thread = None
|
self.thread = None
|
||||||
var.playlist.clear()
|
var.playlist.clear()
|
||||||
self.is_playing = False
|
self.is_playing = False
|
||||||
|
logging.info("bot: music stopped. playlist trashed.")
|
||||||
|
|
||||||
def pause(self):
|
def pause(self):
|
||||||
# Kill the ffmpeg thread
|
# Kill the ffmpeg thread
|
||||||
@ -878,6 +888,7 @@ class MumbleBot:
|
|||||||
self.thread = None
|
self.thread = None
|
||||||
self.is_playing = False
|
self.is_playing = False
|
||||||
self.is_pause = True
|
self.is_pause = True
|
||||||
|
logging.info("bot: music paused.")
|
||||||
|
|
||||||
def set_comment(self):
|
def set_comment(self):
|
||||||
self.mumble.users.myself.comment(var.config.get('bot', 'comment'))
|
self.mumble.users.myself.comment(var.config.get('bot', 'comment'))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user