Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

Commit

Permalink
feat: Added youtu.be links check and tests (#125)
Browse files Browse the repository at this point in the history
* added youtu.be as youtube host

* updated tests for youtu.be links

* Added missing semicolon to main-test.js

* Added test for youtu.be link with ytpl.validateID

* updated validateID test for youtu.be links

Co-authored-by: TimeForANinja <TimeForANinja@users.noreply.github.com>

Co-authored-by: TimeForANinja <TimeForANinja@users.noreply.github.com>
  • Loading branch information
th0m4s and TimeForANinja committed Mar 4, 2022
1 parent 3af56e1 commit dc21c3b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const QS = require('querystring');
const PARSE_ITEM = require('./parseItem.js');
const MINIGET = require('miniget');

const YT_HOSTS = ['www.youtube.com', 'youtube.com', 'music.youtube.com'];
const YT_HOSTS = ['www.youtube.com', 'youtube.com', 'music.youtube.com', 'youtu.be'];
const BASE_PLIST_URL = 'https://www.youtube.com/playlist?';
const BASE_API_URL = 'https://www.youtube.com/youtubei/v1/browse?key=';

Expand Down
15 changes: 13 additions & 2 deletions test/main-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,11 +396,11 @@ describe('YTPL.getPlaylistID()', () => {
);
});

it('errors for youtu.be links', async() => {
it('errors for invalid youtu.be links', async() => {
const ref = 'https://youtu.be/channel/whatever';
await ASSERT.rejects(
YTPL.getPlaylistID(ref),
/not a known youtube link/,
/Unable to find a id in ./,
);
});

Expand Down Expand Up @@ -487,6 +487,12 @@ describe('YTPL.getPlaylistID()', () => {
const uploads = await YTPL.getPlaylistID(ref);
ASSERT.equal(uploads, 'UUqwGaUvq_l0RKszeHhZ5leA');
});

it('resolves playlist from youtu.be share link', async() => {
const ref = 'https://youtu.be/hIaYzwf0A8A?list=PL37UZ2QfPUvyeqqNi4m_byAjAbSHBIosW';
const playlist = await YTPL.getPlaylistID(ref);
ASSERT.equal(playlist, 'PL37UZ2QfPUvyeqqNi4m_byAjAbSHBIosW');
});
});

describe('YTPL.validateID()', () => {
Expand Down Expand Up @@ -572,4 +578,9 @@ describe('YTPL.validateID()', () => {
const ref = 'https://www.youtube.com/watch?v=ASDF&list=UUqwGaUvq_l0RKszeHhZ5leA';
ASSERT.ok(YTPL.validateID(ref));
});

it('true for youtu.be share link', () => {
const ref = 'https://youtu.be/hIaYzwf0A8A?list=PL37UZ2QfPUvyeqqNi4m_byAjAbSHBIosW';
ASSERT.ok(YTPL.validateID(ref));
});
});

0 comments on commit dc21c3b

Please sign in to comment.