From cc13f09860a44770e410eb812dbbc1528c185ada Mon Sep 17 00:00:00 2001 From: Matthieu Grieger Date: Wed, 17 Sep 2014 15:50:51 -0700 Subject: [PATCH] Volume is now set during encode with ffmpeg. --- mumbledj/config.lua | 27 +++++++++++++++++++-------- mumbledj/download_audio.py | 3 ++- mumbledj/mumbledj.lua | 12 +++++++++--- mumbledj/song_queue.lua | 6 ++---- 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/mumbledj/config.lua b/mumbledj/config.lua index db372a9..84e6866 100644 --- a/mumbledj/config.lua +++ b/mumbledj/config.lua @@ -29,9 +29,17 @@ config.OUTPUT = true -- DEFAULT VALUE: 1 config.USER_SOUND_PAUSE_TARGET = 1 --- Default volume (1 being normal volume) --- DEFAULT VALUE: 0.25 -config.VOLUME = 0.25 +-- Default volume (256 being normal volume) +-- DEFAULT VALUE: 32 +config.VOLUME = 32 + +-- Lowest volume allowed +-- DEFAULT VALUE: 16 +config.LOWEST_VOLUME = 16 + +-- Highest volume allowed +-- DEFAULT VALUE: 512 +config.HIGHEST_VOLUME = 512 -- Ratio that must be met or exceeded to trigger a song skip. -- DEFAULT VALUE: 0.5 @@ -91,11 +99,6 @@ config.ADMIN_KILL = true -- DEFAULT VALUE: true config.SHOW_NOTIFICATIONS = true --- Enable/disable YouTube thumbnails (true = on, false = off) --- DEFAULT VALUE: true -config.SHOW_THUMBNAILS = true - - ------------------------- -- MESSAGE CONFIGURATION ------------------------- @@ -124,6 +127,14 @@ config.NO_MUSIC_PLAYING_MSG = "There is no music playing at the moment." -- DEFAULT VALUE: "There are no songs currently in the queue. Use " .. config.COMMAND_PREFIX .. "add to add a song to the queue." config.NO_SONGS_AVAILABLE = "There are no songs currently in the queue. Use " .. config.COMMAND_PREFIX .. "add to add a song to the queue." +-- Message shown to users when they issue a command that requires an argument and one was not supplied. +-- DEFAULT VALUE: "The command you issued requires an argument and you did not provide one. Make sure a space exists between the command and argument." +config.NO_ARGUMENT = "The command you issued requires an argument and you did not provide one. Make sure a space exists between the command and the argument." + +-- Message shown to users when they try to change the volume to a value outside the volume range. +-- DEFAULT VALUE: "The volume you tried to supply is not in the allowed volume range. The value must be between " .. config.LOWEST_VOLUME .. " and " .. config.HIGHEST_VOLUME .. "." +config.NOT_IN_VOLUME_RANGE = "The volume you tried to supply is not in the allowed volume range. The value must be between " .. config.LOWEST_VOLUME .. " and " .. config.HIGHEST_VOLUME .. "." + ---------------------- -- HTML CONFIGURATION diff --git a/mumbledj/download_audio.py b/mumbledj/download_audio.py index 192a680..607edf2 100644 --- a/mumbledj/download_audio.py +++ b/mumbledj/download_audio.py @@ -16,6 +16,7 @@ from os import remove, system from time import sleep url = argv[1] +volume = argv[2] video = pafy.new(url) try: @@ -29,7 +30,7 @@ except: while isfile('song.ogg.temp'): sleep(1) -system('ffmpeg -i song.ogg -ar 48000 -ac 1 -loglevel quiet song-converted.ogg -y') +system('ffmpeg -i song.ogg -ar 48000 -ac 1 -loglevel quiet -vol ' + str(volume) + ' song-converted.ogg -y') while not isfile("song-converted.ogg"): sleep(1) diff --git a/mumbledj/mumbledj.lua b/mumbledj/mumbledj.lua index 1d0eb3d..6787244 100644 --- a/mumbledj/mumbledj.lua +++ b/mumbledj/mumbledj.lua @@ -48,7 +48,7 @@ function parseCommand(message) if piepan.Audio.isPlaying() then message.user:send(config.MUSIC_PLAYING_MSG) else - piepan.me.channel:play("song-converted.ogg", config.VOLUME, nextSong) + piepan.me.channel:play("song-converted.ogg", nextSong) end end @@ -104,8 +104,14 @@ function parseCommand(message) if has_permission then if config.OUTPUT then print(message.user.name .. " has changed the volume to the following: " .. argument .. ".") - if 0.1 < argument < 2 then - config.VOLUME = argument + if argument ~= nil then + if config.LOWEST_VOLUME < argument < config.HIGHEST_VOLUME then + config.VOLUME = argument + else + message.user:send(config.NOT_IN_VOLUME_RANGE) + end + else + message.user:send(config.NO_ARGUMENT) end end end diff --git a/mumbledj/song_queue.lua b/mumbledj/song_queue.lua index 463d380..9c26f6b 100644 --- a/mumbledj/song_queue.lua +++ b/mumbledj/song_queue.lua @@ -26,7 +26,6 @@ function SongQueue.addSong(url, username) local video_id = string.match(url, pattern) if video_id ~= nil and string.len(video_id) < 20 then print("YouTube URL is valid!") - --piepan.Thread.new(getYoutubeInfo, youtubeInfoCompleted, {video_id, username}) getYoutubeInfo(video_id, username) end end @@ -66,12 +65,11 @@ function youtubeInfoCompleted(info) song_queue:push_right(info) if song_queue:length() == 1 then - os.execute("python download_audio.py " .. info.id) + os.execute("python download_audio.py " .. info.id .. " " .. config.VOLUME) while not file_exists("song-converted.ogg") do os.execute("sleep " .. tonumber(2)) end - print("we done here") - piepan.me.channel:play("song-converted.ogg", config.VOLUME, nextSong) + piepan.me.channel:play("song-converted.ogg", nextSong) end if piepan.Audio:isPlaying() then