2
2
using System . Collections . Generic ;
3
3
using TagLib ;
4
4
5
- public class BatchSet
5
+ namespace BatchSet ;
6
+
7
+ public class Program
6
8
{
7
- private enum Mode {
8
- Tag , Value , File
9
+ enum Mode {
10
+ Tag ,
11
+ Value ,
12
+ File
9
13
}
10
-
14
+
11
15
public static void Main ( string [ ] args )
12
16
{
13
17
if ( args . Length < 3 ) {
14
18
Console . Error . WriteLine ( "USAGE: BatchSet.exe -tag value [-tag2 value ...] File1 [File2 ...]" ) ;
15
19
return ;
16
20
}
17
-
21
+
18
22
Mode mode = Mode . Tag ;
19
- List < string > files = new List < string > ( ) ;
20
- Dictionary < string , string > tags = new Dictionary < string , string > ( ) ;
21
-
23
+ var files = new List < string > ( ) ;
24
+ var tags = new Dictionary < string , string > ( ) ;
25
+
22
26
string tag = null ;
23
-
27
+
24
28
foreach ( string str in args ) {
25
29
if ( mode == Mode . Tag ) {
26
30
if ( str [ 0 ] == '-' ) {
@@ -30,30 +34,30 @@ public static void Main(string [] args)
30
34
tag = str . Substring ( 1 ) ;
31
35
mode = Mode . Value ;
32
36
}
33
-
37
+
34
38
continue ;
35
39
}
36
40
mode = Mode . File ;
37
41
}
38
-
42
+
39
43
if ( mode == Mode . Value ) {
40
44
if ( ! tags . ContainsKey ( tag ) )
41
45
tags . Add ( tag , str ) ;
42
46
mode = Mode . Tag ;
43
47
continue ;
44
48
}
45
-
49
+
46
50
if ( mode == Mode . File )
47
51
files . Add ( str ) ;
48
52
}
49
-
53
+
50
54
foreach ( string filename in files ) {
51
- TagLib . File file = TagLib . File . Create ( filename ) ;
55
+ using var file = TagLib . File . Create ( filename ) ;
52
56
if ( file == null )
53
57
continue ;
54
-
55
- Console . WriteLine ( "Updating Tags For: " + filename ) ;
56
-
58
+
59
+ Console . WriteLine ( $ "Updating Tags For: { filename } " ) ;
60
+
57
61
foreach ( string key in tags . Keys ) {
58
62
string value = tags [ key ] ;
59
63
try {
@@ -63,19 +67,15 @@ public static void Main(string [] args)
63
67
if ( number == 1 ) {
64
68
file . RemoveTags ( TagTypes . Id3v2 ) ;
65
69
} else {
66
- TagLib . Id3v2 . Tag v2 =
67
- file . GetTag ( TagTypes . Id3v2 , true )
68
- as TagLib . Id3v2 . Tag ;
69
-
70
- if ( v2 != null )
70
+ if ( file . GetTag ( TagTypes . Id3v2 , true ) is TagLib . Id3v2 . Tag v2 )
71
71
v2 . Version = number ;
72
72
}
73
73
break ;
74
74
case "album" :
75
75
file . Tag . Album = value ;
76
76
break ;
77
77
case "artists" :
78
- file . Tag . AlbumArtists = value . Split ( new char [ ] { ';' } ) ;
78
+ file . Tag . AlbumArtists = value . Split ( [ ';' ] ) ;
79
79
break ;
80
80
case "comment" :
81
81
file . Tag . Comment = value ;
@@ -84,7 +84,7 @@ public static void Main(string [] args)
84
84
file . Tag . Lyrics = value ;
85
85
break ;
86
86
case "composers" :
87
- file . Tag . Composers = value . Split ( new char [ ] { ';' } ) ;
87
+ file . Tag . Composers = value . Split ( [ ';' ] ) ;
88
88
break ;
89
89
case "disc" :
90
90
file . Tag . Disc = uint . Parse ( value ) ;
@@ -93,10 +93,10 @@ public static void Main(string [] args)
93
93
file . Tag . DiscCount = uint . Parse ( value ) ;
94
94
break ;
95
95
case "genres" :
96
- file . Tag . Genres = value . Split ( new char [ ] { ';' } ) ;
96
+ file . Tag . Genres = value . Split ( [ ';' ] ) ;
97
97
break ;
98
98
case "performers" :
99
- file . Tag . Performers = value . Split ( new char [ ] { ';' } ) ;
99
+ file . Tag . Performers = value . Split ( [ ';' ] ) ;
100
100
break ;
101
101
case "title" :
102
102
file . Tag . Title = value ;
@@ -111,20 +111,20 @@ public static void Main(string [] args)
111
111
file . Tag . Year = uint . Parse ( value ) ;
112
112
break ;
113
113
case "pictures" :
114
- List < Picture > pics = new List < Picture > ( ) ;
114
+ var pics = new List < Picture > ( ) ;
115
115
if ( ! string . IsNullOrEmpty ( value ) )
116
- foreach ( string path in value . Split ( new char [ ] { ';' } ) ) {
116
+ foreach ( string path in value . Split ( [ ';' ] ) ) {
117
117
pics . Add ( new Picture ( path ) ) ;
118
118
}
119
119
file . Tag . Pictures = pics . ToArray ( ) ;
120
120
break ;
121
121
}
122
122
} catch ( Exception e ) {
123
- Console . WriteLine ( "Error setting tag " + key + " :") ;
123
+ Console . WriteLine ( $ "Error setting tag { key } :") ;
124
124
Console . WriteLine ( e ) ;
125
125
}
126
126
}
127
-
127
+
128
128
file . Save ( ) ;
129
129
}
130
130
}
0 commit comments