use file extension for media detection
This commit is contained in:
parent
6eba5f8823
commit
6a21ea7d72
1 changed files with 8 additions and 8 deletions
16
src/lbry.js
16
src/lbry.js
|
@ -109,13 +109,13 @@ Lbry.connect = () => {
|
||||||
return Lbry.connectPromise;
|
return Lbry.connectPromise;
|
||||||
};
|
};
|
||||||
|
|
||||||
Lbry.getMediaType = (contentType, fileName) => {
|
Lbry.getMediaType = (contentType, extname) => {
|
||||||
if (fileName) {
|
if (extname) {
|
||||||
const formats = [
|
const formats = [
|
||||||
[/^.+\.(mp4|m4v|webm|flv|f4v|ogv)$/i, 'video'],
|
[/^(mp4|m4v|webm|flv|f4v|ogv)$/i, 'video'],
|
||||||
[/^.+\.(mp3|m4a|aac|wav|flac|ogg|opus)$/i, 'audio'],
|
[/^(mp3|m4a|aac|wav|flac|ogg|opus)$/i, 'audio'],
|
||||||
[/^.+\.(html|htm|xml|pdf|odf|doc|docx|md|markdown|txt|epub|org)$/i, 'document'],
|
[/^(html|htm|xml|pdf|odf|doc|docx|md|markdown|txt|epub|org)$/i, 'document'],
|
||||||
[/^.+\.(stl|obj|fbx|gcode)$/i, '3D-file'],
|
[/^(stl|obj|fbx|gcode)$/i, '3D-file'],
|
||||||
];
|
];
|
||||||
const res = formats.reduce((ret, testpair) => {
|
const res = formats.reduce((ret, testpair) => {
|
||||||
switch (testpair[0].test(ret)) {
|
switch (testpair[0].test(ret)) {
|
||||||
|
@ -124,8 +124,8 @@ Lbry.getMediaType = (contentType, fileName) => {
|
||||||
default:
|
default:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}, fileName);
|
}, extname);
|
||||||
return res === fileName ? 'unknown' : res;
|
return res === extname ? 'unknown' : res;
|
||||||
} else if (contentType) {
|
} else if (contentType) {
|
||||||
return /^[^/]+/.exec(contentType)[0];
|
return /^[^/]+/.exec(contentType)[0];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue