mpv-nihongo icon indicating copy to clipboard operation
mpv-nihongo copied to clipboard

Add work around for subtitle timings so as to not use the patched mpv version

Open oudajosefu opened this issue 5 years ago • 8 comments

I made a script recently that works off another mpv script author's work which does something similar to yours in that it records the audio of a subtitle's timestamps in one press of a button. I would like to use your scripts too but I'm quite disheartened that I'd also need to download your patched version of mpv. Therefore, to eliminate that requirement, maybe it would be better to incorporate my script's work around for using the subtitle timestamps. What I did can be seen below (I apologize in advance for using es5... I'm pretty sure mpv's engine is limited to es5 though so I don't know how you were able to use ts with es6 conventions).

function cut_audio_fragment_quickly() {
    mp.set_property("pause", "yes");
    set_end_timestamp();
    print("End timestamp: success!")

    do { 
        dump(mp.wait_event(0));
        replay_sub();
        set_start_timestamp();
    } while (mp.wait_event(0).event !== "none");
    print("Start timestamp: success!");
    
    do {
        dump(mp.wait_event(0));
        mp.commandv("seek", end_timestamp, "absolute+exact");
        cut_audio_fragment();
        if (!pauseAfterQuickCut) {
            mp.set_property("pause", "no");
        }
    } while (mp.wait_event(0).event !== "none");
    print("Audio fragment cut: success!");
}

oudajosefu avatar Jan 16 '20 00:01 oudajosefu

I upstreamed my patches some months ago. It's even in the stable releases:

https://github.com/mpv-player/mpv/releases/tag/v0.30.0 command: add sub-start & sub-end properties

Sorry but the readme is a bit old. Updating it soon.

pigoz avatar Jan 16 '20 08:01 pigoz

Ahhh, thanks for clarifying, I asked because I wanted to see if your script would work on the app IINA which is based off mpv. I have now confirmed that it does, thanks to your clarification.

Another question: How did you manage to get typescript to work as a scripting language in mpv? I thought only es5 javascript and lua were allowed.

oudajosefu avatar Jan 16 '20 22:01 oudajosefu

I compile the typescript down to es5: https://github.com/pigoz/mpv-nihongo/blob/master/package.json#L28 https://github.com/pigoz/mpv-nihongo/blob/master/package.json#L30

This project is really not very clean at the moment. I should make it more generic so that other people can use it.

pigoz avatar Jan 17 '20 08:01 pigoz

Interesting how you managed that. I agree that the project should be made more generic, because I'm having trouble getting it to work at the moment. Your instructions aren't exactly very clear. I assumed that you add the cloned repository into the scripts folder and yarn compile and build there. Is this how it works? Or am I missing something obvious because it's not working for me.

oudajosefu avatar Jan 17 '20 10:01 oudajosefu

No, I just clone it anywhere. And run yarn install && yarn build. In the dist folder then you can find the JavaScript files compatible with mpv.

pigoz avatar Jan 17 '20 10:01 pigoz

Last question. Any chance I can get a copy of your mpv-blacklist.txt? Don't know what it's used for but if it's necessary then I'd like to use it to make your script work. Thanks

oudajosefu avatar Jan 17 '20 21:01 oudajosefu

Nevermind, I think I understand what it does. I will make my own. Yours would be nice to have though lol.

oudajosefu avatar Jan 17 '20 21:01 oudajosefu

my mpv-blacklist, it's kinda dependent on the words you want to be excluded: https://0x0.st/zF8U.txt

pigoz avatar Jan 17 '20 22:01 pigoz