yt-andrewroth 0.25.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (191) hide show
  1. data/.gitignore +27 -0
  2. data/.rspec +3 -0
  3. data/.travis.yml +9 -0
  4. data/.yardopts +5 -0
  5. data/CHANGELOG.md +732 -0
  6. data/Gemfile +4 -0
  7. data/MIT-LICENSE +20 -0
  8. data/README.md +489 -0
  9. data/Rakefile +11 -0
  10. data/YOUTUBE_IT.md +835 -0
  11. data/bin/yt +30 -0
  12. data/gemfiles/Gemfile.activesupport-3.x +4 -0
  13. data/gemfiles/Gemfile.activesupport-4.x +4 -0
  14. data/lib/yt.rb +21 -0
  15. data/lib/yt/actions/base.rb +32 -0
  16. data/lib/yt/actions/delete.rb +19 -0
  17. data/lib/yt/actions/delete_all.rb +32 -0
  18. data/lib/yt/actions/insert.rb +42 -0
  19. data/lib/yt/actions/list.rb +139 -0
  20. data/lib/yt/actions/modify.rb +37 -0
  21. data/lib/yt/actions/patch.rb +19 -0
  22. data/lib/yt/actions/update.rb +19 -0
  23. data/lib/yt/associations/has_attribute.rb +55 -0
  24. data/lib/yt/associations/has_authentication.rb +214 -0
  25. data/lib/yt/associations/has_many.rb +22 -0
  26. data/lib/yt/associations/has_one.rb +22 -0
  27. data/lib/yt/associations/has_reports.rb +320 -0
  28. data/lib/yt/collections/advertising_options_sets.rb +34 -0
  29. data/lib/yt/collections/annotations.rb +62 -0
  30. data/lib/yt/collections/assets.rb +58 -0
  31. data/lib/yt/collections/authentications.rb +47 -0
  32. data/lib/yt/collections/base.rb +62 -0
  33. data/lib/yt/collections/channels.rb +31 -0
  34. data/lib/yt/collections/claim_histories.rb +34 -0
  35. data/lib/yt/collections/claims.rb +56 -0
  36. data/lib/yt/collections/content_details.rb +30 -0
  37. data/lib/yt/collections/content_owner_details.rb +34 -0
  38. data/lib/yt/collections/content_owners.rb +32 -0
  39. data/lib/yt/collections/device_flows.rb +23 -0
  40. data/lib/yt/collections/file_details.rb +30 -0
  41. data/lib/yt/collections/ids.rb +27 -0
  42. data/lib/yt/collections/live_streaming_details.rb +30 -0
  43. data/lib/yt/collections/ownerships.rb +34 -0
  44. data/lib/yt/collections/partnered_channels.rb +28 -0
  45. data/lib/yt/collections/players.rb +30 -0
  46. data/lib/yt/collections/playlist_items.rb +53 -0
  47. data/lib/yt/collections/playlists.rb +28 -0
  48. data/lib/yt/collections/policies.rb +28 -0
  49. data/lib/yt/collections/ratings.rb +23 -0
  50. data/lib/yt/collections/references.rb +46 -0
  51. data/lib/yt/collections/related_playlists.rb +43 -0
  52. data/lib/yt/collections/reports.rb +161 -0
  53. data/lib/yt/collections/resources.rb +57 -0
  54. data/lib/yt/collections/resumable_sessions.rb +51 -0
  55. data/lib/yt/collections/snippets.rb +27 -0
  56. data/lib/yt/collections/statistics_sets.rb +30 -0
  57. data/lib/yt/collections/statuses.rb +27 -0
  58. data/lib/yt/collections/subscribed_channels.rb +46 -0
  59. data/lib/yt/collections/subscribers.rb +33 -0
  60. data/lib/yt/collections/subscriptions.rb +50 -0
  61. data/lib/yt/collections/user_infos.rb +36 -0
  62. data/lib/yt/collections/video_categories.rb +35 -0
  63. data/lib/yt/collections/videos.rb +137 -0
  64. data/lib/yt/config.rb +54 -0
  65. data/lib/yt/errors/forbidden.rb +13 -0
  66. data/lib/yt/errors/missing_auth.rb +81 -0
  67. data/lib/yt/errors/no_items.rb +13 -0
  68. data/lib/yt/errors/request_error.rb +74 -0
  69. data/lib/yt/errors/server_error.rb +13 -0
  70. data/lib/yt/errors/unauthorized.rb +50 -0
  71. data/lib/yt/models/account.rb +216 -0
  72. data/lib/yt/models/advertising_options_set.rb +38 -0
  73. data/lib/yt/models/annotation.rb +132 -0
  74. data/lib/yt/models/asset.rb +111 -0
  75. data/lib/yt/models/asset_metadata.rb +38 -0
  76. data/lib/yt/models/asset_snippet.rb +46 -0
  77. data/lib/yt/models/authentication.rb +83 -0
  78. data/lib/yt/models/base.rb +32 -0
  79. data/lib/yt/models/channel.rb +302 -0
  80. data/lib/yt/models/claim.rb +156 -0
  81. data/lib/yt/models/claim_event.rb +67 -0
  82. data/lib/yt/models/claim_history.rb +29 -0
  83. data/lib/yt/models/configuration.rb +70 -0
  84. data/lib/yt/models/content_detail.rb +65 -0
  85. data/lib/yt/models/content_owner.rb +48 -0
  86. data/lib/yt/models/content_owner_detail.rb +18 -0
  87. data/lib/yt/models/description.rb +58 -0
  88. data/lib/yt/models/device_flow.rb +16 -0
  89. data/lib/yt/models/file_detail.rb +21 -0
  90. data/lib/yt/models/id.rb +9 -0
  91. data/lib/yt/models/iterator.rb +16 -0
  92. data/lib/yt/models/live_streaming_detail.rb +23 -0
  93. data/lib/yt/models/match_policy.rb +34 -0
  94. data/lib/yt/models/ownership.rb +75 -0
  95. data/lib/yt/models/player.rb +18 -0
  96. data/lib/yt/models/playlist.rb +218 -0
  97. data/lib/yt/models/playlist_item.rb +112 -0
  98. data/lib/yt/models/policy.rb +36 -0
  99. data/lib/yt/models/policy_rule.rb +124 -0
  100. data/lib/yt/models/rating.rb +37 -0
  101. data/lib/yt/models/reference.rb +172 -0
  102. data/lib/yt/models/resource.rb +136 -0
  103. data/lib/yt/models/resumable_session.rb +52 -0
  104. data/lib/yt/models/right_owner.rb +58 -0
  105. data/lib/yt/models/snippet.rb +50 -0
  106. data/lib/yt/models/statistics_set.rb +26 -0
  107. data/lib/yt/models/status.rb +32 -0
  108. data/lib/yt/models/subscription.rb +38 -0
  109. data/lib/yt/models/timestamp.rb +13 -0
  110. data/lib/yt/models/url.rb +90 -0
  111. data/lib/yt/models/user_info.rb +26 -0
  112. data/lib/yt/models/video.rb +630 -0
  113. data/lib/yt/models/video_category.rb +12 -0
  114. data/lib/yt/request.rb +278 -0
  115. data/lib/yt/version.rb +3 -0
  116. data/spec/collections/claims_spec.rb +30 -0
  117. data/spec/collections/playlist_items_spec.rb +44 -0
  118. data/spec/collections/playlists_spec.rb +27 -0
  119. data/spec/collections/policies_spec.rb +30 -0
  120. data/spec/collections/references_spec.rb +30 -0
  121. data/spec/collections/reports_spec.rb +30 -0
  122. data/spec/collections/subscriptions_spec.rb +25 -0
  123. data/spec/collections/videos_spec.rb +43 -0
  124. data/spec/errors/forbidden_spec.rb +10 -0
  125. data/spec/errors/missing_auth_spec.rb +24 -0
  126. data/spec/errors/no_items_spec.rb +10 -0
  127. data/spec/errors/request_error_spec.rb +44 -0
  128. data/spec/errors/server_error_spec.rb +10 -0
  129. data/spec/errors/unauthorized_spec.rb +10 -0
  130. data/spec/models/account_spec.rb +138 -0
  131. data/spec/models/annotation_spec.rb +180 -0
  132. data/spec/models/asset_spec.rb +20 -0
  133. data/spec/models/channel_spec.rb +127 -0
  134. data/spec/models/claim_event_spec.rb +62 -0
  135. data/spec/models/claim_history_spec.rb +27 -0
  136. data/spec/models/claim_spec.rb +211 -0
  137. data/spec/models/configuration_spec.rb +44 -0
  138. data/spec/models/content_detail_spec.rb +45 -0
  139. data/spec/models/content_owner_detail_spec.rb +6 -0
  140. data/spec/models/description_spec.rb +94 -0
  141. data/spec/models/file_detail_spec.rb +13 -0
  142. data/spec/models/live_streaming_detail_spec.rb +6 -0
  143. data/spec/models/ownership_spec.rb +59 -0
  144. data/spec/models/player_spec.rb +13 -0
  145. data/spec/models/playlist_item_spec.rb +120 -0
  146. data/spec/models/playlist_spec.rb +138 -0
  147. data/spec/models/policy_rule_spec.rb +63 -0
  148. data/spec/models/policy_spec.rb +41 -0
  149. data/spec/models/rating_spec.rb +12 -0
  150. data/spec/models/reference_spec.rb +249 -0
  151. data/spec/models/request_spec.rb +163 -0
  152. data/spec/models/resource_spec.rb +57 -0
  153. data/spec/models/right_owner_spec.rb +71 -0
  154. data/spec/models/snippet_spec.rb +13 -0
  155. data/spec/models/statistics_set_spec.rb +13 -0
  156. data/spec/models/status_spec.rb +13 -0
  157. data/spec/models/subscription_spec.rb +30 -0
  158. data/spec/models/url_spec.rb +78 -0
  159. data/spec/models/video_category_spec.rb +21 -0
  160. data/spec/models/video_spec.rb +669 -0
  161. data/spec/requests/as_account/account_spec.rb +125 -0
  162. data/spec/requests/as_account/authentications_spec.rb +139 -0
  163. data/spec/requests/as_account/channel_spec.rb +259 -0
  164. data/spec/requests/as_account/channels_spec.rb +18 -0
  165. data/spec/requests/as_account/playlist_item_spec.rb +56 -0
  166. data/spec/requests/as_account/playlist_spec.rb +244 -0
  167. data/spec/requests/as_account/resource_spec.rb +18 -0
  168. data/spec/requests/as_account/thumbnail.jpg +0 -0
  169. data/spec/requests/as_account/video.mp4 +0 -0
  170. data/spec/requests/as_account/video_spec.rb +408 -0
  171. data/spec/requests/as_content_owner/account_spec.rb +25 -0
  172. data/spec/requests/as_content_owner/advertising_options_set_spec.rb +15 -0
  173. data/spec/requests/as_content_owner/asset_spec.rb +20 -0
  174. data/spec/requests/as_content_owner/channel_spec.rb +1934 -0
  175. data/spec/requests/as_content_owner/claim_history_spec.rb +20 -0
  176. data/spec/requests/as_content_owner/content_owner_spec.rb +241 -0
  177. data/spec/requests/as_content_owner/match_policy_spec.rb +17 -0
  178. data/spec/requests/as_content_owner/ownership_spec.rb +25 -0
  179. data/spec/requests/as_content_owner/playlist_spec.rb +782 -0
  180. data/spec/requests/as_content_owner/video_spec.rb +1239 -0
  181. data/spec/requests/as_server_app/channel_spec.rb +74 -0
  182. data/spec/requests/as_server_app/playlist_item_spec.rb +30 -0
  183. data/spec/requests/as_server_app/playlist_spec.rb +53 -0
  184. data/spec/requests/as_server_app/video_spec.rb +58 -0
  185. data/spec/requests/as_server_app/videos_spec.rb +40 -0
  186. data/spec/requests/unauthenticated/video_spec.rb +22 -0
  187. data/spec/spec_helper.rb +20 -0
  188. data/spec/support/fail_matcher.rb +15 -0
  189. data/spec/support/global_hooks.rb +48 -0
  190. data/yt.gemspec +32 -0
  191. metadata +416 -0
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler"
2
+ Bundler.setup
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ require "rspec/core/rake_task"
6
+ require "rspec/core/version"
7
+
8
+ desc "Run all examples"
9
+ RSpec::Core::RakeTask.new :spec
10
+
11
+ task default: [:spec]
data/YOUTUBE_IT.md ADDED
@@ -0,0 +1,835 @@
1
+ How to migrate from youtube_it
2
+ ==============================
3
+
4
+ If you are used to access the YouTube API with [youtube_it](https://github.com/kylejginavan/youtube_it),
5
+ this guide will help you translate your code to use Yt instead.
6
+
7
+ This guide follows [youtube_it README.rdoc](https://github.com/kylejginavan/youtube_it/blob/f61ed0b00905e048dcbed12457d02f52ddbae45d/README.rdoc)
8
+ listing the original `youtube_it` commands and their equivalent `Yt` versions.
9
+
10
+ Establishing a client
11
+ ---------------------
12
+
13
+ While `youtube_it` supports authentication with developer key, AuthSub and
14
+ OAuth, `Yt` only supports OAuth 2.0, because this is the only process that has
15
+ not been deprecated by YouTube Data API V3.
16
+
17
+ Another difference is that `youtube_it` authentication methods are invoked on
18
+ a generic `Client` class, while with `Yt` you can specify whether you want to
19
+ authenticate as a YouTube `Account` or as a `ContentOwner`.
20
+ Content owners are special [CMS accounts](https://cms.youtube.com) that can
21
+ manage multiple YouTube accounts at once.
22
+
23
+ Creating a client:
24
+
25
+ ```ruby
26
+ # with youtube_it
27
+ client = YouTubeIt::Client.new
28
+ # with yt
29
+ account = Yt::Account.new # or Yt::ContentOwner.new
30
+ ```
31
+
32
+ Client with developer key:
33
+
34
+ ```ruby
35
+ # with youtube_it
36
+ client = YouTubeIt::Client.new(:dev_key => "developer_key")
37
+ # with yt: not supported (must use OAuth 2.0)
38
+ ```
39
+
40
+ Client with youtube account and developer key:
41
+
42
+ ```ruby
43
+ # with youtube_it
44
+ client = YouTubeIt::Client.new(:username => "youtube_username", :password => "youtube_passwd", :dev_key => "developer_key")
45
+ # with yt: not supported (must use OAuth 2.0)
46
+ ```
47
+
48
+ Client with AuthSub:
49
+
50
+ ```ruby
51
+ # with youtube_it
52
+ client = YouTubeIt::AuthSubClient.new(:token => "token" , :dev_key => "developer_key")
53
+ # with yt: not supported (must use OAuth 2.0)
54
+ ```
55
+
56
+ Client with OAuth:
57
+
58
+ ```ruby
59
+ # with youtube_it
60
+ client = YouTubeIt::OAuthClient.new("consumer_key", "consumer_secret", "youtube_username", "developer_key")
61
+ client.authorize_from_access("access_token", "access_secret")
62
+ # with yt: not supported (must use OAuth 2.0)
63
+ ```
64
+
65
+ Client with OAuth2:
66
+
67
+ ```ruby
68
+ # with youtube_it
69
+ 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")
70
+ client.refresh_access_token!
71
+ # with yt
72
+ Yt.configure do |config|
73
+ config.client_id = 'client_id'
74
+ config.client_secret = 'client_secret'
75
+ end
76
+ account = Yt::Account.new access_token: 'access_token', refresh_token: 'refresh_token'
77
+ ```
78
+
79
+ Profiles
80
+ --------
81
+
82
+ With `youtube_it`, you can use multiple profiles in the same account:
83
+
84
+ ```ruby
85
+ profiles = client.profiles(['username1','username2'])
86
+ profiles['username1'].username, "username1"
87
+ ```
88
+
89
+ With `yt`, you can access all the channels managed by the same YouTube account:
90
+
91
+ ```ruby
92
+ first_channel = Yt::Channel.new id: 'UCx12345', auth: account
93
+ second_channel = Yt::Channel.new id: 'UCy45678', auth: account
94
+ first_channel.title
95
+ ```
96
+
97
+ Video queries
98
+ -------------
99
+
100
+ List videos by keyword:
101
+
102
+ ```ruby
103
+ # with youtube_it
104
+ client = YouTubeIt::Client.new
105
+ client.videos_by(:query => "penguin")
106
+ # with yt
107
+ videos = Yt::Collections::Videos.new
108
+ videos.where(q: 'penguin')
109
+ ```
110
+
111
+ List videos by page:
112
+
113
+ ```ruby
114
+ # with youtube_it
115
+ client = YouTubeIt::Client.new
116
+ client.videos_by(:query => "penguin", :page => 2, :per_page => 15)
117
+ # with yt: pagination is automatically supported by collection, which iterates
118
+ # though all the pages, not just the first one
119
+ videos = Yt::Collections::Videos.new
120
+ videos.where(q: 'penguin')
121
+ ```
122
+
123
+ List videos by region:
124
+
125
+ ```ruby
126
+ # with youtube_it
127
+ client = YouTubeIt::Client.new
128
+ client.videos_by(:query => "penguin", :restriction => "DE")
129
+ # with yt
130
+ # Note that some users report that regionCode does not work in YouTube API V3
131
+ # See https://code.google.com/p/gdata-issues/issues/detail?id=4110
132
+ videos = Yt::Collections::Videos.new
133
+ videos.where(q: 'penguin', region_code: 'DE')
134
+ ```
135
+
136
+ List videos by author:
137
+
138
+ ```ruby
139
+ # with youtube_it
140
+ client = YouTubeIt::Client.new
141
+ client.videos_by(:query => "penguin", :author => "liz")
142
+ # with yt: the 'author' filter was removed from YouTube API V3, so the
143
+ # request must be done using the channel of the requested author
144
+ channel = Yt::Channel.new url: 'youtube.com/liz'
145
+ channel.videos.where(q: 'penguin')
146
+ ```
147
+
148
+ List videos by categories:
149
+
150
+ ```ruby
151
+ # with youtube_it
152
+ client = YouTubeIt::Client.new
153
+ client.videos_by(:categories => [:news, :sports])
154
+ # with yt: the 'categories' filter was removed from YouTube API V3, so the
155
+ # request must be done using one category_id at the time
156
+ videos = Yt::Collections::Videos.new
157
+ videos.where(video_category_id: 25) #=> News
158
+ videos.where(video_category_id: 17) #=> Sports
159
+ ```
160
+
161
+ List videos by tags:
162
+
163
+ ```ruby
164
+ # with youtube_it
165
+ client = YouTubeIt::Client.new
166
+ client.videos_by(:tags => ['tiger', 'leopard'])
167
+ client.videos_by(:categories => [:news, :sports], :tags => ['soccer', 'football'])
168
+ # with yt: not supported (was removed from YouTube API V3)
169
+ ```
170
+
171
+ List videos by user:
172
+
173
+ ```ruby
174
+ # with youtube_it
175
+ client = YouTubeIt::Client.new
176
+ client.videos_by(:user => 'liz')
177
+ # with yt: the 'author' filter was removed from YouTube API V3, so the
178
+ # request must be done using the channel of the requested author
179
+ channel = Yt::Channel.new url: 'youtube.com/liz'
180
+ channel.videos.where(q: 'penguin')
181
+ ```
182
+
183
+ List videos favorited by user:
184
+
185
+ ```ruby
186
+ # with youtube_it
187
+ client = YouTubeIt::Client.new
188
+ client.videos_by(:favorites, :user => 'liz')
189
+ # with yt: note that only *old* channels have a "Favorites" playlist, since
190
+ # "Favorites" has been deprecated by YouTube in favor of "Liked Videos".
191
+ channel = Yt::Channel.new url: 'youtube.com/liz'
192
+ channel.related_playlists.find{|p| p.title == 'Favorites'}
193
+ ```
194
+
195
+
196
+ Retrieve video by ID:
197
+
198
+ ```ruby
199
+ # with youtube_it
200
+ client = YouTubeIt::Client.new
201
+ client.video_by("FQK1URcxmb4")
202
+ # with yt
203
+ Yt::Video.new id: 'FQK1URcxmb4'
204
+ ```
205
+
206
+ Retrieve video by URL:
207
+
208
+ ```ruby
209
+ # with youtube_it
210
+ client = YouTubeIt::Client.new
211
+ client.video_by("https://www.youtube.com/watch?v=QsbmrCtiEUU")
212
+ # with yt
213
+ Yt::Video.new url: 'https://www.youtube.com/watch?v=QsbmrCtiEUU'
214
+ ```
215
+
216
+ Retrieve video of a user by ID:
217
+
218
+ ```ruby
219
+ # with youtube_it
220
+ client = YouTubeIt::Client.new
221
+ client.video_by_user("chebyte","FQK1URcxmb4")
222
+ # with yt
223
+ Yt::Video.new id: 'FQK1URcxmb4'
224
+ ```
225
+
226
+ List most viewed videos:
227
+
228
+ ```ruby
229
+ # with youtube_it
230
+ client = YouTubeIt::Client.new
231
+ client.videos_by(:most_viewed)
232
+ # with yt
233
+ videos = Yt::Collections::Videos.new
234
+ videos.where(order: 'viewCount')
235
+ ```
236
+
237
+ List most linked videos:
238
+
239
+ ```ruby
240
+ # with youtube_it
241
+ client = YouTubeIt::Client.new
242
+ client.videos_by(:most_linked, :page => 3)
243
+ # with yt: not supported (was removed from YouTube API V3)
244
+ ```
245
+
246
+ List most popular video:
247
+
248
+ ```ruby
249
+ # with youtube_it
250
+ client = YouTubeIt::Client.new
251
+ client.videos_by(:top_rated, :time => :today).first
252
+ # with yt
253
+ videos = Yt::Collections::Videos.new
254
+ videos.where(chart: 'mostPopular').first
255
+ ```
256
+
257
+ List *all* most popular videos:
258
+
259
+ ```ruby
260
+ # with youtube_it
261
+ client = YouTubeIt::Client.new
262
+ client.videos_by(:top_rated, :time => :today)
263
+ # with yt: YouTube API V3 only returns the top 50
264
+ videos = Yt::Collections::Videos.new
265
+ videos.where(chart: 'mostPopular')
266
+ ```
267
+
268
+ List most popular video by region and category:
269
+
270
+ ```ruby
271
+ # with youtube_it
272
+ client = YouTubeIt::Client.new
273
+ client.videos_by(:top_rated, :region => "RU", :category => "News").first
274
+ # with yt
275
+ videos = Yt::Collections::Videos.new
276
+ videos.where(chart: 'mostPopular', region_code: 'RU', video_category_id: 25).first
277
+ ```
278
+
279
+ Advanced Queries (with boolean operators OR (either), AND (include), NOT (exclude)):
280
+
281
+ ```ruby
282
+ # with youtube_it
283
+ client = YouTubeIt::Client.new
284
+ client.videos_by(:categories => { :either => [:news, :sports], :exclude => [:comedy] }, :tags => { :include => ['football'], :exclude => ['soccer'] })
285
+ # with yt: not supported (was removed from YouTube API V3)
286
+ ```
287
+
288
+ Custom Query Params:
289
+
290
+ ```ruby
291
+ # with youtube_it
292
+ client = YouTubeIt::Client.new
293
+ client.videos_by(:query => "penguin", :safe_search => "strict")
294
+ client.videos_by(:query => "penguin", :duration => "long")
295
+ client.videos_by(:query => "penguin", :hd => "true")
296
+ client.videos_by(:query => "penguin", :region => "AR")
297
+ # with yt
298
+ videos = Yt::Collections::Videos.new
299
+ videos.where(q: 'penguin', safe_search: 'strict')
300
+ videos.where(q: 'penguin', duration: 'long')
301
+ videos.where(q: 'penguin', video_definition: 'high')
302
+ videos.where(q: 'penguin', region_code: 'AR')
303
+ ```
304
+
305
+ Return videos with more than 1,000 views:
306
+
307
+ ```ruby
308
+ # with youtube_it
309
+ client = YouTubeIt::Client.new
310
+ client.videos_by(:fields => {:view_count => "1000"})
311
+ # with yt: the most similar method in YouTube API V3 is to return the results by view count
312
+ videos = Yt::Collections::Videos.new
313
+ videos.where(order: 'viewCount')
314
+ ```
315
+
316
+ Filter by date (also with range):
317
+
318
+ ```ruby
319
+ # with youtube_it
320
+ client = YouTubeIt::Client.new
321
+ client.videos_by(:fields => {:published => (Date.today)})
322
+ client.videos_by(:fields => {:recorded => (Date.today)})
323
+ client.videos_by(:fields => {:published => ((Date.today - 30)..(Date.today))})
324
+ client.videos_by(:fields => {:recorded => ((Date.today - 30)..(Date.today))})
325
+ # with yt (only published is available in YouTube API V3, not recorded date)
326
+ videos = Yt::Collections::Videos.new
327
+ videos.where(published_before: 0.days.ago.utc.iso8601(0), published_after: 30.day.ago.utc.iso8601(0))
328
+ ```
329
+
330
+ Filter including private videos:
331
+
332
+ ```ruby
333
+ # with youtube_it
334
+ client = # new client initialized with either OAuth or AuthSub
335
+ client.my_video("FQK1URcxmb4")
336
+ client.my_videos(:query => "penguin")
337
+ # with yt
338
+ account = Yt::Account.new access_token: 'access_token'
339
+ video = Yt::Video.new id: 'FQK1URcxmb4', auth: account
340
+ account.videos.where(q: 'penguin')
341
+ ```
342
+
343
+ Video management
344
+ ----------------
345
+
346
+ Upload video:
347
+
348
+ ```ruby
349
+ # with youtube_it
350
+ client = # new client initialized with either OAuth or AuthSub
351
+ client.video_upload(File.open("test.mov"), :title => "test",:description => 'some description', :category => 'People',:keywords => %w[cool blah test])
352
+ # with yt
353
+ account = Yt::Account.new access_token: 'access_token'
354
+ account.upload_video 'test.mov', title: 'test', description: 'some description', category_id: '22', tags: %w(cool blah test)
355
+ ```
356
+
357
+ Upload remote video:
358
+
359
+ ```ruby
360
+ # with youtube_it
361
+ client = # new client initialized with either OAuth or AuthSub
362
+ client.video_upload("http://url/myvideo.mp4", :title => "test",:description => 'some description', :category => 'People',:keywords => %w[cool blah test])
363
+ # with yt
364
+ account = Yt::Account.new access_token: 'access_token'
365
+ account.upload_video 'http://url/myvideo.mp4', title: 'test', description: 'some description', category_id: '22', tags: %w(cool blah test)
366
+ ```
367
+
368
+ Upload video with a developer tag:
369
+
370
+ ```ruby
371
+ # with youtube_it
372
+ client = # new client initialized with either OAuth or AuthSub
373
+ client.video_upload(File.open("test.mov"), :title => "test",:description => 'some description', :category => 'People',:keywords => %w[cool blah test], :dev_tag => 'tagdev')
374
+ # with yt: not supported (was removed from YouTube API V3)
375
+ ```
376
+
377
+ Upload video from URL:
378
+
379
+ ```ruby
380
+ # with youtube_it
381
+ client = # new client initialized with either OAuth or AuthSub
382
+ 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])
383
+ # with yt
384
+ account = Yt::Account.new access_token: 'access_token'
385
+ account.upload_video 'http://media.railscasts.com/assets/episodes/videos/412-fast-rails-commands.mp4', title: 'test', description: 'some description', category_id: '22', tags: %w(cool blah test)
386
+ ```
387
+
388
+ Upload private video:
389
+
390
+ ```ruby
391
+ # with youtube_it
392
+ client = # new client initialized with either OAuth or AuthSub
393
+ client.video_upload(File.open("test.mov"), :title => "test",:description => 'some description', :category => 'People',:keywords => %w[cool blah test], :private => true)
394
+ # with yt
395
+ account = Yt::Account.new access_token: 'access_token'
396
+ account.upload_video 'test.mov', privacy_status: :private, title: 'test', description: 'some description', category_id: '22', tags: %w(cool blah test)
397
+ ```
398
+
399
+ Update video:
400
+
401
+ ```ruby
402
+ # with youtube_it
403
+ client = # new client initialized with either OAuth or AuthSub
404
+ client.video_update("FQK1URcxmb4", :title => "new test",:description => 'new description', :category => 'People',:keywords => %w[cool blah test])
405
+ # with yt: only provides the values that need to be updated; the remaining ones
406
+ # will automatically be kept as they are
407
+ account = Yt::Account.new access_token: 'access_token'
408
+ video = Yt::Video.new id: 'FQK1URcxmb4', auth: account
409
+ video.update title: 'new test', description: 'new description'
410
+ ```
411
+
412
+ Delete video:
413
+
414
+ ```ruby
415
+ # with youtube_it
416
+ client = # new client initialized with either OAuth or AuthSub
417
+ client.video_delete("FQK1URcxmb4")
418
+ # with yt
419
+ account = Yt::Account.new access_token: 'access_token'
420
+ video = Yt::Video.new id: 'FQK1URcxmb4'
421
+ video.delete
422
+ ```
423
+
424
+ My videos:
425
+
426
+ ```ruby
427
+ # with youtube_it
428
+ client = # new client initialized with either OAuth or AuthSub
429
+ client.my_videos
430
+ # with yt
431
+ account = Yt::Account.new access_token: 'access_token'
432
+ account.videos
433
+ ```
434
+
435
+ My video:
436
+
437
+ ```ruby
438
+ # with youtube_it
439
+ client = # new client initialized with either OAuth or AuthSub
440
+ client.my_video(video_id)
441
+ # with yt
442
+ account = Yt::Account.new access_token: 'access_token'
443
+ Yt::Video.new id: video_id, auth: account
444
+ ```
445
+
446
+ Profile details:
447
+
448
+ ```ruby
449
+ # with youtube_it
450
+ client = # new client initialized with either OAuth or AuthSub
451
+ client.profile(user)
452
+ # with yt
453
+ account = Yt::Account.new access_token: 'access_token'
454
+ account.user_info
455
+ ```
456
+
457
+ List comments:
458
+
459
+ ```ruby
460
+ # with youtube_it
461
+ client = YouTubeIt::Client.new
462
+ client.comments(video_id)
463
+ # with yt: not supported (was removed from YouTube API V3)
464
+ ```
465
+
466
+ Add a comment:
467
+
468
+ ```ruby
469
+ # with youtube_it
470
+ client = # new client initialized with either OAuth or AuthSub
471
+ client.add_comment(video_id, "test comment!")
472
+ # with yt: not supported (was removed from YouTube API V3)
473
+ ```
474
+
475
+ Add a reply comment:
476
+
477
+ ```ruby
478
+ # with youtube_it
479
+ client = # new client initialized with either OAuth or AuthSub
480
+ client.add_comment(video_id, "test reply!", :reply_to => another_comment)
481
+ # with yt: not supported (was removed from YouTube API V3)
482
+ ```
483
+
484
+ Delete a comment:
485
+
486
+ ```ruby
487
+ # with youtube_it
488
+ client = # new client initialized with either OAuth or AuthSub
489
+ client.delete_comment(video_id, comment_id)
490
+ # with yt: not supported (was removed from YouTube API V3)
491
+ ```
492
+
493
+ List Favorites:
494
+
495
+ ```ruby
496
+ # with youtube_it
497
+ client = # new client initialized with either OAuth or AuthSub
498
+ client.favorites(user) # default: current user
499
+ # with yt: note that only *old* channels have a "Favorites" playlist, since
500
+ # "Favorites" has been deprecated by YouTube in favor of "Liked Videos".
501
+ account = Yt::Account.new access_token: 'access_token'
502
+ account.related_playlists.find{|p| p.title == 'Favorites'}
503
+ ```
504
+
505
+ Add Favorite:
506
+
507
+ ```ruby
508
+ # with youtube_it
509
+ client = # new client initialized with either OAuth or AuthSub
510
+ client.add_favorite(video_id)
511
+ # with yt: "like" a video to mark as favorite with YouTube API V3
512
+ account = Yt::Account.new access_token: 'access_token'
513
+ video = Yt::Video.new id: video_id, auth: account
514
+ video.like
515
+ ```
516
+
517
+ Delete Favorite:
518
+
519
+ ```ruby
520
+ # with youtube_it
521
+ client = # new client initialized with either OAuth or AuthSub
522
+ client.delete_favorite(favorite_entry_id)
523
+ # with yt: "unlike" a video to remove from favorites with YouTube API V3
524
+ account = Yt::Account.new access_token: 'access_token'
525
+ video = Yt::Video.new id: video_id, auth: account
526
+ video.unlike
527
+ ```
528
+
529
+ -->
530
+
531
+ Like a video:
532
+
533
+ ```ruby
534
+ # with youtube_it
535
+ client = # new client initialized with either OAuth or AuthSub
536
+ client.like_video(video_id)
537
+ # with yt
538
+ account = Yt::Account.new access_token: 'access_token'
539
+ video = Yt::Video.new id: video_id, auth: account
540
+ video.like
541
+ ```
542
+
543
+ Dislike a video:
544
+
545
+ ```ruby
546
+ # with youtube_it
547
+ client = # new client initialized with either OAuth or AuthSub
548
+ client.dislike_video(video_id)
549
+ # with yt
550
+ account = Yt::Account.new access_token: 'access_token'
551
+ video = Yt::Video.new id: video_id, auth: account
552
+ video.dislike
553
+ ```
554
+
555
+ List Subscriptions (channels an account is subscribed to):
556
+
557
+ ```ruby
558
+ # with youtube_it
559
+ client = # new client initialized with either OAuth or AuthSub
560
+ client.subscriptions(user) # default: current user
561
+ # with yt
562
+ account = Yt::Account.new access_token: 'access_token'
563
+ account.subscribed_channels
564
+ ```
565
+
566
+ Subscribe to a channel:
567
+
568
+ ```ruby
569
+ # with youtube_it
570
+ client = # new client initialized with either OAuth or AuthSub
571
+ client.subscribe_channel(channel_name)
572
+ # with yt
573
+ account = Yt::Account.new access_token: 'access_token'
574
+ channel = Yt::Channel.new id: channel_id, auth: account
575
+ channel.subscribe
576
+ ```
577
+
578
+ Unsubscribe from a channel:
579
+
580
+ ```ruby
581
+ # with youtube_it
582
+ client = # new client initialized with either OAuth or AuthSub
583
+ client.unsubscribe_channel(subscription_id)
584
+ # with yt
585
+ account = Yt::Account.new access_token: 'access_token'
586
+ channel = Yt::Channel.new id: channel_id, auth: account
587
+ channel.unsubscribe
588
+ ```
589
+
590
+ List New Subscription Videos:
591
+
592
+
593
+ ```ruby
594
+ # with youtube_it
595
+ client = # new client initialized with either OAuth or AuthSub
596
+ client.new_subscription_videos(user) # default: current user
597
+ # with yt: not supported (was removed from YouTube API V3)
598
+ ```
599
+
600
+ List Playlists:
601
+
602
+ ```ruby
603
+ # with youtube_it
604
+ client = # new client initialized with either OAuth or AuthSub
605
+ client.playlists(user) # default order, by position
606
+ client.playlists(user, "title") # order by title
607
+ # with yt: available without order; ordering was removed from YouTube API V3
608
+ account = Yt::Account.new access_token: 'access_token'
609
+ account.playlists
610
+ ```
611
+
612
+ Select Playlist:
613
+
614
+ ```ruby
615
+ # with youtube_it
616
+ client.playlist(playlist_id)
617
+ # with yt
618
+ Yt::Playlist.new id: playlist_id
619
+ ```
620
+
621
+ Select All Videos From A Playlist:
622
+
623
+ ```ruby
624
+ # with youtube_it
625
+ playlist = client.playlist(playlist_id)
626
+ playlist.videos
627
+ # with yt
628
+ playlist = Yt::Playlist.new id: playlist_id
629
+ playlist.playlist_items.map &:video
630
+ ```
631
+
632
+ Create Playlist:
633
+
634
+ ```ruby
635
+ # with youtube_it
636
+ client = # new client initialized with either OAuth or AuthSub
637
+ playlist = client.add_playlist(:title => "new playlist", :description => "playlist description")
638
+ # with yt
639
+ account = Yt::Account.new access_token: 'access_token'
640
+ account.create_playlist title: 'new playlist', description: 'playlist description'
641
+ ```
642
+
643
+ Delete Playlist:
644
+
645
+ ```ruby
646
+ # with youtube_it
647
+ client = # new client initialized with either OAuth or AuthSub
648
+ client.delete_playlist(playlist_id)
649
+ # with yt
650
+ account = Yt::Account.new access_token: 'access_token'
651
+ playlist = Yt::Playlist.new id: playlist_id, auth: account
652
+ playlist.delete
653
+ ```
654
+
655
+ Add Video To Playlist:
656
+
657
+ ```ruby
658
+ # with youtube_it
659
+ client = # new client initialized with either OAuth or AuthSub
660
+ client.add_video_to_playlist(playlist_id, video_id, position)
661
+ # with yt
662
+ account = Yt::Account.new access_token: 'access_token'
663
+ playlist = Yt::Playlist.new id: playlist_id, auth: account
664
+ playlist.add_video video_id, position: position
665
+ ```
666
+
667
+ Remove Video From Playlist:
668
+
669
+ ```ruby
670
+ # with youtube_it
671
+ client = # new client initialized with either OAuth or AuthSub
672
+ client.delete_video_from_playlist(playlist_id, playlist_entry_id)
673
+ # with yt
674
+ account = Yt::Account.new access_token: 'access_token'
675
+ playlist_item = Yt::PlaylistItem.new id: playlist_entry_id, auth: account
676
+ playlist_item.delete
677
+ ```
678
+
679
+ Update Position Video From Playlist:
680
+
681
+ ```ruby
682
+ # with youtube_it
683
+ client = # new client initialized with either OAuth or AuthSub
684
+ client.update_position_video_from_playlist(playlist_id, playlist_entry_id, position)
685
+ # with yt
686
+ account = Yt::Account.new access_token: 'access_token'
687
+ playlist_item = Yt::PlaylistItem.new id: playlist_entry_id, auth: account
688
+ playlist_item.update position: position
689
+ ```
690
+
691
+ Select All Videos From your Watch Later Playlist:
692
+
693
+ ```ruby
694
+ # with youtube_it
695
+ watcher_later = client.watcherlater(user) #default: current user
696
+ watcher_later.videos
697
+ # with yt
698
+ account = Yt::Account.new access_token: 'access_token'
699
+ watch_later = account.related_playlists.find{|p| p.title == 'Watch Later'}
700
+ watch_later.playlist_items.map{|item| item.video}
701
+ ```
702
+
703
+ Add Video To Watcher Later Playlist:
704
+
705
+ ```ruby
706
+ # with youtube_it
707
+ client.add_video_to_watchlater(video_id)
708
+ # with yt
709
+ account = Yt::Account.new access_token: 'access_token'
710
+ watch_later = account.related_playlists.find{|p| p.title == 'Watch Later'}
711
+ watch_later.add_video video_id
712
+ ```
713
+
714
+ Remove Video From Watch Later Playlist:
715
+
716
+ ```ruby
717
+ # with youtube_it
718
+ client.delete_video_from_watchlater(watchlater_entry_id)
719
+ # with yt
720
+ account = Yt::Account.new access_token: 'access_token'
721
+ watch_later = account.related_playlists.find{|p| p.title == 'Watch Later'}
722
+ watch_later.delete_playlist_items video_id: video_id
723
+ ```
724
+
725
+ <!-- TODO: Add using https://developers.google.com/youtube/v3/docs/search/list#relatedToVideoId
726
+
727
+ List Related Videos:
728
+
729
+ ```ruby
730
+ # with youtube_it
731
+ client = # new client initialized with either OAuth or AuthSub
732
+ video = client.video_by("https://www.youtube.com/watch?v=QsbmrCtiEUU&feature=player_embedded")
733
+ video.related.videos
734
+ # with yt:
735
+ ```
736
+
737
+ -->
738
+
739
+ Add Response Video:
740
+
741
+ ```ruby
742
+ # with youtube_it
743
+ client = # new client initialized with either OAuth or AuthSub
744
+ video.add_response(original_video_id, response_video_id)
745
+ # with yt: not supported (was removed from YouTube API V3)
746
+ ```
747
+
748
+ Delete Response Video:
749
+
750
+ ```ruby
751
+ # with youtube_it
752
+ client = # new client initialized with either OAuth or AuthSub
753
+ video.delete_response(original_video_id, response_video_id)
754
+ # with yt: not supported (was removed from YouTube API V3)
755
+ ```
756
+
757
+ List Response Videos:
758
+
759
+ ```ruby
760
+ # with youtube_it
761
+ client = # new client initialized with either OAuth or AuthSub
762
+ video = client.video_by("https://www.youtube.com/watch?v=QsbmrCtiEUU&feature=player_embedded")
763
+ video.responses.videos
764
+ # with yt: not supported (was removed from YouTube API V3)
765
+ ```
766
+
767
+ Batch videos (list multiple videos):
768
+
769
+ ```ruby
770
+ # with youtube_it
771
+ client = # new client initialized with either OAuth or AuthSub
772
+ client.videos(['video_id_1', 'video_id_2',...])
773
+ # with yt
774
+ Yt::Collections::Videos.new.where(id: 'video_id_1,video_id_2')
775
+ ```
776
+
777
+ Access control list
778
+ -------------------
779
+
780
+ While `youtube_it` allows users to give and revoke permissions to rate, comment,
781
+ respond, list, embed and syndicate uploaded videos, `Yt` does not.
782
+
783
+ The reason is that most of these permissions have been deprecated in YouTube
784
+ Data API V3. The only parameter that can still be passed when updating a
785
+ video is 'embeddable'; however many users have reported that updating this
786
+ setting through the API simply does not work.
787
+ See https://code.google.com/p/gdata-issues/issues/detail?id=4861
788
+
789
+ Block users from commenting on a video:
790
+
791
+ ```ruby
792
+ # with youtube_it
793
+ client = YouTubeIt::Client.new(:username => "youtube_username", :password => "youtube_passwd", :dev_key => "developer_key")
794
+ client.video_upload(File.open("test.mov"), :title => "test",:description => 'some description', :category => 'People',:keywords => %w[cool blah test], :comment => "denied")
795
+ # with yt: not supported (was removed from YouTube API V3; only the embeddable setting can be specified)
796
+ ```
797
+
798
+ Block users from embedding a video:
799
+
800
+ ```ruby
801
+ # with youtube_it
802
+ client = YouTubeIt::Client.new(:username => "youtube_username", :password => "youtube_passwd", :dev_key => "developer_key")
803
+ client.video_upload(File.open("test.mov"), :title => "test",:description => 'some description', :category => 'People',:keywords => %w[cool blah test], :embed => "denied")
804
+ # with yt: not supported (it is documented in YouTube API V3 but looks like it is not working)
805
+ ```
806
+
807
+ Partial updates
808
+ ---------------
809
+
810
+ While `youtube_it` uses a separate method to specify that an UPDATE request
811
+ should not modify any field that has not been explicitly specified, `Yt`
812
+ applies this behavior by default
813
+
814
+ Change the title of a video, but not its privacy status or its description:
815
+
816
+ ```ruby
817
+ # with youtube_it
818
+ client = # new client initialized with either OAuth or AuthSub
819
+ client.video_partial_update(video_id, :title => 'new title')
820
+ # with yt
821
+ account = Yt::Account.new access_token: 'access_token'
822
+ video = Yt::Video.new id: video_id, auth: account
823
+ video.update title: 'new title'
824
+ ```
825
+
826
+ <!--
827
+
828
+ TODO
829
+
830
+ == User Activity
831
+ You can get user activity with the followings params:
832
+
833
+ $ client.activity(user) #default current user
834
+
835
+ -->