File tree Expand file tree Collapse file tree 3 files changed +33
-0
lines changed
Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -92,6 +92,10 @@ func TestGetVideoWithoutManifestURL(t *testing.T) {
9292 assert .Empty (video .HLSManifestURL )
9393 assert .Empty (video .DASHManifestURL )
9494
95+ assert .NotEmpty (video .CaptionTracks )
96+ assert .Greater (len (video .CaptionTracks ), 0 )
97+ assert .NotEmpty (video .CaptionTracks [0 ].BaseURL )
98+
9599 assert .Equal ("rFejpH_tAHM" , video .ID )
96100 assert .Equal ("dotGo 2015 - Rob Pike - Simplicity is Complicated" , video .Title )
97101 assert .Equal ("dotconferences" , video .Author )
Original file line number Diff line number Diff line change 11package youtube
22
33type playerResponseData struct {
4+ Captions struct {
5+ PlayerCaptionsTracklistRenderer struct {
6+ CaptionTracks []CaptionTrack `json:"captionTracks"`
7+ AudioTracks []struct {
8+ CaptionTrackIndices []int `json:"captionTrackIndices"`
9+ } `json:"audioTracks"`
10+ TranslationLanguages []struct {
11+ LanguageCode string `json:"languageCode"`
12+ LanguageName struct {
13+ SimpleText string `json:"simpleText"`
14+ } `json:"languageName"`
15+ } `json:"translationLanguages"`
16+ DefaultAudioTrackIndex int `json:"defaultAudioTrackIndex"`
17+ } `json:"playerCaptionsTracklistRenderer"`
18+ } `json:"captions"`
19+
420 PlayabilityStatus struct {
521 Status string `json:"status"`
622 Reason string `json:"reason"`
@@ -110,3 +126,14 @@ type Thumbnail struct {
110126 Width uint
111127 Height uint
112128}
129+
130+ type CaptionTrack struct {
131+ BaseURL string `json:"baseUrl"`
132+ Name struct {
133+ SimpleText string `json:"simpleText"`
134+ } `json:"name"`
135+ VssID string `json:"vssId"`
136+ LanguageCode string `json:"languageCode"`
137+ Kind string `json:"kind,omitempty"`
138+ IsTranslatable bool `json:"isTranslatable"`
139+ }
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ type Video struct {
2424 Thumbnails Thumbnails
2525 DASHManifestURL string // URI of the DASH manifest file
2626 HLSManifestURL string // URI of the HLS manifest file
27+ CaptionTracks []CaptionTrack
2728}
2829
2930const dateFormat = "2006-01-02"
@@ -98,6 +99,7 @@ func (v *Video) extractDataFromPlayerResponse(prData playerResponseData) error {
9899 v .Author = prData .VideoDetails .Author
99100 v .Thumbnails = prData .VideoDetails .Thumbnail .Thumbnails
100101 v .ChannelID = prData .VideoDetails .ChannelID
102+ v .CaptionTracks = prData .Captions .PlayerCaptionsTracklistRenderer .CaptionTracks
101103
102104 if views , _ := strconv .Atoi (prData .VideoDetails .ViewCount ); views > 0 {
103105 v .Views = views
You can’t perform that action at this time.
0 commit comments