-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Loom video support #105
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* eslint max-len: 0 */ | ||
import fn from '../src/index.js'; | ||
|
||
/** | ||
* Loom should be able to find these patterns: | ||
* | ||
* Urls: | ||
* https://www.loom.com/share/7c7ced4911904070a5627374ccd84e8c | ||
* https://www.loom.com/share/5bbdeb480ba84e65b1b3de8c190e2003?source=embed&t=20 | ||
* https://www.loom.com/embed/7c7ced4911904070a5627374ccd84e8c | ||
*/ | ||
describe('Loom', () => { | ||
test('Loom basic link', () => { | ||
expect(fn('https://www.loom.com/share/7c7ced4911904070a5627374ccd84e8c').id).toBe('7c7ced4911904070a5627374ccd84e8c'); | ||
expect(fn('https://www.loom.com/share/5bbdeb480ba84e65b1b3de8c190e2003?source=embed&t=20').id).toBe('5bbdeb480ba84e65b1b3de8c190e2003'); | ||
}); | ||
|
||
test('Loom embed', () => { | ||
expect(fn('<div style="position: relative; padding-bottom: 62.5%; height: 0;"><iframe src="https://www.loom.com/embed/7c7ced4911904070a5627374ccd84e8c" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></iframe></div>').id).toBe('7c7ced4911904070a5627374ccd84e8c'); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also add a test to be sure that the |
||
|
||
test('returns undefined for unknown video ids', () => { | ||
const actual = fn('https://www.loom.com'); | ||
expect(actual.id).toBe(undefined); | ||
expect(actual.service).toBe('loom'); | ||
}); | ||
}); | ||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -274,6 +274,20 @@ http://dai.ly/* | |||||||||
**:warning: Unsupported Dailymotion urls** | ||||||||||
* Channel id urls: `http://www.dailymotion.com/hub/*_title` | ||||||||||
|
||||||||||
### Loom | ||||||||||
|
||||||||||
**Loom urls** | ||||||||||
``` | ||||||||||
https://www.loom.com/share/7c7ced4911904070a5627374ccd84e8c | ||||||||||
https://www.loom.com/share/5bbdeb480ba84e65b1b3de8c190e2003?source=embed&t=20 | ||||||||||
Comment on lines
+281
to
+282
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I try to keep links to real videos out of the documentation
Suggested change
|
||||||||||
``` | ||||||||||
|
||||||||||
**Loom iframe** | ||||||||||
``` | ||||||||||
<div style="position: relative; padding-bottom: 62.5%; height: 0;"><iframe src="https://www.loom.com/embed/7c7ced4911904070a5627374ccd84e8c" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></iframe></div> | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
``` | ||||||||||
|
||||||||||
|
||||||||||
## Contributing | ||||||||||
|
||||||||||
If you discover a url pattern that is not covered by this module, please [open an issue](https://github.com/radiovisual/get-video-id/issues) to report it, or [submit a Pull Request](https://github.com/radiovisual/get-video-id/pull/new/master). For any submitted pull requests, please ensure that you include unit test(s) to fully cover your code contribution(s). | ||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,16 @@ | ||||||
/** | ||||||
* Get the loom id. | ||||||
* @param {string} urlString - the url from which you want to extract the id | ||||||
* @returns {string|undefined} | ||||||
*/ | ||||||
export default function loom(urlString) { | ||||||
// Parse basic url and embeds | ||||||
const basicReg | ||||||
= /(https?:\/\/)?(www\.)?loom\.com\/?(.*\/)?([\d)([a-z]{32})\??.*/; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like this RegEx is way to strict which might present problems (false positives, not flexible, etc), so I think you can really simplify this RegEx to make it focus on the specific strings you are looking for, and don't force length limits on the hashed id. something like (this is not tested, so please test it or modify it accordingly):
Suggested change
|
||||||
const basicParsed = urlString.match(basicReg); | ||||||
if (basicParsed && basicParsed.length === 5) { | ||||||
return basicParsed[4]; | ||||||
} | ||||||
|
||||||
return undefined; | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I try to keep links to real videos out of the documentation