@@ -16,12 +16,12 @@ pub use tag_name::*;
16
16
pub use target:: * ;
17
17
18
18
use crate :: config:: { WriteOptions , global_options} ;
19
+ use crate :: ebml:: tag:: write:: { ElementWriterCtx , WriteableElement } ;
19
20
use crate :: error:: { LoftyError , Result } ;
20
21
use crate :: io:: { FileLike , Length , Truncate } ;
21
22
use crate :: picture:: Picture ;
22
23
use crate :: tag:: companion_tag:: CompanionTag ;
23
24
use crate :: tag:: { Accessor , MergeTag , SplitTag , TagExt , TagType } ;
24
- use crate :: ebml:: tag:: write:: { ElementWriterCtx , WriteableElement } ;
25
25
26
26
use std:: borrow:: Cow ;
27
27
use std:: collections:: HashMap ;
@@ -35,7 +35,7 @@ macro_rules! impl_accessor {
35
35
paste:: paste! {
36
36
$(
37
37
fn $method( & self ) -> Option <Cow <' _, str >> {
38
- self . get_str( MatroskaTagKey ( TargetType :: $target, $name. into ( ) ) )
38
+ self . get_str( TargetType :: $target, $name)
39
39
}
40
40
41
41
fn [ <set_ $method>] ( & mut self , value: String ) {
@@ -72,8 +72,11 @@ pub struct MatroskaTag {
72
72
pub struct MatroskaTagKey < ' a > ( TargetType , Cow < ' a , str > ) ;
73
73
74
74
impl MatroskaTag {
75
- fn get ( & self , key : MatroskaTagKey < ' _ > ) -> Option < & SimpleTag < ' _ > > {
76
- let MatroskaTagKey ( target, key) = key;
75
+ fn get < ' a , K > ( & self , target : TargetType , key : K ) -> Option < & SimpleTag < ' _ > >
76
+ where
77
+ K : Into < Cow < ' a , str > > ,
78
+ {
79
+ let key = key. into ( ) ;
77
80
78
81
let applicable_tags = self . tags . iter ( ) . filter ( |tag| tag. matches_target ( target) ) ;
79
82
for applicable_tag in applicable_tags {
@@ -112,8 +115,11 @@ impl MatroskaTag {
112
115
self . tags . get_mut ( pos. unwrap ( ) ) . unwrap ( )
113
116
}
114
117
115
- fn get_str ( & self , key : MatroskaTagKey < ' _ > ) -> Option < Cow < ' _ , str > > {
116
- let simple_tag = self . get ( key) ?;
118
+ fn get_str < ' a , K > ( & self , target : TargetType , key : K ) -> Option < Cow < ' _ , str > >
119
+ where
120
+ K : Into < Cow < ' a , str > > ,
121
+ {
122
+ let simple_tag = self . get ( target, key) ?;
117
123
simple_tag. get_str ( ) . map ( Cow :: from)
118
124
}
119
125
@@ -279,39 +285,60 @@ impl Accessor for MatroskaTag {
279
285
) ;
280
286
281
287
fn track ( & self ) -> Option < u32 > {
282
- self . get ( MatroskaTagKey (
283
- TargetType :: Track ,
284
- Cow :: Borrowed ( "PART_NUMBER" ) ,
285
- ) )
286
- . and_then ( SimpleTag :: get_str)
287
- . and_then ( |val| val. parse :: < u32 > ( ) . ok ( ) )
288
+ self . get_str ( TargetType :: Track , TagName :: PartNumber )
289
+ . and_then ( |val| val. parse :: < u32 > ( ) . ok ( ) )
288
290
}
289
291
290
- fn set_track ( & mut self , _value : u32 ) {
291
- todo ! ( )
292
+ fn set_track ( & mut self , value : u32 ) {
293
+ let tag = SimpleTag :: new ( TagName :: PartNumber , value. to_string ( ) ) ;
294
+ self . push ( TargetType :: Track , tag) ;
292
295
}
293
296
294
297
fn remove_track ( & mut self ) {
295
298
todo ! ( )
296
299
}
297
300
298
301
fn track_total ( & self ) -> Option < u32 > {
299
- self . get ( MatroskaTagKey (
300
- TargetType :: Album ,
301
- Cow :: Borrowed ( "TOTAL_PARTS" ) ,
302
- ) )
303
- . and_then ( SimpleTag :: get_str)
304
- . and_then ( |val| val. parse :: < u32 > ( ) . ok ( ) )
302
+ self . get ( TargetType :: Album , TagName :: TotalParts )
303
+ . and_then ( SimpleTag :: get_str)
304
+ . and_then ( |val| val. parse :: < u32 > ( ) . ok ( ) )
305
305
}
306
306
307
- fn set_track_total ( & mut self , _value : u32 ) {
308
- todo ! ( )
307
+ fn set_track_total ( & mut self , value : u32 ) {
308
+ let tag = SimpleTag :: new ( TagName :: TotalParts , value. to_string ( ) ) ;
309
+ self . push ( TargetType :: Album , tag) ;
309
310
}
310
311
311
312
fn remove_track_total ( & mut self ) {
312
313
todo ! ( )
313
314
}
314
315
316
+ fn disk ( & self ) -> Option < u32 > {
317
+ self . get ( TargetType :: Edition , TagName :: PartNumber )
318
+ . and_then ( SimpleTag :: get_str)
319
+ . and_then ( |val| val. parse :: < u32 > ( ) . ok ( ) )
320
+ }
321
+
322
+ fn set_disk ( & mut self , value : u32 ) {
323
+ let tag = SimpleTag :: new ( TagName :: PartNumber , value. to_string ( ) ) ;
324
+ self . push ( TargetType :: Edition , tag) ;
325
+ }
326
+
327
+ fn remove_disk ( & mut self ) { }
328
+
329
+ fn disk_total ( & self ) -> Option < u32 > {
330
+ self . get ( TargetType :: Edition , TagName :: TotalParts )
331
+ . and_then ( SimpleTag :: get_str)
332
+ . and_then ( |val| val. parse :: < u32 > ( ) . ok ( ) )
333
+ }
334
+
335
+ fn set_disk_total ( & mut self , value : u32 ) {
336
+ let tag = SimpleTag :: new ( TagName :: TotalParts , value. to_string ( ) ) ;
337
+ self . push ( TargetType :: Edition , tag) ;
338
+ }
339
+
340
+ fn remove_disk_total ( & mut self ) { }
341
+
315
342
fn year ( & self ) -> Option < u32 > {
316
343
// `DATE_RELEASED`
317
344
todo ! ( )
@@ -441,15 +468,14 @@ impl From<crate::tag::Tag> for MatroskaTag {
441
468
}
442
469
}
443
470
444
- pub ( crate ) struct MatroskaTagRef < ' a >
445
- {
471
+ pub ( crate ) struct MatroskaTagRef < ' a > {
446
472
pub ( crate ) tags : Vec < TagRef < ' a > > ,
447
473
}
448
474
449
475
impl < ' a > From < & ' a MatroskaTag > for MatroskaTagRef < ' a > {
450
476
fn from ( value : & ' a MatroskaTag ) -> Self {
451
477
Self {
452
- tags : value. tags . iter ( ) . map ( Into :: into) . collect :: < Vec < _ > > ( )
478
+ tags : value. tags . iter ( ) . map ( Into :: into) . collect :: < Vec < _ > > ( ) ,
453
479
}
454
480
}
455
481
}
@@ -459,7 +485,9 @@ impl<'a> From<&'a crate::tag::Tag> for MatroskaTagRef<'static> {
459
485
let mut mapped_tags: HashMap < TargetType , Vec < Cow < ' static , SimpleTag < ' static > > > > =
460
486
HashMap :: new ( ) ;
461
487
for item in & value. items {
462
- if let Some ( ( simple_tag, target_type) ) = generic:: simple_tag_for_item ( Cow :: Borrowed ( item) ) {
488
+ if let Some ( ( simple_tag, target_type) ) =
489
+ generic:: simple_tag_for_item ( Cow :: Borrowed ( item) )
490
+ {
463
491
mapped_tags
464
492
. entry ( target_type)
465
493
. or_default ( )
@@ -472,16 +500,14 @@ impl<'a> From<&'a crate::tag::Tag> for MatroskaTagRef<'static> {
472
500
. map ( |( target_type, simple_tags) | TagRef {
473
501
targets : TargetDescriptor :: Basic ( target_type) ,
474
502
simple_tags,
475
- } ) . collect :: < Vec < _ > > ( ) ;
503
+ } )
504
+ . collect :: < Vec < _ > > ( ) ;
476
505
477
- Self {
478
- tags
479
- }
506
+ Self { tags }
480
507
}
481
508
}
482
509
483
- impl < ' a > MatroskaTagRef < ' a >
484
- {
510
+ impl < ' a > MatroskaTagRef < ' a > {
485
511
pub ( crate ) fn write_to < F > ( & mut self , file : & mut F , write_options : WriteOptions ) -> Result < ( ) >
486
512
where
487
513
F : FileLike ,
0 commit comments