mirror of
https://github.com/xuthus83/pigallery2.git
synced 2025-01-14 14:43:17 +08:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
a5c90c7dad
@ -79,6 +79,36 @@ export class MetadataLoader {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For some filetypes (for instance Matroska), bitrate and duration are stored in
|
||||||
|
// the format section, not in the stream section.
|
||||||
|
|
||||||
|
// Only use duration from container header if necessary (stream duration is usually more accurate)
|
||||||
|
if (
|
||||||
|
metadata.duration === 0 &&
|
||||||
|
data.format.duration !== undefined &&
|
||||||
|
Utils.isInt32(Math.floor(data.format.duration * 1000))
|
||||||
|
) {
|
||||||
|
metadata.duration = Math.floor(data.format.duration * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefer bitrate from container header (includes video and audio)
|
||||||
|
if (
|
||||||
|
data.format.bit_rate !== undefined &&
|
||||||
|
Utils.isInt32(data.format.bit_rate)
|
||||||
|
) {
|
||||||
|
metadata.bitRate = data.format.bit_rate;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
data.format.tags !== undefined &&
|
||||||
|
typeof data.format.tags.creation_time === 'string'
|
||||||
|
) {
|
||||||
|
metadata.creationDate =
|
||||||
|
Date.parse(data.format.tags.creation_time) ||
|
||||||
|
metadata.creationDate;
|
||||||
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line no-empty
|
// eslint-disable-next-line no-empty
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"bitRate": 11464,
|
"bitRate": 146656,
|
||||||
"creationDate": 1550265200000,
|
"creationDate": 1550265200000,
|
||||||
"duration": 13666,
|
"duration": 13666,
|
||||||
"fileSize": 251571,
|
"fileSize": 251571,
|
||||||
|
11
test/backend/assets/video_mkv.json
Normal file
11
test/backend/assets/video_mkv.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"bitRate": 186114,
|
||||||
|
"creationDate": 1548316884000,
|
||||||
|
"duration": 13699,
|
||||||
|
"fileSize": 318697,
|
||||||
|
"fps": 15,
|
||||||
|
"size": {
|
||||||
|
"height": 44,
|
||||||
|
"width": 80
|
||||||
|
}
|
||||||
|
}
|
BIN
test/backend/assets/video_mkv.mkv
Normal file
BIN
test/backend/assets/video_mkv.mkv
Normal file
Binary file not shown.
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"bitRate": 11464,
|
"bitRate": 142006,
|
||||||
"creationDate": 1550265200000,
|
"creationDate": 1550265200000,
|
||||||
"duration": 13666,
|
"duration": 13666,
|
||||||
"fileSize": 242601,
|
"fileSize": 242601,
|
||||||
|
@ -23,7 +23,7 @@ describe('DiskMangerWorker', () => {
|
|||||||
ProjectPath.ImageFolder = path.join(__dirname, '/../../../assets');
|
ProjectPath.ImageFolder = path.join(__dirname, '/../../../assets');
|
||||||
const dir = await DiskMangerWorker.scanDirectory('/');
|
const dir = await DiskMangerWorker.scanDirectory('/');
|
||||||
// should match the number of media (photo/video) files in the assets folder
|
// should match the number of media (photo/video) files in the assets folder
|
||||||
expect(dir.media.length).to.be.equals(9);
|
expect(dir.media.length).to.be.equals(10);
|
||||||
const expected = require(path.join(__dirname, '/../../../assets/test image öüóőúéáű-.,.json'));
|
const expected = require(path.join(__dirname, '/../../../assets/test image öüóőúéáű-.,.json'));
|
||||||
const i = dir.media.findIndex(m => m.name === 'test image öüóőúéáű-.,.jpg');
|
const i = dir.media.findIndex(m => m.name === 'test image öüóőúéáű-.,.jpg');
|
||||||
expect(Utils.clone(dir.media[i].name)).to.be.deep.equal('test image öüóőúéáű-.,.jpg');
|
expect(Utils.clone(dir.media[i].name)).to.be.deep.equal('test image öüóőúéáű-.,.jpg');
|
||||||
|
@ -144,4 +144,10 @@ describe('MetadataLoader', () => {
|
|||||||
expect(Utils.clone(data)).to.be.deep.equal(expected);
|
expect(Utils.clone(data)).to.be.deep.equal(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should load mkv', async () => {
|
||||||
|
const data = await MetadataLoader.loadVideoMetadata(path.join(__dirname, '/../../../assets/video_mkv.mkv'));
|
||||||
|
const expected = require(path.join(__dirname, '/../../../assets/video_mkv.json'));
|
||||||
|
expect(Utils.clone(data)).to.be.deep.equal(expected);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user