From 6c9dfdc5adc4eedb0681f17a57e969b4244f32e6 Mon Sep 17 00:00:00 2001 From: azlux Date: Fri, 18 May 2018 20:21:27 +0200 Subject: [PATCH 1/7] UPDATE UPDATE and Feature news --- README.md | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index fdd840a..15e272a 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,13 @@ Botamusique is a mumble bot which goal is to allow users to listen music together with its audio output. Predicted functionnalities will be the one you could expect from any classic music player. -1. Where to start +Bot the can play : +- Radio url +- Youtube/Soundcloud URL (everything supported by youtube-dl) +- Local folder (disabled, I need to work on the web interface) + +#### Web interface +* Disable * I need to work on it. Since I use this bot for radio, youtube/soundcloud and folder music, the web interace isn't ready. You need to create a folder for all your music. Organize your music by subfolder. The main folder need to be declare into the config (with a '/' at the end) @@ -30,7 +36,7 @@ chmod +x ./mumbleBot.py #### Starting the bot ./mumbleBot.py -s HOST -u BOTNAME -P PASSWORD -p PORT -c CHANNEL -The bot listen to the 8181 port so you should redirect to this one in you NAT configuration to let others peoples access the web interface. +The bot listen to the 8181 port so you should redirect to this one in you NAT configuration to let others peoples access the web interface. (DISABLED) 2.TODO list @@ -38,12 +44,11 @@ The bot listen to the 8181 port so you should redirect to this one in you NAT co ### TODOLIST #### Features -- [ ] Next song -- [ ] Previous song +- [x] Next song - [x] Randomizer -- [ ] Looking for songs previously downloaded in a folder by users. +- [ ]Graphical interface -#### Commands with the interface +#### Commands with the interface (disabled) - [x] list - [x] play - [x] playfolder @@ -51,12 +56,13 @@ The bot listen to the 8181 port so you should redirect to this one in you NAT co #### Commands by message to the bot - [x] volume -- [ ] skip +- [x] next - [x] stop - [x] joinme - [x] away +- [x] help -#### Web Interface +#### Web Interface (disabled for now) - [x] Primary functions - [ ] CSS From 7057252420c89c3d1ff08efc66605f9c996b1a27 Mon Sep 17 00:00:00 2001 From: azlux Date: Thu, 31 May 2018 22:39:42 +0200 Subject: [PATCH 2/7] Lot of new features Web interface almost ready, better bot --- configuration.ini | 18 +++++++++---- interface.py | 21 ++++++++------- media.py | 19 ++++++++++--- mumbleBot.py | 63 ++++++++++++++++++++++++++++---------------- templates/index.html | 20 +++++++++++--- 5 files changed, 98 insertions(+), 43 deletions(-) diff --git a/configuration.ini b/configuration.ini index 894a72f..94a58c6 100644 --- a/configuration.ini +++ b/configuration.ini @@ -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:
!play_file @@ -45,3 +49,7 @@ help = Command available:
!play_file - stop + Go to default channel
!v - get or change the volume (in %)
!joinme + +[debug] +ffmpeg = False +mumbleConnection = False \ No newline at end of file diff --git a/interface.py b/interface.py index 8307595..05f1af0 100644 --- a/interface.py +++ b/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) diff --git a/media.py b/media.py index 64af452..8fbae1d 100644 --- a/media.py +++ b/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 diff --git a/mumbleBot.py b/mumbleBot.py index 66f7637..420ec01 100644 --- a/mumbleBot.py +++ b/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 : ## [("","")] @@ -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 - interface.init_proxy() - - # t = threading.Thread(target=start_web_interface) - # t.daemon = True - # t.start() + if args.web_interace: + interface.init_proxy() + 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'): - var.current_music = var.playlist[0] - var.playlist.pop(0) - self.launch_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(" 0: time.sleep(0.01) diff --git a/templates/index.html b/templates/index.html index 2550d46..07f1513 100644 --- a/templates/index.html +++ b/templates/index.html @@ -20,10 +20,24 @@ +
+ Add Youtube/Soundcloud URL : +
+ + +
+
+
+ Add Radio URL : +
+ + +
+
Current Playing : {% if current_music %} - {{ current_music }} + {{ current_music[0] }} > {{ current_music[2] }} {% else %} No music {% endif %} @@ -33,8 +47,8 @@
    {% for m in playlist %} -
  • {{ m }} -
    +
  • {{ m[0] }} - {{ m[1] }} +
  • {% endfor %}
