-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·104 lines (85 loc) · 3.15 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env python3
import sys
import argparse
import functions
import connectionhandler
if __name__ == "__main__":
# handle argument parsing
parser = argparse.ArgumentParser(
description="This tool finds .torrent files in your download folder\
and gives the option to move them directly into a shared seedbox via\
FTP. it also allows for download of that file, as well as moving the\
.torrent files somewhere convenient after processing."
)
# only upload files to seedbox.io,
parser.add_argument(
"--upload",
"-u",
action="store_true",
help="upload files to seedbox.io using the\
credentials in the config",
)
parser.add_argument(
"--print",
"-p",
action="store_true",
help="print files in inbound torrent folder",
)
parser.add_argument(
"--move",
"-m",
action="store_true",
help="move files in inbound folder to outbound torrent folder",
) # move torrent files locally
parser.add_argument(
"--download",
"-d",
action="store_true",
help="Download torrents from seedbox.io to the specified folder.",
) # download torrents
args = parser.parse_args()
# Handle the config file
config = functions.yamlDataExtract()
TORRENT_DIR = config["torrent_dir"]
TARGET_DIR = config["target_dir"]
SEEDBOX_ADDR = config["seedbox_addr"]
SEEDBOX_LOGIN = config["seedbox_login"]
SEEDBOX_PW = config["seedbox_pw"]
# create list of torrent files present in from_torrents, not present in to_torrents
torrents = functions.getTorrentDiffList(TARGET_DIR, TORRENT_DIR)
num_torrents = len(torrents)
if num_torrents == 0:
print(f"Aborting because no torrents were found in {TARGET_DIR}")
sys.exit()
if args.print or args.download or args.upload is True:
for entry in torrents:
print(f"Found torrent file ::: {entry.name}")
if args.upload or args.download is True:
sftp = connectionhandler.SeedboxFTP(SEEDBOX_ADDR, SEEDBOX_LOGIN, SEEDBOX_PW)
print(f"attempting to connect to {SEEDBOX_ADDR}")
sftp.connect()
if args.upload is True:
print(f"attempting to upload {num_torrents} to {SEEDBOX_ADDR}.")
# set CWD to Watch folder
sftp.changeWorkingDirectory(remotePath="watch")
# loop through torrent list, and send them to the seedbox
for torrent in torrents:
sftp.testUpload(torrent)
if args.download is True:
sftp.changeWorkingDirectory(remotePath="/files/")
for torrent in torrents:
torrentfile = functions.getFileNamefromTorrent(torrent)
print(f"processing {torrentfile}")
sftp.downloadRemoteDir(
torrentfile,
destination=TARGET_DIR,
)
if args.move is True:
print(f"moving torrents to {TORRENT_DIR}")
functions.moveManager(torrents, TORRENT_DIR)
# this just sees if an ftp instance was created, and if it does exist, disconnects.
try:
sftp.disconnect()
print("disconnected successfully.")
except NameError:
pass