Skip to content
Open
Show file tree
Hide file tree
Changes from 9 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
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ module.exports = {
browser: true,
es6: true,
node: true,
'jest/globals': true,
},
plugins: ['prettier'],
plugins: ['prettier', 'jest'],
extends: ['eslint:recommended', 'plugin:prettier/recommended', 'prettier'],
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
Expand Down
59 changes: 59 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Heavily based on https://joelhooks.com/jest-and-github-actions
Comment thread
robbertvancaem marked this conversation as resolved.
Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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'
Comment thread
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
Comment thread
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 }}"
}'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.DS_store
.idea
coverage
7 changes: 7 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
env: {
test: {
plugins: ['@babel/plugin-transform-modules-commonjs'],
},
},
}
63 changes: 63 additions & 0 deletions docs/plugins/subtitles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Subtitles
Comment thread
robbertvancaem marked this conversation as resolved.
Outdated
Comment thread
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'
Comment thread
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()
```

66 changes: 66 additions & 0 deletions docs/plugins/videoplayer.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Comment thread
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){
Comment thread
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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be this.tag('Subtitles').text.text = _subtitleText;?

}

const _subtitleText = VideoPlayer.currentSubtitleText || ''
this.tag('Subtitles').text = _subtitleText;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why are these lines needed?

}
```

36 changes: 36 additions & 0 deletions github-actions-reporter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* eslint-disable no-console */
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ export { default as TV, initTV } from './src/TV'
export { default as Pin, initPin } from './src/Pin'
export { default as VideoPlayer, initVideoPlayer, mediaUrl } from './src/VideoPlayer'
export { initLightningSdkPlugin } from './src/LightningSdkPlugins'
export { default as SubtitlesParser } from './src/SubtitlesParser'
Comment thread
robbertvancaem marked this conversation as resolved.
27 changes: 27 additions & 0 deletions jest.config.js
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',
Comment thread
robbertvancaem marked this conversation as resolved.
Outdated
}
Loading