-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from nypublicradio/mime-types
Use mime types for playability checks on connections instead of file extensions, and if no mime type is found try it on the connection anyway
- Loading branch information
Showing
15 changed files
with
390 additions
and
27 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
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
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
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
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
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
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
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,230 @@ | ||
// we are only concerned with a subset of all available mime types | ||
// data and function lifted from https://github.com/jshttp/mime-db | ||
const MIME_TYPES = { | ||
"audio/3gpp": { | ||
"source": "iana", | ||
"extensions": ["3gpp"] | ||
}, | ||
"audio/adpcm": { | ||
"source": "apache", | ||
"extensions": ["adp"] | ||
}, | ||
"audio/basic": { | ||
"source": "iana", | ||
"compressible": false, | ||
"extensions": ["au","snd"] | ||
}, | ||
"audio/midi": { | ||
"source": "apache", | ||
"extensions": ["mid","midi","kar","rmi"] | ||
}, | ||
"audio/mp3": { | ||
"compressible": false, | ||
"extensions": ["mp3"] | ||
}, | ||
"audio/mp4": { | ||
"source": "iana", | ||
"compressible": false, | ||
"extensions": ["m4a","mp4a"] | ||
}, | ||
"audio/mpeg": { | ||
"source": "iana", | ||
"compressible": false, | ||
"extensions": ["mpga","mp2","mp2a","mp3","m2a","m3a"] | ||
}, | ||
"audio/ogg": { | ||
"source": "iana", | ||
"compressible": false, | ||
"extensions": ["oga","ogg","spx"] | ||
}, | ||
"audio/s3m": { | ||
"source": "apache", | ||
"extensions": ["s3m"] | ||
}, | ||
"audio/silk": { | ||
"source": "apache", | ||
"extensions": ["sil"] | ||
}, | ||
"audio/vnd.dece.audio": { | ||
"source": "iana", | ||
"extensions": ["uva","uvva"] | ||
}, | ||
"audio/vnd.digital-winds": { | ||
"source": "iana", | ||
"extensions": ["eol"] | ||
}, | ||
"audio/vnd.dra": { | ||
"source": "iana", | ||
"extensions": ["dra"] | ||
}, | ||
"audio/vnd.dts": { | ||
"source": "iana", | ||
"extensions": ["dts"] | ||
}, | ||
"audio/vnd.dts.hd": { | ||
"source": "iana", | ||
"extensions": ["dtshd"] | ||
}, | ||
"audio/vnd.lucent.voice": { | ||
"source": "iana", | ||
"extensions": ["lvp"] | ||
}, | ||
"audio/vnd.ms-playready.media.pya": { | ||
"source": "iana", | ||
"extensions": ["pya"] | ||
}, | ||
"audio/vnd.nuera.ecelp4800": { | ||
"source": "iana", | ||
"extensions": ["ecelp4800"] | ||
}, | ||
"audio/vnd.nuera.ecelp7470": { | ||
"source": "iana", | ||
"extensions": ["ecelp7470"] | ||
}, | ||
"audio/vnd.nuera.ecelp9600": { | ||
"source": "iana", | ||
"extensions": ["ecelp9600"] | ||
}, | ||
"audio/vnd.rip": { | ||
"source": "iana", | ||
"extensions": ["rip"] | ||
}, | ||
"audio/wav": { | ||
"compressible": false, | ||
"extensions": ["wav"] | ||
}, | ||
"audio/wave": { | ||
"compressible": false, | ||
"extensions": ["wav"] | ||
}, | ||
"audio/webm": { | ||
"source": "apache", | ||
"compressible": false, | ||
"extensions": ["weba"] | ||
}, | ||
"audio/x-aac": { | ||
"source": "apache", | ||
"compressible": false, | ||
"extensions": ["aac"] | ||
}, | ||
"audio/x-aiff": { | ||
"source": "apache", | ||
"extensions": ["aif","aiff","aifc"] | ||
}, | ||
"audio/x-caf": { | ||
"source": "apache", | ||
"compressible": false, | ||
"extensions": ["caf"] | ||
}, | ||
"audio/x-flac": { | ||
"source": "apache", | ||
"extensions": ["flac"] | ||
}, | ||
"audio/x-m4a": { | ||
"source": "nginx", | ||
"extensions": ["m4a"] | ||
}, | ||
"audio/x-matroska": { | ||
"source": "apache", | ||
"extensions": ["mka"] | ||
}, | ||
"audio/x-mpegurl": { | ||
"source": "apache", | ||
"extensions": ["m3u"] | ||
}, | ||
"audio/x-ms-wax": { | ||
"source": "apache", | ||
"extensions": ["wax"] | ||
}, | ||
"audio/x-ms-wma": { | ||
"source": "apache", | ||
"extensions": ["wma"] | ||
}, | ||
"audio/x-pn-realaudio": { | ||
"source": "apache", | ||
"extensions": ["ram","ra"] | ||
}, | ||
"audio/x-pn-realaudio-plugin": { | ||
"source": "apache", | ||
"extensions": ["rmp"] | ||
}, | ||
"audio/x-realaudio": { | ||
"source": "nginx", | ||
"extensions": ["ra"] | ||
}, | ||
"audio/x-wav": { | ||
"source": "apache", | ||
"extensions": ["wav"] | ||
}, | ||
"audio/xm": { | ||
"source": "apache", | ||
"extensions": ["xm"] | ||
}, | ||
"application/vnd.apple.mpegurl": { | ||
"source": "iana", | ||
"extensions": ["m3u8"] | ||
}, | ||
"audio/x-mpepgurl": { | ||
"source": "apache", | ||
"extensions": ["m3u"] | ||
} | ||
}; | ||
|
||
const TYPES = Object.create(null); | ||
const EXTENSIONS = Object.create(null); | ||
|
||
function populateMaps(extensions, types) { | ||
// source preference (least -> most) | ||
let preference = ['nginx', 'apache', undefined, 'iana']; | ||
|
||
Object.keys(MIME_TYPES).forEach(function(type) { | ||
let mime = MIME_TYPES[type]; | ||
let exts = mime.extensions; | ||
|
||
if (!exts || !exts.length) { | ||
return false; | ||
} | ||
|
||
// mime -> extensions | ||
extensions[type] = exts; | ||
|
||
// extension -> mime | ||
for (let i = 0; i < exts.length; i++) { | ||
let extension = exts[i]; | ||
|
||
if (types[extension]) { | ||
let start = preference.indexOf(MIME_TYPES[types[extension]].source); | ||
let end = preference.indexOf(mime.source); | ||
|
||
if (types[extension] !== 'application/octet-stream' && | ||
start > end || (start === end && types[extension].substr(0, 12) === 'application/')) { | ||
// skip the remapping | ||
continue; | ||
} | ||
} | ||
|
||
// set the extension -> mime | ||
types[extension] = type; | ||
} | ||
}); | ||
} | ||
|
||
populateMaps(EXTENSIONS, TYPES); | ||
|
||
export function getMimeType(url) { | ||
if (!url || typeof url !== 'string') { | ||
return false; | ||
} | ||
|
||
let extension = url | ||
.toLowerCase() | ||
.split('.').pop() | ||
.split('?').shift() | ||
.split('#').shift(); | ||
|
||
if (!extension) { | ||
return false; | ||
} | ||
|
||
return TYPES[extension] || false; | ||
} |
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 @@ | ||
export { getMimeType } from 'ember-hifi/utils/mime-types'; |
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
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
Oops, something went wrong.