1 |
|
2 |
|
3 |
|
4 | 'use strict';
|
5 |
|
6 | module.exports = {
|
7 | parseVideoUrl( url ) {
|
8 | function getIdFromUrl( videoUrl, re ) {
|
9 | let matches = videoUrl.match( re );
|
10 | return ( matches && matches[ 1 ] ) || null;
|
11 | }
|
12 |
|
13 | let id;
|
14 |
|
15 |
|
16 |
|
17 | if ( url.includes( 'youtube.com/' ) ) {
|
18 | id = getIdFromUrl( url, /\/watch\?v=([A-Z0-9_-]+)/i );
|
19 |
|
20 | return id ? [ 'youtube', id ] : null;
|
21 | }
|
22 |
|
23 |
|
24 | if ( url.includes( 'vimeo.com/' ) ) {
|
25 | id = getIdFromUrl( url, /\/([0-9]+)/ );
|
26 |
|
27 | return id ? [ 'vimeo', id ] : null;
|
28 | }
|
29 |
|
30 | return null;
|
31 | }
|
32 | };
|