百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
Y

youtube_it

> 编程语言
开源

一个面向对象的 Ruby 封装,用于 YouTube GData API

590 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

一个面向对象的 Ruby 封装,用于 YouTube GData API

== YOUTUBE_IT {}[http://travis-ci.org/kylejginavan/youtube_it] {}[http://badge.fury.io/rb/youtube_it] {}[https://gemnasium.com/kylejginavan/youtube_it]

== DONATION

YOUTUBE_IT is developed by many contributors who are passioned about opensource projects and selflessly donate their time and work. Following that spirit your donations to this project will be destined to the Tuquito Libre Foundation(http://fundacion.tuquito.org.ar) for developing technology projects intended to close the digital gap in Latin America.

{}[http://www.pledgie.com/campaigns/16746]

== DESCRIPTION

youtube_it is the most complete Ruby client for the YouTube GData API. It provides an easy way to access the latest and most complete access to YouTube's video API. In comparison with the earlier Youtube interfaces, this new API and library offers much-improved flexibility around executing complex search queries to obtain well-targeted video search results. In addition, standard video management including but not limited to uploading, deleting, updating, like, dislike, ratings and comments.

== INSTALLATION & SETUP:

  • Create a youtube account.
  • Create a developer key here http://code.google.com/apis/youtube/dashboard.
  • sudo gem install youtube_it

Note: youtube_it supports ClientLogin(YouTube account), OAuth or AuthSub authentication methods.

== Example Rails 3 App

You can get an example how you can use youtube_it with Rails 3 here: http://github.com/chebyte/youtube_it_rails_app_example

== DEMO

You can see to youtube_it in action here: http://youtube-it.heroku.com

== ESTABLISHING A CLIENT

Important: The Account Authentication API for OAuth 1.0, AuthSub and Client Login has been officially deprecated as of April 20, 2012. It will continue to work as per our deprecation policy(https://developers.google.com/accounts/terms), but we encourage you to migrate to OAuth 2.0 authentication as soon as possible. If you are building a new application, you should use OAuth 2.0 authentication.

Creating a client: $ require 'youtube_it' $ client = YouTubeIt::Client.new

Client with developer key: $ client = YouTubeIt::Client.new(:dev_key => "developer_key")

Client with youtube account and developer key: $ client = YouTubeIt::Client.new(:username => "youtube_username", :password => "youtube_passwd", :dev_key => "developer_key")

Client with AuthSub: $ client = YouTubeIt::AuthSubClient.new(:token => "token" , :dev_key => "developer_key")

Client with OAuth: $ client = YouTubeIt::OAuthClient.new("consumer_key", "consumer_secret", "youtube_username", "developer_key") $ client.authorize_from_access("access_token", "access_secret")

Client with OAuth2: $ client = YouTubeIt::OAuth2Client.new(client_access_token: "access_token", client_refresh_token: "refresh_token", client_id: "client_id", client_secret: "client_secret", dev_key: "dev_key", expires_at: "expiration time")

If your access token is still valid (be careful, access tokens may only be valid for about 1 hour), you can use the client directly. If you want to refresh the access token using the refresh token just do:

$ client.refresh_access_token!

  • You can see more about oauth 2 in the wiki: https://github.com/kylejginavan/youtube_it/wiki/How-To:-Use-OAuth-2

== PROFILES you can use multiple profiles in the same account like that

$ profiles = client.profiles(['username1','username2']) $ profiles['username1'].username, "username1"

== VIDEO QUERIES

Note: Each type of client enables searching capabilities.

Basic Queries: $ client.videos_by(:query => "penguin") $ client.videos_by(:query => "penguin", :page => 2, :per_page => 15) $ client.videos_by(:query => "penguin", :restriction => "DE") $ client.videos_by(:query => "penguin", :author => "liz") $ client.videos_by(:tags => ['tiger', 'leopard']) $ client.videos_by(:categories => [:news, :sports]) $ client.videos_by(:categories => [:news, :sports], :tags => ['soccer', 'football']) $ client.videos_by(:user => 'liz') $ client.videos_by(:favorites, :user => 'liz') $ client.video_by("FQK1URcxmb4") $ client.video_by("https://www.youtube.com/watch?v=QsbmrCtiEUU")
$ client.video_by_user("chebyte","FQK1URcxmb4")

Standard Queries: $ client.videos_by(:most_viewed) $ client.videos_by(:most_linked, :page => 3) $ client.videos_by(:top_rated, :time => :today) $ client.get_all_videos(:top_rated, :time => :today) $ client.videos_by(:top_rated, :region => "RU", :category => "News") Advanced Queries (with boolean operators OR (either), AND (include), NOT (exclude)): $ client.videos_by(:categories => { :either => [:news, :sports], :exclude => [:comedy] }, :tags => { :include => ['football'], :exclude => ['soccer'] })

Custom Query Params You can use custom query params like that:

$ client.videos_by(:query => "penguin", :safe_search => "strict") $ client.videos_by(:query => "penguin", :duration => "long") $ client.videos_by(:query => "penguin", :hd => "true") $ client.videos_by(:query => "penguin", :region => "AR")

you can see more options here https://developers.google.com/youtube/2.0/reference#yt_format

Fields Parameter(experimental features): Return videos more than 1000 views $ client.videos_by(:fields => {:view_count => "1000"})

Filter by date $ client.videos_by(:fields => {:published => (Date.today)}) $ client.videos_by(:fields => {:recorded => (Date.today)})

Filter by date with range $ client.videos_by(:fields => {:published => ((Date.today - 30)..(Date.today))}) $ client.videos_by(:fields => {:recorded => ((Date.today - 30)..(Date.today))})

Note: These queries do not find private videos! Use these methods instead: $ client.my_video("FQK1URcxmb4") $ client.my_videos(:query => "penguin")

== VIDEO MANAGEMENT

Note: YouTube account, OAuth or AuthSub enables video management.

Upload Video: $ client.video_upload(File.open("test.mov"), :title => "test",:description => 'some description', :category => 'People',:keywords => %w[cool blah test])

Upload Remote Video: $ client.video_upload("http://url/myvideo.mp4", :title => "test",:description => 'some description', :category => 'People',:keywords => %w[cool blah test])

Upload Video With A Developer Tag (Note the tags are not immediately available): $ client.video_upload(File.open("test.mov"), :title => "test",:description => 'some description', :category => 'People',:keywords => %w[cool blah test], :dev_tag => 'tagdev')

Upload Video from url: $ client.video_upload("http://media.railscasts.com/assets/episodes/videos/412-fast-rails-commands.mp4", :title => "test",:description => 'some description', :category => 'People',:keywords => %w[cool blah test])

Upload Private Video: $ client.video_upload(File.open("test.mov"), :title => "test",:description => 'some description', :category => 'People',:keywords => %w[cool blah test], :private => true)

Update Video: $ client.video_update("FQK1URcxmb4", :title => "new test",:description => 'new description', :category => 'People',:keywords => %w[cool blah test])

Delete Video: $ client.video_delete("FQK1URcxmb4")

My Videos: $ client.my_videos

My Video: $ client.my_video(video_id)

Profile Details: $ client.profile(user) #default: current user

List Comments: $ client.comments(video_id)

Add A Comment: $ client.add_comment(video_id, "test comment!")

Add A Reply Comment: $ client.add_comment(video_id, "test reply!", :reply_to => another_comment)

Delete A Comment: $ client.delete_comment(video_id, comment_id)

List Favorites: $ client.favorites(user) # default: current user

Add Favorite: $ client.add_favorite(video_id)

Delete Favorite: $ client.delete_favorite(favorite_entry_id)

Like A Video: $ client.like_video(video_id)

Dislike A Video: $ client.dislike_video(video_id)

List Subscriptions: $ client.subscriptions(user) # default: current user

Subscribe To A Channel: $ client.subscribe_channel(channel_name)

Unsubscribe To A Channel: $ client.unsubscribe_channel(subscription_id)

List New Subscription Videos: $ client.new_subscription_videos(user) # default: current user

List Playlists: $ client.playlists(user, order_by) # default: current user, position

for example you can get the videos of your playlist ordered by title

$ client.playlists(user, "title")

you can see more about options for order_by here: https://developers.google.com/youtube/2.0/reference#orderbysp

Select Playlist: $ client.playlist(playlist_id)

Select All Videos From A Playlist: $ playlist = client.playlist(playlist_id) $ playlist.videos

Create Playlist: $ playlist = client.add_playlist(:title => "new playlist", :description => "playlist description")

Delete Playlist: $ client.delete_playlist(playlist_id)

Add Video To Playlist: $ client.add_video_to_playlist(playlist_id, video_id, position)

Remove Video From Playlist: $ client.delete_video_from_playlist(playlist_id, playlist_entry_id)

Update Position Video From Playlist: $ client.update_position_video_from_playlist(playlist_id, playlist_entry_id, position)

Select All Videos From your Watch Later Playlist: $ watcher_later = client.watcherlater(user) #default: current user $ watcher_later.videos

Add Video To Watcher Later Playlist: $ client.add_video_to_watchlater(video_id)

Remove Video From Watch Later Playlist: $ client.delete_video_from_watchlater(watchlater_entry_id)

List Related Videos $ video = client.video_by("https://www.youtube.com/watch?v=QsbmrCtiEUU&feature=player_embedded") $ video.related.videos

Add Response Video $ video.add_response(original_video_id, response_video_id)

Delete Response Video $ video.delete_response(original_video_id, response_video_id)

List Response Videos $ video = client.video_by("https://www.youtube.com/watch?v=QsbmrCtiEUU&feature=player_embedded") $ video.responses.videos

== BATCH VIDEOS you can list many videos at the same time

$ client.videos(['video_id_1', 'video_id_2',...])

== ACCESS CONTROL LIST

You can give permissions in your videos, for example denied comments, rate, etc... you can read more there http://code.google.com/apis/youtube/2.0/reference.html#youtube_data_api_tag_yt:accessControl you have available the followings options:

  • :rate, :comment, :commentVote, :videoRespond, :list, :embed, :syndicate

    with just two values:

  • allowed or denied

Example

client = YouTubeIt::Client.new(:username => "youtube_username", :password => "youtube_passwd", :dev_key => "developer_key")

  • upload video with denied comments

    client.video_upload(File.open("test.mov"), :title => "test",:description => 'some description', :category => 'People',:keywords => %w[cool blah test], :comment => "denied")

== Partial Updates You can send a single PATCH request to add, replace and/or delete specific fields for a particular resource.

client.video_partial_update(video.unique_id, :list => 'denied', :embed => 'allowed')

== User Activity You can get user activity with the followings params:

$ client.activity(user) #default current user

== Video Upload From Browser:

When uploading a video from your browser you need make a form upload with the followings params: $ upload_token(params, nexturl) params => params like :title => "title", :description => "description", :category => "People", :keywords => ["test"] nexturl => redirect to this url after upload

Controller def upload @upload_info = YouTubeIt::Client.new.upload_token(params, videos_url) end

View (upload.html.erb) true do %>

== WIDESCREEN VIDEOS

If the videos has support for widescreen: $ video.embed_html_with_width(1280)

Note: you can specify width or just use the default of 1280.

== USING HTML5

Now you can embed videos without use flash using html5, usefull for mobiles that not support flash but has html5 browser

You can specify these options $ video.embed_html5({:class => 'video-player'

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言