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

Feat: Allow using YouTube links in addition to video IDs #76

Merged
merged 8 commits into from
Oct 23, 2020

Conversation

Phixyn
Copy link
Owner

@Phixyn Phixyn commented Oct 22, 2020

Pull Request Submission

Thank you for taking the time to contribute to this project! Please take the time to tell us a bit about the changes you've made.

Description

Give a short and brief description of the pull request. Add a screenshot if appropriate and helpful. Changes can be listed in the next section.

Users are now able to submit YouTube links containing a video ID, to load a new video.

If an error occurs in extracting or using a video ID, users are not yet notified. This will be done as part of #38 and #75.

Closes #24.

Changes

List the changes made.

  • Added a new function to check if a string is a valid URL
  • Added a new function to extract and validate a video ID from a given URL
  • Refactored updatePlayer() to check if the value of the input is a URL, and if so extract the ID from it
  • Updated video ID input label to say "Video URL or ID"

Breaking Change?

Will these changes cause existing functionality to not work as expected? Will contributors be able to run the project after these changes are merged, without needing to take any additional steps?

  • Please tick if this is a breaking change and describe why below

Merging Checklist

Lastly, before merging we need to make sure that these are done.

  • Project builds and runs
  • All changes were tested
  • All tests are up-to-date
  • All tests pass
  • Code style follows current style guide
  • Code documentation is up-to-date
  • Project documentation is up-to-date

Implements `getVideoId(youtubeUrl)`, which takes in a string containing a
YouTube URL and tries to extract a video ID from it. This uses the querystring
parser.

If no querystring is found in the URL, it splits the URL's path by a '/' and
checks if the last part of the URL is a valid YouTube ID. This handles URLs
like 'https://youtu.be/id'.

A function to check if a string is a valid HTTP or HTTPS URL has also been
added for convenience.
Refactor updatePlayer() to handle YouTube video URLs in addition to IDs. Makes
use of the previously implemented functions (see parent commit) to check if
the string in the input field is a URL.

For video IDs, an additional check has been put in place to somewhat validate
the ID (just by checking its length for now).

If the URL does not contain a video ID, or if the video ID is invalid, then the
function returns to exit, and nothing is sent to the WebSocket server. However,
errors are only logged, not shown to the user yet.
Update "Video ID" string to "Video URL or ID".
Add JSDoc to the new functions. Add some extra logging in these new functions.
Update some of the logging. Rename getVideoId() to extractVideoId().
Refactor some of the conditional logic to use early returns.
@Phixyn Phixyn added frontend client Client-side JavaScript new feature A shiny new feature labels Oct 22, 2020
@Phixyn Phixyn added this to the v1.1.0 milestone Oct 22, 2020
@Phixyn
Copy link
Owner Author

Phixyn commented Oct 22, 2020

Needs a little bit more testing.

Also add some links to the URL API docs.
@Phixyn Phixyn merged commit 274eb8c into master Oct 23, 2020
@Phixyn Phixyn deleted the feat/allow-using-urls branch October 23, 2020 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend client Client-side JavaScript new feature A shiny new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow using video URL as well as video ID
1 participant