-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make rclone only download specified torrent instead of all of em
- Loading branch information
1 parent
a0e240b
commit fe37543
Showing
3 changed files
with
46 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
.prev_kindle_ip | ||
/scripts/testtorrents |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters