-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTagToolbox0.3.vbs
503 lines (465 loc) · 16.7 KB
/
TagToolbox0.3.vbs
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
'
' MediaMonkey Script
'
' NAME: TagToolbox
'
' AUTHOR: C. Seeling
' DATE : 2020-09-29
'
' ENTRY Point is showFormTlBx
''''''''''''''''''''''''''''
'' Global Variables ''
''''''''''''''''''''''
Btny = 20
Btnx = 90
' various genres or lanuage keywords for dropdown list
Keywords = Array(_
"= Languages =",_
"_Instrumental",_
"_mul",_
"_unknown",_
"Chinese Cantonese",_
"French",_
"",_
"= Genres =",_
"_cover",_
"_mp3.320")
"_flac",_
"_HQcopy",_
'''''''''''''''''''''''''''
'' GUI Tag Toolbox ''
'''''''''''''''''''''''''''
Dim FormTlBx : Set FormTlBx = SDB.UI.NewForm
FormTlBx.Common.SetRect 0, 0, 193, 250
FormTlBx.Caption = "Tag Toolbox"
FormTlBx.StayOnTop = True
FormTlBx.FormPosition = 4
Set PnlTag=SDB.UI.NewTranspPanel(FormTlBx)
PnlTag.Common.SetRect 0,0,210, 90
PnlTag.Common.ControlName="PanelTags"
Set BtnGerman = SDB.UI.NewButton(PnlTag)
BtnGerman.Caption = "German"
BtnGerman.Common.SetRect 0, 0, Btnx, Btny
Script.RegisterEvent BtnGerman, "OnClick", "LangGerman"
Set BtnEnglish = SDB.UI.NewButton(PnlTag)
BtnEnglish.Caption = "English"
BtnEnglish.Common.SetRect 0, 20, Btnx, Btny
Script.RegisterEvent BtnEnglish, "OnClick", "LangEnglish"
Set BtnChineseMandarin = SDB.UI.NewButton(PnlTag)
BtnChineseMandarin.Caption = "Chinese Mandarin"
BtnChineseMandarin.Common.SetRect 90, 0, Btnx, Btny
Script.RegisterEvent BtnChineseMandarin, "OnClick", "LangChineseMandarin"
Set BtnJapanese = SDB.UI.NewButton(PnlTag)
BtnJapanese.Caption = "Japanese"
BtnJapanese.Common.SetRect 90, 20, Btnx, Btny
Script.RegisterEvent BtnJapanese, "OnClick", "LangJapanese"
Set DDetc = SDB.UI.NewDropDown(PnlTag)
DDetc.Common.SetRect 0, 40, Btnx*2, Btny
For Each keyword In Keywords
DDetc.AddItem keyword
Next
'OnSelect
'OnChange
Script.RegisterEvent DDetc, "OnChange", "DDetcOnChange"
Script.RegisterEvent DDetc, "OnSelect", "DDetcOnChange"
Set LblDescription = SDB.UI.NewLabel(PnlTag)
LblDescription.Caption = "for multiple tags delimiter = ;"
LblDescription.Common.SetRect 5, DDetc.Common.Top+DDetc.Common.Height+2, 180, 20
LblDescription.Multiline = True
Set PnlCat=SDB.UI.NewTranspPanel(FormTlBx)
PnlCat.Common.SetRect 0,PnlTag.Common.Height,Btnx-20,40
PnlCat.Common.ControlName="PanelCategory"
Set RBCat=SDB.UI.NewRadioButton(PnlCat)
RBCat.Common.SetRect 0,0,60,20
RBCat.Caption="Genre"
RBCat.Checked=False
RBCat.Common.ControlName="RBCatGenre"
Set RBCat=SDB.UI.NewRadioButton(PnlCat)
RBCat.Common.SetRect 0,20,60,20
RBCat.Caption="Language"
RBCat.Checked=False
RBCat.Common.ControlName="RBCatLang"
Set PnlAction=SDB.UI.NewTranspPanel(FormTlBx)
PnlAction.Common.SetRect PnlCat.Common.Width+10,PnlCat.Common.Top,Btnx+50,100
'PnlAction.Common.SetRect 0,300,100,100
PnlAction.Common.ControlName="PanelAction"
Set BtnAdd = SDB.UI.NewButton(PnlAction)
BtnAdd.Caption = "Add"
BtnAdd.Common.SetRect 0, 0, Btnx-40, Btny
Script.RegisterEvent BtnAdd, "OnClick", "BtnAddClick"
Set BtnAssign = SDB.UI.NewButton(PnlAction)
BtnAssign.Caption = "Assign"
BtnAssign.Common.SetRect 0, 20, Btnx-40, Btny
Script.RegisterEvent BtnAssign, "OnClick", "BtnAssignClick"
Set CBInstant = SDB.UI.NewCheckBox(PnlAction)
CBInstant.Caption = "instant"
CBInstant.Common.SetRect BtnAdd.Common.Left+BtnAdd.Common.Width, 0, 30, 20
CBInstant.Checked = False
Set BtnRemove = SDB.UI.NewButton(PnlAction)
BtnRemove.Caption = "Remove"
BtnRemove.Common.SetRect 0, 50, Btnx-40, Btny
Script.RegisterEvent BtnRemove, "OnClick", "BtnRemoveClick"
Set CBRemove = SDB.UI.NewCheckBox(PnlAction)
CBRemove.Caption = "!"
CBRemove.Common.SetRect BtnRemove.Common.Left+BtnRemove.Common.Width, BtnRemove.Common.Top, 30, 20
CBRemove.Checked = False
Set CBSubstr = SDB.UI.NewCheckBox(PnlAction)
CBSubstr.Caption = "substr"
CBSubstr.Common.SetRect BtnRemove.Common.Left, BtnRemove.Common.Top+BtnRemove.Common.Height, 50, 20
CBSubstr.Checked = False
Set BtncopyLangToGenre = SDB.UI.NewButton(FormTlBx)
BtncopyLangToGenre.Caption = "copy LANGUAGE --> Genre"
BtncopyLangToGenre.Common.SetRect 5, PnlAction.Common.Top+PnlAction.Common.Height, 170, 20
Script.RegisterEvent BtncopyLangToGenre, "OnClick", "copyLangToGenre"
''''''''''''''''''
'' Subroutines ''
''''''''''''''''''
Sub showFormTlBx()
FormTlBx.Common.Visible = True
FormTlBx.Common.BringToFront()
End Sub
Sub LangGerman()
DDetc.Text = "German"
Call TextChange
If CBInstant.Checked Then
Call BtnAddClick
End If
End Sub
Sub LangEnglish()
DDetc.Text = "English"
Call TextChange
If CBInstant.Checked Then
Call BtnAddClick
End If
End Sub
Sub LangChineseMandarin()
DDetc.Text = "Chinese Mandarin"
Call TextChange
If CBInstant.Checked Then
Call BtnAddClick
End If
End Sub
Sub LangJapanese()
DDetc.Text = "Japanese"
Call TextChange
If CBInstant.Checked Then
Call BtnAddClick
End If
End Sub
Sub DDetcOnChange(ctrl)
Call TextChange
End Sub
Sub TextChange
CBRemove.Checked = False
End Sub
sub BtnAddClick
TagName = getTagname
If TagnameChoosen(Tagname) Then
Select Case Tagname
Case "Genre"
call addToTag(TagName,DDetc.Text,"","")
Case "Lang"
call addToTag_LANG(DDetc.Text,"","")
Case Else pass = NULL
End Select
End If
end Sub
sub BtnAssignClick
TagName = getTagname
If TagnameChoosen(Tagname) Then
call assignToTag(TagName,DDetc.Text,"","")
End If
end Sub
Sub BtnRemoveClick
TagName = getTagname
If TagnameChoosen(Tagname) Then
If Not CBRemove.Checked Then
SDB.MessageBox "PROTECTED!" & vbCrLf & vbCrLf & "Checkbox '!' next to the Remove button needs to be checked!", mtInformation, Array(mbOk)
Else
Select Case Tagname
Case "Genre"
Call removeFromTag(TagName, CBSubstr.Checked)
Case "Lang"
Call removeFromTag(TagName, CBSubstr.Checked)
Call removeLangFromGenre(CBSubstr.Checked)
Case Else writeTag = False
End Select
End If
End If
End Sub
Sub addToTag(Tagname,values,prefix,suffix)
if len(values) > 0 Then
Set list = SDB.SelectedSongList
For i = 0 to list.count - 1
Set objSongData = list.Item(i)
Keywords = Split(values,";")
tagvalues = readTag(objSongData,Tagname)
' genre = objSongData.Genre
newKeywords = ""
for each kword in Keywords
kword = trim(kword)
' if InStr(1,tagvalues,kword,1) = 0 then
if not findKeywordInList(kword,tagvalues) then
if len(newKeywords) > 0 then
newKeywords = newKeywords & ";"
end if
newKeywords = newKeywords & prefix & kword & suffix
end if
Next
if len(newKeywords) > 0 then
if len(tagvalues) > 0 and right(trim(tagvalues),1) <> ";" then
tagvalues = tagvalues & ";"
end if
' objSongData.Genre = tagvalues & newKeywords
writeTag objSongData,Tagname,tagvalues & newKeywords
end if
Next
list.UpdateAll
end if
End Sub
Sub addToTag_LANG(values,prefix,suffix)
Tagname = "Lang"
if len(values) > 0 Then
Set list = SDB.SelectedSongList
For i = 0 to list.count - 1
Set objSongData = list.Item(i)
Keywords = Split(values,";")
tagvalues = readTag(objSongData,Tagname)
' genre = objSongData.Genre
newKeywords = ""
for each kword in Keywords
kword = trim(kword)
' if InStr(1,tagvalues,kword,1) = 0 then
if not findKeywordInList(kword,tagvalues) then
if len(newKeywords) > 0 then
newKeywords = newKeywords & ";"
end if
newKeywords = newKeywords & prefix & kword & suffix
end if
Next
if len(newKeywords) > 0 then
if len(tagvalues) > 0 and right(trim(tagvalues),1) <> ";" then
tagvalues = tagvalues & ";"
end if
' objSongData.Genre = tagvalues & newKeywords
writeTag objSongData,Tagname,tagvalues & newKeywords
end if
Next
list.UpdateAll
Call copyLangToGenre
end if
End Sub
Sub assignToTag(Tagname,values,prefix,suffix)
if len(values) > 0 Then
Set list = SDB.SelectedSongList
For i = 0 to list.count - 1
Set objSongData = list.Item(i)
Keywords = Split(values,";")
newKeywords = ""
for each kword in Keywords
kword = trim(kword)
if len(newKeywords) > 0 then
newKeywords = newKeywords & ";"
end if
newKeywords = newKeywords & prefix & kword & suffix
Next
if len(newKeywords) > 0 then
writeTag objSongData,Tagname,newKeywords
end if
Next
list.UpdateAll
end if
End Sub
Sub removeFromTag(Tagname,removeSubstring)
Set list = SDB.SelectedSongList
str = DDetc.Text
' https://www.mediamonkey.com/wiki/index.php?title=ISDBApplication::MessageBox
' answer = SDB.MessageBox( "remove: " & str, mtConfirmation, Array(mbYes,mbNo) )
' SDB.MessageBox "your answwer: " & answer, mtInformation, Array(mbOk)
' if len(str) > 0 and answer = 6 then
if len(str) > 0 then
For i = 0 to list.count - 1
Set objSongData = list.Item(i)
' genres = Split(objSongData.Genre,";")
genres = Split(readTag(objSongData,Tagname),";")
values = Split(str,";")
newKeywords = ""
changed = False
for each genre in genres
genre = trim(genre)
remove = False
for each keyword in values
keyword=trim(keyword)
if len(keyword) > 0 then
if (not removeSubstring and genre = keyword) or ((removeSubstring) and InStr(1,genre,keyword,1) > 0) then
remove = True
end if
end if
next
if not remove then
if len(newKeywords) > 0 then
newKeywords = newKeywords & ";"
end if
newKeywords = newKeywords & genre
else
changed = True
end if
next
if changed then
writeTag objSongData,Tagname,newKeywords
end if
Next
end if
list.UpdateAll
end sub
Sub removeLangFromGenre(removeSubstring)
Tagname = "Genre"
Set list = SDB.SelectedSongList
str = DDetc.Text
' https://www.mediamonkey.com/wiki/index.php?title=ISDBApplication::MessageBox
' answer = SDB.MessageBox( "remove: " & str, mtConfirmation, Array(mbYes,mbNo) )
' SDB.MessageBox "your answwer: " & answer, mtInformation, Array(mbOk)
' if len(str) > 0 and answer = 6 then
if len(str) > 0 then
For i = 0 to list.count - 1
Set objSongData = list.Item(i)
' genres = Split(objSongData.Genre,";")
genres = Split(readTag(objSongData,Tagname),";")
values = Split(str,";")
newKeywords = ""
changed = False
for each genre in genres
genre = trim(genre)
remove = False
for each keyword in values
keyword=trim(keyword)
if len(keyword) > 0 then
if (not removeSubstring and genre = "["&keyword&"]") then
remove = True
else
If ( removeSubstring and (InStr(1,genre,keyword,1)>0 and Left(genre,1)="[" and Right(genre,1)="]") ) Then remove = True
end if
end if
next
if not remove then
if len(newKeywords) > 0 then
newKeywords = newKeywords & ";"
end if
newKeywords = newKeywords & genre
else
changed = True
end if
next
if changed then
writeTag objSongData,Tagname,newKeywords
end if
Next
end if
list.UpdateAll
end sub
Sub copyLangToGenre
Set list = SDB.SelectedSongList
For i = 0 to list.count - 1
Set objSongData = list.Item(i)
langs = Split(objSongData.Custom1,";")
' genres = Split(objSongData.Genre,";")
genre = objSongData.Genre
newGenres = ""
' for each g in genres
for each l in langs
l = trim(l)
' SDB.MessageBox "g = " & trim(genre) & " ; l = " & trim(l), mtError, Array(mbOK)
if InStr(1,genre,l,1) = 0 then
' if not foundTagInList(l,genre) then
if len(newGenres) > 0 then
newGenres = newGenres & ";"
end if
newGenres = newGenres & "[" & l & "]"
end if
next
' next
if len(newGenres) > 0 then
' SDB.MessageBox "len(newGenres) = " & len(newGenres) , mtError, Array(mbOK) ''' for DEBUGGING
if len(genre) > 0 and right(trim(genre),1) <> ";" then
objSongData.Genre = objSongData.Genre & ";"
end if
objSongData.Genre = objSongData.Genre & newGenres
end If
' SDB.MessageBox "new Genre tag = " & objSongData.Genre , mtError, Array(mbOK)
Next
list.UpdateAll
End Sub
''''''''''''''''''
'' Functions ''
''''''''''''''''''
Function findKeywordInList(kword,listt)
list = Split(listt,";")
kword = trim(kword)
if len(kword) > 0 then
found = False
for each l in list
if kword = trim(l) then
found = True
end if
next
end if
findKeywordInList = found
end Function
Function readTag(objSongData,Tagname)
Select Case Tagname
Case "Genre" readTag = objSongData.Genre
Case "Lang" readTag = objSongData.Custom1
Case Else readTag = ""
End Select
End Function
Function writeTag(objSongData,Tagname,value)
Select Case Tagname
Case "Genre"
objSongData.Genre = value
writeTag = True
Case "Lang"
objSongData.Custom1 = value
writeTag = True
Case Else writeTag = False
End Select
End Function
Function TagnameChoosen(Tagname)
If Tagname = "" Then
TagnameChoosen = False
SDB.MessageBox "Choose Tag on which to apply the action! (Genre or Language)", mtInformation, Array(mbOk)
Else
TagnameChoosen = True
End If
End Function
Function getTagname
getTagname = ""
If PnlCat.Common.ChildControl("RBCatGenre").Checked Then
getTagname = "Genre"
Else
If PnlCat.Common.ChildControl("RBCatLang").Checked Then getTagname = "Lang"
End If
End Function
''' DEBUGGING '''
'DEVELOPMENT SECTION below'
' Set BtnReloadScript = SDB.UI.NewButton(FormTlBx)
' BtnReloadScript.Caption = "reloadScript()"
' 'BtnReloadScript.Common.SetRect 10, 80, 100, 20
' BtnReloadScript.Common.SetRect FormTlBx.Common.ClientWidth-100, FormTlBx.Common.ClientHeight-20, 100, 20
' BtnReloadScript.Common.Anchors = 4+8 ' The button is always in a constant distance from Bottom Right corner. ' https://www.mediamonkey.com/wiki/index.php?title=ISDBUICommon::Anchors
' Script.RegisterEvent BtnReloadScript, "OnClick", "reloadScript"
'
' Sub reloadScript()
' Set FormTlBx = SDB.Objects("SyncTheSyncFormTlBx")
' If Not (FormTlBx Is Nothing) Then
' Script.UnregisterEvents FormTlBx
' FormTlBx.Common.Visible = False
' FormTlBx.Common.ControlName = ""
' Set FormTlBx = Nothing
' End If
' Script.UnRegisterAllEvents()
' Script.Reload(Script.ScriptPath)
' ' SDB.ScriptControl.UnRegisterAllEvents()
' ' SDB.ScriptControl.Reload(SDB.ScriptControl.ScriptPath)
' SDB.RefreshScriptItems()
' Set SDB.Objects("SyncTheSyncFormTlBx") = Nothing
' End Sub