Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting to blur and unblur subtitle tracks on mouse hover #413

Merged
merged 5 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions common/app/services/video-channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,9 @@ export default class VideoChannel {
subtitleCustomStyles,
imageBasedSubtitleScaleFactor,
subtitleAlignment,
subtitleBlurTrack1,
subtitleBlurTrack2,
subtitleBlurTrack3,
subtitlePositionOffset,
} = settings;
const message: SubtitleSettingsToVideoMessage = {
Expand All @@ -427,6 +430,9 @@ export default class VideoChannel {
subtitleCustomStyles,
imageBasedSubtitleScaleFactor,
subtitleAlignment,
subtitleBlurTrack1,
subtitleBlurTrack2,
subtitleBlurTrack3,
subtitlePositionOffset,
},
};
Expand Down
54 changes: 54 additions & 0 deletions common/components/SettingsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,9 @@ export default function SettingsForm({
subtitlePreview,
subtitlePositionOffset,
subtitleAlignment,
subtitleBlurTrack1,
subtitleBlurTrack2,
subtitleBlurTrack3,
audioPaddingStart,
audioPaddingEnd,
maxImageWidth,
Expand Down Expand Up @@ -1534,6 +1537,57 @@ export default function SettingsForm({
onChange={(e) => handleSettingChanged('subtitlePositionOffset', Number(e.target.value))}
/>
</div>
<FormLabel className={classes.top} component="legend">
{t('settings.subtitleBlur')}
</FormLabel>
<Grid container>
<Grid item xs={4}>
<LabelWithHoverEffect
control={
<Switch
checked={subtitleBlurTrack1}
onChange={(e) => {
handleSettingChanged('subtitleBlurTrack1', e.target.checked);
}}
/>
}
label={t('settings.subtitleBlurTrack1')}
labelPlacement="start"
className={classes.switchLabel}
/>
</Grid>
<Grid item xs={4}>
<LabelWithHoverEffect
control={
<Switch
checked={subtitleBlurTrack2}
onChange={(e) => {
handleSettingChanged('subtitleBlurTrack2', e.target.checked);
}}
/>
}
label={t('settings.subtitleBlurTrack2')}
labelPlacement="start"
className={classes.switchLabel}
/>
</Grid>
<Grid item xs={4}>
<LabelWithHoverEffect
control={
<Switch
checked={subtitleBlurTrack3}
onChange={(e) => {
handleSettingChanged('subtitleBlurTrack3', e.target.checked);
}}
/>
}
label={t('settings.subtitleBlurTrack3')}
labelPlacement="start"
className={classes.switchLabel}
/>
</Grid>
</Grid>
<FormHelperText>{t('settings.subtitleBlurDescription')}</FormHelperText>
</FormGroup>
</Grid>
</TabPanel>
Expand Down
5 changes: 5 additions & 0 deletions common/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,11 @@
"subtitleAlignment": "Subtitle Alignment",
"subtitleAlignmentBottom": "Bottom",
"subtitleAlignmentTop": "Top",
"subtitleBlur": "Subtitle blur",
"subtitleBlurTrack1": "Track 1",
"subtitleBlurTrack2": "Track 2",
"subtitleBlurTrack3": "Track 3",
"subtitleBlurDescription": "Hides selected subtitle tracks by blurring them, can be unblurred on mouse hover",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Hides selected subtitle tracks by blurring them. Can be un-blurred on mouse hover.

"tabName": "Name of the tab",
"subtitleRegexFilter": "Subtitle regex filter",
"subtitleRegexFilterTextReplacement": "Subtitle regex filter text replacement",
Expand Down
3 changes: 3 additions & 0 deletions common/settings/settings-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export const defaultSettings: AsbplayerSettings = {
subtitlePreview: 'アあ安Aa',
subtitlePositionOffset: 75,
subtitleAlignment: 'bottom',
subtitleBlurTrack1: false,
subtitleBlurTrack2: false,
subtitleBlurTrack3: false,
audioPaddingStart: 0,
audioPaddingEnd: 500,
maxImageWidth: 0,
Expand Down
3 changes: 3 additions & 0 deletions common/settings/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ export interface SubtitleSettings extends TextSubtitleSettings {
readonly imageBasedSubtitleScaleFactor: number;
readonly subtitlePositionOffset: number;
readonly subtitleAlignment: SubtitleAlignment;
readonly subtitleBlurTrack1: boolean;
readonly subtitleBlurTrack2: boolean;
readonly subtitleBlurTrack3: boolean;
}

export interface KeyBind {
Expand Down
45 changes: 33 additions & 12 deletions extension/src/controllers/subtitle-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default class SubtitleController {
private subtitlesElementOverlay: ElementOverlay;
private notificationElementOverlay: ElementOverlay;
disabledSubtitleTracks: { [key: number]: boolean | undefined };
blurredSubtitleTracks: { [key: number]: boolean | undefined };
subtitleFileNames?: string[];
_forceHideSubtitles: boolean;
_displaySubtitles: boolean;
Expand Down Expand Up @@ -70,6 +71,7 @@ export default class SubtitleController {
this.subtitleCollection = new SubtitleCollection<SubtitleModelWithIndex>([]);
this.showingSubtitles = [];
this.disabledSubtitleTracks = {};
this.blurredSubtitleTracks = {};
this._forceHideSubtitles = false;
this._displaySubtitles = true;
this.lastLoadedMessageTimestamp = 0;
Expand Down Expand Up @@ -127,7 +129,12 @@ export default class SubtitleController {
setSubtitleSettings(subtitleSettings: SubtitleSettings) {
const styles = computeStyleString(subtitleSettings);

if (styles !== this.subtitleStyles) {
const shouldForceRerender =
this.subtitleSettings?.subtitleBlurTrack1 !== subtitleSettings.subtitleBlurTrack1 ||
this.subtitleSettings?.subtitleBlurTrack2 !== subtitleSettings.subtitleBlurTrack2 ||
this.subtitleSettings?.subtitleBlurTrack3 !== subtitleSettings.subtitleBlurTrack3;

if (styles !== this.subtitleStyles || shouldForceRerender) {
this.subtitleStyles = styles;
this.cacheHtml();
}
Expand All @@ -152,6 +159,16 @@ export default class SubtitleController {
return this._subtitleAlignment;
}

setBlurredSubtitleTracks(values: boolean[]) {
values.forEach((value, trackIndex) => {
this.blurredSubtitleTracks[trackIndex] = value;
});
}

getBlurredSubtitleTrack(trackIndex: number) {
return this.blurredSubtitleTracks[trackIndex] || false;
}

private _applyElementOverlayParams(overlay: ElementOverlay, params: ElementOverlayParams) {
overlay.offsetAnchor = params.offsetAnchor;
overlay.fullscreenContainerClassName = params.fullscreenContainerClassName;
Expand Down Expand Up @@ -345,6 +362,10 @@ export default class SubtitleController {
return subtitles.map((subtitle) => {
return {
html: () => {
const blurClass = this.getBlurredSubtitleTrack(subtitle.track)
? 'asbplayer-subtitles-blurred'
: undefined;

if (subtitle.textImage) {
const imageScale =
((this.subtitleSettings?.imageBasedSubtitleScaleFactor ?? 1) *
Expand All @@ -353,25 +374,25 @@ export default class SubtitleController {
const width = imageScale * subtitle.textImage.image.width;

return `
<div style="max-width:${width}px;">
<img
style="width:100%;"
alt="subtitle"
src="${subtitle.textImage.dataUrl}"
/>
</div>
`;
<div style="max-width:${width}px;" ${blurClass ? `class="${blurClass}"` : ''}">
<img
style="width:100%;"
alt="subtitle"
src="${subtitle.textImage.dataUrl}"
/>
</div>
`;
} else {
return this._buildTextHtml(subtitle.text);
return this._buildTextHtml(subtitle.text, blurClass);
}
},
key: String(subtitle.index),
};
});
}

private _buildTextHtml(text: string) {
return `<span style="${this._subtitleStyles()}">${text}</span>`;
private _buildTextHtml(text: string, className?: string) {
return `<span ${className ? `class="${className}"` : ''}" style="${this._subtitleStyles()}">${text}</span>`;
}

unbind() {
Expand Down
5 changes: 5 additions & 0 deletions extension/src/services/binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,11 @@ export default class Binding {
this.subtitleController.displaySubtitles = currentSettings.streamingDisplaySubtitles;
this.subtitleController.subtitlePositionOffset = currentSettings.subtitlePositionOffset;
this.subtitleController.subtitleAlignment = currentSettings.subtitleAlignment;
this.subtitleController.setBlurredSubtitleTracks([
currentSettings.subtitleBlurTrack1,
currentSettings.subtitleBlurTrack2,
currentSettings.subtitleBlurTrack3,
]);
this.subtitleController.surroundingSubtitlesCountRadius = currentSettings.surroundingSubtitlesCountRadius;
this.subtitleController.surroundingSubtitlesTimeRadius = currentSettings.surroundingSubtitlesTimeRadius;
this.subtitleController.autoCopyCurrentSubtitle = currentSettings.autoCopyCurrentSubtitle;
Expand Down
8 changes: 8 additions & 0 deletions extension/src/video.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@
white-space: pre-wrap !important;
}

.asbplayer-subtitles-blurred {
filter: blur(10px);
}

.asbplayer-subtitles-blurred:hover {
filter: none;
}

.asbplayer-notification-container-bottom {
position: absolute !important;
left: 50%;
Expand Down