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 "age restricted" label to age restricted YouTube videos #251

Merged
merged 3 commits into from
Dec 19, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- YouTube: Added a red `AGE RESTRICTED` label to the YouTube video tooltip. (#251)
- YouTube: Removed dislike count from rich tooltips since YouTube removed it. (#243)
- Twitter: Blacklist special pages from being resolved as user pages. (#220)
- Twitch: Handle Twitch clips from `m.twitch.tv` domain. (#239)
Expand Down
21 changes: 15 additions & 6 deletions internal/resolvers/youtube/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,22 @@ func loadVideos(videoID string, r *http.Request) (interface{}, time.Duration, er
return &resolver.Response{Status: 500, Message: "video unavailable"}, cache.NoSpecialDur, nil
}

// Check if a video is age resricted: https://stackoverflow.com/a/33750307
var ageRestricted = false
if video.ContentDetails.ContentRating != nil {
if video.ContentDetails.ContentRating.YtRating == "ytAgeRestricted" {
ageRestricted = true
}
}

data := youtubeVideoTooltipData{
Title: video.Snippet.Title,
ChannelTitle: video.Snippet.ChannelTitle,
Duration: humanize.DurationPT(video.ContentDetails.Duration),
PublishDate: humanize.CreationDateRFC3339(video.Snippet.PublishedAt),
Views: humanize.Number(video.Statistics.ViewCount),
LikeCount: humanize.Number(video.Statistics.LikeCount),
Title: video.Snippet.Title,
ChannelTitle: video.Snippet.ChannelTitle,
Duration: humanize.DurationPT(video.ContentDetails.Duration),
PublishDate: humanize.CreationDateRFC3339(video.Snippet.PublishedAt),
Views: humanize.Number(video.Statistics.ViewCount),
LikeCount: humanize.Number(video.Statistics.LikeCount),
AgeRestricted: ageRestricted,
}

var tooltip bytes.Buffer
Expand Down
13 changes: 7 additions & 6 deletions internal/resolvers/youtube/model.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package youtube

type youtubeVideoTooltipData struct {
Title string
ChannelTitle string
Duration string
PublishDate string
Views string
LikeCount string
Title string
ChannelTitle string
Duration string
PublishDate string
Views string
LikeCount string
AgeRestricted bool
}

type youtubeChannelTooltipData struct {
Expand Down
1 change: 1 addition & 0 deletions internal/resolvers/youtube/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
<br><b>Duration:</b> {{.Duration}}
<br><b>Published:</b> {{.PublishDate}}
<br><b>Views:</b> {{.Views}}
{{ if .AgeRestricted }}<br><b><span style="color: red;">AGE RESTRICTED</span></b>{{ end }}
<br><span style="color: #2ecc71;">{{.LikeCount}} likes</span>
</div>
`
Expand Down