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

Commit

Permalink
drop support for mixes (#104)
Browse files Browse the repository at this point in the history
* drop support for mixes

* fix tests
  • Loading branch information
TimeForANinja authored Feb 1, 2021
1 parent 2335766 commit 62e2a5f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
[![Known Vulnerabilities](https://snyk.io/test/github/timeforaninja/node-ytpl/badge.svg)](https://snyk.io/test/github/timeforaninja/node-ytpl)
[![Discord](https://img.shields.io/discord/484464227067887645.svg)](https://discord.gg/V3vSCs7)

Simple js only module to resolve YouTube playlist ids
Doesn't need any login or GoogleAPI key
Simple js only package to resolve YouTube Playlists.
Does not require any login or Google-API-Key.

# Support
You can contact us for support on our [chat server](https://discord.gg/V3vSCs7)
Expand Down
11 changes: 8 additions & 3 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ main.validateID = linkOrId => {
if (PLAYLIST_REGEX.test(parsed.query.list) || ALBUM_REGEX.test(parsed.query.list)) {
return true;
}
// Mixes currently not supported
// They would require fetching a video page & resolving the side-loaded playlist
if (parsed.query.list && parsed.query.list.startsWith('RD')) {
return false;
}
return false;
}
// Shortened channel or user page provided
Expand All @@ -179,8 +184,8 @@ main.validateID = linkOrId => {
};

// Parse the input to a id (or error)
const PLAYLIST_REGEX = exports.PLAYLIST_REGEX = /^(FL|PL|UU|LL|RD)[a-zA-Z0-9-_]{16,41}$/;
const ALBUM_REGEX = exports.ALBUM_REGEX = /^OLAK5uy_[a-zA-Z0-9-_]{33}$/;
const PLAYLIST_REGEX = exports.PLAYLIST_REGEX = /^(FL|PL|UU|LL)[a-zA-Z0-9-_]{16,41}$/;
const ALBUM_REGEX = exports.ALBUM_REGEX = /^(RDC|O)LAK5uy_[a-zA-Z0-9-_]{33}$/;
const CHANNEL_REGEX = exports.CHANNEL_REGEX = /^UC[a-zA-Z0-9-_]{22,32}$/;
main.getPlaylistID = async linkOrId => {
// Validate inputs
Expand All @@ -203,7 +208,7 @@ main.getPlaylistID = async linkOrId => {
}
// Mixes currently not supported
// They would require fetching a video page & resolving the side-loaded playlist
if (parsed.query.list && parsed.query.list.startsWith('RD') && parsed.query.list.length < 18) {
if (parsed.query.list && parsed.query.list.startsWith('RD')) {
throw new Error('Mixes not supported');
}
// Default case
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "ytpl",
"version": "2.0.4",
"description": "Anonymous YouTube playlist resolver.",
"description": "Simple package to resolve YouTube playlists - no strings attached.",
"keywords": [
"youtube",
"playlist",
"yt",
"video",
"videos",
"api",
"playlist",
"pl",
"scrape",
"pagination",
Expand Down
19 changes: 16 additions & 3 deletions test/main-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,14 @@ describe('YTPL.getPlaylistID()', () => {
);
});

it('errors for video links with an embedded mix-playlist', async() => {
const ref = 'https://www.youtube.com/watch?v=XgxMCUJwV7o&list=RDCMUCFmuxtfNr8z4q4dPlLNozzA&index=1';
await ASSERT.rejects(
YTPL.getPlaylistID(ref),
/Mixes not supported/,
);
});

it('errors for unknown list query', async() => {
const ref = 'https://www.youtube.com/watch?v=J2X5mJ3HDYE&list=ASDF';
await ASSERT.rejects(
Expand Down Expand Up @@ -379,8 +387,8 @@ describe('YTPL.getPlaylistID()', () => {
);
// Album:
ASSERT.equal(
await YTPL.getPlaylistID('RDqwGaUvq_l0RKszeHhZ5leA'),
'RDqwGaUvq_l0RKszeHhZ5leA',
await YTPL.getPlaylistID('OLAK5uy_qwGaUvq_l0RKszeHhZ5leA12345asdf12'),
'OLAK5uy_qwGaUvq_l0RKszeHhZ5leA12345asdf12',
);
// Playlist:
ASSERT.equal(
Expand Down Expand Up @@ -474,6 +482,11 @@ describe('YTPL.validateID()', () => {
ASSERT.equal(YTPL.validateID(ref), false);
});

it('false for video links with an embedded mix-playlist', () => {
const ref = 'https://www.youtube.com/watch?v=XgxMCUJwV7o&list=RDCMUCFmuxtfNr8z4q4dPlLNozzA&index=1';
ASSERT.equal(YTPL.validateID(ref), false);
});

it('false for unknown list query', () => {
const ref = 'https://www.youtube.com/watch?v=J2X5mJ3HDYE&list=ASDF';
ASSERT.equal(YTPL.validateID(ref), false);
Expand Down Expand Up @@ -503,7 +516,7 @@ describe('YTPL.validateID()', () => {
// Channel:
ASSERT.ok(YTPL.validateID('UCqwGaUvq_l0RKszeHhZ5leA'));
// Album:
ASSERT.ok(YTPL.validateID('RDqwGaUvq_l0RKszeHhZ5leA'));
ASSERT.ok(YTPL.validateID('OLAK5uy_qwGaUvq_l0RKszeHhZ5leA12345asdf12'));
// Playlist:
ASSERT.ok(YTPL.validateID('PLqwGaUvq_l0RKszeHhZ5leA'));
// Channel-Uploads-Playlist:
Expand Down

0 comments on commit 62e2a5f

Please sign in to comment.