-
Notifications
You must be signed in to change notification settings - Fork 7
Added subtitles plugin #2
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
base: master
Are you sure you want to change the base?
Changes from 9 commits
afcbbaa
ccc62f6
9a52ced
22fca8c
2cc68a7
5d49f22
4f89744
b235980
a113ab8
b095094
be698d7
99e2730
fcaa26c
3b77e58
b7b79ec
e751fd8
191d353
a8449ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # Heavily based on https://joelhooks.com/jest-and-github-actions | ||
|
Contributor
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. @gvamshi-metrological Could you please remove this file from your PR? Regrettably, we can't use Github actions with our Github subscription. This will not change; the repo will most likely move to a Bitbucket environment somewhere in the upcoming months. So basically; we'll never get this to work I'm afraid 😩 |
||
| name: Tests CI | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths-ignore: | ||
| - 'README.md' | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v3 | ||
|
|
||
| - name: Reconfigure git to use HTTPS authentication | ||
| uses: GuillaumeFalourd/SSH-to-HTTPS@v1 | ||
|
|
||
| - name: Setup Node | ||
| uses: actions/setup-node@v1 | ||
| with: | ||
| node-version: '17' | ||
|
robbertvancaem marked this conversation as resolved.
Outdated
|
||
|
|
||
| - name: Install | ||
| run: | | ||
| npm ci | ||
|
|
||
| - name: Run ESLint | ||
| run: npm run lint | ||
|
|
||
| - name: Run Jest tests | ||
| run: npm run test:ci | ||
|
robbertvancaem marked this conversation as resolved.
Outdated
|
||
|
|
||
| - name: Tests ✅ | ||
| if: ${{ success() }} | ||
| run: | | ||
| curl --request POST \ | ||
| --url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }} \ | ||
| --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \ | ||
| --header 'content-type: application/json' \ | ||
| --data '{ | ||
| "context": "tests", | ||
| "state": "success", | ||
| "description": "Tests passed", | ||
| "target_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" | ||
| }' | ||
|
|
||
| - name: Tests 🚨 | ||
| if: ${{ failure() }} | ||
| run: | | ||
| curl --request POST \ | ||
| --url https://api.github.com/repos/${{ github.repository }}/statuses/${{ github.sha }} \ | ||
| --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' \ | ||
| --header 'content-type: application/json' \ | ||
| --data '{ | ||
| "context": "tests", | ||
| "state": "failure", | ||
| "description": "Tests failed", | ||
| "target_url": "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" | ||
| }' | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| node_modules | ||
| .DS_store | ||
| .idea | ||
| coverage |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| module.exports = { | ||
| env: { | ||
| test: { | ||
| plugins: ['@babel/plugin-transform-modules-commonjs'], | ||
| }, | ||
| }, | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # Subtitles | ||
|
robbertvancaem marked this conversation as resolved.
Outdated
robbertvancaem marked this conversation as resolved.
Outdated
|
||
|
|
||
| subtitle plugin allows you to fetch and parse the subtitle file from the given URL and you can read the subtitle text from the parsed file based on the current videoplayback time. | ||
|
|
||
| ## Usage | ||
|
|
||
| If you want to access Subtitles in your App code directly, import the *Subtitles* plugin from the Lightning SDK: | ||
|
|
||
| ```js | ||
| import { Subtitles } from '@lightningjs/sdk' | ||
|
robbertvancaem marked this conversation as resolved.
Outdated
|
||
| ``` | ||
|
|
||
|
|
||
| ## Available methods | ||
|
|
||
| ### fetchAndParseSubs | ||
|
|
||
| `fetchAndParseSubs` method expects a valid file URL as an argument. | ||
| This method will fetch a file from the URL and parse it to create a list of objects. created subtitles list is stored in the plugin. | ||
| This method returns a promise that resolves to parsed subtitles as a list of objects containing {start, end, payload}. | ||
| ```js | ||
| const subtitlesUrl = 'http://abc.def.com/xyz.srt' | ||
| Subtitles.fetchAndParseSubs(URL) | ||
| ``` | ||
| ### customParser | ||
|
|
||
| you can also send a customParser as a callback to `fetchAndParseSubs` as a second argument, customParser should return a list of subtitle objects that contains | ||
| {start: <float>, end: <float>, payload: <string>} | ||
|
|
||
|
|
||
| ```js | ||
| const customParser = (str) = { | ||
| ... | ||
| ... | ||
| return [{start: 3, end: 10, payload: 'this is subtitle text'}, { start: 11, end: 14, payload: 'this is subtitle text2'}, ...] | ||
| } | ||
| const subtitlesUrl = 'http://abc.def.com/xyz.srt' | ||
| Subtitles.fetchAndParseSubs(URL, customParser) | ||
| ``` | ||
|
|
||
| ### removeSubtitleTextStyles | ||
|
|
||
| By default, all the TextStyles in the subtitle string are removed, you can pass {removeSubtitleTextStyles: false} as | ||
| the third argument to keep text styles in subtitle string | ||
|
|
||
| ```js | ||
| Subtitles.fetchAndParseSubs(URL, null, {removeSubtitleTextStyles: false}) | ||
| ``` | ||
| ### getSubtitleByTimeIndex | ||
| From the stored subtitles you can get subtitles as text when you pass currentTime(in seconds) as an argument to the method. | ||
|
|
||
| ```js | ||
| Subtitles.getSubtitleByTimeIndex(currentTime) | ||
| ``` | ||
|
|
||
| ### clearCurrentSubtitle | ||
|
|
||
| `clearCurrentSubtitle` method will clear all the stored subtitles in the plugin. | ||
|
|
||
| ```js | ||
| Subtitles.clearCurrentSubtitle() | ||
| ``` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -476,3 +476,69 @@ The available events are: | |
| * $videoPlayerVolumeChange | ||
| * $videoPlayerWaiting | ||
| * $videoPlayerClear | ||
|
|
||
| ### SubtitlesParse | ||
|
|
||
| subtitle plugin allows you to fetch and parse the subtitle file from the given URL and you can read the subtitle text from the parsed file based on the current videoplayback time. | ||
|
robbertvancaem marked this conversation as resolved.
|
||
|
|
||
| ```js | ||
| const subtitlesUrl = 'http://abc.def.com/xyz.srt' | ||
| VideoPlayer.openSubtitles(subtitlesUrl) | ||
| ``` | ||
| If you don't want to use the default parser you can also pass a custom parser as a callback as the second argument. | ||
|
|
||
| NOTE: customParser must return list of subtitle object contains {start: \<float\>, end: \<float\>, payload: \<string\>} | ||
|
|
||
| ```js | ||
| const customParser = (str) = { | ||
| ... | ||
| ... | ||
| return [{start: 3, end: 10, payload: 'this is subtitle text'}, { start: 11, end: 14, payload: 'this is subtitle text2'}, ...] | ||
| } | ||
| const subtitlesUrl = 'http://abc.def.com/xyz.srt' | ||
| VideoPlayer.openSubtitles(subtitlesUrl, customParser) | ||
| ``` | ||
| By default, all the TextStyles are removed in subtitle text, you can pass {removeSubtitleTextStyles: false} as | ||
| the third argument to keep text styles in subtitle string | ||
|
|
||
| ```js | ||
| const subtitlesUrl = 'http://abc.def.com/xyz.srt' | ||
| VideoPlayer.openSubtitles(subtitlesUrl, null, {removeSubtitleTextStyles: false}) | ||
| ``` | ||
| on successful parsing of subtitles $videoPlayerSubtitlesReady is fired on the consumer. | ||
| if VideoPlayer fails to parse subtitles a $videoPlayerSubtitlesError is fired on the consumer. error returned as first argument. | ||
|
|
||
|
|
||
| ### currentSubtitleText | ||
|
|
||
| getter that retrieves the current subtitle as a string based on videoPlayer currentTime, which can be rendered in your app using the text component. | ||
| or | ||
| you can use the $VidePlayerSubtitleTextChanged event that fires when there is a subtitle text change, in this event you will receive | ||
| subtitle string as the first argument. | ||
| videoPlayer current time as the second argument. | ||
| ```js | ||
| class DummyComponent extends Lightning.component { | ||
| static _template() { | ||
| return { | ||
| Subtitles: { | ||
| text: { | ||
| text: '' | ||
| textColor: 0xff000000, | ||
| fontSize: 48, | ||
| textAlign: 'center', | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| $videoPlayerSubtitleTextChanged(text, currentTime){ | ||
|
robbertvancaem marked this conversation as resolved.
|
||
| const _subtitleText = text || ''// current subtitle to render depending on video playback | ||
| // update subtitle text to your template | ||
| this.tag('Subtitles').text = _subtitleText; | ||
|
Contributor
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. Shouldn't this be |
||
| } | ||
|
|
||
| const _subtitleText = VideoPlayer.currentSubtitleText || '' | ||
| this.tag('Subtitles').text = _subtitleText; | ||
|
Contributor
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. Why are these lines needed? |
||
| } | ||
| ``` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* eslint-disable no-console */ | ||
|
Contributor
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. @gvamshi-metrological Can you please remove this file, also because we can't use Github actions 😩 |
||
| class GithubActionsReporter { | ||
| constructor(globalConfig, options) { | ||
| this._globalConfig = globalConfig | ||
| this._options = options | ||
| } | ||
|
|
||
| onRunComplete(contexts, results) { | ||
| results.testResults.forEach(testResultItem => { | ||
| const testFilePath = testResultItem.testFilePath | ||
|
|
||
| testResultItem.testResults.forEach(result => { | ||
| if (result.status !== 'failed') { | ||
| return | ||
| } | ||
|
|
||
| result.failureMessages.forEach(failureMessages => { | ||
| const newLine = '%0A' | ||
| const message = failureMessages.replace(/\n/g, newLine) | ||
| const captureGroup = message.match(/:([0-9]+):([0-9]+)/) | ||
|
|
||
| if (!captureGroup) { | ||
| console.log('Unable to extract line number from call stack') | ||
| return | ||
| } | ||
|
|
||
| const [, line, col] = captureGroup | ||
| console.log(`::error file=${testFilePath},line=${line},col=${col}::${message}`) | ||
| }) | ||
| }) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // eslint-disable-next-line no-undef | ||
| module.exports = GithubActionsReporter | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /* | ||
| * For a detailed explanation regarding each configuration property, visit: | ||
| * https://jestjs.io/docs/configuration | ||
| */ | ||
|
|
||
| module.exports = { | ||
| clearMocks: true, | ||
| collectCoverage: true, | ||
| coverageDirectory: 'coverage', | ||
| coverageProvider: 'v8', | ||
| coverageThreshold: { | ||
| global: { | ||
| lines: 70, | ||
| }, | ||
| }, | ||
| testEnvironment: 'jsdom', // jsdom | ||
| testEnvironmentOptions: { resources: 'usable' }, | ||
| moduleNameMapper: { | ||
| '@/(.*)$': '<rootDir>/src/$1', | ||
| '^src(.*)': '<rootDir>/src$1', | ||
| '^test(.*)': '<rootDir>/test$1', | ||
| }, | ||
| transform: { '^.+\\.[m|t]?js$': 'babel-jest' }, | ||
| transformIgnorePatterns: [], | ||
| verbose: true, | ||
| testURL: 'http://github.com/andreyvit/subtitle-tools/blob/master/sample.srt', | ||
|
robbertvancaem marked this conversation as resolved.
Outdated
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.