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
|
||||
music_folder = /home/dmichel/botamusique/music/
|
||||
tmp_folder = /tmp/
|
||||
is_proxified = True
|
||||
|
||||
[debug]
|
||||
ffmpeg = False
|
||||
mumbleConnection = False
|
||||
web_interace = False
|
||||
is_web_proxified = True
|
||||
|
||||
[command]
|
||||
play_file = file
|
||||
@ -25,6 +22,12 @@ kill = kill
|
||||
stop_and_getout = oust
|
||||
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]
|
||||
current_volume = volume : %d%%
|
||||
@ -35,6 +38,7 @@ not_playing = Aucun stream en lecture
|
||||
bad_file = Bad file asked
|
||||
no_file = Not file here
|
||||
bad_url = Bad URL asked
|
||||
empty_playlist = No more music into the playlist
|
||||
|
||||
help = Command available:
|
||||
<br />!play_file <path>
|
||||
@ -45,3 +49,7 @@ help = Command available:
|
||||
<br />!play_file - stop + Go to default channel
|
||||
<br />!v - get or change the volume (in %)
|
||||
<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))]
|
||||
|
||||
if request.method == 'POST':
|
||||
if 'add_file' in request.form and ".." not in request.form['add_music']:
|
||||
var.playlist.append((request.form['type'], request.form['add_music']))
|
||||
if 'add_music' in request.form and ".." not in 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']:
|
||||
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)
|
||||
elif 'delete_music' in request.form:
|
||||
try:
|
||||
var.playlist.remove("file", request.form['delete_music'])
|
||||
var.playlist.remove(["file", request.form['delete_music']])
|
||||
except ValueError:
|
||||
pass
|
||||
elif 'action' in request.form:
|
||||
action = request.form['action']
|
||||
if action == "randomize":
|
||||
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',
|
||||
current_music=current_music,
|
||||
current_music=var.current_music,
|
||||
user=var.user,
|
||||
playlist=var.playlist,
|
||||
all_files=files)
|
||||
|
19
media.py
19
media.py
@ -18,7 +18,7 @@ def get_radio_server_description(url):
|
||||
response = urllib.request.urlopen(request)
|
||||
data = json.loads(response.read().decode("utf-8"))
|
||||
title_server = data['servertitle']
|
||||
logging.debug("TITLE FOUND SHOUTCAST: " + title_server)
|
||||
logging.info("TITLE FOUND SHOUTCAST: " + title_server)
|
||||
except urllib.error.HTTPError:
|
||||
pass
|
||||
except http.client.BadStatusLine:
|
||||
@ -30,9 +30,9 @@ def get_radio_server_description(url):
|
||||
try:
|
||||
request = urllib.request.Request(url_icecast)
|
||||
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']
|
||||
logging.debug("TITLE FOUND ICECAST: " + title_server)
|
||||
logging.info("TITLE FOUND ICECAST: " + title_server)
|
||||
if not title_server:
|
||||
title_server = url
|
||||
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 = response.read(metadata_length).rstrip(b'\0')
|
||||
logging.debug(metadata)
|
||||
logging.info(metadata)
|
||||
# extract title from the metadata
|
||||
m = re.search(br"StreamTitle='([^']*)';", metadata)
|
||||
if m:
|
||||
@ -65,3 +65,14 @@ def get_radio_title(url):
|
||||
except (urllib.error.URLError, urllib.error.HTTPError):
|
||||
pass
|
||||
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 youtube_dl
|
||||
import media
|
||||
import logging
|
||||
|
||||
|
||||
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", "--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("-q", "--quiet", dest="quiet", action="store_true", help="Only Error logs")
|
||||
|
||||
args = parser.parse_args()
|
||||
self.volume = self.config.getfloat('bot', 'volume')
|
||||
@ -40,6 +42,12 @@ class MumbleBot:
|
||||
self.channel = args.channel
|
||||
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 :
|
||||
## [("<type>","<path>")]
|
||||
@ -59,16 +67,17 @@ class MumbleBot:
|
||||
|
||||
var.user = args.user
|
||||
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.nb_exit = 0
|
||||
self.thread = None
|
||||
|
||||
if args.web_interace:
|
||||
interface.init_proxy()
|
||||
|
||||
# t = threading.Thread(target=start_web_interface)
|
||||
# t.daemon = True
|
||||
# t.start()
|
||||
t = threading.Thread(target=start_web_interface)
|
||||
t.daemon = True
|
||||
t.start()
|
||||
|
||||
self.mumble = pymumble.Mumble(args.host, user=args.user, port=args.port, password=args.password,
|
||||
debug=self.config.getboolean('debug', 'mumbleConnection'))
|
||||
@ -86,11 +95,11 @@ class MumbleBot:
|
||||
self.loop()
|
||||
|
||||
def ctrl_caught(self, signal, frame):
|
||||
print("\ndeconnection asked")
|
||||
logging.info("\ndeconnection asked")
|
||||
self.exit = True
|
||||
self.stop()
|
||||
if self.nb_exit > 1:
|
||||
print("Forced Quit")
|
||||
logging.info("Forced Quit")
|
||||
sys.exit(0)
|
||||
self.nb_exit += 1
|
||||
|
||||
@ -106,7 +115,7 @@ class MumbleBot:
|
||||
else:
|
||||
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:
|
||||
path = self.config.get('bot', 'music_folder') + parameter
|
||||
@ -121,6 +130,8 @@ class MumbleBot:
|
||||
var.playlist.append(["url", 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])
|
||||
|
||||
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'))
|
||||
|
||||
elif command == self.config.get('command', 'next'):
|
||||
if var.playlist:
|
||||
var.current_music = var.playlist[0]
|
||||
var.playlist.pop(0)
|
||||
self.launch_next()
|
||||
else:
|
||||
self.mumble.users[text.actor].send_message(self.config.get('strings', 'empty_playlist'))
|
||||
self.stop()
|
||||
|
||||
else:
|
||||
self.mumble.users[text.actor].send_message(self.config.get('strings', 'bad_command'))
|
||||
|
||||
@ -180,9 +196,9 @@ class MumbleBot:
|
||||
path = ""
|
||||
title = ""
|
||||
if var.current_music[0] == "url":
|
||||
regex = re.compile("<a href=\"(.*?)\"")
|
||||
m = regex.match(var.current_music[1])
|
||||
url = m.group(1)
|
||||
url = media.get_url(var.current_music[1])
|
||||
if not url:
|
||||
return
|
||||
path, title = self.download_music(url)
|
||||
var.current_music[1] = url
|
||||
|
||||
@ -191,9 +207,9 @@ class MumbleBot:
|
||||
title = var.current_music[1]
|
||||
|
||||
elif var.current_music[0] == "radio":
|
||||
regex = re.compile("<a href=\"(.*?)\"")
|
||||
m = regex.match(var.current_music[1])
|
||||
url = m.group(1)
|
||||
url = media.get_url(var.current_music[1])
|
||||
if not url:
|
||||
return
|
||||
var.current_music[1] = url
|
||||
path = url
|
||||
title = media.get_radio_server_description(url)
|
||||
@ -249,10 +265,13 @@ class MumbleBot:
|
||||
else:
|
||||
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.playlist.pop(0)
|
||||
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:
|
||||
time.sleep(0.01)
|
||||
|
@ -20,10 +20,24 @@
|
||||
<input type="submit" value="Upload"/>
|
||||
</form>
|
||||
</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">
|
||||
Current Playing :
|
||||
{% if current_music %}
|
||||
{{ current_music }}
|
||||
{{ current_music[0] }} > {{ current_music[2] }}
|
||||
{% else %}
|
||||
No music
|
||||
{% endif %}
|
||||
@ -33,8 +47,8 @@
|
||||
|
||||
<ul>
|
||||
{% for m in playlist %}
|
||||
<li>{{ m }}
|
||||
<form method="post"><input type=text value="{{ m }}" name="delete_music" hidden><input type="submit" value="X"></form>
|
||||
<li>{{ m[0] }} - {{ m[1] }}
|
||||
<form method="post"><input type=text value="{{ m }}" name="delete_music" type="file" hidden><input type="submit" value="X"></form>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
Loading…
x
Reference in New Issue
Block a user