@@ -26,12 +26,6 @@ struct Video
26
26
@[DB ::Field (ignore: true )]
27
27
@captions = [] of Invidious ::Videos ::Captions ::Metadata
28
28
29
- @[DB ::Field (ignore: true )]
30
- property adaptive_fmts : Array (Hash (String , JSON ::Any ))?
31
-
32
- @[DB ::Field (ignore: true )]
33
- property fmt_stream : Array (Hash (String , JSON ::Any ))?
34
-
35
29
@[DB ::Field (ignore: true )]
36
30
property description : String ?
37
31
@@ -98,72 +92,24 @@ struct Video
98
92
99
93
# Methods for parsing streaming data
100
94
101
- def convert_url (fmt )
102
- if cfr = fmt[" signatureCipher" ]?.try { |json | HTTP ::Params .parse(json.as_s) }
103
- sp = cfr[" sp" ]
104
- url = URI .parse(cfr[" url" ])
105
- params = url.query_params
106
-
107
- LOGGER .debug(" Videos: Decoding '#{ cfr } '" )
108
-
109
- unsig = DECRYPT_FUNCTION .try & .decrypt_signature(cfr[" s" ])
110
- params[sp] = unsig if unsig
95
+ def fmt_stream : Array (Hash (String , JSON ::Any ))
96
+ if formats = info.dig?(" streamingData" , " formats" )
97
+ return formats
98
+ .as_a.map(& .as_h)
99
+ .sort_by! { |f | f[" width" ]?.try & .as_i || 0 }
111
100
else
112
- url = URI .parse(fmt[" url" ].as_s)
113
- params = url.query_params
114
- end
115
-
116
- n = DECRYPT_FUNCTION .try & .decrypt_nsig(params[" n" ])
117
- params[" n" ] = n if n
118
-
119
- if token = CONFIG .po_token
120
- params[" pot" ] = token
121
- end
122
-
123
- params[" host" ] = url.host.not_nil!
124
- if region = self .info[" region" ]?.try & .as_s
125
- params[" region" ] = region
126
- end
127
-
128
- url.query_params = params
129
- LOGGER .trace(" Videos: new url is '#{ url } '" )
130
-
131
- return url.to_s
132
- rescue ex
133
- LOGGER .debug(" Videos: Error when parsing video URL" )
134
- LOGGER .trace(ex.inspect_with_backtrace)
135
- return " "
136
- end
137
-
138
- def fmt_stream
139
- return @fmt_stream .as(Array (Hash (String , JSON ::Any ))) if @fmt_stream
140
-
141
- fmt_stream = info.dig?(" streamingData" , " formats" )
142
- .try & .as_a.map & .as_h || [] of Hash (String , JSON ::Any )
143
-
144
- fmt_stream.each do |fmt |
145
- fmt[" url" ] = JSON ::Any .new(self .convert_url(fmt))
101
+ return [] of Hash (String , JSON ::Any )
146
102
end
147
-
148
- fmt_stream.sort_by! { |f | f[" width" ]?.try & .as_i || 0 }
149
- @fmt_stream = fmt_stream
150
- return @fmt_stream .as(Array (Hash (String , JSON ::Any )))
151
103
end
152
104
153
- def adaptive_fmts
154
- return @adaptive_fmts .as(Array (Hash (String , JSON ::Any ))) if @adaptive_fmts
155
-
156
- fmt_stream = info.dig(" streamingData" , " adaptiveFormats" )
157
- .try & .as_a.map & .as_h || [] of Hash (String , JSON ::Any )
158
-
159
- fmt_stream.each do |fmt |
160
- fmt[" url" ] = JSON ::Any .new(self .convert_url(fmt))
105
+ def adaptive_fmts : Array (Hash (String , JSON ::Any ))
106
+ if formats = info.dig?(" streamingData" , " adaptiveFormats" )
107
+ return formats
108
+ .as_a.map(& .as_h)
109
+ .sort_by! { |f | f[" width" ]?.try & .as_i || 0 }
110
+ else
111
+ return [] of Hash (String , JSON ::Any )
161
112
end
162
-
163
- fmt_stream.sort_by! { |f | f[" width" ]?.try & .as_i || 0 }
164
- @adaptive_fmts = fmt_stream
165
-
166
- return @adaptive_fmts .as(Array (Hash (String , JSON ::Any )))
167
113
end
168
114
169
115
def video_streams
0 commit comments