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 Subtitle generator feature #1728

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,10 @@ ipcMain.on('set-user-setting', (event, settingChanger) => {
mainWindow.webContents.send('set-user-setting', settingChanger);
});

ipcMain.on('download-subtitle', (event, filename) => {
mainWindow.webContents.downloadURL(filename);
})

module.exports = {
openSecondaryWindow,
appVersion,
Expand Down
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
"scroll": "^3.0.1",
"sharp": "^0.31.3",
"socket.io": "^4.5.1",
"subtitle-generator": "^0.0.4",
"tippy.js": "^6.3.7",
"universal-analytics": "^0.5.3",
"update": "^0.7.4",
Expand Down
4 changes: 3 additions & 1 deletion www/configs/navigator-settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@
"copyToClipboard": false
},
"minimizedBySingleDisplay": false,
"isDontSaveHistory": false
"isDontSaveHistory": false,
"isSubtitleRecording": false,
"subtitleData": []
}
17 changes: 12 additions & 5 deletions www/main/navigator/Navigator.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const remote = require('@electron/remote');
const analytics = remote.getGlobal('analytics');

const Navigator = () => {
const { isSingleDisplayMode, akhandpatt } = useStoreState(state => state.userSettings);
const { setAkhandpatt } = useStoreState(state => state.userSettings);
const { isSingleDisplayMode, akhandpatt } = useStoreState((state) => state.userSettings);
const { setAkhandpatt } = useStoreState((state) => state.userSettings);
const {
minimizedBySingleDisplay,
shortcuts,
Expand All @@ -23,7 +23,8 @@ const Navigator = () => {
isSundarGutkaBani,
isCeremonyBani,
ceremonyId,
} = useStoreState(state => state.navigator);
isSubtitleRecording,
} = useStoreState((state) => state.navigator);
const {
setShortcuts,
setIsMiscSlide,
Expand All @@ -32,9 +33,9 @@ const Navigator = () => {
setIsSundarGutkaBani,
setIsCeremonyBani,
setCeremonyId,
} = useStoreActions(state => state.navigator);
} = useStoreActions((state) => state.navigator);

const addMiscSlide = givenText => {
const addMiscSlide = (givenText) => {
if (isAnnoucement) {
setIsAnnoucement(false);
}
Expand Down Expand Up @@ -134,6 +135,12 @@ const Navigator = () => {
<ShabadPane />
</div>
<div className="navigator-row">
{isSubtitleRecording && (
<div className="subtitle-status">
<i class="fa fa-circle"></i>
<span>Recording</span>
Copy link
Collaborator

Choose a reason for hiding this comment

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

veerji I think this should come from i18n

</div>
)}
<ViewerPane />
<MiscPane
waheguruSlide={openWaheguruSlide}
Expand Down
2 changes: 2 additions & 0 deletions www/main/navigator/misc/components/MiscContent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useDataLayerValue } from '../state-manager/DataLayer';
import { HistoryPane } from './HistoryPane';
import { InsertPane } from './InsertPane';
import { OtherPane } from './OtherPane';
import { RecordPane } from './RecordPane';

export const MiscContent = () => {
const [{ miscPanel }] = useDataLayerValue();
Expand All @@ -12,6 +13,7 @@ export const MiscContent = () => {
<HistoryPane className={miscPanel === 'History' ? '' : 'd-none'} />
<InsertPane className={miscPanel === 'Insert' ? '' : 'd-none'} />
<OtherPane className={miscPanel === 'Others' ? '' : 'd-none'} />
<RecordPane className={miscPanel === 'Record' ? '' : 'd-none'} />
</>
);
};
19 changes: 15 additions & 4 deletions www/main/navigator/misc/components/MiscHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useDataLayerValue } from '../state-manager/DataLayer';

export const MiscHeader = () => {
const [{ miscPanel }, dispatch] = useDataLayerValue();
const SetOpenTab = event => {
const SetOpenTab = (event) => {
dispatch({
type: 'SET_PANEL',
miscPanel: event.target.textContent,
Expand All @@ -12,11 +12,12 @@ export const MiscHeader = () => {
const isHistory = miscPanel === 'History';
const isInsert = miscPanel === 'Insert';
const isOther = miscPanel === 'Others';
const isRecord = miscPanel === 'Record';
return (
<div className="misc-header">
<a
className={`misc-button ${isHistory ? 'misc-active' : ''}`}
onClick={event => SetOpenTab(event)}
onClick={(event) => SetOpenTab(event)}
>
<i className="fa fa-clock-o">
<span className="Icon-label" key="History">
Expand All @@ -27,17 +28,27 @@ export const MiscHeader = () => {

<a
className={`misc-button ${isInsert ? 'misc-active' : ''}`}
onClick={event => SetOpenTab(event)}
onClick={(event) => SetOpenTab(event)}
>
<i className="fa fa-desktop">
<span className="Icon-label" key="Insert">
Insert
</span>
</i>
</a>
<a
className={`misc-button ${isRecord ? 'misc-active' : ''}`}
onClick={(event) => SetOpenTab(event)}
>
<i className="fa fa-circle">
<span className="Icon-label" key="Record">
Record
Copy link
Collaborator

Choose a reason for hiding this comment

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

veerji this should be coming from i18n

</span>
</i>
</a>
<a
className={`misc-button ${isOther ? 'misc-active' : ''}`}
onClick={event => SetOpenTab(event)}
onClick={(event) => SetOpenTab(event)}
>
<i className="fa fa-ellipsis-h">
<span className="Icon-label" key="Others">
Expand Down
125 changes: 125 additions & 0 deletions www/main/navigator/misc/components/RecordPane.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import { useStoreState, useStoreActions } from 'easy-peasy';
import { ipcRenderer } from 'electron/renderer';
import anvaad from 'anvaad-js';

import { generateSRT } from 'subtitle-generator';

const path = require('path');
const remote = require('@electron/remote');
const { i18n } = remote.require('./app');
const fs = require('fs');

export const RecordPane = ({ className }) => {
const { isSubtitleRecording, subtitleData } = useStoreState((state) => state.navigator);
const { setIsSubtitleRecording } = useStoreActions((state) => state.navigator);
const [fileList, setFileList] = useState([]);

const userData = remote.app.getPath('userData');
const directory = path.resolve(userData, 'subtitles');

const startRecording = () => {
if (!isSubtitleRecording) {
setIsSubtitleRecording(true);
}
};

const stopRecording = () => {
const parsed = subtitleData.map((data, index) => {
return {
id: index,
seconds: data.seconds,
content: anvaad.unicode(data.content),
};
});
const srt = generateSRT(parsed, 'seconds');
if (isSubtitleRecording) {
setIsSubtitleRecording(false);
}
if (!fs.existsSync(directory)) {
fs.mkdirSync(directory);
}
const currentDate = new Date();
const filename = `${currentDate.getFullYear()}-${currentDate.getMonth()}-${currentDate.getDate()}-${currentDate.getHours()}${currentDate.getMinutes()}${currentDate.getSeconds()}.srt`;
Copy link
Collaborator

Choose a reason for hiding this comment

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

veerji this string is way too lengthy. It should not cross more than 100 letters.

const filePath = path.resolve(directory, filename);

fs.writeFile(filePath, srt, updateList);
};

const updateList = () => {
fs.readdir(directory, (error, files) => {
const sortedFiles = files
.map((fileName) => ({
name: fileName,
time: fs.statSync(`${directory}/${fileName}`).mtime.getTime(),
}))
.sort((a, b) => b.time - a.time)
.map((file) => file.name);
setFileList(sortedFiles);
});
};

useEffect(() => {
updateList();
});

const download = (fileName) => {
const filePath = path.resolve(directory, fileName);
ipcRenderer.send('download-subtitle', filePath);
};

const deleteFile = (filename) => {
const filePath = path.resolve(directory, filename);
fs.unlink(filePath, (err) => {
if (err) throw err;
});
updateList();
};

return (
<div className={`subtitle-pane ${className}`}>
<h3>Record Subtitles</h3>
<p>To generate subtitles as you go through the shabads, click on the record button below:</p>
Comment on lines +82 to +83
Copy link
Collaborator

Choose a reason for hiding this comment

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

veerji static strings should come from i18n. There are a lot of other places in this file which needs this issue to be fixed.

{isSubtitleRecording ? (
<button className="button subtitle-btn" onClick={stopRecording}>
Stop Recording
</button>
) : (
<button className="button subtitle-btn" onClick={startRecording}>
Record
</button>
)}
{fileList.length > 0 && <h3>Previous recordings</h3>}
{fileList.map((file) => {
return (
<div class="subtitle-item">
<p>{file}</p>
<div class="controls">
<button
className="button"
onClick={() => {
download(file);
}}
>
<i class="fa fa-download"></i>
</button>
<button
className="button"
onClick={() => {
deleteFile(file);
}}
>
<i class="fa fa-trash"></i>
</button>
</div>
</div>
);
})}
</div>
);
};

RecordPane.propTypes = {
className: PropTypes.string,
};
1 change: 1 addition & 0 deletions www/main/navigator/misc/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { HistoryPane } from './HistoryPane';
export { InsertPane } from './InsertPane';
export { OtherPane } from './OtherPane';
export { MiscPane } from './MiscPane';
export { RecordPane } from './RecordPane';
Loading