muzuiget / dualsub-support

Dualsub - Dual Subtitles for YouTube
https://www.dualsub.xyz/
281 stars 24 forks source link

Support local video files #372

Closed Manishearth closed 2 years ago

Manishearth commented 2 years ago

It's possible to simply open local video files in the browser, and they play as usual using a regular <video> tag.

Since the extension has support for uploading custom subtitle files, it would be nice if it would be possible to use local video files as well by opening them in the browser and then adding the custom subtitle files.

muzuiget commented 2 years ago

Yes, is possible, here is a quick & dirty solution.

Make sure the video file can be play in Chrome

Open a blank page about:blank, then "drag & drop" the video file in it, to check if Chrome shows a embed player and plays the file.

If Chrome popup a save-as file dialog, rename to video file extension name to .webm(eg: test.mkv to test.webm) and try again.

Create a script type plugin in Dualsub

Screenshot_20220207_204506

Here is the code for you to paste:

document.body.addEventListener('dragover', function(event) {
    event.preventDefault();
});
document.body.addEventListener('drop', function(event) {
    event.preventDefault();
    const file = event.dataTransfer.items[0].getAsFile();
    const video = document.querySelector('video[src]');
    video.src = URL.createObjectURL(file);
});

Replace the video file

Open a random YouTube video page, then "drag & drop" the locale file in it, then the YouTube player will the local file.


The final solution is create a standalone website for this use case, see #315 I posted before, you can check it out with Google Translate if you're interested.

Manishearth commented 2 years ago

Sweet, thank you!

muzuiget commented 2 years ago

Now you can try player.dualsub.xyz with Dualsub v1.79.0.

Open https://player.dualsub.xyz/?if=p then drag a video file and some subtitle files to the page.

Manishearth commented 2 years ago

Thanks!