@@ -351,7 +351,7 @@ sub set_lwp_useragent {
351
351
my $cookies = HTTP::Cookies-> new();
352
352
353
353
# Consent cookie
354
- $cookies -> set_cookie(0, " CONSENT" , " YES+cb-m.20210516-15 -p0.en+FX+687 " ,
354
+ $cookies -> set_cookie(0, " CONSENT" , " YES+cb-m.20210615-14 -p0.en+FX+096 " ,
355
355
" /" , " .youtube.com" , undef , 0, 1, ' 21' . join (' ' , map { int (rand (10)) } 1 .. 8),
356
356
0, {});
357
357
@@ -1196,6 +1196,64 @@ sub _make_translated_captions {
1196
1196
return @asr ;
1197
1197
}
1198
1198
1199
+ sub _fallback_extract_captions {
1200
+ my ($self , $videoID ) = @_ ;
1201
+
1202
+ if ($self -> get_debug) {
1203
+ say STDERR " :: Extracting closed-caption URLs with `youtube-dl`..." ;
1204
+ }
1205
+
1206
+ # Extract closed-caption URLs with youtube-dl if our code failed
1207
+ my $ytdl_info = $self -> _info_from_ytdl($videoID );
1208
+
1209
+ my @caption_urls ;
1210
+
1211
+ if (defined ($ytdl_info ) and ref ($ytdl_info ) eq ' HASH' ) {
1212
+
1213
+ my $has_subtitles = 0;
1214
+
1215
+ foreach my $key (qw( subtitles automatic_captions) ) {
1216
+
1217
+ my $ccaps = $ytdl_info -> {$key } // next ;
1218
+
1219
+ ref ($ccaps ) eq ' HASH' or next ;
1220
+
1221
+ foreach my $lang_code (sort keys %$ccaps ) {
1222
+
1223
+ my ($caption_info ) = grep { $_ -> {ext } eq ' srv1' } @{$ccaps -> {$lang_code }};
1224
+
1225
+ if (defined ($caption_info ) and ref ($caption_info ) eq ' HASH' and defined ($caption_info -> {url })) {
1226
+
1227
+ push @caption_urls ,
1228
+ scalar {
1229
+ kind => ($key eq ' automatic_captions' ? ' asr' : ' ' ),
1230
+ languageCode => $lang_code ,
1231
+ baseUrl => $caption_info -> {url },
1232
+ };
1233
+
1234
+ if ($key eq ' subtitles' ) {
1235
+ $has_subtitles = 1;
1236
+ }
1237
+ }
1238
+ }
1239
+
1240
+ last if $has_subtitles ;
1241
+ }
1242
+
1243
+ # Auto-translated captions
1244
+ if ($has_subtitles ) {
1245
+
1246
+ if ($self -> get_debug) {
1247
+ say STDERR " :: Generating translated closed-caption URLs..." ;
1248
+ }
1249
+
1250
+ push @caption_urls , $self -> _make_translated_captions(\@caption_urls );
1251
+ }
1252
+ }
1253
+
1254
+ return @caption_urls ;
1255
+ }
1256
+
1199
1257
=head2 get_streaming_urls($videoID)
1200
1258
1201
1259
Returns a list of streaming URLs for a videoID.
@@ -1233,59 +1291,11 @@ sub get_streaming_urls {
1233
1291
# Try again with youtube-dl
1234
1292
if (!@streaming_urls or (($caption_data -> {playabilityStatus }{status } // ' ' ) =~ / fail|error/i )) {
1235
1293
@streaming_urls = $self -> _fallback_extract_urls($videoID );
1294
+ push @caption_urls , $self -> _fallback_extract_captions($videoID );
1236
1295
}
1237
1296
}
1238
1297
else {
1239
-
1240
- if ($self -> get_debug) {
1241
- say STDERR " :: Extracting closed-caption URLs with `youtube-dl`..." ;
1242
- }
1243
-
1244
- # Extract closed-caption URLs with youtube-dl if our code failed
1245
- my $ytdl_info = $self -> _info_from_ytdl($videoID );
1246
-
1247
- if (defined ($ytdl_info ) and ref ($ytdl_info ) eq ' HASH' ) {
1248
-
1249
- my $has_subtitles = 0;
1250
-
1251
- foreach my $key (qw( subtitles automatic_captions) ) {
1252
-
1253
- my $ccaps = $ytdl_info -> {$key } // next ;
1254
-
1255
- ref ($ccaps ) eq ' HASH' or next ;
1256
-
1257
- foreach my $lang_code (sort keys %$ccaps ) {
1258
-
1259
- my ($caption_info ) = grep { $_ -> {ext } eq ' srv1' } @{$ccaps -> {$lang_code }};
1260
-
1261
- if (defined ($caption_info ) and ref ($caption_info ) eq ' HASH' and defined ($caption_info -> {url })) {
1262
-
1263
- push @caption_urls ,
1264
- scalar {
1265
- kind => ($key eq ' automatic_captions' ? ' asr' : ' ' ),
1266
- languageCode => $lang_code ,
1267
- baseUrl => $caption_info -> {url },
1268
- };
1269
-
1270
- if ($key eq ' subtitles' ) {
1271
- $has_subtitles = 1;
1272
- }
1273
- }
1274
- }
1275
-
1276
- last if $has_subtitles ;
1277
- }
1278
-
1279
- # Auto-translated captions
1280
- if ($has_subtitles ) {
1281
-
1282
- if ($self -> get_debug) {
1283
- say STDERR " :: Generating translated closed-caption URLs..." ;
1284
- }
1285
-
1286
- push @caption_urls , $self -> _make_translated_captions(\@caption_urls );
1287
- }
1288
- }
1298
+ push @caption_urls , $self -> _fallback_extract_captions($videoID );
1289
1299
}
1290
1300
1291
1301
if ($self -> get_debug) {
@@ -1296,6 +1306,7 @@ sub get_streaming_urls {
1296
1306
# Try again with youtube-dl
1297
1307
if (!@streaming_urls or (($info {status } // ' ' ) =~ / fail|error/i )) {
1298
1308
@streaming_urls = $self -> _fallback_extract_urls($videoID );
1309
+ push @caption_urls , $self -> _fallback_extract_captions($videoID );
1299
1310
}
1300
1311
1301
1312
if ($self -> get_prefer_mp4 or $self -> get_prefer_av1) {
0 commit comments