Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add region_restricted? for video #408

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ For more information about changelogs, check
[Keep a Changelog](http://keepachangelog.com) and
[Vandamme](http://tech-angels.github.io/vandamme).

## Unreleased

* [FEATURE] New Video#region_restricted? method

## 0.33.4 - 2021-01-15

* [REMOVAL] remove retry for quota errors
Expand Down
1 change: 1 addition & 0 deletions lib/yt/models/content_detail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def initialize(options = {})
has_attribute :licensed_content
has_attribute :content_rating, default: {}
has_attribute :item_count
has_attribute :region_restriction

def youtube_rating
content_rating['ytRating']
Expand Down
5 changes: 5 additions & 0 deletions lib/yt/models/video.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ def licensed?
content_detail.licensed_content || false
end

# @return [Boolean] whether the video is only viewable in limited countries.
def region_restricted?
content_detail.region_restriction
end
Copy link
Contributor

@kangkyu kangkyu Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does it return when not region restricted? In my opinion we'd better return true when region restricted, false when not.


# @return [Boolean] whether the video is identified by YouTube as
# age-restricted content.
def age_restricted?
Expand Down
12 changes: 12 additions & 0 deletions spec/models/video_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,18 @@
end
end

describe '#region_restricted?' do
context 'given a video with region restricted content' do
let(:attrs) { {content_details: {"regionRestriction"=>{"allowed"=>["TW"]}}} }
it { expect(video).to be_region_restricted }
end

context 'given a video without region restricted content' do
let(:attrs) { {content_details: {}} }
it { expect(video).not_to be_region_restricted }
end
end

describe '#age_restricted?' do
context 'given a video with age restricted content' do
let(:attrs) { {content_details: {"contentRating"=>{"ytRating"=>"ytAgeRestricted"}}} }
Expand Down