74 lines
2.4 KiB
Python
74 lines
2.4 KiB
Python
import openDrive
|
|
import time
|
|
import os
|
|
from imdb import Cinemagoer
|
|
import paramiko
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv()
|
|
|
|
DVD_DEVICE = "/dev/sr0"
|
|
|
|
uploadPath = os.getenv('UPLOAD_PATH')
|
|
|
|
sftpHost = os.getenv('SFTP_HOST')
|
|
sftpPort = int(os.getenv('SFTP_PORT'))
|
|
sftpUsername = os.getenv('SFTP_USERNAME')
|
|
sftpPassword = os.getenv('SFTP_PASSWORD')
|
|
|
|
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')
|
|
sftpTransport = paramiko.Transport((sftpHost, sftpPort))
|
|
sftpTransport.connect(username = sftpUsername, password = sftpPassword)
|
|
sftp = paramiko.SFTPClient.from_transport(sftpTransport)
|
|
print("- Movie has been ripped, will now procede to upload file")
|
|
sftp.put('output/"' + movieName + '.mp4"', uploadPath + movieName + '.mp4')
|
|
sftp.close()
|
|
sftpTransport.close()
|
|
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()
|