Skip to content

Commit

Permalink
Fix user links (#22)
Browse files Browse the repository at this point in the history
* linting tweaks

* ignore username only links

* disable max-len rule in tests

* 3.1.3
  • Loading branch information
radiovisual authored Jun 8, 2019
1 parent 61461d8 commit 61cf386
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
23 changes: 20 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = function (str) {
throw new TypeError('get-video-id expects a string');
}

if (/<iframe/ig.test(str)) {
if (/<iframe/gi.test(str)) {
str = getSrc(str);
}

Expand Down Expand Up @@ -73,12 +73,22 @@ function vimeo(str) {
var id;
var arr;

if (/https?:\/\/vimeo\.com\/[0-9]+$|https?:\/\/player\.vimeo\.com\/video\/[0-9]+$|https?:\/\/vimeo\.com\/channels|groups|album/igm.test(str)) {
const vimeoPipe = [
'https?:\/\/vimeo\.com\/[0-9]+$',
'https?:\/\/player\.vimeo\.com\/video\/[0-9]+$',
'https?:\/\/vimeo\.com\/channels',
'groups',
'album'
].join('|');

const vimeoRegex = new RegExp(vimeoPipe, 'gim');

if (vimeoRegex.test(str)) {
arr = str.split('/');
if (arr && arr.length) {
id = arr.pop();
}
} else if (/clip_id=/igm.test(str)) {
} else if (/clip_id=/gim.test(str)) {
arr = str.split('clip_id=');
if (arr && arr.length) {
id = arr[1].split('&')[0];
Expand Down Expand Up @@ -145,6 +155,13 @@ function youtube(str) {
return stripParameters(embedid);
}

// ignore /user/username pattern
var usernamereg = /\/user\/([a-zA-Z0-9]*)$/g;

if (usernamereg.test(str)) {
return undefined;
}

// user
var userreg = /\/user\/(?!.*videos)/g;

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "get-video-id",
"version": "3.1.2",
"version": "3.1.3",
"description": "Get the YouTube, Vimeo, Vine or VideoPress video id from a url or embed string.",
"license": "MIT",
"repository": "radiovisual/get-video-id",
Expand Down
5 changes: 5 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint max-len: 0 */
import test from 'ava';
import fn from './';

Expand Down Expand Up @@ -266,6 +267,10 @@ test('handles youtube /user/ formats', t => {
t.is(fn('http://www.youtube.com/user/username#p/u/1/ABC12302?rel=0').service, 'youtube');
});

test('ignores youtube.com/user/* patterns', t => {
t.is(fn('https://www.youtube.com/user/ThreeDaysGraceVideos').id, undefined);
});

test('returns id:undefined with /user/ format that does not have a video id', t => {
t.is(fn('https://www.youtube.com/user/ThreeDaysGraceVideos/videos').id, undefined);
});
Expand Down

0 comments on commit 61cf386

Please sign in to comment.