@@ -96,7 +96,10 @@ private static int MuxByMp4box(string videoPath, string audioPath, string outPat
96
96
return RunExe ( MP4BOX , arguments , MP4BOX != "mp4box" ) ;
97
97
}
98
98
99
- public static int MuxAV ( bool useMp4box , string videoPath , string audioPath , List < AudioMaterial > audioMaterial , string outPath , string desc = "" , string title = "" , string author = "" , string episodeId = "" , string pic = "" , string lang = "" , List < Subtitle > ? subs = null , bool audioOnly = false , bool videoOnly = false , List < ViewPoint > ? points = null , long pubTime = 0 , bool simplyMux = false , MyOption myOption = null )
99
+ public static int MuxAV ( bool useMp4box , string videoPath , string audioPath , List < AudioMaterial > audioMaterial , string outPath ,
100
+ string desc = "" , string title = "" , string author = "" , string episodeId = "" , string pic = "" , string lang = "" , List < Subtitle > ? subs = null ,
101
+ bool audioOnly = false , bool videoOnly = false , List < ViewPoint > ? points = null ,
102
+ long pubTime = 0 , bool simplyMux = false , MyOption myOption = null , Page p = null , int pagesCount = 0 )
100
103
{
101
104
if ( audioOnly && audioPath != "" )
102
105
videoPath = "" ;
@@ -195,7 +198,7 @@ public static int MuxAV(bool useMp4box, string videoPath, string audioPath, List
195
198
if ( match . Success )
196
199
{
197
200
string key = match . Groups [ 1 ] . Value ;
198
- string value = GetValueForReplacement ( key , metadata ) ;
201
+ string value = FormatValue ( GetValueForReplacement ( key , metadata ) , title , p , pagesCount ) ;
199
202
if ( ! string . IsNullOrEmpty ( value ) )
200
203
{
201
204
argsBuilder . Replace ( $ "{ key } ={ match . Groups [ 2 ] . Value } ", $ "{ key } =\" { value } \" ") ;
@@ -207,10 +210,10 @@ public static int MuxAV(bool useMp4box, string videoPath, string audioPath, List
207
210
foreach ( var keyValuePair in keyValuePairs )
208
211
{
209
212
string [ ] parts = keyValuePair . Split ( '=' ) ;
210
- if ( parts . Length == 2 )
213
+ if ( parts . Length == 2 )
211
214
{
212
215
string key = parts [ 0 ] ;
213
- string value = parts [ 1 ] ;
216
+ string value = FormatValue ( parts [ 1 ] , title , p , pagesCount ) ;
214
217
argsBuilder . Append ( $ "-metadata { key } =\" { value } \" ") ;
215
218
}
216
219
}
@@ -262,5 +265,28 @@ private static string GetValueForReplacement(string key, string input)
262
265
return string . Empty ;
263
266
}
264
267
}
268
+
269
+ private static string FormatValue ( string value , string title , Page p , int pagesCount ) {
270
+ var regex = Program . InfoRegex ( ) ;
271
+ foreach ( Match m in regex . Matches ( value ) . Cast < Match > ( ) )
272
+ {
273
+ var key = m . Groups [ 1 ] . Value ;
274
+ var v = key switch
275
+ {
276
+ "videoTitle" => Program . GetValidFileName ( title , filterSlash : true ) . Trim ( ) . TrimEnd ( '.' ) . Trim ( ) ,
277
+ "pageNumber" => p . index . ToString ( ) ,
278
+ "pageNumberWithZero" => p . index . ToString ( ) . PadLeft ( pagesCount . ToString ( ) . Length , '0' ) ,
279
+ "pageTitle" => Program . GetValidFileName ( p . title , filterSlash : true ) . Trim ( ) . TrimEnd ( '.' ) . Trim ( ) ,
280
+ "bvid" => p . bvid ,
281
+ "aid" => p . aid ,
282
+ "cid" => p . cid ,
283
+ "ownerName" => p . ownerName == null ? "" : Program . GetValidFileName ( p . ownerName , filterSlash : true ) . Trim ( ) . TrimEnd ( '.' ) . Trim ( ) ,
284
+ "ownerMid" => p . ownerMid ?? "" ,
285
+ _ => $ "<{ key } >"
286
+ } ;
287
+ value = value . Replace ( m . Value , v ) ;
288
+ }
289
+ return value ;
290
+ }
265
291
}
266
292
}
0 commit comments