summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Hipp <patrick.hipp@student.tugraz.at>2015-03-23 16:18:18 +0100
committerwm4 <wm4@nowhere>2015-03-23 20:46:22 +0100
commitdd08aa7364e061132b795f6e55aaeeb2e4854b8e (patch)
tree2e20c9984ec1a1dcc916c3e70c245e7673824be5
parentc48de9e399cad3c1b181d0e0e53841e5c15e7610 (diff)
downloadmpv-dd08aa7364e061132b795f6e55aaeeb2e4854b8e.tar.bz2
mpv-dd08aa7364e061132b795f6e55aaeeb2e4854b8e.tar.xz
TOOLS: add a lua scripts for extracting and setting starttime with ytdl
Signed-off-by: wm4 <wm4@nowhere>
-rw-r--r--TOOLS/lua/youtube-starttime.lua34
1 files changed, 34 insertions, 0 deletions
diff --git a/TOOLS/lua/youtube-starttime.lua b/TOOLS/lua/youtube-starttime.lua
new file mode 100644
index 0000000000..ea8e9abe3f
--- /dev/null
+++ b/TOOLS/lua/youtube-starttime.lua
@@ -0,0 +1,34 @@
+--sets the startime of a youtube video as specified in the "t=HHhMMmSSs" part of the url
+--NOTE: This might become obsolete once youtube-dl adds the functionality
+
+local msg = require 'mp.msg'
+
+function youtube_starttime()
+ url = mp.get_property("path", "")
+ start = 0
+
+ if string.find(url, "youtu%.?be") and
+ ((url:find("http://") == 1) or (url:find("https://") == 1)) then
+ time = string.match(url, "[#&%?]t=%d*h?%d*m?%d+s?m?h?")
+ --the time-string can start with #, & or ? followed by t= and the timing parameters
+ --at least one number needs to be present after t=, followed by h, m, s or nothing (>implies s)
+
+ if time then
+ for pos in string.gmatch(time,"%d+%a?") do
+ if string.match(pos,"%d+h") then --find out multiplier for
+ multiplier = 60*60 --hours
+ elseif string.match(pos,"%d+m") then
+ multiplier = 60 --minutes
+ else multiplier = 1 end --seconds
+
+ start = start + (string.match(pos,"%d+") * multiplier)
+ end
+
+ msg.info("parsed '" .. time .. "' into '" .. start .. "' seconds")
+ end
+
+ mp.set_property("file-local-options/start",start)
+ end
+end
+
+mp.add_hook("on_load", 50, youtube_starttime)