-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathautorip.ps1
121 lines (110 loc) · 4.42 KB
/
autorip.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
#Copyright (C) 2013 E.J. Bevenour
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#This program 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 General Public License for more details.
#You should have received a copy of the GNU General Public License along
#with this program; if not, write to the Free Software Foundation, Inc.,
#51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Function Get-ADComputerCDRomInfo
{
# Function variables
$deviceId = ""
$volumeName = ""
$err = ""
$makemkvpath = 'C:\Program Files (x86)\MakeMKV\'
if (!(Test-Path $makemkvpath\makemkvcon.exe))
{
$makemkvpath = Read-Host 'What is your makemkvcon.exe folder path'
}
echo "Welcome to autorip."
$dir1 = Read-Host 'Directory to save to'
$device = Read-Host 'What is your disc drive letter'
$semicolon = ":"
try
{
while (1-eq 1)
{
# Grab WMI object
$w = Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType = 5 and DeviceID = '$device$semicolon' " -errorvariable MyErr -erroraction Stop;
$w | ForEach-Object {
# Populate the properties
$deviceId = $_.DeviceID
$volumeName = $_.VolumeName
# If the drive letter length is 0, populate the default error
if ($deviceId.Length -eq 0)
{
echo "No drive found."
}
elseif ($volumeName.Length -eq 0)
{
echo "No disc mounted."
}
else
{
echo 'Mounted'
$dir1 = "C:\library\rips\$volumeName"
New-Item $dir1 -type directory -force
invoke-expression "& '$makemkvpath\makemkvcon.exe' --minlength=1200 mkv disc:0 all C:\library\rips\$volumename\"
try
{
mv $dir1\title00.mkv $dir1\$volumeName.mkv
}
finally
{
}
Show-BalloonTip -Title 'Autorip' -MessageType Info -Message "$volumeName is ripped" -Duration 10000
Eject -id "$deviceId"
}
}
start-sleep -seconds 10
}
}
Catch [system.exception]
{
# Let's make sure we're populating the correct error
if ($MyErr.Count -gt 0)
{
$err = $MyErr
} else {
$err = $error[0].tostring()
}
echo $err
}
}
function Show-BalloonTip {
[cmdletbinding()]
param(
[parameter(Mandatory=$true)]
[string]$Title,
[ValidateSet("Info","Warning","Error")]
[string]$MessageType = "Info",
[parameter(Mandatory=$true)]
[string]$Message,
[string]$Duration=10000
)
[system.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') | Out-Null
$balloon = New-Object System.Windows.Forms.NotifyIcon
$path = Get-Process -id $pid | Select-Object -ExpandProperty Path
$icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path)
$balloon.Icon = $icon
$balloon.BalloonTipIcon = $MessageType
$balloon.BalloonTipText = $Message
$balloon.BalloonTipTitle = $Title
$balloon.Visible = $true
$balloon.ShowBalloonTip($Duration)
}
function Eject
{
param($id)
$sa = new-object -com Shell.Application
$sa.Namespace(17).ParseName($id).InvokeVerb("Eject")
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($sa) | Out-Null
Remove-Variable sa
}
# Execute this function
Get-ADComputerCDRomInfo