Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a --likes flag (fixes #16) #17

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

Conversation

ArcticZeroo
Copy link

@ArcticZeroo ArcticZeroo commented Oct 29, 2017

This PR does a few things:

  • Adds an option to getSortedPlaylist which allows custom comparators to be used
  • Adds a generic statistic comparator which should make it easier to add future comparators for video stats
  • Adds a try/catch block around the getSortedPlaylist method because async functions don't catch failures in await calls
  • Adds the requested --likes option to sort videos by likes (alias -l) (fixes Provide a flag to sort videos by likes #16 )

@jaydp17
Copy link
Owner

jaydp17 commented Oct 29, 2017

Hey @ArcticZeroo,
Thanks for the PR!

This looks great 🎉
Only issue being, it doesn't follow the code styles used by the project.

To fix that, run

$ ./node_modules/.bin/prettier -l src/*.js

And push those changes, then we can merge this.

* @returns {Promise.<Array.<T>|*>}
*/
async function getSortedPlaylist(playListId, comparator = viewComparator) {
try {
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not sure why a try/catch is required over here?
Because there's a try/catch in the main function

Copy link
Author

Choose a reason for hiding this comment

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

Node's async doesn't catch errors thrown by await, they need to be explicitly thrown with throw or explicitly caught in some way. As a result, if the YouTube API replies with an error of some kind, an error will be printed to console about an uncaught promise, but getSortedPlaylist won't actually reject the promise.

Copy link
Owner

Choose a reason for hiding this comment

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

Are you sure about that?? 🤔
Because I commented out the try/catch added by you over here and explicitly threw an error in api.getVideoIdsFromPlayList and it did get caught by the catch block in main.js

Copy link
Author

Choose a reason for hiding this comment

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

I'm like 75% sure (it's definitely been an issue many times for me on other projects), I'll do some testing of my own when I'm back at my dorm

@ArcticZeroo ArcticZeroo reopened this Oct 29, 2017
@ArcticZeroo
Copy link
Author

Whoops, phone misclick. Ignore that.

I'll make the changes later, just left the dorm!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide a flag to sort videos by likes
2 participants