Skip to content

Commit

Permalink
Make rclone only download specified torrent instead of all of em
Browse files Browse the repository at this point in the history
  • Loading branch information
riley-martine committed May 13, 2023
1 parent a0e240b commit fe37543
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.prev_kindle_ip
/scripts/testtorrents
39 changes: 39 additions & 0 deletions scripts/get_download_target.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/opt/homebrew/bin/python3.11
"""Get the top-level directory or file inside the torrent to look for to download."""

# Needs to be brew python3.11 for libtorrent bindings

import pathlib
import sys
import warnings

import libtorrent

# libtorrent uses dunder methods for some things and we want clean output
warnings.filterwarnings("ignore", category=DeprecationWarning)

if len(sys.argv) != 2:
print("Pass an argument.", file=sys.stderr)
sys.exit(1)

torrent_file = pathlib.Path(sys.argv[1])
if not torrent_file.is_file():
print(f"Cannot find file at: {torrent_file}", file=sys.stderr)
sys.exit(1)

info = libtorrent.torrent_info(torrent_file.resolve().as_posix())
paths = [file.path for file in info.files()]

# Assume everything either has one dir containing everything,
# or one file w/o a dir

chunked_paths = [pathlib.Path(p).parts for p in paths]
if len(["x" for parts in chunked_paths if not len(parts) > 1]) > 1:
print(chunked_paths, file=sys.stderr)
raise NotImplementedError("Expected at most one top level file.")

if len({len(parts) > 1 for parts in chunked_paths}) != 1:
print(chunked_paths, file=sys.stderr)
raise NotImplementedError("Both a top-level directory and file exist.")

print(chunked_paths[0][0])
8 changes: 6 additions & 2 deletions scripts/wait_and_download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ echo "Waiting for $TORRENT_NAME to finish downloading to seedbox..."
retry 240 is_complete "$TORRENT_NAME"
echo "$TORRENT_NAME has completed download to seedbox. Downloading new torrents to local..."

DOWNLOAD_TARGET="$(./get_download_target.py "$1")"
echo "Grabbing $DOWNLOAD_TARGET"

rclone --config "$RCLONE_CONF" --max-age 24h --no-traverse copy \
seedbox:/home/"$SEEDBOX_USER"/twatch_out/ ~/Downloads
echo "Done downloading new torrents."
seedbox:/home/"$SEEDBOX_USER"/twatch_out/"$DOWNLOAD_TARGET" \
~/Downloads/"$DOWNLOAD_TARGET"
echo "Done downloading torrent."

function send_epubs {
set -x
Expand Down

0 comments on commit fe37543

Please sign in to comment.