Skip to content

Commit

Permalink
Merge pull request #74 from radiovisual/cleanup
Browse files Browse the repository at this point in the history
Misc Cleanup
  • Loading branch information
radiovisual authored Sep 1, 2021
2 parents 5fa62aa + 7de2523 commit ef8cec6
Show file tree
Hide file tree
Showing 33 changed files with 10,713 additions and 10,383 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[{package.json,*.yml}]
[*.yml]
indent_style = space
indent_size = 2
14 changes: 0 additions & 14 deletions .eslintrc.js

This file was deleted.

26 changes: 26 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CI
on:
- push
- pull_request
jobs:
test:
name: Node.js ${{ matrix.node-version }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version:
- 16
- 14
- 12
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
- uses: codecov/codecov-action@v1
if: matrix.node-version == 14
with:
fail_ci_if_error: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ node_modules
coverage
dist/
.vscode
yarn.lock

55 changes: 55 additions & 0 deletions __tests__/dailymotion.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* eslint max-len: 0 */
import fn from '../dist/get-video-id.js';

/**
* Dailymotion should be able to find these patterns:
*
* Urls:
* http://www.dailymotion.com/video/id_title_text
* http://www.dailymotion.com/video/id
* http://www.dailymotion.com/fr/relevance/search/search+query/1#video=id
* https://www.dailymotion.com/video/id?playlist=
* https://www.dailymotion.com/embed/video/id?autoplay=1
* http://dai.ly/id
*
* Not supported (channel id only):
* http://www.dailymotion.com/hub/id_title
*/

describe('Dailymotion', () => {
test('Dailymotion basic link/embed', () => {
expect(fn('http://www.dailymotion.com/video/x44lvd_rates-of-exchange-like-a-renegade_music').id).toBe('x44lvd');
expect(fn('http://www.dailymotion.com/video/x44lvd').id).toBe('x44lvd');
expect(fn('http://www.dailymotion.com/video/xn1bi0_hakan-yukur-klip_sport').id).toBe('xn1bi0');
expect(fn('https://www.dailymotion.com/video/x82nygx?playlist=x5nmbq').id).toBe('x82nygx');
expect(fn('https://www.dailymotion.com/embed/video/x82nygx?autoplay=1').id).toBe('x82nygx');
expect(fn('http://www.dailymotion.com/fr/relevance/search/gangnam+style/1#video=xsbwie').id).toBe('xsbwie');
});

test('Dailymotion returns the service', () => {
expect(fn('http://www.dailymotion.com/video/1234').service).toBe('dailymotion');
expect(fn('http://www.dailymotion.com/video/1234').id).toBe('1234');
});

test('Dailymotion short link', () => {
expect(fn('http://dai.ly/x2no31b').id).toBe('x2no31b');
});

test('Dailymotion dynamic id', () => {
expect(fn('http://www.dailymotion.com/fr/relevance/search/gangnam+style/1#video=xsbwie').id).toBe('xsbwie');
expect(fn('http://www.dailymotion.com/hub/x9q_Galatasaray#video=xjw21s').id).toBe('xjw21s');
});

test('Dailymotion iframe', () => {
const actual = fn('<iframe src="https://www.dailymotion.com/embed/video/12780" width="600" height="600"></iframe>');
expect(actual.id).toBe('12780');
expect(actual.service).toBe('dailymotion');
});

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

45 changes: 45 additions & 0 deletions __tests__/google-redirect.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/* eslint max-len: 0 */
import fn from '../dist/get-video-id.js';

/**
* Google redirect patterns:
* https://google.cz/url?source=web&url=
* https://google.com/image?url=
*/
describe('Google Redirects', () => {
test('handles google redirection to youtube', () => {
const url = 'https://www.google.cz/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0ahUKEwj30L2MvpDVAhUFZVAKHb8CBaYQuAIIIjAA&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DeG1uDU0rSLw&usg=AFQjCNECyDn3DQL7U6VW2CnXQQjB0gNKqA';
expect(fn(url).id).toBe('eG1uDU0rSLw');
expect(fn(url).service).toBe('youtube');
});

test('handles google redirection to dailymotion', () => {
const url = `https://www.google.cz/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0ahUKEwj30L2MvpDVAhUFZVAKHb8CBaYQuAIIIjAA&url=${encodeURIComponent('http://dai.ly/x2no31b')}&usg=AFQjCNECyDn3DQL7U6VW2CnXQQjB0gNKqA`;
expect(fn(url).id).toBe('x2no31b');
expect(fn(url).service).toBe('dailymotion');
});

test('handles google redirection to tiktok', () => {
const url = `https://www.google.cz/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0ahUKEwj30L2MvpDVAhUFZVAKHb8CBaYQuAIIIjAA&url=${encodeURIComponent('https://www.tiktok.com/@brickabrackcommunity/video/6950630446614990085')}&usg=AFQjCNECyDn3DQL7U6VW2CnXQQjB0gNKqA`;
expect(fn(url).id).toBe('6950630446614990085');
expect(fn(url).service).toBe('tiktok');
});

test('handles google redirection to videopress', () => {
const url = `https://www.google.cz/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0ahUKEwj30L2MvpDVAhUFZVAKHb8CBaYQuAIIIjAA&url=${encodeURIComponent('https://videopress.com/v/dyrgndFq')}&usg=AFQjCNECyDn3DQL7U6VW2CnXQQjB0gNKqA`;
expect(fn(url).id).toBe('dyrgndFq');
expect(fn(url).service).toBe('videopress');
});

test('handles google redirection to vine', () => {
const url = `https://www.google.cz/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0ahUKEwj30L2MvpDVAhUFZVAKHb8CBaYQuAIIIjAA&url=${encodeURIComponent('https://vine.co/v/e5vIvmV5v9J')}&usg=AFQjCNECyDn3DQL7U6VW2CnXQQjB0gNKqA`;
expect(fn(url).id).toBe('e5vIvmV5v9J');
expect(fn(url).service).toBe('vine');
});

test('handles google redirection to microsoft stream', () => {
const url = `https://www.google.cz/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0ahUKEwj30L2MvpDVAhUFZVAKHb8CBaYQuAIIIjAA&url=${encodeURIComponent('https://web.microsoftstream.com/video/73043e0c-cba8-482a-8a8e-0b72bc580ff0')}&usg=AFQjCNECyDn3DQL7U6VW2CnXQQjB0gNKqA`;
expect(fn(url).id).toBe('73043e0c-cba8-482a-8a8e-0b72bc580ff0');
expect(fn(url).service).toBe('microsoftstream');
});
});
21 changes: 21 additions & 0 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint max-len: 0 */
import fn from '../dist/get-video-id.js';

test('expects a string', () => {
expect(() => {
fn({});
}).toThrow(/get-video-id expects a string/);
});

test('returns null as id and service', () => {
const notFound = fn('foo');
expect(notFound.id).toBe(null);
expect(notFound.service).toBe(null);
});

test('google link returns null as id and service if missing url parameter', () => {
const url = 'https://www.google.cz/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&ved=0ahUKEwiz9P3Aw5DVAhUDZVAKHcegCi8QuAIINDAB&usg=AFQjCNG0kTPdL8nC6zCi2QoZ1KVeTXH-pw';
expect(fn(url).id).toBe(null);
expect(fn(url).service).toBe(null);
});

36 changes: 36 additions & 0 deletions __tests__/microsoft-stream.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* eslint max-len: 0 */
import fn from '../dist/get-video-id.js';

/**
* Microsoft Stream should be able to find these patterns:
*
* // urls
* https://web.microsoftstream.com/video/id
*
* // iframe
* <iframe src="https://web.microsoftstream.com/embed/video/id"
*
*/
describe('Microsoft Stream', () => {
test('gets microsoft stream from url', () => {
expect(fn('https://web.microsoftstream.com/video/73043e0c-cba8-482a-8a8e-0b72bc580ff0').id).toBe('73043e0c-cba8-482a-8a8e-0b72bc580ff0');
expect(fn('https://web.microsoftstream.com/video/73043e0c-cba8-482a-8a8e-0b72bc580ff0?list=trending').id).toBe('73043e0c-cba8-482a-8a8e-0b72bc580ff0');
expect(fn('https://web.microsoftstream.com/embed/video/73043e0c-cba8-482a-8a8e-0b72bc580ff0').id).toBe('73043e0c-cba8-482a-8a8e-0b72bc580ff0');

expect(fn('https://web.microsoftstream.com/video/73043e0c-cba8-482a-8a8e-0b72bc580ff0').service).toBe('microsoftstream');
expect(fn('https://web.microsoftstream.com/embed/video/73043e0c-cba8-482a-8a8e-0b72bc580ff0').service).toBe('microsoftstream');
});

test('gets microsoft stream metadata from iframe', () => {
const string_ = '<iframe width="640" height="360" src="https://web.microsoftstream.com/embed/video/73043e0c-cba8-482a-8a8e-0b72bc580ff0?autoplay=false&amp;showinfo=true" allowfullscreen style="border:none;"></iframe>';

expect(fn(string_).id).toBe('73043e0c-cba8-482a-8a8e-0b72bc580ff0');
expect(fn(string_).service).toBe('microsoftstream');
});

test('microsoft stream links returns undefined id if id missing', () => {
const object = fn('https://web.microsoftstream.com/video');
expect(object.id).toBe(undefined);
expect(object.service).toBe('microsoftstream');
});
});
27 changes: 27 additions & 0 deletions __tests__/tiktok.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/* eslint max-len: 0 */
import fn from '../dist/get-video-id.js';

/**
* TikTok should be able to find these patterns:
*
* Urls:
* https://www.tiktok.com/@brickabrackcommunity/video/id
* https://www.tiktok.com/@brickabrackcommunity/video/id?
*
* Not supported yet (requires a fetch):
* https://vm.tiktok.com/ZS9c8yNN/
*/
describe('TikTok', () => {
test('Tiktok basic link/embed', () => {
expect(fn('https://www.tiktok.com/@brickabrackcommunity/video/6950630446614990085').id).toBe('6950630446614990085');
expect(fn('https://www.tiktok.com/@brickabrackcommunity/video/6950630446614990085?lang=fr&is_copy_url=1&is_from_webapp=v1').id).toBe('6950630446614990085');
expect(fn('https://www.tiktok.com/@brickabrackcommunity/video/6950630446614990085?sender_device=pc&sender_web_id=6930592755036374533&is_from_webapp=v1&is_copy_url=0').id).toBe('6950630446614990085');
});

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

37 changes: 37 additions & 0 deletions __tests__/utils/get-src.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import fn from '../../src/utils/get-src.js';

describe('get-src', () => {
test('expects a string', () => {
expect(() => {
fn();
}).toThrow(/getSrc expected a string/);
});

test('extracts the src from iframe strings', () => {
expect(fn('<iframe src="https://player.vimeo.com/video/abc123"')).toBe('https://player.vimeo.com/video/abc123');
expect(fn('<iframe src="https://videopress.com/embed/abc123"')).toBe('https://videopress.com/embed/abc123');
expect(fn(' <iframe src="https://videopress.com/embed/abc123" ')).toBe('https://videopress.com/embed/abc123');
expect(fn(' <iframe src="https://videopress.com/embed/abc123"')).toBe('https://videopress.com/embed/abc123');
expect(fn('<iframe width="400" height="300" src="video.mp4"></iframe>')).toBe('video.mp4');
});

test('extracts the source from simple strings', () => {
expect(fn('src="abc123"')).toBe('abc123');
expect(fn(' src="abc123" ')).toBe('abc123');
expect(fn(' src="abc123"')).toBe('abc123');
expect(fn('src="abc123" ')).toBe('abc123');
});

test('extracts the source from html strings', () => {
expect(fn('<image src="image.png" />')).toBe('image.png');
expect(fn('<source src="audio.mp3" />')).toBe('audio.mp3');
});

test('returns undefined when no src= is found', () => {
expect(fn('hello')).toBe(undefined);
});

test('single quotes return undefined', () => {
expect(fn(' src=\'noop\' ')).toBe(undefined);
});
});
36 changes: 36 additions & 0 deletions __tests__/videopress.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* eslint max-len: 0 */
import fn from '../dist/get-video-id.js';

/**
* VideoPress should be able to find these patterns:
*
* // urls
* https://videopress.com/v/id
* https://videopress.com/embed/id
*
* // iframe
* <iframe src="https://videopress.com/embed/zcnJVzQF"
*
*/

describe('Videopress', () => {
test('gets videopress metadata from url', () => {
expect(fn('https://videopress.com/v/dyrgndFq').id).toBe('dyrgndFq');
expect(fn('https://videopress.com/v/dyrgndFq#fullscreen').id).toBe('dyrgndFq');
expect(fn('https://videopress.com/embed/zcnJVzQz?hd=0&autoPlay=0&permalink=0&loop=0').id).toBe('zcnJVzQz');

expect(fn('https://videopress.com/embed/zcnJVzQz?hd=0&autoPlay=0&permalink=0&loop=0').service).toBe('videopress');
});

test('gets videopress metadata from iframe', () => {
const string_ = '<iframe width="400" height="300" src="https://videopress.com/embed/zcnJVzQz?hd=0&amp;autoPlay=0&amp;permalink=0&amp;loop=0" frameborder="0" allowfullscreen="" sandbox="allow-same-origin allow-scripts allow-popups"></iframe>';
expect(fn(string_).id).toBe('zcnJVzQz');
expect(fn(string_).service).toBe('videopress');
});

test('videopress links returns undefined id if id missing', () => {
const object = fn('https://videopress.com');
expect(object.id).toBe(undefined);
expect(object.service).toBe('videopress');
});
});
Loading

0 comments on commit ef8cec6

Please sign in to comment.