@ormoshe/js-video-url-parser 0.5.5 → 0.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -937,7 +937,7 @@
937
937
  }
938
938
 
939
939
  YouTube.prototype.parseVideoUrl = function (url) {
940
- var match = url.match(/(?:(?:v|vi|be|videos|embed)\/(?!videoseries)|(?:v|ci)=)([\w-]{11})/i);
940
+ var match = url.match(/(?:(?:v|vi|be|videos|shorts|embed)\/(?!videoseries)|(?:v|ci)=)([\w-]{11})/i);
941
941
  return match ? match[1] : undefined;
942
942
  };
943
943
 
@@ -1626,6 +1626,7 @@
1626
1626
  var match = url.match(
1627
1627
  /(?:watch|embed)\/([a-zA-Z\d]+)/i
1628
1628
  );
1629
+ //var match = url.match(/(?:\/(\d+))?\/watch(?:\/.*?)?\/(\d+)/i);
1629
1630
  return match ? match[1] : undefined;
1630
1631
  };
1631
1632
 
@@ -1654,6 +1655,49 @@
1654
1655
 
1655
1656
  base.bind(new Spotlightr());
1656
1657
 
1658
+ var combineParams$h = util.combineParams;
1659
+
1660
+ function Bunny() {
1661
+ this.provider = 'bunnycdn';
1662
+ this.alternatives = ['mediadelivery'];
1663
+ this.defaultFormat = 'long';
1664
+ this.formats = {
1665
+ long: this.createLongUrl,
1666
+ };
1667
+ this.mediaTypes = {
1668
+ VIDEO: 'video',
1669
+ };
1670
+ }
1671
+
1672
+ Bunny.prototype.parse = function(url, params) {
1673
+ var match = url.match(
1674
+ /(?:play|embed)\/([a-zA-Z\d]+)\/([\w-]+)/i
1675
+ );
1676
+ var result = {
1677
+ mediaType: this.mediaTypes.VIDEO,
1678
+ params: params,
1679
+ library: match[1],
1680
+ id: match[2]
1681
+ };
1682
+ return result.id ? result : undefined;
1683
+ };
1684
+
1685
+ Bunny.prototype.createUrl = function(baseUrl, vi, params) {
1686
+ if (!vi.id || vi.mediaType !== this.mediaTypes.VIDEO) {
1687
+ return undefined;
1688
+ }
1689
+
1690
+ var url = baseUrl + vi.library + '/' + vi.id;
1691
+ url += combineParams$h(params);
1692
+ return url;
1693
+ };
1694
+
1695
+ Bunny.prototype.createLongUrl = function(vi, params) {
1696
+ return this.createUrl('https://video.bunnycdn.com/play/', vi, params);
1697
+ };
1698
+
1699
+ base.bind(new Bunny());
1700
+
1657
1701
  var lib = base;
1658
1702
 
1659
1703
  return lib;
package/lib/index.d.ts CHANGED
@@ -16,4 +16,5 @@ export * from './provider/youtube';
16
16
  export * from './provider/ted';
17
17
  export * from './provider/tiktok';
18
18
  export * from './provider/voomly';
19
- export * from './provider/spotlightr';
19
+ export * from './provider/spotlightr';
20
+ export * from './provider/bunny';
package/lib/index.js CHANGED
@@ -14,6 +14,7 @@ require('./provider/teachertube');
14
14
  require('./provider/tiktok');
15
15
  require('./provider/voomly');
16
16
  require('./provider/spotlightr');
17
+ require('./provider/bunny');
17
18
  require('./provider/ted');
18
19
  require('./provider/facebook');
19
20
  module.exports = parser;
@@ -0,0 +1,14 @@
1
+ import { VideoInfo } from '../urlParser';
2
+
3
+ export interface BunnyUrlParameters {
4
+ [key: string]: any;
5
+ }
6
+
7
+ export type BunnyMediaTypes = 'video';
8
+
9
+ export interface BunnyVideoInfo extends VideoInfo<BunnyUrlParameters, BunnyMediaTypes> {
10
+ provider: 'bunny';
11
+ channel: string;
12
+ }
13
+
14
+ export type BunnyParseResult = BunnyVideoInfo | undefined;
@@ -0,0 +1,44 @@
1
+ const { combineParams } = require('../util');
2
+
3
+ function Bunny() {
4
+ this.provider = 'bunnycdn';
5
+ this.alternatives = ['mediadelivery'];
6
+ this.defaultFormat = 'long';
7
+ this.formats = {
8
+ long: this.createLongUrl,
9
+ };
10
+ this.mediaTypes = {
11
+ VIDEO: 'video',
12
+ };
13
+ }
14
+
15
+ module.exports = Bunny;
16
+
17
+ Bunny.prototype.parse = function(url, params) {
18
+ var match = url.match(
19
+ /(?:play|embed)\/([a-zA-Z\d]+)\/([\w-]+)/i
20
+ );
21
+ var result = {
22
+ mediaType: this.mediaTypes.VIDEO,
23
+ params: params,
24
+ library: match[1],
25
+ id: match[2]
26
+ };
27
+ return result.id ? result : undefined;
28
+ };
29
+
30
+ Bunny.prototype.createUrl = function(baseUrl, vi, params) {
31
+ if (!vi.id || vi.mediaType !== this.mediaTypes.VIDEO) {
32
+ return undefined;
33
+ }
34
+
35
+ var url = baseUrl + vi.library + '/' + vi.id;
36
+ url += combineParams(params);
37
+ return url;
38
+ };
39
+
40
+ Bunny.prototype.createLongUrl = function(vi, params) {
41
+ return this.createUrl('https://video.bunnycdn.com/play/', vi, params);
42
+ };
43
+
44
+ require('../base').bind(new Bunny());
@@ -38,7 +38,7 @@ module.exports = YouTube;
38
38
 
39
39
  YouTube.prototype.parseVideoUrl = function(url) {
40
40
  var match = url.match(
41
- /(?:(?:v|vi|be|videos|embed)\/(?!videoseries)|(?:v|ci)=)([\w-]{11})/i
41
+ /(?:(?:v|vi|be|videos|shorts|embed)\/(?!videoseries)|(?:v|ci)=)([\w-]{11})/i
42
42
  );
43
43
  return match ? match[1] : undefined;
44
44
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ormoshe/js-video-url-parser",
3
- "version": "0.5.5",
3
+ "version": "0.5.7",
4
4
  "description": "A parser to extract provider, video id, starttime and others from YouTube, Vimeo, ... urls",
5
5
  "main": "lib/index.js",
6
6
  "browser": "dist/jsVideoUrlParser.js",