Integrated new upload sys with main file

This commit is contained in:
hyvenet
2025-08-22 19:59:26 +01:00
parent 4badbcee58
commit 35633b93ca
2 changed files with 27 additions and 39 deletions

16
main.py
View File

@@ -2,20 +2,13 @@ import openDrive
import time
import os
from imdb import Cinemagoer
import paramiko
import uploadresults
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)
@@ -30,13 +23,8 @@ def ripDvd(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():

View File

@@ -2,35 +2,35 @@ import paramiko
import os
from dotenv import load_dotenv
load_dotenv()
def upload():
load_dotenv()
hostname = os.getenv('SFTP_HOST')
port = int(os.getenv('SFTP_PORT'))
username = os.getenv('SFTP_USERNAME')
password = os.getenv('SFTP_PASSWORD')
hostname = os.getenv('SFTP_HOST')
port = int(os.getenv('SFTP_PORT'))
username = os.getenv('SFTP_USERNAME')
password = os.getenv('SFTP_PASSWORD')
remote_directory = os.getenv('UPLOAD_PATH')
local_directory = 'output/' # Where to save the downloaded files
remote_directory = os.getenv('UPLOAD_PATH')
local_directory = 'output/' # Where to save the downloaded files
# Create an SSH client
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # Automatically add the server's host key, {Link: according to Medium https://medium.com/nerd-for-tech/paramiko-how-to-transfer-files-with-remote-system-sftp-servers-using-python-52d3e51d2cfa}
ssh_client.connect(hostname, port, username, password)
# Create an SSH client
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # Automatically add the server's host key, {Link: according to Medium https://medium.com/nerd-for-tech/paramiko-how-to-transfer-files-with-remote-system-sftp-servers-using-python-52d3e51d2cfa}
ssh_client.connect(hostname, port, username, password)
# Open an SFTP session
sftp = ssh_client.open_sftp()
# Open an SFTP session
sftp = ssh_client.open_sftp()
# List the files in the remote directory
for filename in os.listdir(local_directory):
remote_filepath = os.path.join(remote_directory, filename)
local_filepath = os.path.join(local_directory, filename)
# List the files in the remote directory
for filename in os.listdir(local_directory):
remote_filepath = os.path.join(remote_directory, filename)
local_filepath = os.path.join(local_directory, filename)
# Download each file
sftp.put(local_filepath, remote_filepath)
print(f"Uploaded: {local_filepath} to {remote_filepath}")
# Download each file
sftp.put(local_filepath, remote_filepath)
print(f"Uploaded: {local_filepath} to {remote_filepath}")
# Close the SFTP session and SSH connection
sftp.close()
ssh_client.close()
print("All files downloaded and connections closed.")
# Close the SFTP session and SSH connection
sftp.close()
ssh_client.close()
print("All files downloaded and connections closed.")