@@ -329,7 +329,7 @@ struct Video
329
329
330
330
json.field " subCountText" , self .sub_count_text
331
331
332
- json.field " lengthSeconds" , self .info[ " length_seconds" ].to_i
332
+ json.field " lengthSeconds" , self .length_seconds
333
333
json.field " allowRatings" , self .allow_ratings
334
334
json.field " rating" , self .info[" avg_rating" ].to_f32
335
335
json.field " isListed" , self .is_listed
@@ -563,7 +563,14 @@ struct Video
563
563
fmt[" clen" ] = fmt_stream[" contentLength" ]?.try & .as_s || " 0"
564
564
fmt[" bitrate" ] = fmt_stream[" bitrate" ]?.try & .as_i.to_s || " 0"
565
565
fmt[" itag" ] = fmt_stream[" itag" ].as_i.to_s
566
- fmt[" url" ] = fmt_stream[" url" ].as_s
566
+ if fmt_stream[" url" ]?
567
+ fmt[" url" ] = fmt_stream[" url" ].as_s
568
+ end
569
+ if fmt_stream[" cipher" ]?
570
+ HTTP ::Params .parse(fmt_stream[" cipher" ].as_s).each do |key , value |
571
+ fmt[key] = value
572
+ end
573
+ end
567
574
fmt[" quality" ] = fmt_stream[" quality" ].as_s
568
575
569
576
if fmt_stream[" width" ]?
@@ -635,8 +642,14 @@ struct Video
635
642
fmt[" clen" ] = adaptive_fmt[" contentLength" ]?.try & .as_s || " 0"
636
643
fmt[" bitrate" ] = adaptive_fmt[" bitrate" ]?.try & .as_i.to_s || " 0"
637
644
fmt[" itag" ] = adaptive_fmt[" itag" ].as_i.to_s
638
- fmt[" url" ] = adaptive_fmt[" url" ].as_s
639
-
645
+ if adaptive_fmt[" url" ]?
646
+ fmt[" url" ] = adaptive_fmt[" url" ].as_s
647
+ end
648
+ if adaptive_fmt[" cipher" ]?
649
+ HTTP ::Params .parse(adaptive_fmt[" cipher" ].as_s).each do |key , value |
650
+ fmt[key] = value
651
+ end
652
+ end
640
653
if index = adaptive_fmt[" indexRange" ]?
641
654
fmt[" index" ] = " #{ index[" start" ] } -#{ index[" end" ] } "
642
655
end
@@ -827,7 +840,7 @@ struct Video
827
840
end
828
841
829
842
def length_seconds
830
- return self .info[ " length_seconds " ] .to_i
843
+ self .player_response[ " videoDetails " ][ " lengthSeconds " ].as_s .to_i
831
844
end
832
845
833
846
db_mapping({
@@ -1162,17 +1175,19 @@ def fetch_video(id, region)
1162
1175
end
1163
1176
end
1164
1177
1165
- if info[" errorcode" ]?.try & .== " 2"
1178
+ if info[" errorcode" ]?.try & .== " 2" || ! info[ " player_response " ]
1166
1179
raise " Video unavailable."
1167
1180
end
1168
1181
1169
- if ! info[" title " ]? || info[ " title " ].empty ?
1170
- raise " Video unavailable. "
1182
+ if info[" reason " ] ?
1183
+ raise info[ " reason " ]
1171
1184
end
1172
1185
1173
- title = info[" title" ]
1174
- author = info[" author" ]? || " "
1175
- ucid = info[" ucid" ]? || " "
1186
+ player_json = JSON .parse(info[" player_response" ])
1187
+
1188
+ title = player_json[" videoDetails" ][" title" ].as_s
1189
+ author = player_json[" videoDetails" ][" author" ]?.try & .as_s || " "
1190
+ ucid = player_json[" videoDetails" ][" ucid" ]?.try & .as_s || " "
1176
1191
1177
1192
views = html.xpath_node(%q( //meta[@itemprop="interactionCount"]) )
1178
1193
.try & .[" content" ].to_i64? || 0 _i64
0 commit comments