Page 1 of 1

Auto dvd ripping

Posted: Fri Feb 14, 2025 9:59 pm
by bob5731
i have 500+ dvd that I need rip for plex.
How I rip one after a another in windows 11. I have dvd drives eject the disc then I put another in the it rip it and eject it?
I would like to the the files in mp4.

I was using handbrake 9.1 and now it will copy dvd to css.

I get handbrake to see dvd whit css. but one it scan forever.

Re: Auto dvd ripping

Posted: Fri Feb 14, 2025 10:54 pm
by Ezatoka
bob5731 wrote:
Fri Feb 14, 2025 9:59 pm
I would like to the the files in mp4.
The program is called MakeMKV, not MakeMP4. That's not configurable.

Re: Auto dvd ripping

Posted: Sat Feb 15, 2025 1:13 am
by bob5731
I'm looking to Auto Rip dvd's

Re: Auto dvd ripping

Posted: Sat Feb 15, 2025 3:54 am
by Woodstock
Plex can handle MKV files. The auto-rip-and-eject is your issue.

DVDs are less likely to have names embedded in them than BDs, so you are going to have to manually handle them in any case.

Re: Auto dvd ripping

Posted: Sat Feb 15, 2025 6:46 am
by flojo
Woodstock wrote:
Sat Feb 15, 2025 3:54 am
... manually handle them ...
Take a pic with a cheap webcam, name both the pic and the directory with a common timestamp then name them later.

Code: Select all

now=$(date +%s,%N)
mkdir "$now" # make the directory to rip to
makemkvcon backup --decrypt --cache=16 --noscan -r --progress=-same disc:0 "${now}/"
eject /dev/sr0
sleep 8 # wait for tray to open
ffmpeg -f video4linux2 -s 1920x1080 -i /dev/video0 -ss 0:0:2 -frames 1 "${now}.jpg"
In a thread named "Auto dvd ripping"... you must start to build something auto'ish :-). This really won't happen without at least balls-basic scripting like I posted above, so if the OP wants to do this, now is the time to take the toddler intro course to scripting using at least Bash or something higher like Pearl, Javascript, Python, etc.

Re: Auto dvd ripping

Posted: Sat Feb 15, 2025 2:01 pm
by bob5731
I using windows 11

Re: Auto dvd ripping

Posted: Sat Feb 15, 2025 3:11 pm
by flojo
You're a robot.

LLM's need a disclaimer, otherwise it's automated trolling.

Re: Auto dvd ripping

Posted: Sun Feb 16, 2025 1:51 am
by bob5731
no I'm not a robot. I'm not good at programming.

Re: Auto dvd ripping

Posted: Fri Feb 21, 2025 1:46 pm
by bob5731
can you all look a my python code
see if need to be fix up.

let me know what i need to fix whit new code?

I used chatgpt to make the code for me.

Code: Select all

import os
import time
import subprocess
import logging
import win32com.client
import re
import win32api  # For getting the volume label

# Set paths and variables
DRIVE_LETTERS = ["D:", "E:", "F:"]  # List of DVD/BD drive letters
OUTPUT_FOLDER = r"C:\Users\crock\Videos"  # Output folder
LOG_FILE = os.path.join(OUTPUT_FOLDER, "auto_rip.log")
MAKEMKV_PATH = r"C:\Program Files (x86)\MakeMKV\makemkvcon64.exe"
HANDBRAKE_PATH = r"C:\Program Files\HandBrake\HandBrakeCLI.exe"
HANDBRAKE_PRESET = "Fast 1080p30"

# Ensure the output folder exists
if not os.path.exists(OUTPUT_FOLDER):
    os.makedirs(OUTPUT_FOLDER)

# Set up logging
logging.basicConfig(filename=LOG_FILE, level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")

# Function to sanitize the DVD label to make it a valid folder name
def sanitize_label(dvd_label):
    # Replace the colon with a hyphen or remove it entirely
    sanitized_label = dvd_label.replace(":", "-")  # Replace colon with hyphen
    # Optionally, remove leading/trailing spaces
    sanitized_label = sanitized_label.strip()
    # Ensure the label is not empty after sanitization
    if not sanitized_label:
        sanitized_label = "DVD_Unknown"
    return sanitized_label

# Function to get the volume label of the DVD/Blu-ray using win32api
def get_dvd_label(drive_letter):
    try:
        # Use win32api to get the volume label of the drive
        volume_label = win32api.GetVolumeInformation(drive_letter)[0]
        if not volume_label or volume_label == "":
            # Fallback in case the label is empty
            volume_label = f"DVD_{drive_letter}"
    except Exception as e:
        logging.error(f"Failed to get DVD label for {drive_letter}: {e}")
        volume_label = f"DVD_{drive_letter}"  # Fallback in case of error
    return volume_label

# Function to check if the drive contains a DVD (VIDEO_TS) or Blu-ray (BDMV, CERTIFICATE)
def check_media_type(drive_letter):
    if os.path.exists(os.path.join(drive_letter, "VIDEO_TS")):
        return "DVD"
    elif os.path.exists(os.path.join(drive_letter, "BDMV")) and os.path.exists(os.path.join(drive_letter, "CERTIFICATE")):
        return "Blu-ray"
    else:
        return None

# Function to wait for a DVD/Blu-ray in any of the drives
def wait_for_dvd_or_blu_ray():
    logging.info("Waiting for DVDs or Blu-rays...")
    print("Waiting for DVDs or Blu-rays...")
    while True:
        for drive_letter in DRIVE_LETTERS:
            media_type = check_media_type(drive_letter)
            if media_type:
                dvd_label = get_dvd_label(drive_letter)
                sanitized_label = sanitize_label(dvd_label)  # Sanitize the label for folder name
                logging.info(f"{media_type} Detected in {drive_letter} with label: {sanitized_label}")
                print(f"{media_type} Detected in {drive_letter} with label: {sanitized_label}")
                return drive_letter, sanitized_label, media_type  # Return drive, sanitized label, and media type
        time.sleep(10)

# Function to rip DVD/Blu-ray using MakeMKV
def rip_media(drive_letter, dvd_label, media_type):
    logging.info(f"Ripping {media_type} from {drive_letter} with MakeMKV...")
    print(f"Ripping {media_type} from {drive_letter} with MakeMKV...")
    output_folder = os.path.join(OUTPUT_FOLDER, dvd_label)  # Create a folder named after the sanitized label
    os.makedirs(output_folder, exist_ok=True)
    command = '"{}" mkv disc:0 all "{}"'.format(MAKEMKV_PATH, output_folder)
    subprocess.run(command, shell=True)
    logging.info(f"{media_type} from {drive_letter} ripped successfully to {output_folder}.")

# Function to convert MKV to MP4 using HandBrake
def convert_to_mp4(dvd_label):
    logging.info("Converting to MP4 with HandBrake...")
    print("Converting to MP4 with HandBrake...")
    output_folder = os.path.join(OUTPUT_FOLDER, dvd_label)
    for file in os.listdir(output_folder):
        if file.endswith(".mkv"):
            mkv_file = os.path.join(output_folder, file)
            mp4_file = mkv_file.replace(".mkv", ".mp4")
            command = '"{}" -i "{}" -o "{}" --preset "{}"'.format(HANDBRAKE_PATH, mkv_file, mp4_file, HANDBRAKE_PRESET)
            subprocess.run(command, shell=True)
            os.remove(mkv_file)  # Delete original MKV after conversion
            logging.info(f"Converted {mkv_file} to {mp4_file}.")

# Function to eject the DVD/Blu-ray
def eject_dvd_or_blu_ray(drive_letter):
    logging.info(f"Ejecting media from {drive_letter}...")
    print(f"Ejecting media from {drive_letter}...")
    shell = win32com.client.Dispatch("Shell.Application")
    drives = shell.Namespace(17)
    drive = drives.ParseName(drive_letter)
    drive.InvokeVerb("Eject")
    logging.info(f"Media from {drive_letter} ejected.")

# Run the full process for each DVD/Blu-ray drive
for drive_letter in DRIVE_LETTERS:
    drive, dvd_label, media_type = wait_for_dvd_or_blu_ray()  # Wait for DVD/Blu-ray and get details
    rip_media(drive, dvd_label, media_type)  # Rip the media based on its type (DVD or Blu-ray)
    convert_to_mp4(dvd_label)  # Convert MKV files to MP4 using label-based folder
    eject_dvd_or_blu_ray(drive)  # Eject the media from the drive
    logging.info(f"Process Complete for drive: {drive}")
    print(f"Process Complete for drive {drive} with label: {dvd_label} and media type: {media_type}!")