-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet-Mp3Details.ps1
773 lines (606 loc) · 24.6 KB
/
Get-Mp3Details.ps1
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
Clear-Host
write-host "Warming up... Please Wait"
#--------- Set Parameters ----------#
## Set Tempfolder for last folder use test
$TempFolder = "$env:TEMP\MP3Analyze"
## If first run, no folder is set start in
$InitialFolder = "C:\Temp\Sidify\Download-Temp\"
## Set current date format and stamp
$RunTimeStamp = $((get-date).ToString("yyyyMMdd"))
## Log Powershell output to file in same directory
$Global:LogginEnabled = $true ## $true = yes | $false = no
$Prefix = "(SP-RIP-N)"
#--------- DO Not Edit Below ----------#
# Initial status
$Done = $false
# Load stopwatch
$StopWatch = New-Object System.Diagnostics.Stopwatch
#mediaplayer
Add-Type -AssemblyName presentationCore
$mediaPlayer = New-Object system.windows.media.mediaplayer
# Find Tempfolder and create if not exist
if(!(Test-Path $TempFolder)){
New-Item -ItemType Directory $TempFolder
}
# Check if ID3 powershell gallary module is installed. If not install else import
$ID3Module = Get-Module -Name ID3
if(!($ID3Module)){
Import-Module -Name ID3
}
$ID3Module = Get-Module -Name ID3
if(!($ID3Module)){
$currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
$IsAdmin = $currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if($IsAdmin){
Install-Module -Name ID3
}else{
Write-Warning "Need to be admin to install ID3 Powershell Module"
Read-Host "Press enter to exit"
break
}
}
#check ffmpeg & ffmpeg-nomalize path
$path = $env:Path -split ";"
#$path|?{$_ -like "*ffmpeg.exe"}
$ffmpeg_normalize = pip list| ? {$_ -like "*ffmpeg-normalize*"}
$ffmpeg_status = 0
if(!($path)){
Write-Warning "FFmpeg not fount in Path please install"
$ffmpeg_status = 2
}
if(!($ffmpeg_normalize)){
Write-Warning "ffmpeg-normalize not fount in Path please install"
$ffmpeg_status = 3
}
if($ffmpeg_status -ne 0){
warning "please fix ffmpeg, details: https://github.com/djansen1987/MP3Analyze-Powershell"
break
}
# Find VLC path
#$vlcinstall = Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall | % { Get-ItemProperty $_.PsPath } | Select DisplayName,InstallLocation|?{$_.DisplayName -like "*vlc*"}
#if(!($vlcinstall)){
# if(Test-Path "C:\Program Files\VideoLAN\VLC\vlc.exe"){
# $vlcPath = "C:\Program Files\VideoLAN\VLC\vlc.exe"
# }elseif(Test-Path "C:\Program Files (x86)\VideoLAN\VLC\vlc.exe"){
# $vlcPath = "C:\Program Files (x86)\VideoLAN\VLC\vlc.exe"
# }else{
# write-host "vlc not found, please install vlc"
# read-host -Prompt "Press enter to exit."
# (New-Object -Com Shell.Application).Open("https://www.videolan.org/vlc/")
# break
# }
#}else{
# $vlcPath = "$($vlcinstall.InstallLocation)\vlc.exe"
#}
#--------- Begin of Functions ----------#
Function Get-Folder($initialDirectory){
Add-Type -AssemblyName System.Windows.Forms
$FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog -Property @{
SelectedPath = $initialDirectory; ShowNewFolderButton = $false
}
$Prop = New-Object System.Windows.Forms.Form -Property @{TopMost = $true }
[void]$FolderBrowser.ShowDialog($Prop)
Return $FolderBrowser.SelectedPath
}
Function Get-MP3MetaData{
[CmdletBinding()]
[Alias()]
[OutputType([Psobject])]
Param
(
[String] [Parameter(Mandatory=$true, ValueFromPipeline=$true)] $Directory
)
Begin
{
$shell = New-Object -ComObject "Shell.Application"
}
Process
{
Foreach($Dir in $Directory)
{
$ObjDir = $shell.NameSpace($Dir)
$Files = Get-ChildItem $Dir| ?{$_.Extension -in '.mp3','.mp4'}
Foreach($File in $Files)
{
$ObjFile = $ObjDir.parsename($File.Name)
$MetaData = @{}
$MP3 = ($ObjDir.Items()|?{$_.path -like "*.mp3" -or $_.path -like "*.mp4"})
$PropertArray = 0,1,2,12,13,14,15,16,17,18,19,20,21,22,27,28,36,220,223
Foreach($item in $PropertArray)
{
If($ObjDir.GetDetailsOf($ObjFile, $item)) #To avoid empty values
{
$MetaData[$($ObjDir.GetDetailsOf($MP3,$item))] = $ObjDir.GetDetailsOf($ObjFile, $item)
}
}
New-Object psobject -Property $MetaData |select *, @{n="Directory";e={$Dir}}, @{n="Fullname";e={Join-Path "$Dir" "$($File.Name)" -Resolve}}, @{n="Extension";e={$File.Extension}}
}
}
}
End
{
}
}
Function Show-CurrentSong ($Name,$status,$time) {
Add-Type -AssemblyName System.Windows.Forms
# Build Form
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = $status
$objForm.Size = New-Object System.Drawing.Size(220,100)
# Add Label
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(80,20)
$objLabel.Size = New-Object System.Drawing.Size(100,20)
$objLabel.Text = $Name
$objForm.Controls.Add($objLabel)
# Show the form
$objForm.Show()| Out-Null
# wait 5 seconds
Start-Sleep -Seconds $time
# destroy form
$objForm.Close() | Out-Null
}
function Get-Response($Name){
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$form = New-Object System.Windows.Forms.Form
$form.Text = 'How Was the MP3'
$form.Size = New-Object System.Drawing.Size(475,260)
$form.StartPosition = 'CenterScreen'
$GoodButton = New-Object System.Windows.Forms.Button
$GoodButton.Location = New-Object System.Drawing.Point(75,120)
$GoodButton.Size = New-Object System.Drawing.Size(75,23)
$GoodButton.Text = 'Good'
$GoodButton.DialogResult = [System.Windows.Forms.DialogResult]::yes
$form.AcceptButton = $GoodButton
$form.Controls.Add($GoodButton)
$BadButton = New-Object System.Windows.Forms.Button
$BadButton.Location = New-Object System.Drawing.Point(150,120)
$BadButton.Size = New-Object System.Drawing.Size(75,23)
$BadButton.Text = 'Bad'
$BadButton.DialogResult = [System.Windows.Forms.DialogResult]::no
$form.AcceptButton = $BadButton
$form.Controls.Add($BadButton)
$TopButton = New-Object System.Windows.Forms.Button
$TopButton.Location = New-Object System.Drawing.Point(225,120)
$TopButton.Size = New-Object System.Drawing.Size(75,23)
$TopButton.Text = 'Top'
$TopButton.DialogResult = [System.Windows.Forms.DialogResult]::ok
$form.AcceptButton = $TopButton
$form.Controls.Add($TopButton)
$ReCheckButton = New-Object System.Windows.Forms.Button
$ReCheckButton.Location = New-Object System.Drawing.Point(300,120)
$ReCheckButton.Size = New-Object System.Drawing.Size(75,23)
$ReCheckButton.Text = 'Re-Check'
$ReCheckButton.DialogResult = [System.Windows.Forms.DialogResult]::retry
$form.CancelButton = $ReCheckButton
$form.Controls.Add($ReCheckButton)
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,20)
$label.Size = New-Object System.Drawing.Size(380,200)
$label.Text = "
How Was $Name ?
When Choose Good, go to next.
When Choose Bad, move item to folder Bad and go to next.
When Choose Top, move item to folder Top and go to next.
When Choos Re-Check, play Mp3 Again.
"
$form.Controls.Add($label)
$form.Topmost = $true
$Prop = New-Object System.Windows.Forms.Form -Property @{TopMost = $true }
$form.ShowDialog($prop)
#$form.ShowDialog()
}
function Start-Mp3($data){
try{
$startEnd = ([DateTime]$_.Length).AddSeconds(-[int]$CheckTime).TimeOfDay.TotalSeconds
Write-host "$($_.name) (First $CheckTime seconds)" -ForegroundColor Cyan
$mediaPlayer.open($($_.Fullname))
#mediaPlayer.open("C:\Sidify-download\Top 40 2021\Normalize\Silence\Donnie, Rene Froger - Bon Gepakt (SP-RIP-N).mp3")
$mediaPlayer.Position=New-Object System.TimeSpan(0, 0, 0, 0, 0)
$mediaPlayer.Play()
Start-Sleep ([int]$CheckTime + 2)
$mediaPlayer.Pause()
Start-Sleep -Milliseconds 500
Write-host "$($_.name) (Last $CheckTime seconds)" -ForegroundColor Cyan
$mediaPlayer.Position=New-Object System.TimeSpan(0, 0, 0, $startEnd, 0)
$mediaPlayer.Play()
Start-Sleep -Seconds ([int]$CheckTime + 1)
$mediaPlayer.Stop()
$mediaPlayer.Close()
#Write-host "$($_.name) (Begin)" -ForegroundColor Cyan
#Start-Process $vlcPath -ArgumentList "--qt-start-minimized --play-and-exit --qt-notification=0 `"$($_.Fullname)`" --run-time=$CheckTime " -Wait
#Write-host "$($_.name) (Ending)" -ForegroundColor Cyan
#Start-Process $vlcPath -ArgumentList "--qt-start-minimized --play-and-exit --qt-notification=0 `"$($_.Fullname)`" --start-time=$startend " -Wait
}
catch{
Write-Error "unable to play audio"
}
(Get-Response -Name ($data.name))
}
function Check-File($File){
$response = Start-Mp3 -data $_
if($response -eq "Yes"){
return "Good"
}
if($response -eq "No"){
New-Item -ItemType Directory ($_.Directory + "\Bad\") -Force -ea SilentlyContinue|Out-Null
Move-Item -Path $_.Fullname -Destination ($_.Directory + "\Bad\")
return "Bad"
}
if($response -eq "OK"){
New-Item -ItemType Directory ($_.Directory + "\Top\") -Force -ea SilentlyContinue|Out-Null
Move-Item -Path $_.Fullname -Destination ($_.Directory + "\Top\")
return "OK"
}
if($response -eq "Retry"){
Check-File -file $_
}else{
write-host "You Hit Cancel"
read-host "press enter to exit"
Set-Ending
break
}
}
function Get-CheckTime(){
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$form = New-Object “System.Windows.Forms.Form”;
$form.Width = 300;
$form.Height = 150;
$form.Text = "Number of second's to check (begin-end)";
$form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen;
##############Define text label1
$textLabel1 = New-Object “System.Windows.Forms.Label”;
$textLabel1.Left = 25;
$textLabel1.Top = 10;
$textLabel1.width = 300
$textLabel1.Text = "Number of second's to check (begin-end)";
############Define text box1 for input
$textBox1 = New-Object “System.Windows.Forms.TextBox”;
$textBox1.Left = 25;
$textBox1.Top = 35;
$textBox1.width = 200;
$textBox1.Text = "10";
$button = New-Object “System.Windows.Forms.Button”;
$button.Left = 25;
$button.Top = 70;
$button.Width = 100;
$button.Text = “Ok”;
$button.DialogResult = [System.Windows.Forms.DialogResult]::ok
$eventHandler = [System.EventHandler]{
$textBox1.Text;
$form.Close();};
$button.Add_Click($eventHandler) ;
$form.KeyPreview = $True
$form.Add_KeyDown({
if ($_.KeyCode -eq "Enter") {
# if enter, perform click
$button.PerformClick()
}
})
$form.Add_Shown({$form.Activate(); $textBox1.focus()})
$form.Controls.Add($textLabel1);
$form.Controls.Add($textBox1);
$form.Controls.Add($button);
#$ret = $form.ShowDialog();
$Prop = New-Object System.Windows.Forms.Form -Property @{TopMost = $true }
$show = $form.ShowDialog($prop)
If ($show -eq "OK"){
Return $textBox1.Text
}
Else{
Write-Error "Operation cancelled by user."
Set-Ending
break
}
}
#While file scanning what to do with a bad file name
function Ask-User($Title,$Message){
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$form = New-Object System.Windows.Forms.Form
$form.Text = $Title
$form.Size = New-Object System.Drawing.Size(380,260)
$form.StartPosition = 'CenterScreen'
$GoodButton = New-Object System.Windows.Forms.Button
$GoodButton.Location = New-Object System.Drawing.Point(75,120)
$GoodButton.Size = New-Object System.Drawing.Size(75,23)
$GoodButton.Text = 'Yes'
$GoodButton.DialogResult = [System.Windows.Forms.DialogResult]::yes
$form.AcceptButton = $GoodButton
$form.Controls.Add($GoodButton)
$BadButton = New-Object System.Windows.Forms.Button
$BadButton.Location = New-Object System.Drawing.Point(150,120)
$BadButton.Size = New-Object System.Drawing.Size(75,23)
$BadButton.Text = 'No'
$BadButton.DialogResult = [System.Windows.Forms.DialogResult]::no
$form.AcceptButton = $BadButton
$form.Controls.Add($BadButton)
$ReCheckButton = New-Object System.Windows.Forms.Button
$ReCheckButton.Location = New-Object System.Drawing.Point(225,120)
$ReCheckButton.Size = New-Object System.Drawing.Size(75,23)
$ReCheckButton.Text = 'Stop'
$ReCheckButton.DialogResult = [System.Windows.Forms.DialogResult]::cancel
$form.CancelButton = $ReCheckButton
$form.Controls.Add($ReCheckButton)
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,20)
$label.Size = New-Object System.Drawing.Size(480,180)
$label.Text = $Message
$form.Controls.Add($label)
$form.Topmost = $true
$Prop = New-Object System.Windows.Forms.Form -Property @{TopMost = $true }
$form.ShowDialog($prop)
#$form.ShowDialog()
}
function Start-Normalize($folder){
$items = Get-ChildItem -Path "$folder" -File -filter "*.mp3"
$totalitems = $items.count
$itemstodo = $totalitems
$waitmessage = "Normalizing File...Approx wait Time: " +(0..$totalitems| % -Begin {$Total = 0} -Process {$Total += (New-TimeSpan -second 2)} -End {$Total})
$items|%{
$filename = $_
Clear-Host
write-host $waitmessage
Write-Host "$itemstodo / $totalitems - $filename";$itemstodo = ($itemstodo - 1)
ffmpeg-normalize $filename.FullName -of $($folder + "\Normalize") --normalization-type peak --target-level 0 -c:a libmp3lame -b:a 256k -ext mp3
}
return $($folder + "\Normalize")
}
function Remove-Silence($folder){
New-Item -Path "$($folder + "\Silence\") " -Force -ea SilentlyContinue |Out-Null
$items = Get-ChildItem -Path "$folder" -File -filter "*.mp3"
$totalitems = $items.count
$itemstodo = $totalitems
$waitmessage = "Removing Silence in MP3..."
$items|%{
Clear-Host
$filename = $_
write-host $waitmessage
Write-Host "$itemstodo / $totalitems - $filename"
$itemstodo = ($itemstodo - 1)
ffmpeg -i $($folder + "\"+$filename.name) -hide_banner -loglevel error -af silenceremove=stop_periods=-1:stop_duration=1:stop_threshold=-60dB $($folder + "\Silence\"+$filename.name)
#ffmpeg -i $($folder + "\"+$filename.name) -y -c:a libmp3lame -b:a 256k -af silenceremove=1:0:-50dB -loglevel warning $($folder + "\Silence\"+$filename.name)
}
return $($folder + "\Silence\")
}
function Fix-Id3andFileName ($folder,$Prefix){
$items = Get-ChildItem -Path "$folder" -File -filter "*.mp3"
$totalitems = $items.count
$waitmessage = "Renaming Files and updating ID3Tag... Please Wait"
$itemstodo = $totalitems
$items|%{Clear-Host;$filename = $_ ;write-host $waitmessage;Write-Host "$itemstodo / $totalitems - $filename";$itemstodo = ($itemstodo - 1);`
Write-Host $Prefix
$file = $filename
$CurrentTag = Get-Id3Tag $file.FullName
$Artist = $CurrentTag.Artists
# Strip Title and replace Characters
$Title = $($CurrentTag.Title).replace("7`"","7 inch").replace("12`"","12 inch").replace("?","").replace("`/"," ").replace("`"","").split('[')[0].split(']')[0]
$NewName = "$Artist - $Title $Prefix"
$ext = $file.Extension
$newfilename = Rename-Item -Path $file.FullName -NewName $($NewName + $ext ) -PassThru
Start-Sleep 1
$tag = @{}
$tag.Add('Title',($Title + " $Prefix"))
set-Id3Tag -Path "$($newfilename.FullName)" -Tags $tag
}
}
function Retrive-Tag($File,$Artist, $Title){
$tag = Get-Id3Tag $File
$tag
#[xml]$result = Invoke-WebRequest -Uri "https://musicbrainz.org/ws/2/release/?query=`"Going%20to%20Ibiza`"&artist=venga"
#$result.metadata.'release-list'.release.date
}
function Set-Ending(){
# Were done. Stop The Time!
$StopWatch.Stop()
# Some math (proberbly wrong)
$savedtimecalc = [timespan]::fromseconds( $(( ($TotalMP3Time.TimeOfDay.TotalSeconds) - (($ID3TagData.Count) * ($CheckTime*2)) )) )
# Output some Details/Summary
if($Done){
Write-Host " "
Write-Host " "
Write-Host " "
Write-Host " "
Write-Host " "
Write-Host " "
Write-Host " --------------- Summary -------------- "
Write-Host " "
write-host "Total`t`t`t $($ID3TagData.Count)"
write-host "Total Bad:`t`t $BadCount"
write-host "Total Runtime:`t $([string]::Format("`{0:d2}:{1:d2}:{2:d2}",$StopWatch.Elapsed.hours,$StopWatch.Elapsed.minutes,$StopWatch.Elapsed.seconds))"
write-host "Total playtime:`t $([string]::Format("`{0:d2}:{1:d2}:{2:d2}",$TotalMP3Time.TimeOfDay.hours,$TotalMP3Time.TimeOfDay.minutes,$TotalMP3Time.TimeOfDay.seconds))"
write-host "Saved Time: `t $([string]::Format("`{0:d2}:{1:d2}:{2:d2}",$savedtimecalc.hours,$savedtimecalc.minutes,$savedtimecalc.seconds))"
$response = read-host -Prompt "Press enter to exit and open output folder. R voor restart"
if($response -eq "R"){
Start-Process $env:USERPROFILE\desktop\"Start MP3 Analyse.lnk"
exit
}else{
Start-Process explorer $MessureFolder
}
}else{
Write-Warning "Failed or Cancelled"
}
if($Global:LogginEnabled){
stop-Transcript |Out-Null
}
}
#--------- End of Functions ----------#
#--------- End of Functions ----------#
#--------- End of Functions ----------#
#--------- Start of Process ----------#
# Ask Folder to scan user. Also last choosen path from temp folder
if(Test-Path "$TempFolder\PreviousLocation.json"){
$LastLocation = Get-Content $TempFolder\PreviousLocation.json |ConvertFrom-Json
if(Test-Path $LastLocation.FullName){
$Filepath = Get-Folder -initialDirectory $($LastLocation.FullName)
get-item -Path $Filepath|ConvertTo-Json| Set-Content -Path "$TempFolder\PreviousLocation.json" -Force
}else{
$Filepath = Get-Folder -initialDirectory $InitialFolder
get-item -Path $Filepath|ConvertTo-Json| Set-Content -Path "$TempFolder\PreviousLocation.json" -Force
}
}else{
$Filepath = Get-Folder -initialDirectory $InitialFolder
get-item -Path $Filepath|ConvertTo-Json| Set-Content -Path "$TempFolder\PreviousLocation.json" -Force
}
# Check if choosen path really exist before continue. If exist check filenames for bad Characters and replace
if(!($Filepath)){
Write-Warning "No path selected"
Read-Host "Press enter to exit"
set-ending
break
}else{
#$invalidChars = [IO.Path]::GetInvalidFileNameChars() -join ''
#$re = "[{0}]" -f [RegEx]::Escape($invalidChars +"][")
$re2 = "[{0}]" -f [RegEx]::Escape("][")
#($Name -replace $re)
#$RegEx = '[][]'
$RegEx2 = [string][System.IO.Path]::GetInvalidFileNameChars()
Get-ChildItem $Filepath -File |%{
if($_.FullName -match $re2){
$newname = ($_.FullName.split('[')[0].split(']')[0]+ $_.Extension)
Write-Warning "Bad File name found $($_.FullName)"
Write-Warning "replace with $newname"
$BadFileResponse = Ask-User -Title "Warning Bad File Name" -Message "
Bad File name found:
$($_.FullName)
replace with:
$newname
"
if($BadFileResponse -eq "yes"){
Move-Item -LiteralPath $_.FullName $newname
}elseif ($BadFileResponse -eq "No" -or $BadFileResponse -eq "Cancel"){
Write-Warning "Fix file and try again"
set-ending
break
}
}
}
}
# Set choosen location
Set-Location $Filepath
# Ask begin and end check time
$CheckTime = Get-CheckTime
# Start Logging to output file in choosen folder
if($Global:LogginEnabled){
New-Item -ItemType Directory -Path ($Filepath+"\Log\") -ErrorAction SilentlyContinue|Out-Null
Start-Transcript -Path ($Filepath+"\Log\#1_MP3Analyzed-" + $RunTimeStamp+".log") -Append |Out-Null
}
# Clear screen
Clear-Host
# Ask To do all fixes at once
$FixAllResponse = Ask-User -Title "Normalize Files?" -Message "
Would you like to do all fixes at once? (Normalize, remove Silence, optimize ID3)
"
if ($FixAllResponse -eq "Yes"){
Write-Host "Start Normalize";Start-Sleep 1
$NormFolder = Start-Normalize -folder $Filepath
Write-Host "Start Remove Silence";Start-Sleep 1
$SilenceFolder = Remove-Silence -folder $NormFolder
Write-Host "Start Optimize ID3";Start-Sleep 1
Fix-Id3andFileName -folder $SilenceFolder -Prefix $Prefix
}elseif ($FixAllResponse -eq "No"){
# Ask if we should Normalize the files. If yes start function
$NormalizeResponse = Ask-User -Title "Normalize Files?" -Message "
With this option Mp3Gain will normalize the files to 0dB.
A separated folder will be created `"Normalized`"
"
if ($NormalizeResponse -eq "Yes"){
$NormFolder = Start-Normalize -folder $Filepath
}elseif ($NormalizeResponse -eq "No"){
Write-host "Skipping normalize"
}elseif ($NormalizeResponse -eq "Cancel"){
set-ending
break
}
# Ask if we should Remove silence from begin and end. If yes start function
$RemoveSilenceResponse = Ask-User -Title "Remove Silence?" -Message "
With this option Silence will be removed from the MP3.
ffmpeg setting = silenceremove=1:0:-50dB
Which means:
Remove from the begin till level is abobe 0 DB
Remove at the end everything below -50 db
"
if ($RemoveSilenceResponse -eq "Yes"){
if($NormFolder){
$SilenceFolder = Remove-Silence -folder $NormFolder
}else{
$SilenceFolder = Remove-Silence -folder $Filepath
}
}elseif ($RemoveSilenceResponse -eq "No"){
Write-host "Skipping Remove Silence"
}elseif ($RemoveSilenceResponse -eq "Cancel"){
set-ending
break
}
# Ask if we should fix the Filename and ID3 Tag. If yes start function
$FixID3TagResponse = Ask-User -Title "Fix ID3 and Filenames?" -Message "
With This option we will Correct the filename
with `"Artist - Title (SP-RIP-N)`".
Files will be saved in last option sub-folder
"
if ($FixID3TagResponse -eq "Yes"){
if($SilenceFolder){
Fix-Id3andFileName -folder $SilenceFolder -Prefix $Prefix
}elseif($NormFolder){
Fix-Id3andFileName -folder $NormFolder -Prefix $Prefix
}else{
Fix-Id3andFileName -folder $Filepath -Prefix $Prefix
}
}elseif ($FixID3TagResponse -eq "No"){
Write-host "Skipping normalize"
}elseif ($FixID3TagResponse -eq "Cancel"){
set-ending
break
}
}elseif ($FixAllResponse -eq "Cancel"){
set-ending
break
}
## Determen what options have been run and find right folder to process
if($SilenceFolder){
$MessureFolder = $SilenceFolder
}elseif($NormFolder){
$MessureFolder = $NormFolder
}else{
$MessureFolder = $Filepath
}
# Clear Screen and write text
Clear-Host
write-host "Loading File... Please Wait"
# Analyse Folder and get ID3 Tag and file atributes
$ID3TagData = Get-MP3MetaData -Directory $MessureFolder
# Check if we found files in the above folder
if (!(($ID3TagData.count) -gt 0)){
Write-Warning "No files found"
Read-Host -Prompt "Press enter to exit"
break
}
# Set Counters for reporting
$Total = $ID3TagData.Count
$BadCount = 0
# Set counter total time
Clear-Variable TotalMP3Time -Force -ea SilentlyContinue |Out-Null
$TotalMP3Time = (get-date -Hour 0 -Minute 0 -Second 0 -Millisecond 0)
# Clear the screen once more to be sure
Clear-Host
# Here we go, start stopwatch. For reporting purphose
$StopWatch.Start()
# Finally Run Through Files
$ID3TagData |% {
Clear-Host
write-host "Count: $total / $($ID3TagData.Count)" -ForegroundColor Green
$Result = Check-File -file $_
write-host "$Result" -ForegroundColor Cyan
if($Result -eq "Bad"){
$BadCount = $BadCount + 1
}
$total = $Total - 1
$TotalMP3Time += $_.length
}
# We are at the end of the script. Let ending function know we made it
$Done = $true
# Stop loggin. Stop Stopwatch. Output Reporting. Open destination
Set-Ending
#### It's a wrap ####