Files
autoDvdRipper/main.py
2025-08-22 20:00:14 +01:00

62 lines
1.9 KiB
Python

import openDrive
import time
import os
from imdb import Cinemagoer
import uploadresults
from dotenv import load_dotenv
load_dotenv()
DVD_DEVICE = "/dev/sr0"
def ripDvd(driveName):
print("- DVD has been detected")
print("- Searching IMDB for " + driveName)
ia = Cinemagoer()
try:
movie = ia.get_movie(ia.search_movie(driveName)[0].getID())
movieName = movie['title'] + " (" + str(movie["year"]) + ")"
print("- Movie has been identified as " + movieName)
print("- Movie has been found, will now procede to ripping DVD")
except IndexError:
print("- Movie could not be found, will use name " + driveName)
print("- Will now procede to ripping DVD")
movieName = driveName
os.system('HandBrakeCLI -i /dev/sr0 -o output/"' + movieName + '.mp4" --preset-import-file preset.json')
print("- Movie has been ripped, will now procede to upload file")
uploadresults.upload()
print("- Movie has been uploaded")
def waitForDvd():
print("- Insert a DVD into drive")
time.sleep(3)
dvdfound = False
while (dvdfound == False):
fh = open ("/etc/mtab", "r")
for i in fh:
if i.split(" ", 1)[0] == DVD_DEVICE:
dvdfound = True
driveName = i.split(" ", 1)[1].split("/")[-1].split(" ")[0]
ripDvd(driveName)
fh.close()
time.sleep(1)
def addOutputFolder():
if (os.path.isdir('output') == False):
os.mkdir('output')
addOutputFolder()
print("-----------------------------------------------")
print("- Auto DVD Ripper -")
print("-----------------------------------------------")
input("-------- Press enter to open dvd drive --------\n-----------------------------------------------\n")
openDrive.open()
while True:
waitForDvd()
print("-----------------------")
print("- DVD has been ripped -")
print("-----------------------")
openDrive.open()