Skip to content

Conversation

@kw6423
Copy link
Contributor

@kw6423 kw6423 commented Jun 18, 2025

🚀 Refactor repair.py: Improved Logging and Async Search Status Monitoring

📌 Summary

This PR focuses on enhancing the logging experience within repair.py and integrating non-blocking async monitoring of Radarr/Sonarr search tasks.

Key goals:

  • 🧾 Cleaner and more readable logs
  • 🚦 Standardized log levels (INFO, WARNING, ERROR, SUCCESS)
  • 🧵 Background monitoring for automatic search results

✅ What's Changed

🔹 Logging Enhancements

  • Updated the existing print() wrapper:
    • Removed millisecond precision from timestamps
    • Added support for structured level= log levels (e.g. INFO, ERROR)
  • Introduced print_section(title) helper for clearly labeled output sections
  • Moved the existing logic for [mode]-prefixed Discord messages into wrapper functions:
    • discordUpdate(title, message)
    • discordError(title, message)
    • These simply prepend [args.mode] to match existing message format in a reusable way

🔹 Async Search Monitoring

  • Introduced check_automatic_search_status():
    • Asynchronously polls the Radarr/Sonarr command status via their /command/{id} API
    • Runs in 30-second intervals, up to 3 retries
    • Logs and sends Discord messages on success/failure
  • Implemented run_async_in_thread() to execute the coroutine in a separate thread without blocking the repair loop

🔹 Minor Cleanups

  • Moved some messaging out of tight loops for clarity

🗂 Affected Files

  • repair.py
  • shared/arr.py

📝 Notes

  • No functional logic changes to how repairs or error handling are performed
  • Discord message formatting remains the same — just centralized via wrappers
  • Backward-compatible with existing use cases

📣 Example Output

