URLs

Yt::URL is a convenience class to identify YouTube resources based on their URL patterns:

→ Yt docsurl = Yt::URL.new "youtu.be/gknzFj_0vvY"
→ Yt docsurl.kind # => :video
→ Yt docsurl.id # => "gknzFj_0vvY"
→ Yt docsurl.resource # => #<Yt::Video @id=gknzFj_0vvY>

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_-]+)}
# ]