From 0b97dbdad79e84fcc74fe0211b6bbae50384e273 Mon Sep 17 00:00:00 2001 From: azlux Date: Fri, 1 Jun 2018 00:52:50 +0200 Subject: [PATCH 3/7] Trypo error --- README.fr.md | 24 ------------------------ README.md | 4 +--- configuration.ini | 2 +- mumbleBot.py | 5 ++--- requirements.txt | 3 +++ 5 files changed, 7 insertions(+), 31 deletions(-) delete mode 100644 README.fr.md create mode 100644 requirements.txt diff --git a/README.fr.md b/README.fr.md deleted file mode 100644 index 294675f..0000000 --- a/README.fr.md +++ /dev/null @@ -1,24 +0,0 @@ -# botamusique -[English Version](README.md) - -====== - -##FR: - -Botamusique est un bot pour mumble qui a pour vocation de permettre aux utillisateurs d'écouter de la musique ensemble via sa sortie son. -Les fonctionnalités prévues sont celles qu'on attend d'un lecteur de musique classique (Musique suivante, précédente, aléatoire, lecture d'un repertoire) -Pour ceci il va chercher les musiques téléchargées par les utillisateurs dans un dossier. - -#### Commandes -- [ ] list -- [ ] play -- [ ] playfolder -- [ ] list -- [ ] random -- [ ] volume -- [ ] skip -- [ ] stop -- [ ] joinme - -#### Futur proche -A terme une interface web sera ajoutée pour faciliter son utillisation. \ No newline at end of file diff --git a/README.md b/README.md index 15e272a..cb6e581 100644 --- a/README.md +++ b/README.md @@ -24,12 +24,10 @@ The main folder need to be declare into the config (with a '/' at the end) commands (don't forget the sudo mode): ``` apt-get install python3-pip -pip3 install opuslib -pip3 install protobuf -pip3 install flask apt-get install ffmpeg git clone --recurse-submodules https://github.com/azlux/botamusique.git cd ./botamusique +pip3 install -r requirements.txt chmod +x ./mumbleBot.py ``` diff --git a/configuration.ini b/configuration.ini index 94a58c6..d926ee2 100644 --- a/configuration.ini +++ b/configuration.ini @@ -4,7 +4,7 @@ volume = 0.1 admin = Azlux;AzMobile music_folder = /home/dmichel/botamusique/music/ tmp_folder = /tmp/ -web_interace = False +web_interface = False is_web_proxified = True [command] diff --git a/mumbleBot.py b/mumbleBot.py index 420ec01..28c9edf 100644 --- a/mumbleBot.py +++ b/mumbleBot.py @@ -73,7 +73,7 @@ class MumbleBot: self.nb_exit = 0 self.thread = None - if args.web_interace: + if self.config.getboolean("bot", "web_interface"): interface.init_proxy() t = threading.Thread(target=start_web_interface) t.daemon = True @@ -241,9 +241,8 @@ class MumbleBot: with youtube_dl.YoutubeDL(ydl_opts) as ydl: for i in range(2): try: - info_dict = ydl.extract_info(url, download=False) + info_dict = ydl.extract_info(url) video_title = info_dict['title'] - ydl.download([url]) except youtube_dl.utils.DownloadError: pass else: diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e6b1ef3 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +opuslib==2.0.0 +protobuf==3.4.0 +flask \ No newline at end of file From 7d546919797b9b64946c0ff9258db9bb79a7950c Mon Sep 17 00:00:00 2001 From: azlux Date: Fri, 1 Jun 2018 01:08:22 +0200 Subject: [PATCH 4/7] Better README --- README.md | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index cb6e581..a6bbec2 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,9 @@ The main folder need to be declare into the config (with a '/' at the end) commands (don't forget the sudo mode): ``` -apt-get install python3-pip -apt-get install ffmpeg +apt install python3-pip +apt install ffmpeg +apt install youtube-dl git clone --recurse-submodules https://github.com/azlux/botamusique.git cd ./botamusique pip3 install -r requirements.txt @@ -32,7 +33,7 @@ chmod +x ./mumbleBot.py ``` #### Starting the bot -./mumbleBot.py -s HOST -u BOTNAME -P PASSWORD -p PORT -c CHANNEL +`./mumbleBot.py -s HOST -u BOTNAME -P PASSWORD -p PORT -c CHANNEL` The bot listen to the 8181 port so you should redirect to this one in you NAT configuration to let others peoples access the web interface. (DISABLED) @@ -41,26 +42,4 @@ The bot listen to the 8181 port so you should redirect to this one in you NAT co ### TODOLIST -#### Features -- [x] Next song -- [x] Randomizer -- [ ]Graphical interface - -#### Commands with the interface (disabled) -- [x] list -- [x] play -- [x] playfolder -- [x] random - -#### Commands by message to the bot -- [x] volume -- [x] next -- [x] stop -- [x] joinme -- [x] away -- [x] help - -#### Web Interface (disabled for now) -- [x] Primary functions -- [ ] CSS - +Check the issue #3 From e1b4ef08738d6235220cfa3916ee529652ed362d Mon Sep 17 00:00:00 2001 From: azlux Date: Fri, 1 Jun 2018 01:11:30 +0200 Subject: [PATCH 5/7] Update pymumble --- pymumble | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymumble b/pymumble index d9f70dd..4916949 160000 --- a/pymumble +++ b/pymumble @@ -1 +1 @@ -Subproject commit d9f70dd61d69c80e322aa1185d541e6e04376148 +Subproject commit 4916949a124b8acbbb1336e30bfb96f2a81bf919 From 5944ba7709edb28d6b1ec75a679462f3d7f8ed21 Mon Sep 17 00:00:00 2001 From: azlux Date: Fri, 1 Jun 2018 01:26:08 +0200 Subject: [PATCH 6/7] Removing pymumble --- .gitmodules | 4 +--- pymumble | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) delete mode 160000 pymumble diff --git a/.gitmodules b/.gitmodules index 853108d..8b13789 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1 @@ -[submodule "pymumble"] - path = pymumble - url = https://github.com/azlux/pymumble + diff --git a/pymumble b/pymumble deleted file mode 160000 index 4916949..0000000 --- a/pymumble +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4916949a124b8acbbb1336e30bfb96f2a81bf919 From b674029f446ac3ba6eeb2ed810c38ccd4949250e Mon Sep 17 00:00:00 2001 From: azlux Date: Fri, 1 Jun 2018 01:29:53 +0200 Subject: [PATCH 7/7] adding good version of pymumble --- .gitmodules | 3 +++ pymumble | 1 + 2 files changed, 4 insertions(+) create mode 160000 pymumble diff --git a/.gitmodules b/.gitmodules index 8b13789..0ff38ab 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1 +1,4 @@ +[submodule "pymumble"] + path = pymumble + url = git://github.com/azlux/pymumble.git diff --git a/pymumble b/pymumble new file mode 160000 index 0000000..d2ad1fd --- /dev/null +++ b/pymumble @@ -0,0 +1 @@ +Subproject commit d2ad1fde0c9e427622fb9c69ca7e20783a19d101