Implement "enqueue", "next" and a URL-less "play" to resume from paused tracks.

develop
Icedream 2015-10-21 15:37:02 +02:00
parent e0379895d7
commit f368221b3b
1 changed files with 57 additions and 2 deletions

View File

@ -146,8 +146,14 @@ ts3clientService.on "started", (ts3proc) =>
switch name.toLowerCase() switch name.toLowerCase()
when "play" when "play"
inputBB = paramline inputBB = paramline.trim()
input = removeBB paramline
# we gonna interpret play without a url as an attempt to unpause the current song
if inputBB.length <= 0
vlc.status.resume()
return
input = removeBB inputBB
# only allow playback from file if it's a preconfigured alias # only allow playback from file if it's a preconfigured alias
if isValidUrl input if isValidUrl input
@ -190,6 +196,55 @@ ts3clientService.on "started", (ts3proc) =>
ts3query.sendtextmessage args.targetmode, invoker.id, "Something seems to be wrong with that media. Maybe check the URL/sound name you provided?" ts3query.sendtextmessage args.targetmode, invoker.id, "Something seems to be wrong with that media. Maybe check the URL/sound name you provided?"
return return
ts3query.sendtextmessage args.targetmode, invoker.id, "Now playing [URL=#{input}]#{info.title}[/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 unfortunately didn't work out, I'm sorry."
return
ts3query.sendtextmessage args.targetmode, invoker.id, "Going to the next playlist entry."
when "enqueue"
inputBB = paramline
input = removeBB paramline
# only allow playback from file if it's a preconfigured alias
if isValidUrl input
log.debug "Got input URL:", input
else
input = config.get "aliases:#{input}"
if not(isValidUrl input) and not(fs.existsSync input)
log.debug "Got neither valid URL nor valid alias:", input
ts3query.sendtextmessage args.targetmode, invoker.id, "Sorry, you're not allowed to play #{inputBB} via the bot."
return
# TODO: permission system to check if uid is allowed to play this url or alias
# let's give youtube-dl a shot!
await youtubedl.getInfo input, [
"--format=bestaudio"
], defer(err, info)
if err or not info?
log.debug "There is no audio-only download for #{inputBB}, downloading full video instead."
await youtubedl.getInfo input, [
"--format=best"
], defer(err, info)
if err or not info?
info =
url: input
if not info.url?
info.url = input
info.title = input # URL as title
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 that media. Maybe check the URL/sound name you provided?"
return
ts3query.sendtextmessage args.targetmode, invoker.id, "Now playing [URL=#{input}]#{info.title}[/URL]." ts3query.sendtextmessage args.targetmode, invoker.id, "Now playing [URL=#{input}]#{info.title}[/URL]."
when "stop" when "stop"
await vlc.status.stop defer(err) await vlc.status.stop defer(err)