-
Notifications
You must be signed in to change notification settings - Fork 35
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
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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"> | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"> | ||
|
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`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
}; |
There was a problem hiding this comment.
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