@ormoshe/js-video-url-parser 0.5.1

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.
Files changed (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +195 -0
  3. package/dist/jsVideoUrlParser.js +1571 -0
  4. package/dist/jsVideoUrlParser.min.js +1 -0
  5. package/lib/base.d.ts +2 -0
  6. package/lib/base.js +3 -0
  7. package/lib/index.d.ts +17 -0
  8. package/lib/index.js +18 -0
  9. package/lib/provider/allocine.d.ts +13 -0
  10. package/lib/provider/allocine.js +36 -0
  11. package/lib/provider/base-provider.d.ts +13 -0
  12. package/lib/provider/canalplus.d.ts +13 -0
  13. package/lib/provider/canalplus.js +46 -0
  14. package/lib/provider/coub.d.ts +13 -0
  15. package/lib/provider/coub.js +54 -0
  16. package/lib/provider/dailymotion.d.ts +14 -0
  17. package/lib/provider/dailymotion.js +70 -0
  18. package/lib/provider/facebook.d.ts +14 -0
  19. package/lib/provider/facebook.js +78 -0
  20. package/lib/provider/loom.d.ts +13 -0
  21. package/lib/provider/loom.js +51 -0
  22. package/lib/provider/soundcloud.d.ts +16 -0
  23. package/lib/provider/soundcloud.js +125 -0
  24. package/lib/provider/teachertube.d.ts +14 -0
  25. package/lib/provider/teachertube.js +110 -0
  26. package/lib/provider/ted.d.ts +14 -0
  27. package/lib/provider/ted.js +96 -0
  28. package/lib/provider/tiktok.d.ts +14 -0
  29. package/lib/provider/tiktok.js +50 -0
  30. package/lib/provider/twitch.d.ts +15 -0
  31. package/lib/provider/twitch.js +150 -0
  32. package/lib/provider/vimeo.d.ts +14 -0
  33. package/lib/provider/vimeo.js +89 -0
  34. package/lib/provider/voomly.d.ts +14 -0
  35. package/lib/provider/voomly.js +46 -0
  36. package/lib/provider/wistia.d.ts +15 -0
  37. package/lib/provider/wistia.js +112 -0
  38. package/lib/provider/youku.d.ts +13 -0
  39. package/lib/provider/youku.js +83 -0
  40. package/lib/provider/youtube.d.ts +15 -0
  41. package/lib/provider/youtube.js +205 -0
  42. package/lib/testUrls.js +11 -0
  43. package/lib/urlParser.d.ts +23 -0
  44. package/lib/urlParser.js +81 -0
  45. package/lib/util.js +104 -0
  46. package/package.json +59 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Julian Hangstörfer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,195 @@
1
+ A javascript parser to extract information like provider, id, channel, start time from media urls.
2
+
3
+ # Supported providers
4
+ - [YouTube](https://www.youtube.com/)
5
+ - [Vimeo](https://vimeo.com/)
6
+ - [Twitch](https://www.twitch.tv/)
7
+ - [Dailymotion](https://www.dailymotion.com)
8
+ - [Canal+](https://www.mycanal.fr/)
9
+ - [Youku](https://www.youku.com/)
10
+ - [Coub](https://coub.com/)
11
+ - [Wistia](https://wistia.com/)
12
+ - [SoundCloud](https://soundcloud.com/)
13
+ - [TeacherTube](https://www.teachertube.com)
14
+ - [Ted](https://www.ted.com)
15
+ - [Tiktok](https://www.tiktok.com)
16
+ - [Facebook](https://www.facebook.com/)
17
+ - [Loom](https://www.loom.com/)
18
+ - [Allociné](https://allocine.fr/)
19
+
20
+
21
+ # Building Locally
22
+
23
+ ```
24
+ npm install
25
+ npm run lint
26
+ npm run test
27
+ npm run build
28
+ ```
29
+
30
+ # npm
31
+
32
+ ```
33
+ npm install js-video-url-parser
34
+ ```
35
+
36
+ # bower
37
+
38
+ ```shell
39
+ bower install js-video-url-parser
40
+ ```
41
+
42
+ # Usage
43
+
44
+ ## ES2015+ / Webpack
45
+
46
+ ```
47
+ // All plugins
48
+ import urlParser from "js-video-url-parser";
49
+
50
+ // Choose individual plugins
51
+ import urlParser from "js-video-url-parser/lib/base";
52
+ import "js-video-url-parser/lib/provider/canalplus";
53
+ import "js-video-url-parser/lib/provider/coub";
54
+ import "js-video-url-parser/lib/provider/dailymotion";
55
+ import "js-video-url-parser/lib/provider/twitch";
56
+ import "js-video-url-parser/lib/provider/vimeo";
57
+ import "js-video-url-parser/lib/provider/wistia";
58
+ import "js-video-url-parser/lib/provider/youku";
59
+ import "js-video-url-parser/lib/provider/youtube";
60
+ import "js-video-url-parser/lib/provider/teachertube";
61
+ import "js-video-url-parser/lib/provider/ted";
62
+ import "js-video-url-parser/lib/provider/tiktok";
63
+ import "js-video-url-parser/lib/provider/loom";
64
+ import "js-video-url-parser/lib/provider/facebook";
65
+ import "js-video-url-parser/lib/provider/allocine";
66
+ ```
67
+
68
+ ## Parsing
69
+
70
+ Parsing a url will return a videoInfo object with all the information
71
+
72
+ ```javascript
73
+ > urlParser.parse('http://www.youtube.com/watch?v=HRb7B9fPhfA')
74
+ {
75
+ mediaType: 'video',
76
+ id: 'HRb7B9fPhfA',
77
+ provider: 'youtube'
78
+ }
79
+
80
+ > urlParser.parse('https://vimeo.com/97276391')
81
+ {
82
+ mediaType: 'video',
83
+ id: '97276391',
84
+ provider: 'vimeo'
85
+ }
86
+ ```
87
+
88
+ Any url parameters expect for ids will be saved in the params object. Some
89
+ providers have special parameters for example the start parameter which dictates
90
+ at how many seconds the video starts. Special parameters can be found in the
91
+ different descriptions for the providers.
92
+
93
+ ```javascript
94
+ > urlParser.parse('https://www.youtube.com/watch?v=6xLcSTDeB7A&index=25&list=PL46F0A159EC02DF82&t=1m40')
95
+ {
96
+ provider: 'youtube',
97
+ id: 'yQaAGmHNn9s',
98
+ list: 'PL46F0A159EC02DF82',
99
+ mediaType: 'video',
100
+ params: {
101
+ start: 100,
102
+ index: '25'
103
+ }
104
+ }
105
+ ```
106
+
107
+ Parsing an incorrect url or trying to create one with an invalid object will return undefined
108
+
109
+ ```javascript
110
+ > urlParser.parse('https://www.youuutube.com/watch?v=97276391')
111
+ > urlParser.create({ videoInfo: { provider: 'youtube' })
112
+ undefined
113
+ ```
114
+
115
+ ## Url Creation
116
+
117
+ The videoInfo objects can be turned back into urls with the `.create` function.
118
+ The required parameter for this is the videoInfo object itself. Optional ones are
119
+ the format of the url and the url parameters that should be added. Each provider
120
+ has it's own default format.
121
+
122
+ ```javascript
123
+ > urlParser.create({
124
+ videoInfo: {
125
+ provider: 'youtube',
126
+ id: 'HRb7B9fPhfA',
127
+ mediaType: 'video'
128
+ },
129
+ format: 'long',
130
+ params: {
131
+ foo: 'bar'
132
+ }
133
+ })
134
+ 'https://www.youtube.com/watch?foo=bar&v=HRb7B9fPhfA'
135
+ ```
136
+
137
+ Parsing and creating can also be chained together to clean up an url for example.
138
+ If you still want to reuse the generated parameters object you can use the keyword
139
+ `'internal'` as params.
140
+
141
+ ```javascript
142
+ > urlParser.create({
143
+ videoInfo: urlParser.parse('https://youtube.com/watch?foo=bar&v=HRb7B9fPhfA')
144
+ })
145
+ 'https://www.youtube.com/watch?v=HRb7B9fPhfA'
146
+
147
+ > urlParser.create({
148
+ videoInfo: urlParser.parse('https://youtube.com/watch?foo=bar&v=HRb7B9fPhfA'),
149
+ params: 'internal'
150
+ })
151
+ 'https://www.youtube.com/watch?foo=bar&v=HRb7B9fPhfA'
152
+ ```
153
+
154
+ ## Typescript
155
+
156
+ ```typescript
157
+ // All plugins
158
+ import urlParser, { YouTubeParseResult } from 'js-video-url-parser';
159
+ const info = urlParser.parse('http://www.youtube.com/watch?v=HRb7B9fPhfA') as YouTubeParseResult;
160
+
161
+ // Choose individual plugins
162
+ import urlParser from 'js-video-url-parser/lib/base';
163
+ import { YouTubeParseResult } from 'js-video-url-parser/lib/provider/youtube';
164
+
165
+ const info = urlParser.parse('http://www.youtube.com/watch?v=HRb7B9fPhfA') as YouTubeParseResult;
166
+
167
+ // Parse results can be undefined
168
+ const id = info?.id;
169
+ ```
170
+
171
+ ## Adding a provider
172
+
173
+ Add a new file in the `lib/provider/` directory with the template found [here](lib/provider/template.js) and also add it to [index.js](lib/index.js).
174
+ <br>
175
+ Add some tests in `lib/provider/` with the template found
176
+ [here](lib/provider/template.test.js).
177
+
178
+ Run `npm run test` to create the parser and test your plugin.
179
+
180
+ ## Provider information and examples
181
+
182
+ - [YouTube](https://github.com/Zod-/jsVideoUrlParser/wiki/YouTube)
183
+ - [Vimeo](https://github.com/Zod-/jsVideoUrlParser/wiki/Vimeo)
184
+ - [Twitch](https://github.com/Zod-/jsVideoUrlParser/wiki/Twitch)
185
+ - [Dailymotion](https://github.com/Zod-/jsVideoUrlParser/wiki/Dailymotion)
186
+ - [Canal+](https://github.com/Zod-/jsVideoUrlParser/wiki/Canal-)
187
+ - [Youku](https://github.com/Zod-/jsVideoUrlParser/wiki/Youku)
188
+ - [Coub](https://github.com/Zod-/jsVideoUrlParser/wiki/Coub)
189
+ - [Wistia](https://github.com/Zod-/jsVideoUrlParser/wiki/Wistia)
190
+ - [SoundCloud](https://github.com/Zod-/jsVideoUrlParser/wiki/SoundCloud)
191
+ - [TeacherTube](https://github.com/Zod-/jsVideoUrlParser/wiki/TeacherTube)
192
+
193
+ # License
194
+
195
+ [MIT](https://github.com/Zod-/jsVideoUrlParser/blob/master/LICENSE)