Skip to content

Fix three robustness issues: config encoding, TV category mapping, optional TVDB lookup - #178

Closed
spadieri85 wants to merge 3 commits into
31December99:mainfrom
spadieri85:fix/config-encoding-tv-category-optional-tvdb
Closed

spadieri85 wants to merge 3 commits into
31December99:mainfrom
spadieri85:fix/config-encoding-tv-category-optional-tvdb

Conversation

@spadieri85

@spadieri85 spadieri85 commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

Three small, independent fixes, one commit each so they can be cherry-picked or dropped separately.

Closes #175
Closes #176
Closes #177


1. Read the config file with explicit UTF-8 encoding (common/settings.py)

open() without an encoding falls back to the system locale, so on Windows (cp1252) loading Unit3Dbot.json fails with UnicodeDecodeError. It is reached with the shipped default, because MY_TEXT_H contains ━ (U+2501). Writing already uses encoding="utf-8" in create_ban_list_file(), so this only makes the two read paths consistent.

2. Use CATEGORY_TV in the tv branch of _add_torrent_and_tag() (common/torrent_clients.py)

The tv branch assigned CATEGORY_MOVIE. To be precise about the severity: this block is normally unreachable, because the only caller (send_to_client()) passes a category already resolved by _get_category(), so the == 'tv' comparison does not match and no TV upload is misfiled in a default setup. It becomes a real bug only for users who set CATEGORY_TV to the literal string tv in their config.

The commit takes the conservative option — fix the constant, keep the block — but the block could equally well be deleted, since the value arrives already resolved. Happy to switch to that if you prefer.

3. Make the TVDB lookup optional instead of fatal (common/external_services/theMovieDB/core/api.py)

tvdb_search() built a TVDB client unconditionally — for movies too, and when TVDB_APIKEY is still the generated default "no_key". The resulting 401 aborted the whole run, and it did so after hashing had completed, discarding several minutes of work on large packs.

The lookup is now skipped when no key is configured, and any error degrades to None. The caller already handles a falsy result (if tvdb_result:), and uploads complete with the TMDB id alone — a series upload to a UNIT3D tracker is accepted without tvdb_id.


Testing

  • python -m py_compile on all three touched files.
  • Fix 1 and fix 3 verified in real use: the equivalent patch has been running in a headless Docker deployment without a TVDB key, where both a season-pack upload and several movie dry-runs complete instead of crashing.
  • Fix 2 is verified by inspection only, and is a latent fix rather than an observed failure — see the note above and Unreachable category remapping in _add_torrent_and_tag maps 'tv' to CATEGORY_MOVIE #176.

spadieri85 and others added 3 commits August 31, 2026 14:27
open() without an encoding falls back to the system locale, so on Windows
(cp1252) loading the configuration fails with UnicodeDecodeError. The shipped
default triggers it: MY_TEXT_H contains U+2501, which cp1252 cannot decode.

Writing already uses encoding="utf-8" in create_ban_list_file(); this makes
the read paths consistent.

Fixes #175

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
_add_torrent_and_tag() mapped the 'tv' category to CATEGORY_MOVIE, so every
series was filed under the movie category and CATEGORY_TV was never used on
this path. _get_category() in the same module already maps it correctly.

Fixes #176

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
tvdb_search() built a TVDB client unconditionally, including for movies and
when TVDB_APIKEY is still the generated default "no_key". The resulting 401
aborted the run after hashing had already completed, discarding several
minutes of work on large packs.

Skip the lookup when no key is configured and degrade to None on error; the
caller already handles a falsy result, and uploads succeed with the TMDB id
alone.

Fixes #177

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant