{"id":31,"date":"2020-12-01T05:41:17","date_gmt":"2020-12-01T05:41:17","guid":{"rendered":"https:\/\/stupidtechblog.com\/?p=31"},"modified":"2024-08-13T21:05:21","modified_gmt":"2024-08-13T21:05:21","slug":"automated-dvd-and-blu-ray-ripping-with-powershell","status":"publish","type":"post","link":"https:\/\/stupidtechblog.com\/?p=31","title":{"rendered":"Automated DVD and Blu-Ray Ripping With Powershell"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">I ran into a curious problem recently. My wife had a massive binder full of DVDs that she&#8217;s collected over the years, and she wanted to get them archived to something a little more useful, like the media server that lives in our basement. After a couple hours of fiddling, I put together a nice solution where the end result is a server that waits to have a DVD inserted into it, rips that to a predefined network drive, and then sends an email and ejects the disk when it&#8217;s done. Here, I&#8217;ll show you how to set that up yourself.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1: Get A Server<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">I suppose it doesn&#8217;t need to be a server, per-say, but at the end of the day you need some physical machine running Windows (or VMware, where you can pass the DVD drive through to a Windows VM). There are certainly Linuxy methods of doing this that are probably more reliable, and, well, better, but a Windows server is what I had on hand, so that is what this guide covers.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2: Get MakeMKV<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">MakeMKV is a glorious little utility that automatically scans your DVDs (and blu-rays!), rips out the copyright protection, and converts any video files that are above a certain length. This means that you put a DVD in on one end, and get one or more meaty video files out of the other end, properly encoded and without any of the messy menu content.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a rel=\"noreferrer noopener\" href=\"https:\/\/www.makemkv.com\/download\/\" data-type=\"URL\" data-id=\"https:\/\/www.makemkv.com\/download\/\" target=\"_blank\">Download MakeMKV Here<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3: Write The Script<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">I did say we&#8217;d be using Powershell. Luckily, I&#8217;ve already got the script all made up for you. <strong>Run it as Administrator.<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">function Eject-CD # Great function for simply ejecting a CD drive. Originally sourced here: https:\/\/community.idera.com\/database-tools\/powershell\/powertips\/b\/tips\/posts\/ejecting-cd-drive\n{\n  $drives = Get-WmiObject Win32_Volume -Filter \"DriveType=5\"\n  if ($drives -eq $null)\n  {\n    Write-Warning \"Your computer has no CD drives to eject.\"\n    return\n  } \n  $drives | ForEach-Object {\n    (New-Object -ComObject Shell.Application).Namespace(17).ParseName($_.Name).InvokeVerb(\"Eject\")\n  }\n}\n\n$storageFolder = \"\\\\file.yournetwork.local\\DVDBackups\" # Where should things be backed up to? The script will create a folder inside this for each DVD processed.\n$toEmail = \"toEmail@example.com\" # The email address you want emails to come from\n$fromEmail = \"fromEmail@example.com\" # The email address you want emails to go to\n$retryWaitTime = 10 # How long (in seconds) to wait before checking to see if a DVD is in the drive\n$smtpServerHost = \"mail.yournetwork.local\" #If you have an unauthenticated SMTP server, you can just replace this address with that. If you need to use gmail or something like that, check out the docs for Send-MailMessage and adjust the commands below.\n$smtpServerPort = 25 # Whatever port your SMTP server uses\n$sendEmails= $true # Set this to $false to disable any email functionality, if you'd prefer not to set that up.\n\nwhile ($true){\n    if ((Get-WMIObject -Class Win32_CDROMDrive -Property *).MediaLoaded) {\n        $movieName = (Get-Volume -DriveLetter D).FileSystemLabel.Trim()\n        New-Item -Path \"$storageFolder\\\" -Name $movieName -ItemType \"directory\"\n        try {\n            &amp; \"C:\\Program Files (x86)\\MakeMKV\\makemkvcon64\" mkv disc:0 all $storageFolder\\$movieName\n            if (!$noEmail) {Send-MailMessage -To $toEmail -From $fromEmail  -Subject \u201c$movieName Ripping Complete\u201d -Body \u201cGo put the next one in.\u201d -SmtpServer $smtpServerHost -Port $smtpServerPort}\n            Write-Information \"Ripping Complete! Give me the next disk to eat.\"\n            Eject-CD\n        } catch {\n            if (!$noEmail) {Send-MailMessage -To $toEmail -From $fromEmail  -Subject \u201cERROR! $movieName Ripping Failed!\u201d -Body \u201cPlease send help. &lt;br \/> Error: $_\u201d -SmtpServer $smtpServerHost -Port $smtpServerPort}\n            Write-Error \"Ripping Failed! Help :(\"\n            Write-Error $_\n            exit\n        }\n        \n    } else {\n        Write-Host \"No DVD in tray, waiting and trying again...\"\n        sleep $retryWaitTime\n    }\n}\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Results!<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">With that running, stick a DVD in the drive, and you should see something like this.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"902\" height=\"314\" src=\"https:\/\/stupidtechblog.com\/wp-content\/uploads\/2020\/12\/Capture-6.png\" alt=\"\" class=\"wp-image-152\" style=\"width:902px;height:314px\" srcset=\"https:\/\/stupidtechblog.com\/wp-content\/uploads\/2020\/12\/Capture-6.png 902w, https:\/\/stupidtechblog.com\/wp-content\/uploads\/2020\/12\/Capture-6-300x104.png 300w, https:\/\/stupidtechblog.com\/wp-content\/uploads\/2020\/12\/Capture-6-768x267.png 768w\" sizes=\"auto, (max-width: 902px) 100vw, 902px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Folders will be named based on the name of the DVD volume. It&#8217;s not perfect, but I&#8217;ve made my way through a couple dozen movies and TV shows so far, and have yet to come across any conflicts. Enjoy!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Like this article? Have questions? Want another post about something else?<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Put a comment below and let me know.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I ran into a curious problem recently. My wife had a massive binder full of DVDs that she&#8217;s collected over the years, and she wanted to get them archived to something a little more useful, like the media server that lives in our basement. After a couple hours of fiddling, I put together a nice [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[6],"tags":[11,9,7,10,8],"class_list":["post-31","post","type-post","status-publish","format-standard","hentry","category-how-to","tag-automation","tag-dvd","tag-powershell","tag-ripping","tag-windows"],"_links":{"self":[{"href":"https:\/\/stupidtechblog.com\/index.php?rest_route=\/wp\/v2\/posts\/31","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/stupidtechblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stupidtechblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stupidtechblog.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/stupidtechblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=31"}],"version-history":[{"count":7,"href":"https:\/\/stupidtechblog.com\/index.php?rest_route=\/wp\/v2\/posts\/31\/revisions"}],"predecessor-version":[{"id":153,"href":"https:\/\/stupidtechblog.com\/index.php?rest_route=\/wp\/v2\/posts\/31\/revisions\/153"}],"wp:attachment":[{"href":"https:\/\/stupidtechblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=31"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stupidtechblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=31"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stupidtechblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=31"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}