Integrated new upload sys with main file
This commit is contained in:
16
main.py
16
main.py
@@ -2,20 +2,13 @@ import openDrive
|
|||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
from imdb import Cinemagoer
|
from imdb import Cinemagoer
|
||||||
import paramiko
|
import uploadresults
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
DVD_DEVICE = "/dev/sr0"
|
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):
|
def ripDvd(driveName):
|
||||||
print("- DVD has been detected")
|
print("- DVD has been detected")
|
||||||
print("- Searching IMDB for " + driveName)
|
print("- Searching IMDB for " + driveName)
|
||||||
@@ -30,13 +23,8 @@ def ripDvd(driveName):
|
|||||||
print("- Will now procede to ripping DVD")
|
print("- Will now procede to ripping DVD")
|
||||||
movieName = driveName
|
movieName = driveName
|
||||||
os.system('HandBrakeCLI -i /dev/sr0 -o output/"' + movieName + '.mp4" --preset-import-file preset.json')
|
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")
|
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")
|
print("- Movie has been uploaded")
|
||||||
|
|
||||||
def waitForDvd():
|
def waitForDvd():
|
||||||
|
|||||||
@@ -2,35 +2,35 @@ import paramiko
|
|||||||
import os
|
import os
|
||||||
from dotenv import load_dotenv
|
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')
|
remote_directory = os.getenv('UPLOAD_PATH')
|
||||||
port = int(os.getenv('SFTP_PORT'))
|
local_directory = 'output/' # Where to save the downloaded files
|
||||||
username = os.getenv('SFTP_USERNAME')
|
|
||||||
password = os.getenv('SFTP_PASSWORD')
|
|
||||||
|
|
||||||
remote_directory = os.getenv('UPLOAD_PATH')
|
# Create an SSH client
|
||||||
local_directory = 'output/' # Where to save the downloaded files
|
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
|
# Open an SFTP session
|
||||||
ssh_client = paramiko.SSHClient()
|
sftp = ssh_client.open_sftp()
|
||||||
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
|
# List the files in the remote directory
|
||||||
sftp = ssh_client.open_sftp()
|
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
|
# Download each file
|
||||||
for filename in os.listdir(local_directory):
|
sftp.put(local_filepath, remote_filepath)
|
||||||
remote_filepath = os.path.join(remote_directory, filename)
|
print(f"Uploaded: {local_filepath} to {remote_filepath}")
|
||||||
local_filepath = os.path.join(local_directory, filename)
|
|
||||||
|
|
||||||
# Download each file
|
# Close the SFTP session and SSH connection
|
||||||
sftp.put(local_filepath, remote_filepath)
|
sftp.close()
|
||||||
print(f"Uploaded: {local_filepath} to {remote_filepath}")
|
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.")
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user