URLs
Yt::URL
is a convenience class to identify YouTube resources based on their URL patterns:
Configuration
Yt::URL
is not part of the yt
library, but comes from the yt-url extension.
To use in any bundled Ruby project, remember to add the line gem 'yt-url', '~> 0.0.0'
to its Gemfile.
Authentication
Using Yt::URL
does not require authentication since it is based on matching a set of hard-coded patterns:
Yt::URL::PLAYLIST_PATTERNS # => [
# %r{^(?:https?://)?(?:www\.)?youtube\.com/playlist/?\?list=(?<id>[a-zA-Z0-9_-]+)},
# ]
Yt::URL::VIDEO_PATTERNS # => [
# %r{^(?:https?://)?(?:www\.)?youtube\.com/watch\?v=(?<id>[a-zA-Z0-9_-]{11})},
# %r{^(?:https?://)?(?:www\.)?youtu\.be/(?<id>[a-zA-Z0-9_-]{11})},
# %r{^(?:https?://)?(?:www\.)?youtube\.com/embed/(?<id>[a-zA-Z0-9_-]{11})},
# %r{^(?:https?://)?(?:www\.)?youtube\.com/v/(?<id>[a-zA-Z0-9_-]{11})},
# ]
Yt::URL::CHANNEL_PATTERNS # => [
# %r{^(?:https?://)?(?:www\.)?youtube\.com/channel/(?<id>UC[a-zA-Z0-9_-]{22})},
# %r{^(?:https?://)?(?:www\.)?youtube\.com/(?<format>c/|user/)?(?<name>[a-zA-Z0-9_-]+)}
# ]