Skip to content
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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions __tests__/loom.test.js
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
Comment on lines +8 to +10
Copy link
Owner

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

Suggested change
* https://www.loom.com/share/7c7ced4911904070a5627374ccd84e8c
* https://www.loom.com/share/5bbdeb480ba84e65b1b3de8c190e2003?source=embed&t=20
* https://www.loom.com/embed/7c7ced4911904070a5627374ccd84e8c
* https://www.loom.com/share/{id}
* https://www.loom.com/share/{id}?
* https://www.loom.com/embed/{id}
* https://www.loom.com/embed/{id}?

*/
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');
});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also add a test to be sure that the id is extracted from the embed URL that also has query parameters? For example: https://www.loom.com/embed/123?foo=true => 123


test('returns undefined for unknown video ids', () => {
const actual = fn('https://www.loom.com');
expect(actual.id).toBe(undefined);
expect(actual.service).toBe('loom');
});
});

14 changes: 14 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Owner

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

Suggested change
https://www.loom.com/share/7c7ced4911904070a5627374ccd84e8c
https://www.loom.com/share/5bbdeb480ba84e65b1b3de8c190e2003?source=embed&t=20
https://www.loom.com/share/*
https://www.loom.com/share/*?

```

**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>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<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>
<iframe src="https://www.loom.com/embed/*" ...

```


## 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).
Expand Down
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import videopress from './videopress.js';
import microsoftStream from './microsoftstream.js';
import tiktok from './tiktok.js';
import dailymotion from './dailymotion.js';
import loom from './loom.js';
import getSrc from './utils/get-src.js';

/**
Expand Down Expand Up @@ -84,6 +85,11 @@ function getVideoId(urlString) {
id: dailymotion(string_),
service: 'dailymotion',
};
} else if (/loom\.com/.test(string_)) {
metadata = {
id: loom(string_),
service: 'loom',
};
}

return metadata;
Expand Down
16 changes: 16 additions & 0 deletions src/loom.js
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})\??.*/;
Copy link
Owner

Choose a reason for hiding this comment

The 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
= /(https?:\/\/)?(www\.)?loom\.com\/?(.*\/)?([\d)([a-z]{32})\??.*/;
= /^https?:\/\/(?:www\.)?loom\.com\/(?:share|embed)\/([\da-zA-Z]+);

const basicParsed = urlString.match(basicReg);
if (basicParsed && basicParsed.length === 5) {
return basicParsed[4];
}

return undefined;
}