SelfCensor is a JavaScript library that provides a simple solution for censoring segments of video in the browser. It enables us to define different censor tracks based on age ratings or genres or any other category, and then automatically skip the specified intervals in the video according to the selected track.
With SelfCensor, you can easily add censoring functionality to your video player without the need for any additional plugin or server-side processing. The censoring is performed entirely in the browser, while providing a smooth and uninterrupted viewing experience for the user.
-
Parental Controls: SelfCensor can be used to enable parental controls for video content, allowing parents to restrict their children's access to certain categories of content based on age rating, genre, or other criteria.
-
Online Streaming Platform: SelfCensor can be used by online streaming platforms to provide a more customizable and personalized viewing experience for their users. By providing different censor tracks for a movie, like with subtitles, users get the option to watch different censor versions of the same movie, based on their preference. They can even add their own custom-censored version.
<script type="module">
import SelfCensor from "https://cdn.jsdelivr.net/npm/self-censor@1.0.2/+esm";
</script>
npm i self-censor
Link the JSON file with censor data:
<video id="my-video" data-censor="url-of-my-censor-data.json" controls>
<source src="url-of-my-video.mp4" type="video/mp4" />
</video>
Import the class:
// ESM
import SelfCensor from "self-censor";
// CommonJS
const SelfCensor = require("self-censor");
Instantiate with the id of the target(HTML Video) element:
const censor = new SelfCensor("my-video");
Subscribe to ready
event to get the censor track details:
censor.on("ready", ({ detail: { censorTracks, currentTrack } }) =>
console.dir({ censorTracks, currentTrack })
);
Subscribe to error
event to catch and handle the errors thrown from the service:
censor.on("error", ({ detail }) => console.error(detail));
Start the censoring service:
censor.start();
Temporarily pause the censoring:
censor.pause();
Resume a paused service
censor.resume();
Switch censor track if service is active:
censor.switchTrack("track-name");
Stop the censoring service:
censor.stop();
See Example: Source | Playground
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.