I am using the youtube_it gem to retrieve a list of titles video ID's.
require 'youtube_it'
# query the video title
response = client.videos_by(:query => v, :max_results => 1)
# print out title
puts response.videos.first.title
An error occurs when it encounters a video which has been deleted.
undefined method `title' for nil:NilClass (NoMethodError)
How to handle this?
Solution
# check if the video title exists
v1 = response.videos.first
if v1.nil?
puts "*** VIDEO REMOVED ***"
else
# display video title
puts v1.title
end
Thanks.