Last active
August 29, 2015 14:17
-
-
Save Shudouken/0233126a99627be217a4 to your computer and use it in GitHub Desktop.
youtube-starttime.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--sets the startime of a youtube video as specified in the "t=HHhMMmSSs" part of the url | |
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) |
How do I install and enable this script? I put it under ~/.mpv/scripts, but eg. mpv https://www.youtube.com/watch?v=2FwDy1F7k1M&t=20s
just gives Playing: https://www.youtube.com/watch?v=2FwDy1F7k1M
, like before, and starts playback at the beginning.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sense mpv can save the position on close and the resume info is loaded before scripts
if start ~= 0 then mp.set_property("file-local-options/start",start); end
would allow the resume playback function to continue to work.