Skip to content

Commit

Permalink
Merge branch 'release/0.1.2.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
kalashnikovisme committed Oct 26, 2022
2 parents b4f5c8a + d3ca110 commit 9144ca7
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 33 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
}
Expand All @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions test/video.js
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)
33 changes: 2 additions & 31 deletions test/video/duration.js
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)
34 changes: 34 additions & 0 deletions test/video/shared.js
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)
})
}

0 comments on commit 9144ca7

Please sign in to comment.