@@ -8,7 +8,10 @@ use chrono::{DateTime, Local};
88use serde:: Deserialize ;
99use serde_json as json;
1010use spdlog:: prelude:: * ;
11- use tokio:: sync:: { mpsc, Mutex } ;
11+ use tokio:: {
12+ fs,
13+ sync:: { mpsc, Mutex } ,
14+ } ;
1215use warp:: Filter ;
1316
1417use super :: PLATFORM_METADATA ;
@@ -190,49 +193,61 @@ async fn handle(event: data::WebhookV2, params: &Context) -> anyhow::Result<()>
190193 ) ;
191194 }
192195
193- let file_path = params. working_directory . join ( & file_closed. relative_path ) ;
194-
195- enum FileType {
196- Video ( PlaybackFormat ) ,
197- Metadata ,
198- }
196+ let send_update = async |path : PathBuf | {
197+ enum FileType {
198+ Video ( PlaybackFormat ) ,
199+ Metadata ,
200+ }
201+
202+ let file_type = match path
203+ . extension ( )
204+ . map ( |ext| ext. to_string_lossy ( ) . to_ascii_lowercase ( ) )
205+ . as_deref ( )
206+ {
207+ Some ( "flv" ) => FileType :: Video ( PlaybackFormat :: Flv ) ,
208+ Some ( "xml" ) => FileType :: Metadata ,
209+ _ => bail ! (
210+ "bililive-recorder closed a file with an unknown extension '{path:?}'"
211+ ) ,
212+ } ;
213+
214+ let status = Update :: new (
215+ match file_type {
216+ FileType :: Video ( format) => UpdateKind :: Playback ( Playback {
217+ live_start_time : session. live_start_time ,
218+ file_path : path,
219+ format,
220+ } ) ,
221+ FileType :: Metadata => UpdateKind :: Document ( Document { file_path : path } ) ,
222+ } ,
223+ StatusSource {
224+ platform : PLATFORM_METADATA ,
225+ user : None ,
226+ } ,
227+ ) ;
199228
200- let file_type = match file_path
201- . extension ( )
202- . map ( |ext| ext. to_string_lossy ( ) . to_ascii_lowercase ( ) )
203- . as_deref ( )
204- {
205- Some ( "flv" ) => FileType :: Video ( PlaybackFormat :: Flv ) ,
206- Some ( "xml" ) => FileType :: Metadata ,
207- _ => bail ! (
208- "bililive-recorder closed a file with an unknown extension '{file_path:?}'"
209- ) ,
229+ params
230+ . senders
231+ . lock ( )
232+ . await
233+ . get ( & session. room_id )
234+ . ok_or_else ( || anyhow ! ( "room id {} has no sender" , session. room_id) ) ?
235+ . send ( status)
236+ . await
237+ . map_err ( |err| anyhow ! ( "failed to send status: {err}. session: {session:?}" ) )
210238 } ;
211239
212- let status = Update :: new (
213- match file_type {
214- FileType :: Video ( format) => UpdateKind :: Playback ( Playback {
215- live_start_time : session. live_start_time ,
216- file_path,
217- format,
218- } ) ,
219- FileType :: Metadata => UpdateKind :: Document ( Document { file_path } ) ,
220- } ,
221- StatusSource {
222- platform : PLATFORM_METADATA ,
223- user : None ,
224- } ,
225- ) ;
226-
227- params
228- . senders
229- . lock ( )
230- . await
231- . get ( & session. room_id )
232- . ok_or_else ( || anyhow ! ( "room id {} has no sender" , session. room_id) ) ?
233- . send ( status)
234- . await
235- . map_err ( |err| anyhow ! ( "failed to send status: {err}. session: {session:?}" ) )
240+ let playback_file = params. working_directory . join ( & file_closed. relative_path ) ;
241+ let metadate_file = playback_file. with_extension ( "xml" ) ;
242+
243+ let ret1 = send_update ( playback_file) . await ;
244+ let mut ret2 = Ok ( ( ) ) ;
245+ if let Ok ( true ) = fs:: try_exists ( & metadate_file) . await {
246+ ret2 = send_update ( metadate_file) . await ;
247+ }
248+ ret1?;
249+ ret2?;
250+ Ok ( ( ) )
236251 }
237252 data:: EventKind :: FileOpening { }
238253 | data:: EventKind :: StreamStarted { }
0 commit comments