Lot of new features
Web interface almost ready, better bot
This commit is contained in:
parent
6c9dfdc5ad
commit
7057252420
@ -4,11 +4,8 @@ volume = 0.1
|
|||||||
admin = Azlux;AzMobile
|
admin = Azlux;AzMobile
|
||||||
music_folder = /home/dmichel/botamusique/music/
|
music_folder = /home/dmichel/botamusique/music/
|
||||||
tmp_folder = /tmp/
|
tmp_folder = /tmp/
|
||||||
is_proxified = True
|
web_interace = False
|
||||||
|
is_web_proxified = True
|
||||||
[debug]
|
|
||||||
ffmpeg = False
|
|
||||||
mumbleConnection = False
|
|
||||||
|
|
||||||
[command]
|
[command]
|
||||||
play_file = file
|
play_file = file
|
||||||
@ -25,6 +22,12 @@ kill = kill
|
|||||||
stop_and_getout = oust
|
stop_and_getout = oust
|
||||||
joinme = joinme
|
joinme = joinme
|
||||||
|
|
||||||
|
[radio]
|
||||||
|
ponyville = http://192.99.131.205:8000/stream.mp3
|
||||||
|
luna = http://radio.ponyvillelive.com:8002/stream
|
||||||
|
radiobrony = http://62.210.138.34:8000/live
|
||||||
|
celestiaradio = http://celestia.aiverse.org:8000/mp3_256
|
||||||
|
jazz = http://jazz-wr04.ice.infomaniak.ch/jazz-wr04-128.mp3
|
||||||
|
|
||||||
[strings]
|
[strings]
|
||||||
current_volume = volume : %d%%
|
current_volume = volume : %d%%
|
||||||
@ -35,6 +38,7 @@ not_playing = Aucun stream en lecture
|
|||||||
bad_file = Bad file asked
|
bad_file = Bad file asked
|
||||||
no_file = Not file here
|
no_file = Not file here
|
||||||
bad_url = Bad URL asked
|
bad_url = Bad URL asked
|
||||||
|
empty_playlist = No more music into the playlist
|
||||||
|
|
||||||
help = Command available:
|
help = Command available:
|
||||||
<br />!play_file <path>
|
<br />!play_file <path>
|
||||||
@ -45,3 +49,7 @@ help = Command available:
|
|||||||
<br />!play_file - stop + Go to default channel
|
<br />!play_file - stop + Go to default channel
|
||||||
<br />!v - get or change the volume (in %)
|
<br />!v - get or change the volume (in %)
|
||||||
<br />!joinme
|
<br />!joinme
|
||||||
|
|
||||||
|
[debug]
|
||||||
|
ffmpeg = False
|
||||||
|
mumbleConnection = False
|
21
interface.py
21
interface.py
@ -64,27 +64,30 @@ def index():
|
|||||||
files[director] = [f for f in listdir(folder_path + director) if os.path.isfile(os.path.join(folder_path + director, f))]
|
files[director] = [f for f in listdir(folder_path + director) if os.path.isfile(os.path.join(folder_path + director, f))]
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
if 'add_file' in request.form and ".." not in request.form['add_music']:
|
if 'add_music' in request.form and ".." not in request.form['add_music']:
|
||||||
var.playlist.append((request.form['type'], request.form['add_music']))
|
var.playlist.append(['file', request.form['add_music']])
|
||||||
|
|
||||||
|
if 'add_url' in request.form :
|
||||||
|
var.playlist.append(['url', request.form['add_url']])
|
||||||
|
|
||||||
|
if 'add_radio' in request.form:
|
||||||
|
var.playlist.append(['radio', request.form['add_radio']])
|
||||||
|
|
||||||
if 'add_folder' in request.form and ".." not in request.form['add_folder']:
|
if 'add_folder' in request.form and ".." not in request.form['add_folder']:
|
||||||
dir_files = [("file", request.form['add_folder'] + '/' + i) for i in files[request.form['add_folder']]]
|
dir_files = [["file", request.form['add_folder'] + '/' + i] for i in files[request.form['add_folder']]]
|
||||||
var.playlist.extend(dir_files)
|
var.playlist.extend(dir_files)
|
||||||
elif 'delete_music' in request.form:
|
elif 'delete_music' in request.form:
|
||||||
try:
|
try:
|
||||||
var.playlist.remove("file", request.form['delete_music'])
|
var.playlist.remove(["file", request.form['delete_music']])
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
elif 'action' in request.form:
|
elif 'action' in request.form:
|
||||||
action = request.form['action']
|
action = request.form['action']
|
||||||
if action == "randomize":
|
if action == "randomize":
|
||||||
random.shuffle(var.playlist)
|
random.shuffle(var.playlist)
|
||||||
if var.current_music:
|
|
||||||
current_music = var.current_music[len(var.music_folder):]
|
|
||||||
else:
|
|
||||||
current_music = None
|
|
||||||
|
|
||||||
return render_template('index.html',
|
return render_template('index.html',
|
||||||
current_music=current_music,
|
current_music=var.current_music,
|
||||||
user=var.user,
|
user=var.user,
|
||||||
playlist=var.playlist,
|
playlist=var.playlist,
|
||||||
all_files=files)
|
all_files=files)
|
||||||
|
17
media.py
17
media.py
@ -18,7 +18,7 @@ def get_radio_server_description(url):
|
|||||||
response = urllib.request.urlopen(request)
|
response = urllib.request.urlopen(request)
|
||||||
data = json.loads(response.read().decode("utf-8"))
|
data = json.loads(response.read().decode("utf-8"))
|
||||||
title_server = data['servertitle']
|
title_server = data['servertitle']
|
||||||
logging.debug("TITLE FOUND SHOUTCAST: " + title_server)
|
logging.info("TITLE FOUND SHOUTCAST: " + title_server)
|
||||||
except urllib.error.HTTPError:
|
except urllib.error.HTTPError:
|
||||||
pass
|
pass
|
||||||
except http.client.BadStatusLine:
|
except http.client.BadStatusLine:
|
||||||
@ -32,7 +32,7 @@ def get_radio_server_description(url):
|
|||||||
response = urllib.request.urlopen(request)
|
response = urllib.request.urlopen(request)
|
||||||
data = json.loads(response.read().decode('utf-8', errors='ignore'), strict=False)
|
data = json.loads(response.read().decode('utf-8', errors='ignore'), strict=False)
|
||||||
title_server = data['icestats']['source'][0]['server_name'] + ' - ' + data['icestats']['source'][0]['server_description']
|
title_server = data['icestats']['source'][0]['server_name'] + ' - ' + data['icestats']['source'][0]['server_description']
|
||||||
logging.debug("TITLE FOUND ICECAST: " + title_server)
|
logging.info("TITLE FOUND ICECAST: " + title_server)
|
||||||
if not title_server:
|
if not title_server:
|
||||||
title_server = url
|
title_server = url
|
||||||
except urllib.error.URLError:
|
except urllib.error.URLError:
|
||||||
@ -55,7 +55,7 @@ def get_radio_title(url):
|
|||||||
|
|
||||||
metadata_length = struct.unpack('B', response.read(1))[0] * 16 # length byte
|
metadata_length = struct.unpack('B', response.read(1))[0] * 16 # length byte
|
||||||
metadata = response.read(metadata_length).rstrip(b'\0')
|
metadata = response.read(metadata_length).rstrip(b'\0')
|
||||||
logging.debug(metadata)
|
logging.info(metadata)
|
||||||
# extract title from the metadata
|
# extract title from the metadata
|
||||||
m = re.search(br"StreamTitle='([^']*)';", metadata)
|
m = re.search(br"StreamTitle='([^']*)';", metadata)
|
||||||
if m:
|
if m:
|
||||||
@ -65,3 +65,14 @@ def get_radio_title(url):
|
|||||||
except (urllib.error.URLError, urllib.error.HTTPError):
|
except (urllib.error.URLError, urllib.error.HTTPError):
|
||||||
pass
|
pass
|
||||||
return 'Impossible to get the music title'
|
return 'Impossible to get the music title'
|
||||||
|
|
||||||
|
|
||||||
|
def get_url(string):
|
||||||
|
if string.startswith('http'):
|
||||||
|
return string
|
||||||
|
p = re.compile('href="(.+)"', re.IGNORECASE)
|
||||||
|
res = re.search(p, string)
|
||||||
|
if res:
|
||||||
|
return res.group(1)
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
49
mumbleBot.py
49
mumbleBot.py
@ -18,6 +18,7 @@ import variables as var
|
|||||||
import hashlib
|
import hashlib
|
||||||
import youtube_dl
|
import youtube_dl
|
||||||
import media
|
import media
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
class MumbleBot:
|
class MumbleBot:
|
||||||
@ -33,6 +34,7 @@ class MumbleBot:
|
|||||||
parser.add_argument("-P", "--password", dest="password", type=str, default="", help="Password if server requires one")
|
parser.add_argument("-P", "--password", dest="password", type=str, default="", help="Password if server requires one")
|
||||||
parser.add_argument("-p", "--port", dest="port", type=int, default=64738, help="Port for the mumble server")
|
parser.add_argument("-p", "--port", dest="port", type=int, default=64738, help="Port for the mumble server")
|
||||||
parser.add_argument("-c", "--channel", dest="channel", type=str, default="", help="Default chanel for the bot")
|
parser.add_argument("-c", "--channel", dest="channel", type=str, default="", help="Default chanel for the bot")
|
||||||
|
parser.add_argument("-q", "--quiet", dest="quiet", action="store_true", help="Only Error logs")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
self.volume = self.config.getfloat('bot', 'volume')
|
self.volume = self.config.getfloat('bot', 'volume')
|
||||||
@ -40,6 +42,12 @@ class MumbleBot:
|
|||||||
self.channel = args.channel
|
self.channel = args.channel
|
||||||
var.current_music = None
|
var.current_music = None
|
||||||
|
|
||||||
|
FORMAT = '%(asctime)s: %(message)s'
|
||||||
|
if args.quiet:
|
||||||
|
logging.basicConfig(format=FORMAT, level=logging.ERROR, datefmt='%Y-%m-%d %H:%M:%S')
|
||||||
|
else:
|
||||||
|
logging.basicConfig(format=FORMAT, level=logging.DEBUG, datefmt='%Y-%m-%d %H:%M:%S')
|
||||||
|
|
||||||
######
|
######
|
||||||
## Format of the Playlist :
|
## Format of the Playlist :
|
||||||
## [("<type>","<path>")]
|
## [("<type>","<path>")]
|
||||||
@ -59,16 +67,17 @@ class MumbleBot:
|
|||||||
|
|
||||||
var.user = args.user
|
var.user = args.user
|
||||||
var.music_folder = self.config.get('bot', 'music_folder')
|
var.music_folder = self.config.get('bot', 'music_folder')
|
||||||
var.is_proxified = self.config.getboolean("bot", "is_proxified")
|
var.is_proxified = self.config.getboolean("bot", "is_web_proxified")
|
||||||
|
|
||||||
self.exit = False
|
self.exit = False
|
||||||
self.nb_exit = 0
|
self.nb_exit = 0
|
||||||
self.thread = None
|
self.thread = None
|
||||||
|
|
||||||
|
if args.web_interace:
|
||||||
interface.init_proxy()
|
interface.init_proxy()
|
||||||
|
t = threading.Thread(target=start_web_interface)
|
||||||
# t = threading.Thread(target=start_web_interface)
|
t.daemon = True
|
||||||
# t.daemon = True
|
t.start()
|
||||||
# t.start()
|
|
||||||
|
|
||||||
self.mumble = pymumble.Mumble(args.host, user=args.user, port=args.port, password=args.password,
|
self.mumble = pymumble.Mumble(args.host, user=args.user, port=args.port, password=args.password,
|
||||||
debug=self.config.getboolean('debug', 'mumbleConnection'))
|
debug=self.config.getboolean('debug', 'mumbleConnection'))
|
||||||
@ -86,11 +95,11 @@ class MumbleBot:
|
|||||||
self.loop()
|
self.loop()
|
||||||
|
|
||||||
def ctrl_caught(self, signal, frame):
|
def ctrl_caught(self, signal, frame):
|
||||||
print("\ndeconnection asked")
|
logging.info("\ndeconnection asked")
|
||||||
self.exit = True
|
self.exit = True
|
||||||
self.stop()
|
self.stop()
|
||||||
if self.nb_exit > 1:
|
if self.nb_exit > 1:
|
||||||
print("Forced Quit")
|
logging.info("Forced Quit")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
self.nb_exit += 1
|
self.nb_exit += 1
|
||||||
|
|
||||||
@ -106,7 +115,7 @@ class MumbleBot:
|
|||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
print(command + ' - ' + parameter + ' by ' + self.mumble.users[text.actor]['name'])
|
logging.info(command + ' - ' + parameter + ' by ' + self.mumble.users[text.actor]['name'])
|
||||||
|
|
||||||
if command == self.config.get('command', 'play_file') and parameter:
|
if command == self.config.get('command', 'play_file') and parameter:
|
||||||
path = self.config.get('bot', 'music_folder') + parameter
|
path = self.config.get('bot', 'music_folder') + parameter
|
||||||
@ -121,6 +130,8 @@ class MumbleBot:
|
|||||||
var.playlist.append(["url", parameter])
|
var.playlist.append(["url", parameter])
|
||||||
|
|
||||||
elif command == self.config.get('command', 'play_radio') and parameter:
|
elif command == self.config.get('command', 'play_radio') and parameter:
|
||||||
|
if self.config.has_option('radio', parameter):
|
||||||
|
parameter = self.config.get('radio', parameter)
|
||||||
var.playlist.append(["radio", parameter])
|
var.playlist.append(["radio", parameter])
|
||||||
|
|
||||||
elif command == self.config.get('command', 'help'):
|
elif command == self.config.get('command', 'help'):
|
||||||
@ -162,9 +173,14 @@ class MumbleBot:
|
|||||||
self.mumble.users[text.actor].send_message(self.config.get('strings', 'not_playing'))
|
self.mumble.users[text.actor].send_message(self.config.get('strings', 'not_playing'))
|
||||||
|
|
||||||
elif command == self.config.get('command', 'next'):
|
elif command == self.config.get('command', 'next'):
|
||||||
|
if var.playlist:
|
||||||
var.current_music = var.playlist[0]
|
var.current_music = var.playlist[0]
|
||||||
var.playlist.pop(0)
|
var.playlist.pop(0)
|
||||||
self.launch_next()
|
self.launch_next()
|
||||||
|
else:
|
||||||
|
self.mumble.users[text.actor].send_message(self.config.get('strings', 'empty_playlist'))
|
||||||
|
self.stop()
|
||||||
|
|
||||||
else:
|
else:
|
||||||
self.mumble.users[text.actor].send_message(self.config.get('strings', 'bad_command'))
|
self.mumble.users[text.actor].send_message(self.config.get('strings', 'bad_command'))
|
||||||
|
|
||||||
@ -180,9 +196,9 @@ class MumbleBot:
|
|||||||
path = ""
|
path = ""
|
||||||
title = ""
|
title = ""
|
||||||
if var.current_music[0] == "url":
|
if var.current_music[0] == "url":
|
||||||
regex = re.compile("<a href=\"(.*?)\"")
|
url = media.get_url(var.current_music[1])
|
||||||
m = regex.match(var.current_music[1])
|
if not url:
|
||||||
url = m.group(1)
|
return
|
||||||
path, title = self.download_music(url)
|
path, title = self.download_music(url)
|
||||||
var.current_music[1] = url
|
var.current_music[1] = url
|
||||||
|
|
||||||
@ -191,9 +207,9 @@ class MumbleBot:
|
|||||||
title = var.current_music[1]
|
title = var.current_music[1]
|
||||||
|
|
||||||
elif var.current_music[0] == "radio":
|
elif var.current_music[0] == "radio":
|
||||||
regex = re.compile("<a href=\"(.*?)\"")
|
url = media.get_url(var.current_music[1])
|
||||||
m = regex.match(var.current_music[1])
|
if not url:
|
||||||
url = m.group(1)
|
return
|
||||||
var.current_music[1] = url
|
var.current_music[1] = url
|
||||||
path = url
|
path = url
|
||||||
title = media.get_radio_server_description(url)
|
title = media.get_radio_server_description(url)
|
||||||
@ -249,10 +265,13 @@ class MumbleBot:
|
|||||||
else:
|
else:
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
if (self.thread is None or not raw_music) and len(var.playlist) != 0:
|
if self.thread is None or not raw_music:
|
||||||
|
if len(var.playlist) != 0:
|
||||||
var.current_music = var.playlist[0]
|
var.current_music = var.playlist[0]
|
||||||
var.playlist.pop(0)
|
var.playlist.pop(0)
|
||||||
self.launch_next()
|
self.launch_next()
|
||||||
|
elif len(var.playlist) == 0 and var.current_music:
|
||||||
|
var.current_music = None
|
||||||
|
|
||||||
while self.mumble.sound_output.get_buffer_size() > 0:
|
while self.mumble.sound_output.get_buffer_size() > 0:
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
|
@ -20,10 +20,24 @@
|
|||||||
<input type="submit" value="Upload"/>
|
<input type="submit" value="Upload"/>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="url">
|
||||||
|
Add Youtube/Soundcloud URL :
|
||||||
|
<form method="post">
|
||||||
|
<input type=text name="add_url">
|
||||||
|
<input type="submit" value="Add URL">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div id="radio">
|
||||||
|
Add Radio URL :
|
||||||
|
<form method="post">
|
||||||
|
<input type=text name="add_radio">
|
||||||
|
<input type="submit" value="Add Radio">
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
<div id="playlist">
|
<div id="playlist">
|
||||||
Current Playing :
|
Current Playing :
|
||||||
{% if current_music %}
|
{% if current_music %}
|
||||||
{{ current_music }}
|
{{ current_music[0] }} > {{ current_music[2] }}
|
||||||
{% else %}
|
{% else %}
|
||||||
No music
|
No music
|
||||||
{% endif %}
|
{% endif %}
|
||||||
@ -33,8 +47,8 @@
|
|||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
{% for m in playlist %}
|
{% for m in playlist %}
|
||||||
<li>{{ m }}
|
<li>{{ m[0] }} - {{ m[1] }}
|
||||||
<form method="post"><input type=text value="{{ m }}" name="delete_music" hidden><input type="submit" value="X"></form>
|
<form method="post"><input type=text value="{{ m }}" name="delete_music" type="file" hidden><input type="submit" value="X"></form>
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user