Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pymumble.pymumble_py3 as pymumble
- import subprocess as sp
- import time
- import audioop
- import pafy.pafy as pafy
- import os
- #import http.client
- #import urllib.request, urllib.error, urllib.parse
- bot_host = 'mumble.kafnasetpo.re'
- bot_user = "Jukebox"
- bot_port = 64738
- bot_password = 'masters'
- bot_reconnect = False
- bot_debug = False
- class bot:
- def __init__(self):
- self.bot = pymumble.Mumble(host = bot_host, user = bot_user, port = bot_port, password = bot_password,
- reconnect = bot_reconnect, debug = bot_debug)
- self.bot.start()
- self.bot.is_ready()
- self.bot.set_codec_profile("audio")
- self.bot.callbacks.set_callback("text_received", self.message_recu)
- self.exit = False
- self.playing = False
- self.volume = 0.15
- self.channel = 'Dev'
- self.loop()
- if self.channel:
- self.bot.channels.find_by_name(self.channel).move_in()
- def message_recu(self, objet_text):
- message = objet_text.message.split(' ')
- if message[0] == "!play":
- self.player()
- if message[0] == "!stop":
- self.playing = False
- if message[0] == "!stream":
- url = message[1]
- stream = pafy.new(url)
- audio = stream.getbestaudio()
- try :
- audio.download()
- #fichier =
- finally :
- self.stream()
- else :
- return
- def player(self):
- path = '/home/hmg/PycharmProjects/Mumble_bot/'
- fichier = 'Wiz Khalifa - "Paperbond".opus'
- url = 'https://www.youtube.com/watch?v=jOMXMmKg74Y'
- stream = pafy.new(url)
- audio = stream.getbestaudio()
- #musique = path + fichier
- ffmpeg_debug = "warning"
- command = ["ffmpeg", '-v', ffmpeg_debug, '-nostdin', '-i', audio, '-ac', '1', '-f', 's16le', '-ar', '48000', '-']
- self.thread = sp.Popen(command, stdout=sp.PIPE, bufsize=480)
- self.playing = True
- #self.url = 'https://www.youtube.com/watch?v=TNjE4m7Xlvk'
- def stream(self):
- url = 'https://www.youtube.com/watch?v=TNjE4m7Xlvk'
- ffmpeg_debug = "warning"
- command = ["ffmpeg", '-v', ffmpeg_debug, '-nostdin', '-i', url, '-ac', '1', '-f', 's16le', '-ar', '48000', '-']
- self.thread = sp.Popen(command, stdout=sp.PIPE, bufsize=480)
- time.sleep(3)
- self.playing = True
- def loop(self):
- while not self.exit:
- if self.playing:
- while self.bot.sound_output.get_buffer_size() > 0.5 and self.playing:
- time.sleep(0.01)
- music = self.thread.stdout.read(480)
- if music:
- self.bot.sound_output.add_sound(audioop.mul(music, 2, self.volume))
- else:
- time.sleep(0.01)
- else:
- time.sleep(1)
- while self.bot.sound_output.get_buffer_size() > 0:
- time.sleep(0.01)
- time.sleep(0.5)
- mumble_music = bot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement