Spaces:
Sleeping
Sleeping
Monteeq CI factory-droid[bot] commited on
Commit ·
65bc393
1
Parent(s): 51913a2
🚀 Deploy from GitHub @ f2ad8585d6099ec7f0ee8232853264b5389c693d
Browse filesTriggered by: Smasduq
Message: feat(mobile): add Flutter app with full native UI
- Add Flutter project in mobile/ (Android-first, cross-platform ready)
- Implement auth, home/feed, flash, upload, profile, notifications, search, watch screens
- Add Riverpod + go_router, media_kit playback, Dio API client, secure storage
- Configure Android/iOS manifests, permissions, and app identity (com.monteeq.app)
- Add Outfit fonts, theming, and core networking/storage
- Add Next.js native bridge files and related tweaks
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
- src/main.rs +4 -1
- src/transcoder.rs +87 -13
src/main.rs
CHANGED
|
@@ -45,7 +45,10 @@ struct AppState {
|
|
| 45 |
|
| 46 |
#[tokio::main]
|
| 47 |
async fn main() {
|
| 48 |
-
dotenv()
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
// We bind the port first so Render doesn't time out while we connect to Redis
|
| 51 |
let port = env::var("PORT").unwrap_or_else(|_| "8080".to_string());
|
|
|
|
| 45 |
|
| 46 |
#[tokio::main]
|
| 47 |
async fn main() {
|
| 48 |
+
match dotenv() {
|
| 49 |
+
Ok(path) => println!("Loaded environment from {}", path.display()),
|
| 50 |
+
Err(e) => eprintln!("[WARN] Could not load .env: {}", e),
|
| 51 |
+
}
|
| 52 |
|
| 53 |
// We bind the port first so Render doesn't time out while we connect to Redis
|
| 54 |
let port = env::var("PORT").unwrap_or_else(|_| "8080".to_string());
|
src/transcoder.rs
CHANGED
|
@@ -242,12 +242,45 @@ pub async fn process(
|
|
| 242 |
Ok(())
|
| 243 |
}
|
| 244 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
/// Probe width/height, audio presence, and total duration (seconds).
|
| 246 |
/// Duration comes from format context (`format=duration`), with stream duration as fallback —
|
| 247 |
/// equivalent to reading container duration / stream time_base×duration in ffmpeg-next.
|
| 248 |
async fn get_video_metadata(video_path: &str) -> Result<(i32, i32, bool, f64)> {
|
| 249 |
let output = Command::new("ffprobe")
|
| 250 |
-
.args(
|
| 251 |
"-v",
|
| 252 |
"error",
|
| 253 |
"-select_streams",
|
|
@@ -255,20 +288,21 @@ async fn get_video_metadata(video_path: &str) -> Result<(i32, i32, bool, f64)> {
|
|
| 255 |
"-show_entries",
|
| 256 |
"stream=width,height",
|
| 257 |
"-of",
|
| 258 |
-
"
|
| 259 |
video_path,
|
| 260 |
])
|
| 261 |
.output()
|
| 262 |
.await?;
|
| 263 |
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
|
|
|
|
|
|
| 268 |
}
|
| 269 |
|
| 270 |
-
let width =
|
| 271 |
-
let height = parts[1].parse()?;
|
| 272 |
|
| 273 |
// Check for audio
|
| 274 |
let audio_output = Command::new("ffprobe")
|
|
@@ -593,21 +627,29 @@ async fn run_ffmpeg_with_progress(
|
|
| 593 |
|
| 594 |
async fn get_video_height(input: &str) -> Result<i32> {
|
| 595 |
let output = Command::new("ffprobe")
|
| 596 |
-
.args(
|
| 597 |
"-v",
|
| 598 |
"error",
|
| 599 |
"-select_streams",
|
| 600 |
"v:0",
|
| 601 |
"-show_entries",
|
| 602 |
-
"stream=height",
|
| 603 |
"-of",
|
| 604 |
-
"
|
| 605 |
input,
|
| 606 |
])
|
| 607 |
.output()
|
| 608 |
.await?;
|
| 609 |
-
|
| 610 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 611 |
}
|
| 612 |
|
| 613 |
async fn generate_thumbnail(video_path: &str) -> Result<()> {
|
|
@@ -687,3 +729,35 @@ pub async fn generate_and_upload_auto_cover(
|
|
| 687 |
println!("Auto cover uploaded: {}", cover_key);
|
| 688 |
Ok(cover_key)
|
| 689 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
Ok(())
|
| 243 |
}
|
| 244 |
|
| 245 |
+
/// Pick the first width/height pair from `ffprobe -of json -show_entries stream=width,height`.
|
| 246 |
+
///
|
| 247 |
+
/// JSON is used instead of `-of csv=s=x:p=0` because the CSV writer can emit
|
| 248 |
+
/// extra sections/fields depending on the container (e.g. QuickTime timecode
|
| 249 |
+
/// tracks and MPEG-TS programs produce multiple lines, and some files end with
|
| 250 |
+
/// a bare separator like `1080x1080x`). Splitting the whole stdout on 'x' then
|
| 251 |
+
/// rejects perfectly valid values.
|
| 252 |
+
fn parse_dimensions(stdout: &[u8]) -> Result<(i32, i32)> {
|
| 253 |
+
let raw = String::from_utf8_lossy(stdout);
|
| 254 |
+
let json: serde_json::Value = serde_json::from_str(&raw)
|
| 255 |
+
.map_err(|e| anyhow!("Invalid ffprobe JSON ({}): {}", e, raw.trim()))?;
|
| 256 |
+
|
| 257 |
+
let streams = json
|
| 258 |
+
.get("streams")
|
| 259 |
+
.and_then(|v| v.as_array())
|
| 260 |
+
.ok_or_else(|| anyhow!("ffprobe returned no streams: {}", raw.trim()))?;
|
| 261 |
+
|
| 262 |
+
for stream in streams {
|
| 263 |
+
let width = stream.get("width").and_then(|v| v.as_i64());
|
| 264 |
+
let height = stream.get("height").and_then(|v| v.as_i64());
|
| 265 |
+
if let (Some(w), Some(h)) = (width, height) {
|
| 266 |
+
if w > 0 && h > 0 {
|
| 267 |
+
return Ok((w as i32, h as i32));
|
| 268 |
+
}
|
| 269 |
+
}
|
| 270 |
+
}
|
| 271 |
+
|
| 272 |
+
Err(anyhow!(
|
| 273 |
+
"ffprobe returned no usable width/height: {}",
|
| 274 |
+
raw.trim()
|
| 275 |
+
))
|
| 276 |
+
}
|
| 277 |
+
|
| 278 |
/// Probe width/height, audio presence, and total duration (seconds).
|
| 279 |
/// Duration comes from format context (`format=duration`), with stream duration as fallback —
|
| 280 |
/// equivalent to reading container duration / stream time_base×duration in ffmpeg-next.
|
| 281 |
async fn get_video_metadata(video_path: &str) -> Result<(i32, i32, bool, f64)> {
|
| 282 |
let output = Command::new("ffprobe")
|
| 283 |
+
.args([
|
| 284 |
"-v",
|
| 285 |
"error",
|
| 286 |
"-select_streams",
|
|
|
|
| 288 |
"-show_entries",
|
| 289 |
"stream=width,height",
|
| 290 |
"-of",
|
| 291 |
+
"json",
|
| 292 |
video_path,
|
| 293 |
])
|
| 294 |
.output()
|
| 295 |
.await?;
|
| 296 |
|
| 297 |
+
if !output.status.success() {
|
| 298 |
+
return Err(anyhow!(
|
| 299 |
+
"ffprobe failed for {}: {}",
|
| 300 |
+
video_path,
|
| 301 |
+
String::from_utf8_lossy(&output.stderr).trim()
|
| 302 |
+
));
|
| 303 |
}
|
| 304 |
|
| 305 |
+
let (width, height) = parse_dimensions(&output.stdout)?;
|
|
|
|
| 306 |
|
| 307 |
// Check for audio
|
| 308 |
let audio_output = Command::new("ffprobe")
|
|
|
|
| 627 |
|
| 628 |
async fn get_video_height(input: &str) -> Result<i32> {
|
| 629 |
let output = Command::new("ffprobe")
|
| 630 |
+
.args([
|
| 631 |
"-v",
|
| 632 |
"error",
|
| 633 |
"-select_streams",
|
| 634 |
"v:0",
|
| 635 |
"-show_entries",
|
| 636 |
+
"stream=width,height",
|
| 637 |
"-of",
|
| 638 |
+
"json",
|
| 639 |
input,
|
| 640 |
])
|
| 641 |
.output()
|
| 642 |
.await?;
|
| 643 |
+
|
| 644 |
+
if !output.status.success() {
|
| 645 |
+
return Err(anyhow!(
|
| 646 |
+
"ffprobe failed for {}: {}",
|
| 647 |
+
input,
|
| 648 |
+
String::from_utf8_lossy(&output.stderr).trim()
|
| 649 |
+
));
|
| 650 |
+
}
|
| 651 |
+
|
| 652 |
+
parse_dimensions(&output.stdout).map(|(_, height)| height)
|
| 653 |
}
|
| 654 |
|
| 655 |
async fn generate_thumbnail(video_path: &str) -> Result<()> {
|
|
|
|
| 729 |
println!("Auto cover uploaded: {}", cover_key);
|
| 730 |
Ok(cover_key)
|
| 731 |
}
|
| 732 |
+
|
| 733 |
+
#[cfg(test)]
|
| 734 |
+
mod tests {
|
| 735 |
+
use super::parse_dimensions;
|
| 736 |
+
|
| 737 |
+
#[test]
|
| 738 |
+
fn picks_first_stream_with_dimensions() {
|
| 739 |
+
// `programs` is emitted too for some containers; top-level `streams` wins.
|
| 740 |
+
let out = br#"{
|
| 741 |
+
"programs":[{"streams":[{"width":640,"height":480}]}],
|
| 742 |
+
"streams":[{"width":1080,"height":1080},{"codec_type":"audio"}]
|
| 743 |
+
}"#;
|
| 744 |
+
assert_eq!(parse_dimensions(out).unwrap(), (1080, 1080));
|
| 745 |
+
}
|
| 746 |
+
|
| 747 |
+
#[test]
|
| 748 |
+
fn skips_streams_without_dimensions() {
|
| 749 |
+
let out = br#"{"streams":[{"codec_type":"video"},{"width":720,"height":1280}]}"#;
|
| 750 |
+
assert_eq!(parse_dimensions(out).unwrap(), (720, 1280));
|
| 751 |
+
}
|
| 752 |
+
|
| 753 |
+
#[test]
|
| 754 |
+
fn rejects_zero_dimensions() {
|
| 755 |
+
let out = br#"{"streams":[{"width":0,"height":0}]}"#;
|
| 756 |
+
assert!(parse_dimensions(out).is_err());
|
| 757 |
+
}
|
| 758 |
+
|
| 759 |
+
#[test]
|
| 760 |
+
fn rejects_non_json_output() {
|
| 761 |
+
assert!(parse_dimensions(b"1080x1080x").is_err());
|
| 762 |
+
}
|
| 763 |
+
}
|