-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
47 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,12 +22,12 @@ yarn add nano-metadata | |
## Video duration | ||
|
||
```javascript | ||
import { video } from 'nano-metadata' | ||
import nanoMetadata from 'nano-metadata' | ||
|
||
change(e) { | ||
const file = e.target.files[0] | ||
|
||
video.duration(file).then((duration) => { | ||
nanoMetadata.video.duration(file).then((duration) => { | ||
console.log(duration) // will show you video duration in seconds | ||
}) | ||
} | ||
|
@@ -42,10 +42,15 @@ change(e) { | |
|
||
# Contribute | ||
|
||
## Option 1 | ||
1. Clone repo `git clone [email protected]:kalashnikovisme/nano-metadata` | ||
2. Run `yarn` | ||
3. To run linter `make linter` | ||
|
||
## Option 2 (for [Purple Magic](https://github.com/purple-magic) contributors) | ||
|
||
Just run Codespace | ||
|
||
## Why do tests fail? | ||
|
||
This package uses `onloadedmetadata` event to store video duration. We use [js-dom](https://github.com/jsdom/jsdom) for web implementation in the tests. Looks like it does not support this event for now. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import video from '../lib/video.js' | ||
import videoDurationTest from './video/shared.js' | ||
|
||
videoDurationTest(video.duration) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,4 @@ | ||
import test from 'ava' | ||
import videoDuration from '../../lib/video/duration.js' | ||
import { JSDOM } from 'jsdom' | ||
import fetch from 'node-fetch' | ||
import File from 'file-class' | ||
import videoDurationTest from './shared.js' | ||
|
||
async function videoFile(){ | ||
let response = await fetch('http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/WeAreGoingOnBullrun.mp4') | ||
let data = await response.blob(); | ||
let metadata = { | ||
lastModified: '1665320297477', | ||
name: 'BigBuckBunny.mp4', | ||
type: 'video/mp4', | ||
}; | ||
let file = new File([data], "BigBuckBunny.mp4", metadata); | ||
return file | ||
} | ||
|
||
test.before(() => { | ||
const dom = new JSDOM('<input id="input" name="file" type="file" accept=".mp4">') | ||
global.document = dom.window.document | ||
global.window = dom.window | ||
global.window.URL.createObjectURL = () => {} | ||
global.File = dom.File | ||
}); | ||
|
||
test('Video Duration', async (t) => { | ||
const file = await videoFile() | ||
videoDuration(file).then((duration) => { | ||
t.is(duration, 595) | ||
}) | ||
setTimeout(() => document.getElementsByTagName('video').loadmetadata(), 1000) | ||
}) | ||
videoDurationTest(videoDuration) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import test from 'ava' | ||
import { JSDOM } from 'jsdom' | ||
import fetch from 'node-fetch' | ||
import File from 'file-class' | ||
|
||
async function videoFile(){ | ||
let response = await fetch('http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/WeAreGoingOnBullrun.mp4') | ||
let data = await response.blob(); | ||
let metadata = { | ||
lastModified: '1665320297477', | ||
name: 'BigBuckBunny.mp4', | ||
type: 'video/mp4', | ||
}; | ||
let file = new File([data], "BigBuckBunny.mp4", metadata); | ||
return file | ||
} | ||
|
||
export default (func) => { | ||
test.before(() => { | ||
const dom = new JSDOM('<input id="input" name="file" type="file" accept=".mp4">') | ||
global.document = dom.window.document | ||
global.window = dom.window | ||
global.window.URL.createObjectURL = () => {} | ||
global.File = dom.File | ||
}); | ||
|
||
test('Video Duration', async (t) => { | ||
const file = await videoFile() | ||
func.call(file).then((duration) => { | ||
t.is(duration, 595) | ||
}) | ||
setTimeout(() => document.getElementsByTagName('video').loadmetadata(), 1000) | ||
}) | ||
} |