Skip to content

Commit

Permalink
Don't fail on add_video if the video is forbidden
Browse files Browse the repository at this point in the history
An example is https://www.youtube.com/watch?v=kDCpdKeTe5g

"This video is no longer available because the YouTube account associated with this video has been terminated."
  • Loading branch information
claudiob committed May 15, 2014
1 parent 7ca526e commit e7f7fde
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion HISTORY.md
Expand Up @@ -6,7 +6,7 @@ v0.4 - 2014/05/09
* Supports also ActiveSupport 3 and Ruby 1.9.3 (not just AS4 + Ruby 2)
* Fix parsing annotation and timestamps longer than 1 hour
* Fix delegating tags from resources to snippets
* Two options to add videos to a playlist: fail or not if a video is missing
* Two options to add videos to a playlist: fail or not if a video is missing or its account terminated
* Allow to configure Yt credentials through environment variables

v0.3.0 - 2014/04/16
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -302,7 +302,7 @@ To install on your system, run

To use inside a bundled Ruby project, add this line to the Gemfile:

gem 'yt', '~> 0.4.8'
gem 'yt', '~> 0.4.9'

Since the gem follows [Semantic Versioning](http://semver.org),
indicating the full version in your Gemfile (~> *major*.*minor*.*patch*)
Expand Down
2 changes: 1 addition & 1 deletion lib/yt/associations/playlist_items.rb
Expand Up @@ -11,7 +11,7 @@ def playlist_items
end

def add_video(video_id)
playlist_items.insert({id: video_id, kind: :video}, ignore_not_found: true)
playlist_items.insert({id: video_id, kind: :video}, ignore_errors: true)
end

def add_video!(video_id)
Expand Down
2 changes: 1 addition & 1 deletion lib/yt/collections/playlist_items.rb
Expand Up @@ -12,7 +12,7 @@ def insert(attrs = {}, options = {}) #
snippet = {playlistId: @parent.id, resourceId: resource}
do_insert body: {snippet: snippet}, params: {part: 'snippet,status'}
rescue Yt::RequestError => error
raise error unless options[:ignore_not_found] && error.reasons.include?('videoNotFound')
raise error unless options[:ignore_errors] && (error.reasons.include?('videoNotFound') || error.reasons.include?('forbidden'))
end

def delete_all(params = {})
Expand Down
11 changes: 11 additions & 0 deletions spec/associations/device_auth/playlist_items_spec.rb
Expand Up @@ -30,6 +30,12 @@
it { expect(@playlist.add_video video_id).to be_nil }
it { expect{@playlist.add_video video_id}.not_to change{@playlist.playlist_items.count} }
end

context 'given a video of a terminated account' do
let(:video_id) { 'kDCpdKeTe5g' }
it { expect(@playlist.add_video video_id).to be_nil }
it { expect{@playlist.add_video video_id}.not_to change{@playlist.playlist_items.count} }
end
end

describe '#add_video!' do
Expand All @@ -42,6 +48,11 @@
let(:video_id) { 'not-a-video' }
it { expect{@playlist.add_video! video_id}.to raise_error Yt::RequestError }
end

context 'given a video of a terminated account' do
let(:video_id) { 'kDCpdKeTe5g' }
it { expect{@playlist.add_video! video_id}.to raise_error Yt::RequestError }
end
end

describe '#add_videos' do
Expand Down

0 comments on commit e7f7fde

Please sign in to comment.