From ac3531a8753599c1fd2e712807df29fa187ff213 Mon Sep 17 00:00:00 2001 From: icedream Date: Tue, 27 Oct 2015 00:13:10 +0100 Subject: [PATCH 01/19] Add webchimera.js to dependencies - we're now switching! See issue #17. --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index bc41172..6e5a85e 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "sync": "^0.2.5", "valid-url": "^1.0.9", "vlc-api": "0.0.0", + "webchimera.js": "^0.1.38", "which": "^1.1.2", "winston": "^1.0.1", "xvfb": "git://github.com/icedream/node-xvfb.git", From 394b16ab5eee9780d71961f6c3a0674f5ca69861 Mon Sep 17 00:00:00 2001 From: icedream Date: Tue, 27 Oct 2015 01:14:55 +0100 Subject: [PATCH 02/19] We're now completely getting rid of vlc-api. - Hopefully fixes audio volume not being set to 50% at startup. - Volume now is in the range of 0 to 200 (percentage, so goes from 0% to 200% for those numbers). - Made message displaying volume change display the actual level set. - We're no longer providing an HTTP interface. - Now stores metadata info in a separate variable for later retrieval by input MRL. - Now prints when player reaches end of playlist. - Now supports toggle-pausing using "pause" command. - Should fix playlist not being able to kick off on "play" if stopped. - Removed vlc-api dependency. Relates to issues #17, #10 and #7 (partially). --- app.iced | 85 +++++++++++++++++++++-------------------------- package.json | 1 - services/vlc.iced | 83 +++++++++++---------------------------------- 3 files changed, 56 insertions(+), 113 deletions(-) diff --git a/app.iced b/app.iced index 02782f8..7c48de4 100644 --- a/app.iced +++ b/app.iced @@ -46,13 +46,16 @@ await services.find("pulseaudio").start defer err if err log.warn "PulseAudio could not start up, audio may not act as expected!" -# VLC HTTP API -await services.find("vlc").start defer err +# VLC via WebChimera.js +vlcService = services.find("vlc") +await vlcService.start defer err, vlc if err log.warn "VLC could not start up!" await module.exports.shutdown defer() process.exit 1 -vlc = services.find("vlc").instance + +# Cached information for tracks in playlist +vlcMediaInfo = {} # TeamSpeak3 ts3clientService = services.find("ts3client") @@ -60,6 +63,17 @@ ts3clientService = services.find("ts3client") ts3clientService.on "started", (ts3proc) => ts3query = ts3clientService.query + # VLC event handling + vlc.onPlaying () => + info = vlcMediaInfo[vlc.playlist.items[vlc.playlist.currentItem].mrl] + ts3query.sendtextmessage 2, 0, "Now playing [URL=#{info.originalUrl}]#{info.title}[/URL]." + vlc.onPaused () => ts3query.sendtextmessage 2, 0, "Paused." + vlc.onForward () => ts3query.sendtextmessage 2, 0, "Fast-forwarding..." + vlc.onBackward () => ts3query.sendtextmessage 2, 0, "Rewinding..." + vlc.onEncounteredError () => log.error "VLC has encountered an error! You will need to restart the bot.", arguments + vlc.onEndReached () => ts3query.sendtextmessage 2, 0, "End of playlist reached." + vlc.onStopped () => ts3query.sendtextmessage 2, 0, "Stopped." + ts3query.currentScHandlerID = 1 ts3query.mydata = {} @@ -145,7 +159,8 @@ ts3clientService.on "started", (ts3proc) => switch name.toLowerCase() when "pause" - vlc.status.pause() + # now we can toggle-pause playback this easily! yay! + vlc.togglePause() return when "play" inputBB = paramline.trim() @@ -153,7 +168,7 @@ ts3clientService.on "started", (ts3proc) => # we gonna interpret play without a url as an attempt to unpause the current song if input.length <= 0 - vlc.status.resume() + vlc.play() return # only allow playback from file if it's a preconfigured alias @@ -168,11 +183,7 @@ ts3clientService.on "started", (ts3proc) => # TODO: permission system to check if uid is allowed to play this url or alias - await vlc.status.empty defer(err) - if err - log.warn "Couldn't empty VLC playlist", err - ts3query.sendtextmessage args.targetmode, invoker.id, "Sorry, an error occurred. Try again later." - return + vlc.playlist.clear() # let's give youtube-dl a shot! await youtubedl.getInfo input, [ @@ -189,24 +200,13 @@ ts3clientService.on "started", (ts3proc) => if not info.url? info.url = input info.title = input # URL as title + info.originalUrl = input + vlcMediaInfo[info.url] = info - await vlc.status.play info.url, defer(err) - if err - vlc.status.empty() - log.warn "VLC API returned an error when trying to play", err - ts3query.sendtextmessage args.targetmode, invoker.id, "Something seems to be wrong with the specified media. Try checking the URL/path you provided?" - return - - ts3query.sendtextmessage args.targetmode, invoker.id, "Now playing [URL=#{input}]#{info.title}[/URL]." + # play it in VLC + vlc.play info.url when "next" - await vlc.status.next defer(err) - if err - vlc.status.empty() - log.warn "VLC API returned an error when trying to skip current song", err - ts3query.sendtextmessage args.targetmode, invoker.id, "This didn't work. Does the playlist have multiple songs?" - return - - ts3query.sendtextmessage args.targetmode, invoker.id, "Playing next song in the playlist." + vlc.playlist.next() when "enqueue", "add", "append" inputBB = paramline.trim() input = (removeBB paramline).trim() @@ -242,36 +242,25 @@ ts3clientService.on "started", (ts3proc) => if not info.url? info.url = input info.title = input # URL as title + info.originalUrl = input + vlcMediaInfo[info.url] = info - await vlc.status.enqueue info.url, defer(err) - if err - vlc.status.empty() - log.warn "VLC API returned an error when trying to play", err - ts3query.sendtextmessage args.targetmode, invoker.id, "Something seems to be wrong with the specified media. Try checking the URL/path you provided?" - return - + # add it in VLC + vlc.playlist.add info.url ts3query.sendtextmessage args.targetmode, invoker.id, "Added [URL=#{input}]#{info.title}[/URL] to the playlist." + + # TODO: Do we need to make sure that vlc.playlist.mode is not set to "Single" here or is that handled automatically? when "stop" - await vlc.status.stop defer(err) - - vlc.status.empty() - - ts3query.sendtextmessage args.targetmode, invoker.id, "Stopped playback." + vlc.stop() when "vol" vol = parseInt paramline - if paramline.trim().length <= 0 or vol > 511 or vol < 0 - ts3query.sendtextmessage args.targetmode, invoker.id, "[B]vol [/B] - takes a number between 0 (0%) and 1024 (400%) to set the volume. 100% is 256. Defaults to 128 (50%) on startup." + if paramline.trim().length <= 0 or vol > 200 or vol < 0 + ts3query.sendtextmessage args.targetmode, invoker.id, "[B]vol [/B] - takes a number between 0 (0%) and 200 (200%) to set the volume. 100% is 100. Defaults to 50 (50%) on startup." return - await vlc.status.volume paramline, defer(err) - - if err - log.warn "Failed to set volume", err - ts3query.sendtextmessage args.targetmode, invoker.id, "That unfortunately didn't work out." - return - - ts3query.sendtextmessage args.targetmode, invoker.id, "Volume set." + vlc.audio.volume = vol + ts3query.sendtextmessage args.targetmode, invoker.id, "Volume set to #{vol}%." when "changenick" nick = if paramline.length > params[0].length then paramline else params[0] if nick.length < 3 or nick.length > 30 diff --git a/package.json b/package.json index 6e5a85e..78ac299 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,6 @@ "string.prototype.startswith": "^0.2.0", "sync": "^0.2.5", "valid-url": "^1.0.9", - "vlc-api": "0.0.0", "webchimera.js": "^0.1.38", "which": "^1.1.2", "winston": "^1.0.1", diff --git a/services/vlc.iced b/services/vlc.iced index d0be6c4..b52ee83 100644 --- a/services/vlc.iced +++ b/services/vlc.iced @@ -1,88 +1,43 @@ spawn = require("child_process").spawn services = require("../services") config = require("../config") -VLCApi = require("vlc-api") +wc = require("webchimera.js") StreamSplitter = require("stream-splitter") -require_bin = require("../require_bin") - -vlcBinPath = require_bin "vlc" module.exports = class VLCService extends services.Service dependencies: [ "pulseaudio" ] constructor: -> super "VLC", + ### + # Starts an instance of VLC and keeps it ready for service. + ### start: (cb) -> - if @_process - cb? null, @_process + if @_instance + cb? null, @_instance return calledCallback = false - proc = null - doStart = null - doStart = () => - await services.find("pulseaudio").start defer(err) - if err - throw new Error "Dependency pulseaudio failed." + instance = wc.createPlayer [ + "--aout", "pulse", + "--no-video" + ] + instance.audio.volume = 50 - proc = spawn vlcBinPath, [ - "-I", "http", - "--http-host", config.get("vlc-host"), - "--http-port", config.get("vlc-port"), - "--http-password", config.get("vlc-password") - "--aout", "pulse", - "--volume", "128", # 50% volume - "--no-video" - ], - stdio: ['ignore', 'pipe', 'pipe'] - detached: true - - # logging - stdoutTokenizer = proc.stdout.pipe StreamSplitter "\n" - stdoutTokenizer.encoding = "utf8"; - stdoutTokenizer.on "token", (token) => - token = token.trim() # get rid of \r - @log.debug token - - stderrTokenizer = proc.stderr.pipe StreamSplitter "\n" - stderrTokenizer.encoding = "utf8"; - stderrTokenizer.on "token", (token) => - token = token.trim() # get rid of \r - @log.debug token - - proc.on "exit", () => - if @state == "stopping" - return - if not calledCallback - calledCallback = true - @log.warn "VLC terminated unexpectedly during startup." - cb? new Error "VLC terminated unexpectedly." - @log.warn "VLC terminated unexpectedly, restarting." - doStart() - - @_process = proc - - doStart() - - setTimeout (() => - if not calledCallback - calledCallback = true - - @instance = new VLCApi - host: ":#{encodeURIComponent config.get("vlc-password")}@#{config.get("vlc-host")}", - port: config.get("vlc-port") - cb? null, @instance), 1500 # TODO: Use some more stable condition + @_instance = instance + cb? null, @_instance + ### + # Shuts down the VLC instance. + ### stop: (cb) -> - if not @_process + if not @_instance cb?() return - @instance = null - - @_process.kill() - await @_process.once "exit", defer() + # TODO: Is there even a proper way to shut this down? + @_instance = null cb?() From 852052388df2c469e26a9455d5fd21f5db78c065 Mon Sep 17 00:00:00 2001 From: icedream Date: Tue, 27 Oct 2015 22:40:39 +0100 Subject: [PATCH 03/19] VLC event members are actually properties, not functions. Got the documentation wrong here, I was looking up examples and it looked as if calling the on* fields as functions was the right way to go but it was actually not. https://github.com/RSATom/WebChimera.js/blob/64bf4ffc362898e309c8a444c8888ad7b4bfae92/src/JsVlcPlayer.cpp#L90-L102 clearly defines as set-properties here. --- app.iced | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app.iced b/app.iced index 7c48de4..21826f9 100644 --- a/app.iced +++ b/app.iced @@ -64,15 +64,15 @@ ts3clientService.on "started", (ts3proc) => ts3query = ts3clientService.query # VLC event handling - vlc.onPlaying () => + vlc.onPlaying = () => info = vlcMediaInfo[vlc.playlist.items[vlc.playlist.currentItem].mrl] ts3query.sendtextmessage 2, 0, "Now playing [URL=#{info.originalUrl}]#{info.title}[/URL]." - vlc.onPaused () => ts3query.sendtextmessage 2, 0, "Paused." - vlc.onForward () => ts3query.sendtextmessage 2, 0, "Fast-forwarding..." - vlc.onBackward () => ts3query.sendtextmessage 2, 0, "Rewinding..." - vlc.onEncounteredError () => log.error "VLC has encountered an error! You will need to restart the bot.", arguments - vlc.onEndReached () => ts3query.sendtextmessage 2, 0, "End of playlist reached." - vlc.onStopped () => ts3query.sendtextmessage 2, 0, "Stopped." + vlc.onPaused = () => ts3query.sendtextmessage 2, 0, "Paused." + vlc.onForward = () => ts3query.sendtextmessage 2, 0, "Fast-forwarding..." + vlc.onBackward = () => ts3query.sendtextmessage 2, 0, "Rewinding..." + vlc.onEncounteredError = () => log.error "VLC has encountered an error! You will need to restart the bot.", arguments + vlc.onEndReached = () => ts3query.sendtextmessage 2, 0, "End of playlist reached." + vlc.onStopped = () => ts3query.sendtextmessage 2, 0, "Stopped." ts3query.currentScHandlerID = 1 ts3query.mydata = {} From 8ab524467bb56e90e17b9c9d3da887dd743c8c76 Mon Sep 17 00:00:00 2001 From: icedream Date: Tue, 27 Oct 2015 22:47:29 +0100 Subject: [PATCH 04/19] Fix non-numeric volume value being passed through to VLC as NaN. Those values are not supposed to be accepted in the first place... --- app.iced | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.iced b/app.iced index 21826f9..95c94f1 100644 --- a/app.iced +++ b/app.iced @@ -255,7 +255,7 @@ ts3clientService.on "started", (ts3proc) => when "vol" vol = parseInt paramline - if paramline.trim().length <= 0 or vol > 200 or vol < 0 + if paramline.trim().length <= 0 or vol == NaN or vol > 200 or vol < 0 ts3query.sendtextmessage args.targetmode, invoker.id, "[B]vol [/B] - takes a number between 0 (0%) and 200 (200%) to set the volume. 100% is 100. Defaults to 50 (50%) on startup." return From 824b4b94bd1dfbe12df6fefebe83342b33c27721 Mon Sep 17 00:00:00 2001 From: icedream Date: Tue, 27 Oct 2015 22:59:17 +0100 Subject: [PATCH 05/19] Implement "prev"/"previous" commands. These commands allow going to the previous entry in the playlist. --- app.iced | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app.iced b/app.iced index 95c94f1..4d94018 100644 --- a/app.iced +++ b/app.iced @@ -207,6 +207,8 @@ ts3clientService.on "started", (ts3proc) => vlc.play info.url when "next" vlc.playlist.next() + when "prev", "previous" + vlc.playlist.prev() when "enqueue", "add", "append" inputBB = paramline.trim() input = (removeBB paramline).trim() From 4eed972a235325b26276ad4a6f040b79081019f1 Mon Sep 17 00:00:00 2001 From: icedream Date: Tue, 27 Oct 2015 23:01:23 +0100 Subject: [PATCH 06/19] Implement "empty"/"clear" commands. These commands allow emptying the current playlist. Here another reminder to implement a proper permission system soon! --- app.iced | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app.iced b/app.iced index 4d94018..89e5a8d 100644 --- a/app.iced +++ b/app.iced @@ -209,6 +209,9 @@ ts3clientService.on "started", (ts3proc) => vlc.playlist.next() when "prev", "previous" vlc.playlist.prev() + when "empty", "clear" + vlc.playlist.clear() + ts3query.sendtextmessage args.targetmode, invoker.id, "Cleared the playlist." when "enqueue", "add", "append" inputBB = paramline.trim() input = (removeBB paramline).trim() From cc783d0bc0db4a0b1d69463607a3f0751cb4dd64 Mon Sep 17 00:00:00 2001 From: icedream Date: Tue, 27 Oct 2015 23:09:28 +0100 Subject: [PATCH 07/19] Implement "list"/"playlist" commands. These commands make the bot print out the current playlist in the channel chat. The current track being played back is printed in bold green font. --- app.iced | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app.iced b/app.iced index 89e5a8d..a4cf592 100644 --- a/app.iced +++ b/app.iced @@ -212,6 +212,16 @@ ts3clientService.on "started", (ts3proc) => when "empty", "clear" vlc.playlist.clear() ts3query.sendtextmessage args.targetmode, invoker.id, "Cleared the playlist." + when "list", "playlist" + message = "Currently these tracks are in the playlist:\n" + for i in [ 0 .. vlc.playlist.items.count ] + if vlc.playlist.currentItem == i + message += "[COLOR=green][B]" + info = vlcMediaInfo[vlc.playlist.items[i].mrl] + message += "#{i + 1}. [URL=#{info.originalUrl}]#{info.title}[/URL]" + if vlc.playlist.currentItem == i + message += "[/B][/COLOR]" + ts3query.sendtextmessage args.targetmode, invoker.id, message when "enqueue", "add", "append" inputBB = paramline.trim() input = (removeBB paramline).trim() From ab18c3cd8f2824f94f818550ac77a9e0702dc76d Mon Sep 17 00:00:00 2001 From: icedream Date: Tue, 27 Oct 2015 23:12:47 +0100 Subject: [PATCH 08/19] According to the WebChimera documentation this is not zero-based... --- app.iced | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.iced b/app.iced index a4cf592..da79b65 100644 --- a/app.iced +++ b/app.iced @@ -214,7 +214,7 @@ ts3clientService.on "started", (ts3proc) => ts3query.sendtextmessage args.targetmode, invoker.id, "Cleared the playlist." when "list", "playlist" message = "Currently these tracks are in the playlist:\n" - for i in [ 0 .. vlc.playlist.items.count ] + for i in [ 1 .. vlc.playlist.items.count ] if vlc.playlist.currentItem == i message += "[COLOR=green][B]" info = vlcMediaInfo[vlc.playlist.items[i].mrl] From d61d85e020cfaab777ad7aef978b204df776485f Mon Sep 17 00:00:00 2001 From: icedream Date: Tue, 27 Oct 2015 23:18:13 +0100 Subject: [PATCH 09/19] Got the right CoffeeScript syntax for this loop now. --- app.iced | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.iced b/app.iced index da79b65..ac0a8b1 100644 --- a/app.iced +++ b/app.iced @@ -214,7 +214,7 @@ ts3clientService.on "started", (ts3proc) => ts3query.sendtextmessage args.targetmode, invoker.id, "Cleared the playlist." when "list", "playlist" message = "Currently these tracks are in the playlist:\n" - for i in [ 1 .. vlc.playlist.items.count ] + for i in [ 0 ... vlc.playlist.items.count ] if vlc.playlist.currentItem == i message += "[COLOR=green][B]" info = vlcMediaInfo[vlc.playlist.items[i].mrl] From eb00dc2f8795d15710d368f2fdb2f0df56509c93 Mon Sep 17 00:00:00 2001 From: icedream Date: Tue, 27 Oct 2015 23:19:40 +0100 Subject: [PATCH 10/19] While we're on it, fine-tuning the playlist message. --- app.iced | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app.iced b/app.iced index ac0a8b1..3f6cd34 100644 --- a/app.iced +++ b/app.iced @@ -213,7 +213,8 @@ ts3clientService.on "started", (ts3proc) => vlc.playlist.clear() ts3query.sendtextmessage args.targetmode, invoker.id, "Cleared the playlist." when "list", "playlist" - message = "Currently these tracks are in the playlist:\n" + message = "Currently there are #{vlc.playlist.items.count} tracks are in the playlist" + message += if vlc.playlist.items.count > 0 then ":\n" else "." for i in [ 0 ... vlc.playlist.items.count ] if vlc.playlist.currentItem == i message += "[COLOR=green][B]" From 0762d6d0bdd182a2b0949ab74202df7c3cea9222 Mon Sep 17 00:00:00 2001 From: icedream Date: Tue, 27 Oct 2015 23:38:14 +0100 Subject: [PATCH 11/19] Fix line breaks and tabs not being properly escaped in ts3query.iced. --- ts3query.iced | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/ts3query.iced b/ts3query.iced index a9505e6..3b1b076 100644 --- a/ts3query.iced +++ b/ts3query.iced @@ -10,9 +10,23 @@ merge = require "merge" parserLog = getLogger "parser" -escape = (value) => value.toString().replace(///\\///g, "\\\\").replace(/\//g, "\\/").replace(/\|/g, "\\|").replace(///\ ///g, "\\s") +escape = (value) => value.toString()\ + .replace(/\\/g, "\\\\")\ + .replace(/\//g, "\\/")\ + .replace(/\|/g, "\\|")\ + .replace(/\n/g, "\\n")\ + .replace(/\r/g, "\\r")\ + .replace(/\t/g, "\\t")\ + .replace(/\ /g, "\\s") -unescape = (value) => value.toString().replace(/\\s/g, " ").replace(/\\\//g, "/").replace(/\\\|/g, "|").replace(/\\\\/g, "\\") +unescape = (value) => value.toString()\ + .replace(/\\s/g, " ")\ + .replace(/\\t/g, "\t")\ + .replace(/\\r/g, "\r")\ + .replace(/\\n/g, "\n")\ + .replace(/\\\|/g, "|")\ + .replace(/\\\//g, "/")\ + .replace(/\\\\/g, "\\") buildCmd = (name, namedArgs, posArgs) => # TODO: Add support for collected arguments (aka lists) From d82721128f6319d4382daf0ee9adf9cf010137c1 Mon Sep 17 00:00:00 2001 From: icedream Date: Tue, 27 Oct 2015 23:54:01 +0100 Subject: [PATCH 12/19] Implement "loop" command. This command allows looping the playlist by just passing the command "loop on". Respectively, "loop off" turns off looping again. --- app.iced | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app.iced b/app.iced index 3f6cd34..e009421 100644 --- a/app.iced +++ b/app.iced @@ -205,6 +205,24 @@ ts3clientService.on "started", (ts3proc) => # play it in VLC vlc.play info.url + when "loop" + inputBB = paramline + input = null + switch (removeBB paramline).toLowerCase().trim() + when "" + # just show current mode + ts3query.sendtextmessage args.targetmode, invoker.id, "Playlist looping is #{if vlc.playlist.mode == vlc.playlist.Loop then "on" else "off"}." + when "on" + # enable looping + vlc.playlist.mode = vlc.playlist.Loop + ts3query.sendtextmessage args.targetmode, invoker.id, "Playlist looping is now on." + when "off" + # disable looping + vlc.playlist.mode = vlc.playlist.Normal + ts3query.sendtextmessage args.targetmode, invoker.id, "Playlist looping is now off." + else + ts3query.sendtextmessage args.targetmode, invoker.id, "[B]#{name} on|off[/B] - Turns playlist looping on or off" + return when "next" vlc.playlist.next() when "prev", "previous" From 18b7d8296447e6dbfd8dfa82e7810e602294e40d Mon Sep 17 00:00:00 2001 From: icedream Date: Tue, 27 Oct 2015 23:54:36 +0100 Subject: [PATCH 13/19] Implement "stop-after" command. This command allows stopping the playlist after the current playlist item is finished. --- app.iced | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app.iced b/app.iced index e009421..b8e8fb1 100644 --- a/app.iced +++ b/app.iced @@ -205,6 +205,9 @@ ts3clientService.on "started", (ts3proc) => # play it in VLC vlc.play info.url + when "stop-after" + vlc.playlist.mode = vlc.playlist.Single + ts3query.sendtextmessage args.targetmode, invoker.id, "Playback will stop after the current playlist item." when "loop" inputBB = paramline input = null From 7966bfb0562403214fa673f113fc1664ae30ee3e Mon Sep 17 00:00:00 2001 From: icedream Date: Tue, 27 Oct 2015 23:55:54 +0100 Subject: [PATCH 14/19] Playlist display (command "list"/"playlist") can generate too long messages, commenting out for now. --- app.iced | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app.iced b/app.iced index b8e8fb1..1a751ca 100644 --- a/app.iced +++ b/app.iced @@ -233,6 +233,7 @@ ts3clientService.on "started", (ts3proc) => when "empty", "clear" vlc.playlist.clear() ts3query.sendtextmessage args.targetmode, invoker.id, "Cleared the playlist." + ### when "list", "playlist" message = "Currently there are #{vlc.playlist.items.count} tracks are in the playlist" message += if vlc.playlist.items.count > 0 then ":\n" else "." @@ -244,6 +245,7 @@ ts3clientService.on "started", (ts3proc) => if vlc.playlist.currentItem == i message += "[/B][/COLOR]" ts3query.sendtextmessage args.targetmode, invoker.id, message + ### when "enqueue", "add", "append" inputBB = paramline.trim() input = (removeBB paramline).trim() From b238a655b9b13b1504cdb0f8a0f1823d5904c4f1 Mon Sep 17 00:00:00 2001 From: icedream Date: Tue, 27 Oct 2015 23:57:50 +0100 Subject: [PATCH 15/19] This indenting stuff still sometimes doesn't really want to work out I guess... --- app.iced | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/app.iced b/app.iced index 1a751ca..f56ee7f 100644 --- a/app.iced +++ b/app.iced @@ -233,19 +233,6 @@ ts3clientService.on "started", (ts3proc) => when "empty", "clear" vlc.playlist.clear() ts3query.sendtextmessage args.targetmode, invoker.id, "Cleared the playlist." - ### - when "list", "playlist" - message = "Currently there are #{vlc.playlist.items.count} tracks are in the playlist" - message += if vlc.playlist.items.count > 0 then ":\n" else "." - for i in [ 0 ... vlc.playlist.items.count ] - if vlc.playlist.currentItem == i - message += "[COLOR=green][B]" - info = vlcMediaInfo[vlc.playlist.items[i].mrl] - message += "#{i + 1}. [URL=#{info.originalUrl}]#{info.title}[/URL]" - if vlc.playlist.currentItem == i - message += "[/B][/COLOR]" - ts3query.sendtextmessage args.targetmode, invoker.id, message - ### when "enqueue", "add", "append" inputBB = paramline.trim() input = (removeBB paramline).trim() From a5a8ae1046b453a24c54af816e3e7e66795ef8ec Mon Sep 17 00:00:00 2001 From: icedream Date: Wed, 28 Oct 2015 00:12:50 +0100 Subject: [PATCH 16/19] Implement some easy checks for "next" and "prev" commands. --- app.iced | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app.iced b/app.iced index f56ee7f..834b5f2 100644 --- a/app.iced +++ b/app.iced @@ -227,8 +227,14 @@ ts3clientService.on "started", (ts3proc) => ts3query.sendtextmessage args.targetmode, invoker.id, "[B]#{name} on|off[/B] - Turns playlist looping on or off" return when "next" + if vlc.playlist.mode != vlc.playlist.Loop and vlc.playlist.currentItem == vlc.playlist.items.count - 1 + ts3query.sendtextmessage args.targetmode, invoker.id, "Can't jump to next playlist item, this is the last one!" + return vlc.playlist.next() when "prev", "previous" + if vlc.playlist.mode != vlc.playlist.Loop and vlc.playlist.currentItem == 0 + ts3query.sendtextmessage args.targetmode, invoker.id, "Can't jump to previous playlist item, this is the first one!" + return vlc.playlist.prev() when "empty", "clear" vlc.playlist.clear() From 9417e337087c360b9a32243960d98cbc8d3d6283 Mon Sep 17 00:00:00 2001 From: icedream Date: Wed, 28 Oct 2015 00:14:44 +0100 Subject: [PATCH 17/19] Small fix for "prev" not giving an error when in empty playlist. --- app.iced | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.iced b/app.iced index 834b5f2..cf5006f 100644 --- a/app.iced +++ b/app.iced @@ -232,7 +232,7 @@ ts3clientService.on "started", (ts3proc) => return vlc.playlist.next() when "prev", "previous" - if vlc.playlist.mode != vlc.playlist.Loop and vlc.playlist.currentItem == 0 + if vlc.playlist.mode != vlc.playlist.Loop and vlc.playlist.currentItem <= 0 ts3query.sendtextmessage args.targetmode, invoker.id, "Can't jump to previous playlist item, this is the first one!" return vlc.playlist.prev() From 4d25c2b822d1660546a48b89db34645285408dd7 Mon Sep 17 00:00:00 2001 From: icedream Date: Wed, 28 Oct 2015 00:16:10 +0100 Subject: [PATCH 18/19] Small fixes for empty playlists. --- app.iced | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app.iced b/app.iced index cf5006f..e71ef00 100644 --- a/app.iced +++ b/app.iced @@ -227,11 +227,17 @@ ts3clientService.on "started", (ts3proc) => ts3query.sendtextmessage args.targetmode, invoker.id, "[B]#{name} on|off[/B] - Turns playlist looping on or off" return when "next" + if vlc.playlist.items.count == 0 + ts3query.sendtextmessage args.targetmode, invoker.id, "The playlist is empty." + return if vlc.playlist.mode != vlc.playlist.Loop and vlc.playlist.currentItem == vlc.playlist.items.count - 1 ts3query.sendtextmessage args.targetmode, invoker.id, "Can't jump to next playlist item, this is the last one!" return vlc.playlist.next() when "prev", "previous" + if vlc.playlist.items.count == 0 + ts3query.sendtextmessage args.targetmode, invoker.id, "The playlist is empty." + return if vlc.playlist.mode != vlc.playlist.Loop and vlc.playlist.currentItem <= 0 ts3query.sendtextmessage args.targetmode, invoker.id, "Can't jump to previous playlist item, this is the first one!" return From f3157857c488621ca2d172bf505af47e3cf1249b Mon Sep 17 00:00:00 2001 From: icedream Date: Wed, 28 Oct 2015 00:21:54 +0100 Subject: [PATCH 19/19] Completely remove handler for vlc.onEndReached. onEndReached does not just trigger the callback at the end of the playlist but actually at the end of each track. This should have been better documented. --- app.iced | 1 - 1 file changed, 1 deletion(-) diff --git a/app.iced b/app.iced index e71ef00..a05428b 100644 --- a/app.iced +++ b/app.iced @@ -71,7 +71,6 @@ ts3clientService.on "started", (ts3proc) => vlc.onForward = () => ts3query.sendtextmessage 2, 0, "Fast-forwarding..." vlc.onBackward = () => ts3query.sendtextmessage 2, 0, "Rewinding..." vlc.onEncounteredError = () => log.error "VLC has encountered an error! You will need to restart the bot.", arguments - vlc.onEndReached = () => ts3query.sendtextmessage 2, 0, "End of playlist reached." vlc.onStopped = () => ts3query.sendtextmessage 2, 0, "Stopped." ts3query.currentScHandlerID = 1