From 592872f97d28052da14ac05a3c8b24ea44c2e2a2 Mon Sep 17 00:00:00 2001 From: icedream Date: Sun, 8 Nov 2015 01:08:33 +0100 Subject: [PATCH] Implement "time" command. Aliases: "seek", "pos", "position" This command sets the current position in the playing item, time can be given as an argument of any sensible form like "2m 3s", "2m03s", "2:03" or "2m". This command returns the current position in the playing item if given no arguments. --- app.iced | 15 +++++++++++++++ package.json | 3 +++ parse_duration.iced | 12 ++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 parse_duration.iced diff --git a/app.iced b/app.iced index 24d1bd2..4ab6673 100644 --- a/app.iced +++ b/app.iced @@ -11,6 +11,8 @@ qs = require "querystring" temp = require("temp").track() youtubedl = require "youtube-dl" isValidUrl = (require "valid-url").isWebUri +parseDuration = require "./parse_duration.iced" +prettyMs = require "pretty-ms" log = getLogger "Main" @@ -246,6 +248,19 @@ ts3clientService.on "started", (ts3proc) => # play it in VLC vlc.play info.url + when "time", "seek", "pos", "position" + inputBB = paramline.trim() + input = (removeBB paramline).trim() + + # we gonna interpret no argument as us needing to return the current position + if input.length <= 0 + ts3query.sendtextmessage args.targetmode, invoker.id, "Currently position is #{prettyMs vlc.input.time}." + return + + ts3query.sendtextmessage args.targetmode, invoker.id, "Seeking to #{prettyMs vlc.input.time}." + vlc.input.time = parseDuration input + + return when "stop-after" vlc.playlist.mode = vlc.playlist.Single ts3query.sendtextmessage args.targetmode, invoker.id, "Playback will stop after the current playlist item." diff --git a/package.json b/package.json index f2fba59..71d560f 100644 --- a/package.json +++ b/package.json @@ -31,9 +31,12 @@ "iced-coffee-script": "^108.0.8", "merge": "^1.2.0", "mkdirp": "^0.5.1", + "named-regexp": "^0.1.1", "nconf": "^0.7.2", "npm-which": "^2.0.0", + "parse-duration": "^0.1.1", "password-generator": "^2.0.1", + "pretty-ms": "^2.1.0", "querystring": "^0.2.0", "request": "^2.61.0", "simple-ini": "^1.0.3", diff --git a/parse_duration.iced b/parse_duration.iced new file mode 100644 index 0000000..bf4b563 --- /dev/null +++ b/parse_duration.iced @@ -0,0 +1,12 @@ +parseDuration = require "parse-duration" +namedRegex = require("named-regexp").named + +durationRegex = namedRegex /^(((:[0-9]{0,2}):)?(:[0-9]{0,2}):)?(:[0-9]{0,2})(:\.[0-9]*)?$/ + +module.exports = (str) -> + # check if this is in the colon-separated format + if str.indexOf(":") > -1 and str.match durationRegex + m = durationRegex.exec(str).matches + return m["ms"] + m["s"]*60 + m["m"]*(60*60) + m["h"]*(60*60*60) + + parseDuration str \ No newline at end of file