Skip to content

Commit

Permalink
More opts
Browse files Browse the repository at this point in the history
  • Loading branch information
sdfordham committed Mar 15, 2023
1 parent 9034f01 commit fdaba65
Showing 1 changed file with 43 additions and 13 deletions.
56 changes: 43 additions & 13 deletions tautoloader/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def main(
username: Optional[str],
password: Optional[str],
sleep: int,
cutoff: float,
prompt: bool
):
# Get the files
torrent_files = [
Expand All @@ -32,35 +34,61 @@ def main(
res = cmd.exec()
client_output = parse_list_output(res)

res = None
for tf in torrent_files:
if exclude_tracker and (
tf.tracker is None or re.match(exclude_tracker, tf.tracker)
):
continue
tf.find_data(data_files)
tf.find_data(data_files, cutoff)

if tf.data:
print(f"Torrent file @ {tf.path}\n from tracker {tf.tracker}")

if len(tf.data) == 1:
download_dir = tf.data[0].parent
print(f"matched data @ {download_dir}\nAdding to transmission...")

cmd = TransmissionCommand()
if username and password:
cmd.auth(username, password)
cmd.add(tf.path).download_dir(download_dir)
res = cmd.exec()

print("Transmission response:", res)
time.sleep(sleep)
print(f"matched data @ {download_dir}")
elif len(tf.data) > 1:
uniq_parents = {f.parent for f in tf.data}
if len(uniq_parents) == 1:
print(f"matched data @ {tf.data[0].parent}")
download_dir = tf.data[0].parent
else:
print(f"matched data @ (multiple locations, skipping)")
print(f"matched data @ (multiple locations)")
for idx, f in enumerate(uniq_parents):
print(f" {idx}. {f}")
print("\n ============ \n")
download_dir = None

cmd = TransmissionCommand()
if username and password:
cmd.auth(username, password)
cmd.add(tf.path)

if not prompt and download_dir:
cmd.download_dir(download_dir)
res = cmd.exec()
else:
print("Add to transmission?")
inp = input("1. Yes, 2. No, 3. Provide download directory\n")
if inp.strip('.') == '1' and download_dir:
cmd.download_dir(download_dir)
res = cmd.exec()
elif inp.strip('.') == '2':
continue
elif inp.strip('.') == '3':
inp = input("Enter download directory: ")
if Path(inp).is_dir():
cmd.download_directory(inp)
res = cmd.exec()
else:
raise ValueError("Directory does nae exist.")
else:
raise ValueError("Invalid option and/or no download directory.")

print("Transmission response:", res)
time.sleep(sleep)
else:
print("No torrent data found for", tf)


if __name__ == "__main__":
Expand All @@ -70,6 +98,8 @@ def main(
parser.add_argument("-e", "--exclude_tracker", type=str, default=None)
parser.add_argument("-u", "--username", type=str, default=None)
parser.add_argument("-s", "--sleep", type=int, default=5)
parser.add_argument("-c", "--cutoff", type=float, default=0.9)
parser.add_argument("-p", "--prompt", type=bool, default=True)
args = vars(parser.parse_args())

args["password"] = getpass() if args["username"] else None
Expand Down

0 comments on commit fdaba65

Please sign in to comment.