Skip to content

Commit 6d14d29

Browse files
committed
Changes per review of Dark3clipse
1 parent 5ec2a62 commit 6d14d29

File tree

8 files changed

+38
-26
lines changed

8 files changed

+38
-26
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ jobs:
121121
fi
122122
123123
docker buildx build \
124-
--platform linux/amd64,linux/arm64 -f docker/dockerfile . \
124+
--platform linux/amd64,linux/arm64 -f docker/Dockerfile . \
125125
--progress plain \
126126
-t $IMAGE_NAME:$IMAGE_TAG \
127127
$TAG_LATEST \

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ How to run this:
9898

9999
## Getting started
100100

101-
You can run decluttarr either as local python script, or inside docker.
101+
You can run decluttarr either as local python script, or as a docker container.
102102

103103
### Running locally
104104

@@ -117,7 +117,7 @@ jobs:
117117
remove_bad_files: # This is turned on
118118
# remove_bad_files: # This is turned off
119119
120-
## Note that this is different from docker-compose (where both exsmples above would be turned off; in docker, "true" or additional options are required as value next to the key)
120+
## Note that this is different from docker-compose (where both examples above would be turned off; in docker, "true" or additional options are required as value next to the key)
121121
```
122122

123123

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#FROM python:3.9-slim-buster
22
# For debugging:
33
# First build:
4-
# sudo docker build --no-cache --progress=plain -f ./docker/dockerfile -t decluttarr .
4+
# sudo docker build --no-cache --progress=plain -f ./docker/Dockerfile -t decluttarr .
55

66
# Entering image (and printing env variables):
77
# sudo docker run --rm -it -w /app --entrypoint sh decluttarr -c "printenv; exec sh"

src/jobs/removal_handler.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ async def _get_handling_method(self, download_id, affected_download):
5454
if affected_download['protocol'] != 'torrent':
5555
return "remove" # handling is only implemented for torrent
5656

57-
client_implementation = await self.arr.get_download_client_implementation(affected_download['downloadClient'])
58-
if client_implementation != "QBittorrent":
57+
download_client_name = affected_download["downloadClient"]
58+
_, download_client_type = self.settings.download_clients.get_download_client_by_name(download_client_name)
59+
60+
if download_client_type != "qbittorrent":
5961
return "remove" # handling is only implemented for qbit
6062

6163
if len(self.settings.download_clients.qbittorrent) == 0:

src/jobs/remove_bad_files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# Movies, TV Shows (Radarr, Sonarr, Whisparr)
1010
".webm", ".m4v", ".3gp", ".nsv", ".ty", ".strm", ".rm", ".rmvb", ".m3u", ".ifo", ".mov", ".qt", ".divx", ".xvid", ".bivx", ".nrg", ".pva", ".wmv", ".asf", ".asx", ".ogm", ".ogv", ".m2v", ".avi", ".bin", ".dat", ".dvr-ms", ".mpg", ".mpeg", ".mp4", ".avc", ".vp3", ".svq3", ".nuv", ".viv", ".dv", ".fli", ".flv", ".wpl", ".img", ".iso", ".vob", ".mkv", ".mk3d", ".ts", ".wtv", ".m2ts",
1111
# Subs (Radarr, Sonarr, Whisparr)
12-
".sub", ".srt", ".idx",
12+
".sub", ".srt", ".idx", "vtt",
1313
# Audio (Lidarr, Readarr)
1414
".aac", ".aif", ".aiff", ".aifc", ".ape", ".flac", ".mp2", ".mp3", ".m4a", ".m4b", ".m4p", ".mp4a", ".oga", ".ogg", ".opus", ".vorbis", ".wma", ".wav", ".wv", "wavepack",
1515
# Text (Readarr)

src/jobs/remove_missing_files.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ async def _find_affected_items(self):
99
affected_items = []
1010

1111
for item in self.queue:
12-
if self._is_failed_torrent(item) or self._no_elibible_import(item):
12+
if self._is_failed_torrent(item) or self._no_eligible_import(item):
1313
affected_items.append(item)
1414
return affected_items
1515

@@ -19,19 +19,26 @@ def _is_failed_torrent(item) -> bool:
1919
"status" in item
2020
and item["status"] == "warning"
2121
and "errorMessage" in item
22-
and item["errorMessage"] in [
22+
and item["errorMessage"]
23+
in [
2324
"DownloadClientQbittorrentTorrentStateMissingFiles",
2425
"The download is missing files",
2526
"qBittorrent is reporting missing files",
2627
]
2728
)
2829

2930
@staticmethod
30-
def _no_elibible_import(item) -> bool:
31-
if "status" in item and item["status"] == "completed" and "statusMessages" in item:
31+
def _no_eligible_import(item) -> bool:
32+
if (
33+
"status" in item
34+
and item["status"] == "completed"
35+
and "statusMessages" in item
36+
):
3237
for status_message in item["statusMessages"]:
3338
if "messages" in status_message:
3439
for message in status_message["messages"]:
35-
if message.startswith("No files found are eligible for import in"):
40+
if message.startswith(
41+
"No files found are eligible for import in"
42+
):
3643
return True
3744
return False

src/settings/_download_clients.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ def get_download_client_by_name(self, name: str):
6666
download_clients = getattr(self, download_client_type, [])
6767

6868
# Check each client in the list
69-
for client in download_clients:
70-
if client.name.lower() == name_lower:
71-
return client, download_client_type
69+
for download_client in download_clients:
70+
if download_client.name.lower() == name_lower:
71+
return download_client, download_client_type
7272

7373
return None, None

tests/jobs/test_removal_handler.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,35 @@
55

66

77
@pytest.mark.parametrize(
8-
"qbittorrent_configured, is_private, client_impl, protocol, expected",
8+
"qbittorrent_configured, is_private, client_type, protocol, expected",
99
[
10-
(True, True, "QBittorrent", "torrent", "private_handling"),
11-
(True, False, "QBittorrent", "torrent", "public_handling"),
12-
(False, True, "QBittorrent", "torrent", "remove"),
13-
(False, False, "QBittorrent", "torrent", "remove"),
14-
(True, False, "Transmission", "torrent", "remove"), # unsupported client
15-
(True, False, "MyUseNetClient", "usenet", "remove"), # unsupported protocol
10+
(True, True, "qbittorrent", "torrent", "private_handling"),
11+
(True, False, "qbittorrent", "torrent", "public_handling"),
12+
(False, True, "qbittorrent", "torrent", "remove"),
13+
(False, False, "qbittorrent", "torrent", "remove"),
14+
(True, False, "transmission", "torrent", "remove"), # unsupported client
15+
(True, False, "myusenetclient", "usenet", "remove"), # unsupported protocol
1616
],
1717
)
1818
@pytest.mark.asyncio
1919
async def test_get_handling_method(
2020
qbittorrent_configured,
2121
is_private,
22-
client_impl,
22+
client_type,
2323
protocol,
2424
expected,
2525
):
2626
# Mock arr
2727
arr = AsyncMock()
2828
arr.tracker.private = ["A"] if is_private else []
29-
arr.get_download_client_implementation.return_value = client_impl
3029

31-
# Mock settings
30+
# Mock settings and get_download_client_by_name
3231
settings = MagicMock()
3332
settings.download_clients.qbittorrent = ["dummy"] if qbittorrent_configured else []
33+
34+
# Simulate (client_name, client_type) return
35+
settings.download_clients.get_download_client_by_name.return_value = ("client_name", client_type)
36+
3437
settings.general.private_tracker_handling = "private_handling"
3538
settings.general.public_tracker_handling = "public_handling"
3639

@@ -44,4 +47,4 @@ async def test_get_handling_method(
4447
result = await handler._get_handling_method( # pylint: disable=W0212
4548
"A", affected_download
4649
)
47-
assert result == expected
50+
assert result == expected

0 commit comments

Comments
 (0)