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

Commit

Permalink
fix: yt might serve the landing page for unknown playlists
Browse files Browse the repository at this point in the history
youtube does some trickery to produce a statuscode 204 but for now this should do the trick

closes #119
  • Loading branch information
TimeForANinja committed Aug 4, 2021
1 parent 495a7e5 commit d8c6b26
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ const main = module.exports = async(linkOrId, options, rt = 3) => {
if (error) throw new Error(`API-Error: ${UTIL.parseText(error.alertRenderer.text, '* no message *')}`);
}

// Youtube might just load the main page and set statuscode 204
if (!parsed.json.sidebar) throw new Error('Unknown Playlist');

const info = parsed.json.sidebar
.playlistSidebarRenderer.items
.find(x => Object.keys(x)[0] === 'playlistSidebarPrimaryInfoRenderer')
Expand Down
13 changes: 13 additions & 0 deletions test/main-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ describe('YTPL()', () => {
scope.done();
});

it('Errors for unknown Playlists - variant 2', async() => {
const scope = NOCK(YT_HOST)
.get(PLAYLIST_PATH)
.query({ gl: 'US', hl: 'en', list: 'UU2-i3KuYoODXsM99Z3' })
.replyWithFile(200, 'test/pages/landingPage.html');

await ASSERT.rejects(
YTPL('UU2-i3KuYoODXsM99Z3'),
/Unknown Playlist/,
);
scope.done();
});

it('Errors for private Playlists', async() => {
const scope = NOCK(YT_HOST)
.get(PLAYLIST_PATH)
Expand Down
21 changes: 21 additions & 0 deletions test/pages/landingPage.html

Large diffs are not rendered by default.

0 comments on commit d8c6b26

Please sign in to comment.