Project

youtuberb

0.0
No release in over a year
A Ruby library for interacting with the YouTube API
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

~> 2.0
 Project Readme

YouTubeRB

This library is a work in progress

YouTubeRB is a Ruby library for interacting with the YouTube Data v3 API.

Installation

Add this line to your application's Gemfile:

gem 'youtuberb'

Usage

Set Client Details

Firstly you'll need to set an API Key. A user Access Token is required to access private data. An Access Token will be an OAuth2 token generated after authentication.

# To access public data, just an API Key is required
@client = YouTube::Client.new(api_key: "")

# Or to access data for a user, an Access Token is also required
@client = YouTube::Client.new(api_key: "", access_token: "")

Channels

# Get the Channel details of the currently authenticated user
@client.channels.mine

# Get a Channel by ID
@client.channels.retrieve(id: "channel_id")

# Get a Channel by username
@client.channels.retrieve(username: "username")

Videos

# Get a single video
@client.videos.list(id: "abc123")
# => #<YouTube::Video...

# Get multiple videos
@client.videos.list(ids: ["abc123", "123abc"])
# => #<YouTube::Collection...

# Liked videos for the currently authenticated user
@client.videos.liked
# => #<YouTube::Collection...

# Get a video owned by the current user. This retrieves extra information so will only work on videos owned by the current user.
@client.videos.retrieve(id: "abc123")
# => #<YouTube::Video...

Getting a list of Videos for a Channel

# First, grab the Channel details
channel = @client.channels.retrieve(id: "channel_id")

# Then use the Playlist Items endpoint to get the Videos
@client.playlist_items.list playlist_id: channel.contentDetails.relatedPlaylists.uploads

# Or use the Search endpoint
@client.search.list channelId: channel.id

Playlists

# Playlists created by the authenticated user
@client.playlists.list

# Playlists for a Channel
@client.playlists.list(channel_id: "channel")

# Return a set number of results & use the page_token to select the next/previous page
@client.playlists.list(max_results: 5, page_token: "page_token")

@client.playlists.retrieve(id: "playlist_id")
@client.playlists.create(title: "My Playlist")
@client.playlists.update(id: "playlist_id", title: "My Playlist", privacy_status: "public")
@client.playlists.delete(id: "playlist_id")

Playlist Items

# Playlist Items for a Playlist
@client.playlist_items.list(playlist_id: "playlist_id")

@client.playlist_items.retrieve(id: "playlist_item_id")

# Add a video to a playlist
@client.playlist_items.create(playlist_id: "playlist_id", video_id: "video_id")

@client.playlist_items.update(id: "playlist_item_id", playlist_id: "playlist_id", video_id: "video_id")

@client.playlist_items.delete(id: "playlist_id")

Search

For a full list of parameters, see the YouTube API Docs.

# Search YouTube for a term
@client.search.list(q: "search term")

# Restrict the search to a channel
@client.search.list(channelId: "channel")

# Search a channel for videos only and ordered by date
@client.search.list(channelId: "channel", type: "video", order: "date")

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/deanpcmad/youtuberb.

License

The gem is available as open source under the terms of the MIT License.