I use this code to get info of an youtube video(youtube_it
gem)
video_info = Video.yt_session.video_by(self.source_id)
hits = video_info.view_count
if video_info.rating
self.rating = video_info.rating.average
self.likes = video_info.rating.likes.to_i
end
The problem is that sometimes, the original youtube video is deleted, like this: https://www.youtube.com/watch?v=lsZFkiimpKI
.
So video_info = Video.yt_session.video_by(self.source_id)
will reports OpenURI::HTTPError: 404
, and the code cannot continue to get info of next videos.
I want to delete this non-exist video its source is not available anymore, how can I do that? Maybe by rescue
?
I tried if Video.yt_session.video_by(self.source_id)
, but it doesn't work.