Skip to content

Commit 0244100

Browse files
committed
torrents-add: prevent adding duplicates
1 parent 93c2784 commit 0244100

File tree

4 files changed

+37
-12
lines changed

4 files changed

+37
-12
lines changed

xklb/createdb/torrents_add.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ def torrents_add():
7979
try:
8080
pl_columns = db_utils.columns(args, "playlists")
8181

82+
known_hashes = {d["info_hash"] for d in args.db.query("select info_hash from playlists")}
83+
8284
existing_set = {
8385
d["path"]
8486
for d in args.db.query(
@@ -114,6 +116,15 @@ def torrents_add():
114116
if args.verbose >= consts.LOG_DEBUG:
115117
raise
116118
else:
119+
if torrent_info["info_hash"] in known_hashes and not args.force:
120+
log.info(
121+
"[%s]: Skipping known info_hash %s. Use --force to override",
122+
torrent_info["path"],
123+
torrent_info["info_hash"],
124+
)
125+
continue
126+
known_hashes.add(torrent_info["info_hash"])
127+
117128
percent = (idx + 1) / num_paths * 100
118129
eta = printing.eta(idx + 1, num_paths, start_time=start_time) if num_paths > 2 else ""
119130
printing.print_overwrite(

xklb/playback/torrents_info.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,26 @@ def torrents_info():
3434
processes.no_media_found()
3535

3636
torrents = sorted(torrents, key=lambda t: -t.time_active)
37-
printing.extended_view(torrents)
38-
if args.verbose >= consts.LOG_INFO:
39-
for torrent in torrents:
40-
files = torrent.files
41-
if args.file_search:
42-
files = [f for f in torrent.files if strings.glob_match(args.file_search, [f.name])]
37+
for torrent in torrents:
38+
printing.extended_view(torrent)
4339

40+
files = torrent.files
41+
if args.file_search:
42+
files = [f for f in torrent.files if strings.glob_match(args.file_search, [f.name])]
43+
44+
if args.verbose >= consts.LOG_INFO:
4445
printing.extended_view(files)
4546

47+
if len(torrent.files) == 1:
48+
print('1 file')
49+
elif args.file_search:
50+
print(len(files), 'files of', len(torrent.files), 'matched')
51+
else:
52+
print(len(torrent.files), 'total files')
53+
print()
54+
55+
print(len(torrents), 'matched torrents')
56+
4657
torrent_hashes = [t.hash for t in torrents]
4758
if args.mark_deleted:
4859
qbt_client.torrents_add_tags(tags="xklb-delete", torrent_hashes=torrent_hashes)
@@ -93,8 +104,9 @@ def torrents_info():
93104
for t in torrents
94105
]
95106
)
96-
printing.table(tbl)
97-
print()
107+
if tbl:
108+
printing.table(tbl)
109+
print()
98110

99111
tbl = []
100112
for state in interesting_states:
@@ -120,8 +132,9 @@ def torrents_info():
120132
for t in torrents
121133
]
122134
)
123-
printing.table(tbl)
124-
print()
135+
if tbl:
136+
printing.table(tbl)
137+
print()
125138

126139
categories = []
127140
for state, torrents in torrents_by_state.items():

xklb/scratch/mam_search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def parse_args():
1515
parser.add_argument("--description", action=argparse.BooleanOptionalAction, default=False)
1616
parser.add_argument("--tags", action=argparse.BooleanOptionalAction, default=False)
1717

18-
parser.add_argument("--categories", "--category", type=int, nargs='+')
18+
parser.add_argument("--categories", "--category", type=int, nargs="+")
1919
parser.add_argument("--books", action=argparse.BooleanOptionalAction, default=False)
2020
parser.add_argument("--audiobooks", action=argparse.BooleanOptionalAction, default=False)
2121
parser.add_argument("--comics", action=argparse.BooleanOptionalAction, default=False)

xklb/utils/printing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ def extended_view(iterable):
5050
for key, value in item.items():
5151
formatted_key = f"{key.ljust(max_key_length)} |"
5252
print(formatted_key, value)
53-
print()
53+
if print_index:
54+
print()
5455

5556

5657
def pipe_print(*args) -> None:

0 commit comments

Comments
 (0)