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

fix: Handle empty playlist #122

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

Hazmi35
Copy link

@Hazmi35 Hazmi35 commented Aug 30, 2021

This should fix #121

.twoColumnBrowseResultsRenderer.tabs[0].tabRenderer.content
.sectionListRenderer.contents[0]
.itemSectionRenderer.contents[0]
.playlistVideoListRenderer.contents;
.playlistVideoListRenderer;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use optional chaining here but that requires node v14.5.0 or above, so I used the ternary operator to be compatible with node v8. I do recommend you bump node to v14.5.0 or above because v8 is EOL and v12 is going to EOL next year

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With optional chaining the updated code should look like this

const rawVideoList = parsed.json.contents
    .twoColumnBrowseResultsRenderer.tabs[0].tabRenderer.content
    .sectionListRenderer.contents[0]
    .itemSectionRenderer.contents[0]
    .playlistVideoListRenderer?.contents;

if (rawVideoList === undefined) throw new Error('Playlist is empty');

Copy link
Author

@Hazmi35 Hazmi35 Sep 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the current changes, it would be like this with optional chaining

const playlistVideoListRenderer = parsed.json.contents
    .twoColumnBrowseResultsRenderer.tabs[0].tabRenderer.content
    .sectionListRenderer.contents[0]
    .itemSectionRenderer.contents[0]
    .playlistVideoListRenderer?.contents ?? [];

@Hazmi35
Copy link
Author

Hazmi35 commented Aug 30, 2021

Should test for empty playlist created too?

@TimeForANinja
Copy link
Owner

would be cool 😅

@codecov
Copy link

codecov bot commented Sep 6, 2021

Codecov Report

Merging #122 (d3519ab) into master (fcc26a1) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #122   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            3         3           
  Lines          260       261    +1     
=========================================
+ Hits           260       261    +1     
Impacted Files Coverage Δ
lib/main.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fcc26a1...d3519ab. Read the comment docs.

@TimeForANinja
Copy link
Owner

i'm also more of a empty array fan since doing that you'd get meta information like playlist title and so on...

@Hazmi35
Copy link
Author

Hazmi35 commented Sep 8, 2021

i'm also more of a empty array fan since doing that you'd get meta information like playlist title and so on...

Yes, I didn't think of that before, changed in d3519ab.

Do the test still need to be created?

@stale
Copy link

stale bot commented Nov 7, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Nov 7, 2021
@stale stale bot closed this Nov 14, 2021
@Hazmi35
Copy link
Author

Hazmi35 commented Nov 15, 2021

This should be reopened when you're ready.

@TimeForANinja
Copy link
Owner

not quite ready but i can at least tell the stale bot to ignore this 😉

@TimeForANinja TimeForANinja reopened this Dec 22, 2021
@stale stale bot removed the stale label Dec 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle empty playlists
2 participants