diff --git a/CHANGELOG.md b/CHANGELOG.md index 640d5704..d091314d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/internal/resolvers/youtube/load.go b/internal/resolvers/youtube/load.go index dfaa89e7..eaf469d2 100644 --- a/internal/resolvers/youtube/load.go +++ b/internal/resolvers/youtube/load.go @@ -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 diff --git a/internal/resolvers/youtube/model.go b/internal/resolvers/youtube/model.go index 98a38ae7..9db8ee64 100644 --- a/internal/resolvers/youtube/model.go +++ b/internal/resolvers/youtube/model.go @@ -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 { diff --git a/internal/resolvers/youtube/resolver.go b/internal/resolvers/youtube/resolver.go index 5fc9d1b3..dd4d2414 100644 --- a/internal/resolvers/youtube/resolver.go +++ b/internal/resolvers/youtube/resolver.go @@ -26,6 +26,7 @@ const (
Duration: {{.Duration}}
Published: {{.PublishDate}}
Views: {{.Views}} +{{ if .AgeRestricted }}
AGE RESTRICTED{{ end }}
{{.LikeCount}} likes `