/
Tag.cs
943 lines (871 loc) · 30.3 KB
/
Tag.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
//
// Tag.cs: This abstract class provides generic access to standard tag
// features. All tag types will extend this class.
//
// Author:
// Brian Nickel (brian.nickel@gmail.com)
//
// Original Source:
// tag.cpp from TagLib
//
// Copyright (C) 2005-2007 Brian Nickel
// Copyright (C) 2003 Scott Wheeler
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License version
// 2.1 as published by the Free Software Foundation.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
//
using System;
namespace TagLib {
/// <summary>
/// Indicates the tag types used by a file.
/// </summary>
[Flags]
public enum TagTypes : uint
{
/// <summary>
/// No tag types.
/// </summary>
None = 0x00000000,
/// <summary>
/// Xiph's Vorbis Comment
/// </summary>
Xiph = 0x00000001,
/// <summary>
/// ID3v1 Tag
/// </summary>
Id3v1 = 0x00000002,
/// <summary>
/// ID3v2 Tag
/// </summary>
Id3v2 = 0x00000004,
/// <summary>
/// APE Tag
/// </summary>
Ape = 0x00000008,
/// <summary>
/// Apple's ILST Tag Format
/// </summary>
Apple = 0x00000010,
/// <summary>
/// ASF Tag
/// </summary>
Asf = 0x00000020,
/// <summary>
/// Standard RIFF INFO List Tag
/// </summary>
RiffInfo = 0x00000040,
/// <summary>
/// RIFF Movie ID List Tag
/// </summary>
MovieId = 0x00000080,
/// <summary>
/// DivX Tag
/// </summary>
DivX = 0x00000100,
/// <summary>
/// FLAC Metadata Blocks Tag
/// </summary>
FlacMetadata = 0x00000200,
/// <summary>
/// All tag types.
/// </summary>
AllTags = 0xFFFFFFFF
}
/// <summary>
/// This abstract class provides generic access to standard tag
/// features. All tag types will extend this class.
/// </summary>
/// <remarks>
/// Because not every tag type supports the same features, it may be
/// useful to check that the value is stored by re-reading the
/// property after it is stored.
/// </remarks>
public abstract class Tag
{
/// <summary>
/// Gets the tag types contained in the current instance.
/// </summary>
/// <value>
/// A bitwise combined <see cref="TagLib.TagTypes" />
/// containing the tag types contained in the current
/// instance.
/// </value>
/// <remarks>
/// For a standard tag, the value should be intuitive. For
/// example, <see cref="TagLib.Id3v2.Tag" /> objects have a
/// value of <see cref="TagLib.TagTypes.Id3v2" />. However,
/// for tags of type <see cref="TagLib.CombinedTag" /> may
/// contain multiple or no types.
/// </remarks>
public abstract TagTypes TagTypes {get;}
/// <summary>
/// Gets and sets the title for the media described by the
/// current instance.
/// </summary>
/// <value>
/// A <see cref="string" /> object containing the title for
/// the media described by the current instance or <see
/// langword="null" /> if no value is present.
/// </value>
/// <remarks>
/// The title is most commonly the name of the song or
/// episode or a movie title. For example, "Daydream
/// Believer" (a song by the Monkies), "Space Seed" (an
/// episode of Star Trek), or "Harold and Kumar Go To White
/// Castle" (a movie).
/// </remarks>
public virtual string Title {
get {return null;}
set {}
}
/// <summary>
/// Gets and sets the performers or artists who performed in
/// the media described by the current instance.
/// </summary>
/// <value>
/// A <see cref="string[]" /> containing the performers or
/// artists who performed in the media described by the
/// current instance or an empty array if no value is
/// present.
/// </value>
/// <remarks>
/// <para>This field is most commonly called "Artists" in
/// media applications and should be used to represent each
/// of the artists appearing in the media. It can be simple
/// in theform of "The Beatles", or more complicated in the
/// form of "John Lennon, Paul McCartney, George Harrison,
/// Pete Best", depending on the preferences of the listener
/// and the degree to which they organize their media
/// collection.</para>
/// <para>As the preference of the user may vary,
/// applications should not try to limit the user in what
/// choice they may make.</para>
/// </remarks>
public virtual string [] Performers {
get {return new string [] {};}
set {}
}
/// <summary>
/// Gets and sets the band or artist who is credited in the
/// creation of the entire album or collection containing the
/// media described by the current instance.
/// </summary>
/// <value>
/// A <see cref="string[]" /> containing the band or artist
/// who is credited in the creation of the entire album or
/// collection containing the media described by the current
/// instance or an empty array if no value is present.
/// </value>
/// <remarks>
/// <para>This field is typically optional but aids in the
/// sorting of compilations or albums with multiple artists.
/// For example, if an album has several artists, sorting by
/// artist will split up the album and sorting by album will
/// split up albums by the same artist. Having a single album
/// artist for an entire album will solve this
/// problem.</para>
/// <para>As this value is to be used as a sorting key, it
/// should be used with less variation than <see
/// cref="Performers" />. Where performers can be broken into
/// muliple artist it is best to stick with a single band
/// name. For example, "The Beatles".</para>
/// </remarks>
public virtual string [] AlbumArtists {
get {return new string [] {};}
set {}
}
/// <summary>
/// Gets and sets the composers of the media represented by
/// the current instance.
/// </summary>
/// <value>
/// A <see cref="string[]" /> containing the composers of the
/// media represented by the current instance or an empty
/// array if no value is present.
/// </value>
/// <remarks>
/// <para>This field represents the composers, song writers,
/// script writers, or persons who claim authorship of the
/// media.</para>
/// </remarks>
public virtual string [] Composers {
get {return new string [] {};}
set {}
}
/// <summary>
/// Gets and sets the album of the media represented by the
/// current instance.
/// </summary>
/// <value>
/// A <see cref="string" /> object containing the album of
/// the media represented by the current instance or <see
/// langword="null" /> if no value is present.
/// </value>
/// <remarks>
/// <para>This field represents the name of the album the
/// media belongs to. In the case of a boxed set, it should
/// be the name of the entire set rather than the individual
/// disc.</para>
/// <para>For example, "Rubber Soul" (an album by the
/// Beatles), "The Sopranos: Complete First Season" (a boxed
/// set of TV episodes), or "Back To The Future Trilogy" (a
/// boxed set of movies).</para>
/// </remarks>
public virtual string Album {
get {return null;}
set {}
}
/// <summary>
/// Gets and sets a user comment on the media represented by
/// the current instance.
/// </summary>
/// <value>
/// A <see cref="string" /> object containing user comments
/// on the media represented by the current instance or <see
/// langword="null" /> if no value is present.
/// </value>
/// <remarks>
/// <para>This field should be used to store user notes and
/// comments. There is no constraint on what text can be
/// stored here, but it should not contain program
/// information.</para>
/// <para>Because this field contains notes that the user
/// might think of while listening to the media, it may be
/// useful for an application to make this field easily
/// accessible, perhaps even including it in the main
/// interface.</para>
/// </remarks>
public virtual string Comment {
get {return null;}
set {}
}
/// <summary>
/// Gets and sets the genres of the media represented by the
/// current instance.
/// </summary>
/// <value>
/// A <see cref="string[]" /> containing the genres of the
/// media represented by the current instance or an empty
/// array if no value is present.
/// </value>
/// <remarks>
/// <para>This field represents genres that apply to the song
/// or album. This is often used for filtering media.</para>
/// <para>A list of common audio genres as popularized by
/// ID3v1, are stored in <see cref="Genres.Audio" />.
/// Additionally, <see cref="Genres.Video" /> contains video
/// genres as used by DivX.</para>
/// </remarks>
public virtual string [] Genres {
get {return new string [] {};}
set {}
}
/// <summary>
/// Gets and sets the year that the media represented by the
/// current instance was recorded.
/// </summary>
/// <value>
/// A <see cref="uint" /> containing the year that the media
/// represented by the current instance was created or zero
/// if no value is present.
/// </value>
/// <remarks>
/// <para>Years greater than 9999 cannot be stored by most
/// tagging formats and will be cleared if a higher value is
/// set.</para>
/// <para>Some tagging formats store higher precision dates
/// which will be truncated when this property is set. Format
/// specific implementations are necessary access the higher
/// precision values.</para>
/// </remarks>
public virtual uint Year {
get {return 0;}
set {}
}
/// <summary>
/// Gets and sets the position of the media represented by
/// the current instance in its containing album.
/// </summary>
/// <value>
/// A <see cref="uint" /> containing the position of the
/// media represented by the current instance in its
/// containing album or zero if not specified.
/// </value>
/// <remarks>
/// <para>This value should be the same as is listed on the
/// album cover and no more than <see cref="TrackCount"
/// /> if <see cref="TrackCount" /> is non-zero.</para>
/// </remarks>
public virtual uint Track {
get {return 0;}
set {}
}
/// <summary>
/// Gets and sets the number of tracks in the album
/// containing the media represented by the current instance.
/// </summary>
/// <value>
/// A <see cref="uint" /> containing the number of tracks in
/// the album containing the media represented by the current
/// instance or zero if not specified.
/// </value>
/// <remarks>
/// <para>If non-zero, this value should be at least equal to
/// <see cref="Track" />. If <see cref="Track" /> is zero,
/// this value should also be zero.</para>
/// </remarks>
public virtual uint TrackCount {
get {return 0;}
set {}
}
/// <summary>
/// Gets and sets the number of the disc containing the media
/// represented by the current instance in the boxed set.
/// </summary>
/// <value>
/// A <see cref="uint" /> containing the number of the disc
/// containing the media represented by the current instance
/// in the boxed set.
/// </value>
/// <remarks>
/// <para>This value should be the same as is number that
/// appears on the disc. For example, if the disc is the
/// first of three, the value should be <c>1</c>. It should
/// be no more than <see cref="DiscCount" /> if <see
/// cref="DiscCount" /> is non-zero.</para>
/// </remarks>
public virtual uint Disc {
get {return 0;}
set {}
}
/// <summary>
/// Gets and sets the number of discs in the boxed set
/// containing the media represented by the current instance.
/// </summary>
/// <value>
/// A <see cref="uint" /> containing the number of discs in
/// the boxed set containing the media represented by the
/// current instance or zero if not specified.
/// </value>
/// <remarks>
/// <para>If non-zero, this value should be at least equal to
/// <see cref="Disc" />. If <see cref="Disc" /> is zero,
/// this value should also be zero.</para>
/// </remarks>
public virtual uint DiscCount {
get {return 0;}
set {}
}
/// <summary>
/// Gets and sets the lyrics or script of the media
/// represented by the current instance.
/// </summary>
/// <value>
/// A <see cref="string" /> object containing the lyrics or
/// script of the media represented by the current instance
/// or <see langword="null" /> if no value is present.
/// </value>
/// <remarks>
/// <para>This field contains a plain text representation of
/// the lyrics or scripts with line breaks and whitespace
/// being the only formatting marks.</para>
/// <para>Some formats support more advances lyrics, like
/// synchronized lyrics, but those must be accessed using
/// format specific implementations.</para>
/// </remarks>
public virtual string Lyrics {
get {return null;}
set {}
}
/// <summary>
/// Gets and sets the grouping on the album which the media
/// in the current instance belongs to.
/// </summary>
/// <value>
/// A <see cref="string" /> object containing the grouping on
/// the album which the media in the current instance belongs
/// to or <see langword="null" /> if no value is present.
/// </value>
/// <remarks>
/// <para>This field contains a non-physical grouping to
/// which the track belongs. In classical music, this could
/// be a movement. It could also be parts of a series like
/// "Introduction", "Closing Remarks", etc.</para>
/// </remarks>
public virtual string Grouping {
get {return null;}
set {}
}
/// <summary>
/// Gets and sets the number of beats per minute in the audio
/// of the media represented by the current instance.
/// </summary>
/// <value>
/// A <see cref="uint" /> containing the number of beats per
/// minute in the audio of the media represented by the
/// current instance, or zero if not specified.
/// </value>
/// <remarks>
/// <para>This field is useful for DJ's who are trying to
/// match songs. It should be calculated from the audio or
/// pulled from a database.</para>
/// </remarks>
public virtual uint BeatsPerMinute {
get {return 0;}
set {}
}
/// <summary>
/// Gets and sets the conductor or director of the media
/// represented by the current instance.
/// </summary>
/// <value>
/// A <see cref="string" /> object containing the conductor
/// or director of the media represented by the current
/// instance or <see langref="null" /> if no value present.
/// </value>
/// <remarks>
/// <para>This field is most useful for organizing classical
/// music and movies.</para>
/// </remarks>
public virtual string Conductor {
get {return null;}
set {}
}
/// <summary>
/// Gets and sets the copyright information for the media
/// represented by the current instance.
/// </summary>
/// <value>
/// A <see cref="string" /> object containing the copyright
/// information for the media represented by the current
/// instance or <see langword="null" /> if no value present.
/// </value>
/// <remarks>
/// <para>This field should be used for storing copyright
/// information. It may be useful to show this information
/// somewhere in the program while the media is
/// playing.</para>
/// <para>Players should not support editing this field, but
/// media creation tools should definitely allow
/// modification.</para>
/// </remarks>
public virtual string Copyright {
get {return null;}
set {}
}
/// <summary>
/// Gets and sets a collection of pictures associated with
/// the media represented by the current instance.
/// </summary>
/// <value>
/// A <see cref="IPicture[]" /> containing a collection of
/// pictures associated with the media represented by the
/// current instance or an empty array if none are present.
/// </value>
/// <remarks>
/// <para>Typically, this value is used to store an album
/// cover or icon to use for the file, but it is capable of
/// holding any type of image, including pictures of the
/// band, the recording studio, the concert, etc.</para>
/// </remarks>
public virtual IPicture [] Pictures {
get {return new Picture [] {};}
set {}
}
/// <summary>
/// Gets and sets the same value as <see cref="Performers"
/// />.
/// </summary>
/// <value>
/// The same value as <see cref="Performers" />.
/// </value>
/// <remarks>
/// This property exists to aleviate confusion. Use <see
/// cref="Performers" /> for track artists and <see
/// cref="AlbumArtists" /> for album artists.
/// </remarks>
[Obsolete("For album artists use AlbumArtists. For track artists, use Performers")]
public virtual string [] Artists {
get {return Performers;}
set {Performers = value;}
}
/// <summary>
/// Gets the same value as <see cref="FirstPerformer" />.
/// </summary>
/// <value>
/// The same value as <see cref="FirstPerformer" />.
/// </value>
/// <remarks>
/// This property exists to aleviate confusion. Use <see
/// cref="FirstPerformer" /> for track artists and <see
/// cref="FirstAlbumArtist" /> for album artists.
/// </remarks>
[Obsolete("For album artists use FirstAlbumArtist. For track artists, use FirstPerformer")]
public string FirstArtist {
get {return FirstPerformer;}
}
/// <summary>
/// Gets the first value contained in <see
/// cref="AlbumArtists" />.
/// </summary>
/// <value>
/// The first <see cref="string" /> object in <see
/// cref="AlbumArtists" />, or <see langword="null" /> is it
/// contains no values.
/// </value>
/// <remarks>
/// This property is provided for convenience. Use <see
/// cref="AlbumArtists" /> to set the value.
/// </remarks>
public string FirstAlbumArtist {
get {return FirstInGroup(AlbumArtists);}
}
/// <summary>
/// Gets the first value contained in <see
/// cref="Performers" />.
/// </summary>
/// <value>
/// The first <see cref="string" /> object in <see
/// cref="Performers" />, or <see langword="null" /> is it
/// contains no values.
/// </value>
/// <remarks>
/// This property is provided for convenience. Use <see
/// cref="Performers" /> to set the value.
/// </remarks>
public string FirstPerformer {
get {return FirstInGroup(Performers);}
}
/// <summary>
/// Gets the first value contained in <see
/// cref="Composers" />.
/// </summary>
/// <value>
/// The first <see cref="string" /> object in <see
/// cref="Composers" />, or <see langword="null" /> is it
/// contains no values.
/// </value>
/// <remarks>
/// This property is provided for convenience. Use <see
/// cref="Composers" /> to set the value.
/// </remarks>
public string FirstComposer {
get {return FirstInGroup(Composers);}
}
/// <summary>
/// Gets the first value contained in <see cref="Genres" />.
/// </summary>
/// <value>
/// The first <see cref="string" /> object in <see
/// cref="Genres" />, or <see langword="null" /> is it
/// contains no values.
/// </value>
/// <remarks>
/// This property is provided for convenience. Use <see
/// cref="Genres" /> to set the value.
/// </remarks>
public string FirstGenre {
get {return FirstInGroup(Genres);}
}
/// <summary>
/// Gets the same value as <see cref="JoinedPerformers" />.
/// </summary>
/// <value>
/// The same value as <see cref="JoinedPerformers" />.
/// </value>
/// <remarks>
/// This property exists to aleviate confusion. Use <see
/// cref="JoinedPerformers" /> for track artists and <see
/// cref="JoinedAlbumArtists" /> for album artists.
/// </remarks>
[Obsolete("For album artists use JoinedAlbumArtists. For track artists, use JoinedPerformers")]
public string JoinedArtists {
get {return JoinedPerformers;}
}
/// <summary>
/// Gets a semicolon separated string containing the values
/// in <see cref="AlbumArtists" />.
/// </summary>
/// <value>
/// A semicolon separated <see cref="string" /> object
/// containing the values in <see cref="AlbumArtists" />.
/// </value>
/// <remarks>
/// This property is provided for convenience. Use <see
/// cref="AlbumArtists" /> to set the value.
/// </remarks>
public string JoinedAlbumArtists {
get {return JoinGroup(AlbumArtists);}
}
/// <summary>
/// Gets a semicolon separated string containing the values
/// in <see cref="Performers" />.
/// </summary>
/// <value>
/// A semicolon separated <see cref="string" /> object
/// containing the values in <see cref="Performers" />.
/// </value>
/// <remarks>
/// This property is provided for convenience. Use <see
/// cref="Performers" /> to set the value.
/// </remarks>
public string JoinedPerformers {
get {return JoinGroup(Performers);}
}
/// <summary>
/// Gets a semicolon separated string containing the values
/// in <see cref="Composers" />.
/// </summary>
/// <value>
/// A semicolon separated <see cref="string" /> object
/// containing the values in <see cref="Composers" />.
/// </value>
/// <remarks>
/// This property is provided for convenience. Use <see
/// cref="Composers" /> to set the value.
/// </remarks>
public string JoinedComposers {
get {return JoinGroup(Composers);}
}
/// <summary>
/// Gets a semicolon separated string containing the values
/// in <see cref="Genres" />.
/// </summary>
/// <value>
/// A semicolon separated <see cref="string" /> object
/// containing the values in <see cref="Genres" />.
/// </value>
/// <remarks>
/// This property is provided for convenience. Use <see
/// cref="Genres" /> to set the value.
/// </remarks>
public string JoinedGenres {
get {return JoinGroup(Genres);}
}
/// <summary>
/// Gets the first string in an array.
/// </summary>
/// <param name="group">
/// A <see cref="string[]" /> to get the first string from.
/// </param>
/// <returns>
/// The first <see cref="string" /> object contained in
/// <paramref name="group" />, or <see langword="null" /> if
/// the array is <see langword="null" /> or empty.
/// </returns>
private static string FirstInGroup(string [] group)
{
return group == null || group.Length == 0 ?
null : group [0];
}
/// <summary>
/// Joins a array of strings into a single, semicolon
/// separated, string.
/// </summary>
/// <param name="group">
/// A <see cref="string[]" /> containing values to combine.
/// </param>
/// <returns>
/// A semicolon separated <see cref="string" /> object
/// containing the values from <paramref name="group" />.
/// </returns>
protected static string JoinGroup (string [] group)
{
if (group == null)
return null;
return string.Join ("; ", group);
}
/// <summary>
/// Gets whether or not the current instance is empty.
/// </summary>
/// <value>
/// <see langword="true" /> if the current instance does not
/// any values. Otherwise <see langword="false" />.
/// </value>
/// <remarks>
/// In the default implementation, this checks the values
/// supported by <see cref="Tag" />, but it may be extended
/// by child classes to support other values.
/// </remarks>
public virtual bool IsEmpty {
get {
return IsNullOrLikeEmpty (Title) &&
IsNullOrLikeEmpty (Grouping) &&
IsNullOrLikeEmpty (AlbumArtists) &&
IsNullOrLikeEmpty (Performers) &&
IsNullOrLikeEmpty (Composers) &&
IsNullOrLikeEmpty (Conductor) &&
IsNullOrLikeEmpty (Copyright) &&
IsNullOrLikeEmpty (Album) &&
IsNullOrLikeEmpty (Comment) &&
IsNullOrLikeEmpty (Genres) &&
Year == 0 &&
BeatsPerMinute == 0 &&
Track == 0 &&
TrackCount == 0 &&
Disc == 0 &&
DiscCount == 0;
}
}
/// <summary>
/// Clears the values stored in the current instance.
/// </summary>
/// <remarks>
/// The clearing procedure is format specific and should
/// clear all values.
/// </remarks>
public abstract void Clear ();
/// <summary>
/// Copies all standard values from one tag to another,
/// optionally overwriting existing values.
/// </summary>
/// <param name="source">
/// A <see cref="Tag" /> object containing the source tag to
/// copy the values from.
/// </param>
/// <param name="target">
/// A <see cref="Tag" /> object containing the target tag to
/// copy values to.
/// </param>
/// <param name="overwrite">
/// A <see cref="bool" /> specifying whether or not to copy
/// values over existing one.
/// </param>
/// <remarks>
/// <para>This method only copies the most basic values,
/// those contained in this class, between tags. To copy
/// format specific tags, or additional details, additional
/// implementations need to be applied. For example, copying
/// from one <see cref="TagLib.Id3v2.Tag" /> to another:
/// <c>foreach (TagLib.Id3v2.Frame frame in old_tag)
/// new_tag.AddFrame (frame);</c></para>
/// </remarks>
/// <exception cref="ArgumentNullException">
/// <paramref name="source" /> or <paramref name="target" />
/// is <see langword="null" />.
/// </exception>
[Obsolete("Use Tag.CopyTo(Tag,bool)")]
public static void Duplicate (Tag source, Tag target,
bool overwrite)
{
if (source == null)
throw new ArgumentNullException ("source");
if (target == null)
throw new ArgumentNullException ("target");
source.CopyTo (target, overwrite);
}
/// <summary>
/// Copies the values from the current instance to another
/// <see cref="TagLib.Tag" />, optionally overwriting
/// existing values.
/// </summary>
/// <param name="target">
/// A <see cref="Tag" /> object containing the target tag to
/// copy values to.
/// </param>
/// <param name="overwrite">
/// A <see cref="bool" /> specifying whether or not to copy
/// values over existing one.
/// </param>
/// <remarks>
/// <para>This method only copies the most basic values when
/// copying between different tag formats, however, if
/// <paramref name="target" /> is of the same type as the
/// current instance, more advanced copying may be done.
/// For example, <see cref="TagLib.Id3v2.Tag" /> will copy
/// all of its frames to another tag.</para>
/// </remarks>
/// <exception cref="ArgumentNullException">
/// <paramref name="target" /> is <see langword="null" />.
/// </exception>
public virtual void CopyTo (Tag target, bool overwrite)
{
if (target == null)
throw new ArgumentNullException ("target");
if (overwrite || IsNullOrLikeEmpty (target.Title))
target.Title = Title;
if (overwrite || IsNullOrLikeEmpty (target.AlbumArtists))
target.AlbumArtists = AlbumArtists;
if (overwrite || IsNullOrLikeEmpty (target.Performers))
target.Performers = Performers;
if (overwrite || IsNullOrLikeEmpty (target.Composers))
target.Composers = Composers;
if (overwrite || IsNullOrLikeEmpty (target.Album))
target.Album = Album;
if (overwrite || IsNullOrLikeEmpty (target.Comment))
target.Comment = Comment;
if (overwrite || IsNullOrLikeEmpty (target.Genres))
target.Genres = Genres;
if (overwrite || target.Year == 0)
target.Year = Year;
if (overwrite || target.Track == 0)
target.Track = Track;
if (overwrite || target.TrackCount == 0)
target.TrackCount = TrackCount;
if (overwrite || target.Disc == 0)
target.Disc = Disc;
if (overwrite || target.DiscCount == 0)
target.DiscCount = DiscCount;
if (overwrite || target.BeatsPerMinute == 0)
target.BeatsPerMinute = BeatsPerMinute;
if (overwrite || IsNullOrLikeEmpty (target.Grouping))
target.Grouping = Grouping;
if (overwrite || IsNullOrLikeEmpty (target.Conductor))
target.Conductor = Conductor;
if (overwrite || IsNullOrLikeEmpty (target.Copyright))
target.Conductor = Copyright;
}
/// <summary>
/// Checks if a <see cref="string" /> is <see langword="null"
/// /> or contains only whitespace characters.
/// </summary>
/// <param name="value">
/// A <see cref="string" /> object to check.
/// </param>
/// <returns>
/// <see langword="true" /> if the string is <see
/// langword="null" /> or contains only whitespace
/// characters. Otherwise <see langword="false" />.
/// </returns>
private static bool IsNullOrLikeEmpty (string value)
{
return value == null || value.Trim ().Length == 0;
}
/// <summary>
/// Checks if all the strings in the array return <see
/// langword="true" /> with <see
/// cref="IsNullOrLikeEmpty(string)" /> or if the array is
/// <see langword="null" /> or is empty.
/// </summary>
/// <param name="value">
/// A <see cref="string[]" /> to check the contents of.
/// </param>
/// <returns>
/// <see langword="true" /> if the array is <see
/// langword="null" /> or empty, or all elements return <see
/// langword="true" /> for <see
/// cref="IsNullOrLikeEmpty(string)" />. Otherwise <see
/// langword="false" />.
/// </returns>
private static bool IsNullOrLikeEmpty (string [] value)
{
if (value == null)
return true;
foreach (string s in value)
if (!IsNullOrLikeEmpty (s))
return false;
return true;
}
}
}