This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

🎨 Format code

+84 -87
+84 -87
src/synchronization/cue_markers.rs
··· 1 - use crate::synchronization::sync::Syncable; 2 - use serde::Deserialize; 3 - use serde_aux::field_attributes::deserialize_number_from_string; 4 - use std::{ 5 - collections::HashMap, io::Read, path::PathBuf, process::Stdio, 6 - }; 7 - 8 - use super::sync::TimestampMS; 9 - 10 - pub struct CueMarkersSynchronizer { 11 - pub path: PathBuf, 12 - } 13 - 14 - #[derive(Debug, Deserialize)] 15 - struct FFprobeChapterTags { 16 - title: String, 17 - } 18 - 19 - #[derive(Debug, Deserialize)] 20 - struct FFprobeChapter { 21 - // id: usize, 22 - // time_base: String, 23 - 24 - // start: usize, 25 - #[serde(deserialize_with = "deserialize_number_from_string")] 26 - start_time: f32, 27 - 28 - // end: usize, 29 - // #[serde(deserialize_with = "deserialize_number_from_string")] 30 - // end_time: f32, 31 - 32 - tags: FFprobeChapterTags, 33 - } 34 - 35 - #[derive(Debug, Deserialize)] 36 - struct FFprobeOutput { 37 - chapters: Vec<FFprobeChapter>, 38 - } 39 - 40 - impl Syncable for CueMarkersSynchronizer { 41 - fn new(path: impl Into<PathBuf>) -> Self { 42 - Self { path: path.into() } 43 - } 44 - 45 - fn load( 46 - &self, 47 - progress: Option<&indicatif::ProgressBar>, 48 - ) -> super::sync::SyncData { 49 - let mut ffprobe = std::process::Command::new("ffprobe") 50 - .args(["-v", "error"]) 51 - .args(["-i", &self.path.to_string_lossy()]) 52 - .args(["-output_format", "json"]) 53 - .arg("-show_chapters") 54 - .stdout(Stdio::piped()) 55 - .spawn() 56 - .expect(&format!( 57 - "Couldn't run ffprobe to get chapters of {:?}", 58 - self.path 59 - )); 60 - 61 - let mut raw_output = String::new(); 62 - ffprobe 63 - .stdout 64 - .take() 65 - .expect("Coudln't get stdout of ffprobe run") 66 - .read_to_string(&mut raw_output) 67 - .expect("Couldn't read ffprobe stdout"); 68 - 69 - let output: FFprobeOutput = 70 - serde_json::from_str(&raw_output).expect("Invalid ffprobe output"); 71 - 72 - super::sync::SyncData { 73 - stems: HashMap::new(), 74 - bpm: None, 75 - markers: output 76 - .chapters 77 - .iter() 78 - .map(|ch| { 79 - ( 80 - (ch.start_time.to_owned() * 1_000.0) as TimestampMS, 81 - ch.tags.title.clone(), 82 - ) 83 - }) 84 - .collect(), 85 - } 86 - } 87 - } 1 + use crate::synchronization::sync::Syncable; 2 + use serde::Deserialize; 3 + use serde_aux::field_attributes::deserialize_number_from_string; 4 + use std::{collections::HashMap, io::Read, path::PathBuf, process::Stdio}; 5 + 6 + use super::sync::TimestampMS; 7 + 8 + pub struct CueMarkersSynchronizer { 9 + pub path: PathBuf, 10 + } 11 + 12 + #[derive(Debug, Deserialize)] 13 + struct FFprobeChapterTags { 14 + title: String, 15 + } 16 + 17 + #[derive(Debug, Deserialize)] 18 + struct FFprobeChapter { 19 + // id: usize, 20 + // time_base: String, 21 + 22 + // start: usize, 23 + #[serde(deserialize_with = "deserialize_number_from_string")] 24 + start_time: f32, 25 + 26 + // end: usize, 27 + // #[serde(deserialize_with = "deserialize_number_from_string")] 28 + // end_time: f32, 29 + tags: FFprobeChapterTags, 30 + } 31 + 32 + #[derive(Debug, Deserialize)] 33 + struct FFprobeOutput { 34 + chapters: Vec<FFprobeChapter>, 35 + } 36 + 37 + impl Syncable for CueMarkersSynchronizer { 38 + fn new(path: impl Into<PathBuf>) -> Self { 39 + Self { path: path.into() } 40 + } 41 + 42 + fn load( 43 + &self, 44 + progress: Option<&indicatif::ProgressBar>, 45 + ) -> super::sync::SyncData { 46 + let mut ffprobe = std::process::Command::new("ffprobe") 47 + .args(["-v", "error"]) 48 + .args(["-i", &self.path.to_string_lossy()]) 49 + .args(["-output_format", "json"]) 50 + .arg("-show_chapters") 51 + .stdout(Stdio::piped()) 52 + .spawn() 53 + .expect(&format!( 54 + "Couldn't run ffprobe to get chapters of {:?}", 55 + self.path 56 + )); 57 + 58 + let mut raw_output = String::new(); 59 + ffprobe 60 + .stdout 61 + .take() 62 + .expect("Coudln't get stdout of ffprobe run") 63 + .read_to_string(&mut raw_output) 64 + .expect("Couldn't read ffprobe stdout"); 65 + 66 + let output: FFprobeOutput = 67 + serde_json::from_str(&raw_output).expect("Invalid ffprobe output"); 68 + 69 + super::sync::SyncData { 70 + stems: HashMap::new(), 71 + bpm: None, 72 + markers: output 73 + .chapters 74 + .iter() 75 + .map(|ch| { 76 + ( 77 + (ch.start_time.to_owned() * 1_000.0) as TimestampMS, 78 + ch.tags.title.clone(), 79 + ) 80 + }) 81 + .collect(), 82 + } 83 + } 84 + }