Skip to content

Commit 5eed554

Browse files
committed
handle videos without audio
1 parent 0475d52 commit 5eed554

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/utils.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,20 +195,25 @@ impl Media {
195195
let secure_media = &data["secure_media"]["reddit_video"];
196196
let crosspost_parent_media = &data["crosspost_parent_list"][0]["secure_media"]["reddit_video"];
197197

198+
let mut has_audio=false;
199+
198200
// If post is a video, return the video
199201
let (post_type, url_val, alt_url_val) = if data_preview["fallback_url"].is_string() {
202+
has_audio=data_preview["has_audio"].as_bool().unwrap_or(false);
200203
(
201204
if data_preview["is_gif"].as_bool().unwrap_or(false) { "gif" } else { "video" },
202205
&data_preview["fallback_url"],
203206
Some(&data_preview["hls_url"]),
204207
)
205208
} else if secure_media["fallback_url"].is_string() {
209+
has_audio=secure_media["has_audio"].as_bool().unwrap_or(false);
206210
(
207211
if secure_media["is_gif"].as_bool().unwrap_or(false) { "gif" } else { "video" },
208212
&secure_media["fallback_url"],
209213
Some(&secure_media["hls_url"]),
210214
)
211215
} else if crosspost_parent_media["fallback_url"].is_string() {
216+
has_audio=crosspost_parent_media["has_audio"].as_bool().unwrap_or(false);
212217
(
213218
if crosspost_parent_media["is_gif"].as_bool().unwrap_or(false) { "gif" } else { "video" },
214219
&crosspost_parent_media["fallback_url"],
@@ -273,7 +278,7 @@ impl Media {
273278
// Extract audio URL from video ID
274279
// DASH manifest contains direct audio MP4 files: CMAF_AUDIO_64.mp4 and CMAF_AUDIO_128.mp4
275280
let video_url = format_url(url_val.as_str().unwrap_or_default());
276-
let url_audio = if post_type == "video" {
281+
let url_audio = if post_type == "video" && has_audio {
277282
// Extract video ID from the video URL
278283
// video_url format: /vid/{id}/cmaf/{quality}.mp4 or /vid/{id}/dash/{quality}.mp4
279284
if video_url.starts_with("/vid/") {

0 commit comments

Comments
 (0)