Dev.to WebDev 🛠 Dev 👁 0 📖 3 min read

Give every user on your site their own profanity filter for subtitles

Disclosure: I build Wyzie Subs, the API used below. The per-user part needs a Pro account; everything that needs Pro is marked. If your video site or app has families on it, one filter for everyone does not work. One pa

Disclosure: I build Wyzie Subs, the API used below. The per-user part needs a Pro account; everything that needs Pro is marked.

If your video site or app has families on it, one filter for everyone does not work. One parent wants only the worst words gone. Another wants "oh my god" muted too. A teen profile should keep "damn" and "hell". Until now that meant either one setting for the whole site or building your own word lists.

Wyzie Censored can now take a separate set of rules for each of your users, set from your server. Here is the whole flow.

1. Turn Censored on once

Censored is Pro only, and the on/off switch stays in the console at dash.wyzie.io. That is on purpose: turning it on allows per-minute charges for audio work, so a leaked key can't flip it. Everything after this step is API calls.

2. Set your site's defaults

PATCH /censor/settings sets the account-wide rules. Every field is optional.

curl -X PATCH "https://sub.wyzie.io/censor/settings" \
  -H "Authorization: Bearer YOUR_SERVER_KEY" \
  -H "Content-Type: application/json" \
  -d '{"level":"moderate","mode":"bleep","pad_ms":60}'

The levels run from lenient (severe profanity and slurs only) through moderate, teen and strict up to super_strict, which adds minced oaths like "gosh" and "heck". Blasphemy has two separate toggles: curses, and exclamations such as "oh my god".

3. Give each user their own record (Pro)

Pick an id from your own database. Use something opaque, never an email (an @ is refused on purpose).

curl -X PUT "https://sub.wyzie.io/censor/users/site-user-42" \
  -H "Authorization: Bearer YOUR_SERVER_KEY" \
  -H "Content-Type: application/json" \
  -d '{"level":"teen","words":["frick"],"allow":["god"],"mode":"sound","sound":"chime"}'

Any field you leave out falls back to the account setting. An account holds up to 10,000 users. GET /censor/users lists them and DELETE /censor/users/{user} removes one. These settings routes are free; no request is charged for them.

4. Pass user= when you fetch subtitles

curl "https://sub.wyzie.io/search?id=tt0111161&language=en&censor=1&user=site-user-42&key=YOUR_SERVER_KEY"

Every download link in the result now gives back subtitles cleaned with that user's rules. The id is bound into the link's token, and the user's words never go in a URL. The same user works on the audio routes too: POST /censor, /censor/url, /censor/batch and the live POST /censor/mask.

From your server, in JavaScript:

const res = await fetch(
  `https://sub.wyzie.io/search?id=${imdbId}&language=en&censor=1&user=${userId}`,
  { headers: { Authorization: `Bearer ${process.env.WYZIE_KEY}` } }
);
const subs = await res.json();
// subs[0].url is a clean subtitle for this user

Which rules win

Each request stacks four layers in this order: account settings, then the user, then a named profile (profile=), then options on the request itself. level replaces what came before; words and allow add to it.

Things to know

  • Keep this server-side. Browser keys (wyzie-pub-) get 403 on all of it.
  • Censored works on subtitles in 41 languages with their own word lists.
  • Clean subtitles cost the same as a normal download. Audio cleaning is priced per minute; the docs have the table.

Full reference, error codes included: docs.wyzie.io/subs/usage/censored. A free key for trying the search API is at sub.wyzie.io.

If you run a family or faith-based streaming site and something here doesn't fit how your users pick settings, tell me in the comments.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.