[2025-06-18 03:14:34] [symlink] [INFO]  Running repair once every 6h, and waiting 10m between each repair.
[2025-06-18 03:14:34] [symlink] [INFO] 
[2025-06-18 03:14:34] [symlink] [INFO]  ===========================
[2025-06-18 03:14:34] [symlink] [INFO]    STARTING REPAIR PROCESS
[2025-06-18 03:14:34] [symlink] [INFO]  ===========================
[2025-06-18 03:14:34] [symlink] [INFO] 
[2025-06-18 03:14:34] [symlink] [INFO]  Collecting media from Sonarr and Radarr...
[2025-06-18 03:14:34] [symlink] [SUCCESS]  ✓ Collected 7 Sonarr items and 56 Radarr items
[2025-06-18 03:14:45] [symlink] [INFO] 
[2025-06-18 03:14:45] [symlink] [INFO]  ------------------------------------------------------------
[2025-06-18 03:14:45] [symlink] [INFO]    REPAIRING THE FAST AND THE FURIOUS: TOKYO DRIFT (ID: 84)
[2025-06-18 03:14:45] [symlink] [INFO]  ------------------------------------------------------------
[2025-06-18 03:14:45] [symlink] [INFO] 
[2025-06-18 03:14:45] [symlink] [INFO]  Found 1 broken items:
[2025-06-18 03:14:45] [symlink] [INFO]  /mnt/remote/realdebrid/__all__/The Fast And The Furious Tokyo Drift (2006) [2160p] [4K] [BluRay] [5.1] [YTS.MX]/The.Fast.And.The.Furious.Tokyo.Drift.2006.2160p.4K.BluRay.x265.10bit.AAC5.1-[YTS.MX].mkv
[2025-06-18 03:14:45] [symlink] [INFO] 
[2025-06-18 03:14:45] [symlink] [INFO]  Deleting broken symlinks...
[2025-06-18 03:14:45] [symlink] [INFO]  /mnt/jellyfin/Movies/The Fast and the Furious - Tokyo Drift (2006) [tmdbid-9615]/The Fast and the Furious - Tokyo Drift (2006) Bluray-2160p [tmdbid-9615].mkv
[2025-06-18 03:14:45] [symlink] [INFO]  Re-monitoring
[2025-06-18 03:14:45] [symlink] [INFO]  Searching for replacement files for The Fast and the Furious: Tokyo Drift
[2025-06-18 03:14:45] [symlink] [INFO]  Waiting 10m before next repair...
[2025-06-18 03:15:15] [symlink] [SUCCESS]  Search for The Fast and the Furious: Tokyo Drift succeeded: Completed search for 1 movies. 1 reports downloaded.
[2025-06-18 03:24:45] [symlink] [INFO] 
[2025-06-18 03:24:45] [symlink] [INFO] 
[2025-06-18 03:24:45] [symlink] [INFO]  ======================
[2025-06-18 03:24:45] [symlink] [INFO]    SEASON PACKS START
[2025-06-18 03:24:45] [symlink] [INFO]  ======================
[2025-06-18 03:24:45] [symlink] [INFO] 
[2025-06-18 03:24:45] [symlink] [INFO]  Black Mirror has 6 non-season-pack folders. Run with --season-packs to upgrade to season-pack.
[2025-06-18 03:24:45] [symlink] [INFO]  The Simpsons has 36 non-season-pack folders. Run with --season-packs to upgrade to season-pack.
[2025-06-18 03:24:45] [symlink] [INFO]  Big Mouth has 10 non-season-pack folders. Run with --season-packs to upgrade to season-pack.
[2025-06-18 03:24:45] [symlink] [INFO] 
[2025-06-18 03:24:45] [symlink] [INFO]  ====================
[2025-06-18 03:24:45] [symlink] [INFO]    SEASON PACKS END
[2025-06-18 03:24:45] [symlink] [INFO]  ====================
[2025-06-18 03:24:45] [symlink] [INFO] 
[2025-06-18 03:24:45] [symlink] [INFO] 
[2025-06-18 03:24:45] [symlink] [INFO]  ===================
[2025-06-18 03:24:45] [symlink] [INFO]    REPAIR COMPLETE
[2025-06-18 03:24:45] [symlink] [INFO]  ===================
[2025-06-18 03:24:45] [symlink] [INFO] 
[2025-06-18 03:24:45] [symlink] [INFO]  Run Interval: Waiting for 6h before next run...

@kw6423 kw6423 closed this Jun 18, 2025
@kw6423 kw6423 reopened this Jun 18, 2025
@kw6423 kw6423 closed this Jun 18, 2025
@kw6423 kw6423 reopened this Jun 18, 2025
kw6423 and others added 5 commits June 19, 2025 12:00
…g. Add automatic search status check in Arr.
Co-authored-by: westsurname <155189104+westsurname@users.noreply.github.com>
Changed to camelCase
Other Minor changes

Season Packs
Optimized section
Added empty prints for style
Fixed dry run not applied

checkAutomaticSearchStatus
Removed discordUpdate on search succesful as it's misleading since it doesn't really tell if media was grabbed.
Add 0 reports downloaded in message detection, if True send ErrorUpdate to discord.
… were deleted in media folder but were still in mount
if not args.dry_run and (args.no_confirm or input("Do you want to initiate a search for a season-pack? (y/n): ").lower() == 'y'):
results = arr.automaticSearch(media, childId)
runAsyncInThread(checkAutomaticSearchStatus(arr, results['id'], media.title, childId))
elif args.mode == 'symlink' and childId in media.fullyAvailableChildrenIds and len(parentFolders) > 1:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just as an fyi, sometimes I keep ifs nested for separation of interest purposes

return
elif searchSuccessful is False:
errorMsg = f"Search for {mediaTitle} {seasonNumber} failed: {message}"
if status == "failed" or "0 reports downloaded." in message:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 0 reports downloaded discord messaging might become an issue long term, especially for season upgrade cases. Let's keep an eye on it after the merge before release.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kw6423 This is definitely an issue

@westsurname westsurname merged commit 890e5dc into westsurname:main Jun 24, 2025
0 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants