Install with yarn add media-url-parser
as a npm package.
Or load from a CDN
<script type="module">
import mediaUrlParser from 'https://unpkg.com/media-url-parser'
const x = mediaUrlParser('https://www.youtube.com/watch?v=EFh-vtZHjOQ')
console.log(x) // {url: "https://www.youtube.com/watch?v=EFh-vtZHjOQ", provider: "youtube", id: "EFh-vtZHjOQ"}
</script>
Usage:
const urlA = 'https://www.youtube.com/watch?v=OkR7UNnQU6c'
const urlB = '192.168.0.1/a/longer/path/podcast.ogg'
const resultsA = mediaUrlParser(urlA)
const resultsB = mediaUrlParser(urlB)
This code will output:
// resultsA
{
url: 'https://www.youtube.com/watch?v=OkR7UNnQU6c',
provider: 'youtube',
id: 'OkR7UNnQU6c'
}
// resultsB
{
url: 'https://192.168.0.1/a/longer/path/podcast.ogg',
provider: 'file',
id: 'podcast.ogg'
}
Supported providers are:
Possible future providers are:
Suggestions and PR welcome.