Skip to content

Instantly share code, notes, and snippets.

@wareya
Last active July 18, 2020 11:16
Show Gist options
  • Save wareya/0e090dca608bcc91df95ae198aceef94 to your computer and use it in GitHub Desktop.
Save wareya/0e090dca608bcc91df95ae198aceef94 to your computer and use it in GitHub Desktop.
subtitle text grabbing script for mpv
"use strict";
function on_new_sub(name, text)
{
if(text == null || text == "")
return;
var newtext = "";
for(var i = 0; i < text.length; i += 1)
{
var c = text[i];
if(c == "\n" || c == "\r")
continue;
else if(c == '"')
newtext += "”";
else
newtext += c;
}
//mp.commandv("show-text", newtext);
//mp.commandv("print-text", newtext);
var cmd = 'echo "' + newtext + '" | clip';
//mp.commandv("print-text", cmd);
mp.command("run cmd /D /C " + cmd); // this line may need to be modified to include a chcp 65001 | or chcp 6501 & on some systems
}
mp.observe_property("sub-text", "string", on_new_sub);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment