Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jellyfin notifier option #8730

Merged
merged 4 commits into from
Mar 8, 2024

Conversation

speedfreak01
Copy link

@speedfreak01 speedfreak01 commented Mar 6, 2024

Feature Request

Proposed changes in this pull request:

  • Adds new jellyfin notifier option

Basically a clone of the emby plugin before recent changes. Still uses the X-Emby-Token for auth.

Only minor changes are update the uri's to remove emby
Switch endpoints to use post requests
Fixed the test notification button for jellyfin users. (I never see a message in the jellyfin ui, but the api server responds with 204 ok)

API Endpoint docs
https://api.jellyfin.org/#tag/Notifications/operation/CreateAdminNotification (Used when testing connectivity)
https://api.jellyfin.org/#tag/Library/operation/PostAddedSeries (Used for post processing, updates specific show using tvdbid)
https://api.jellyfin.org/#tag/Library/operation/RefreshLibrary ( Used by Manage -> Update Jellyfin button)

Config
310501041-0e4dff91-5fc6-4531-9c74-0cae96984d7d

Update full library
310500912-b830a977-3323-41a0-af0a-a97a849dd5f9

Update single show
image

  • PR is based on the DEVELOP branch
  • Don't send big changes all at once. Split up big PRs into multiple smaller PRs that are easier to manage and review
  • Read contribution guide

Summary by CodeRabbit

  • New Features
    • Integrated Jellyfin notifier, allowing users to send update commands to Jellyfin Media Server.
    • Added Jellyfin settings in the configuration for enabling notifications, entering address and API key, and testing the connection.
    • Included an "Update Jellyfin" link in the main navigation for quick access if Jellyfin is configured.
  • Enhancements
    • Improved GUI with new icons for Jellyfin integration.
    • Enhanced system to automatically update Jellyfin library upon new episode processing or show updates.

Copy link
Contributor

coderabbitai bot commented Mar 6, 2024

Walkthrough

This update expands SickChill's functionality by integrating Jellyfin, enabling users to seamlessly connect their media library with Jellyfin for automatic updates and notifications.

Changes

File Path Change Summary
sickchill/oldbeard/notifiers/__init__.py, sickchill/oldbeard/views/home.py Added Jellyfin notifier to the list and implemented Jellyfin-specific methods for checking usage, testing notifications, and updating the library.

🐰🌟
CodeRabbit hops with glee,
Jellyfin and SickChill in harmony.
Notifications sing, library in tow,
Entertainment magic in their flow.
Bytes bloom, a digital show,
Users delighted as features grow.
📺🐇🌟

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@BKSteve
Copy link
Collaborator

BKSteve commented Mar 6, 2024

@coderabbitai review

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 5

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 5923ad3 and 61b9f1c.
Files ignored due to path filters (2)
  • sickchill/gui/slick/images/16px_jellyfin_notifier.png is excluded by: !**/*.png
  • sickchill/gui/slick/images/32px_jellyfin_notifier.png is excluded by: !**/*.png
Files selected for processing (13)
  • sickchill/gui/slick/css/style.css (2 hunks)
  • sickchill/gui/slick/js/core.js (1 hunks)
  • sickchill/gui/slick/views/config_notifications.mako (1 hunks)
  • sickchill/gui/slick/views/layouts/main.mako (1 hunks)
  • sickchill/oldbeard/notifiers/init.py (2 hunks)
  • sickchill/oldbeard/notifiers/jellyfin.py (1 hunks)
  • sickchill/oldbeard/postProcessor.py (1 hunks)
  • sickchill/oldbeard/show_queue.py (1 hunks)
  • sickchill/oldbeard/stevedore.py (1 hunks)
  • sickchill/settings.py (2 hunks)
  • sickchill/start.py (3 hunks)
  • sickchill/views/config/notifications.py (2 hunks)
  • sickchill/views/home.py (4 hunks)
Additional comments: 23
sickchill/oldbeard/notifiers/__init__.py (2)
  • 12-12: Adding jellyfin to the list of imported notifiers is a necessary step for integrating Jellyfin as a notifier option. This change correctly follows the pattern established for other notifiers in the system.
  • 39-39: Creating an instance of jellyfin.Notifier() aligns with the instantiation pattern for other notifiers in the system. This ensures that Jellyfin notifications can be utilized in the same manner as other notifiers.
sickchill/oldbeard/notifiers/jellyfin.py (4)
  • 10-13: The _make_headers method correctly constructs headers for Jellyfin API requests, including the necessary X-Emby-Token for authentication. Using settings.JELLYFIN_APIKEY as a default when jellyfin_apikey is not explicitly provided is a good practice for flexibility.
  • 14-36: The _notify_jellyfin method properly handles sending notifications to Jellyfin. It checks if Jellyfin notifications are enabled (settings.USE_JELLYFIN) before proceeding, which is a good practice. However, consider adding a log message or raising an exception when the response status code is not 204 (No Content), indicating that the request was successful but Jellyfin did not return any content. This would help in debugging issues where Jellyfin does not process the notification as expected.
if response.status_code != 204:
-    logger.debug(_("JELLYFIN: Notification sent successfully."))
+    logger.warning(_("JELLYFIN: Expected status code 204, got {status_code}. Check Jellyfin server.").format(status_code=response.status_code))
  • 42-44: The test_notify method provides a way to send a test notification, which is useful for verifying that the Jellyfin notifier is correctly configured. This aligns with the functionality provided for other notifiers and is a good practice for user experience.
  • 45-74: The update_library method correctly handles updating the Jellyfin library. It supports updating the library for a specific show or performing a full library refresh. The use of urljoin to construct the URL is appropriate and prevents errors in URL construction. However, ensure that settings.JELLYFIN_HOST is properly sanitized and validated elsewhere in the code to prevent injection attacks.
Verification successful

The verification process revealed that JELLYFIN_HOST is processed through config.clean_url(jellyfin_host) in sickchill/views/config/notifications.py and check_setting_str(settings.CFG, "Jellyfin", "jellyfin_host") in sickchill/start.py. These instances suggest mechanisms for sanitizing and validating JELLYFIN_HOST, addressing the concern raised in the review comment about ensuring proper sanitization and validation to prevent injection attacks. Therefore, the review comment is consistent with the codebase as it correctly identifies the importance of sanitization and validation, which are indeed implemented.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that settings.JELLYFIN_HOST is sanitized and validated
grep -R "JELLYFIN_HOST" sickchill/ | grep "sanitize"

Length of output: 50



Script:

#!/bin/bash
# Broaden the search to find validation or sanitization of JELLYFIN_HOST
# Look for common validation or sanitization patterns, including the use of "validate", "check", or direct usage contexts
grep -R "JELLYFIN_HOST" sickchill/ | grep -E "validate|check|clean"

Length of output: 285

sickchill/oldbeard/stevedore.py (1)
  • 89-89: Adding "jellyfin = oldbeard.notifiers.jellyfin:Notifier" to the notifiers extension manager is the correct way to register the Jellyfin notifier. This allows SickChill to dynamically discover and use the Jellyfin notifier alongside other notifiers. The change is consistent with the registration of other notifiers and follows best practices for extensibility.
sickchill/settings.py (1)
  • 535-535: The USE_JELLYFIN setting is a straightforward boolean flag to enable or disable Jellyfin integration. This approach is consistent with the existing pattern for other services in the application.

Ensure that the application logic correctly checks this flag before attempting to use Jellyfin-related functionality.

sickchill/views/config/notifications.py (2)
  • 60-62: The addition of use_jellyfin, jellyfin_host, and jellyfin_apikey parameters to the saveNotifications method signature correctly aligns with the PR's objective to integrate Jellyfin as a notifier option. This change allows the method to accept Jellyfin-specific settings from the user interface.
  • 276-278: The logic to set Jellyfin settings based on the provided parameters is correctly implemented. Using config.checkbox_to_value for use_jellyfin ensures that the boolean setting is correctly interpreted from the checkbox input. Similarly, config.clean_url for jellyfin_host and filters.unhide for jellyfin_apikey are appropriate for sanitizing and securely handling these inputs. This ensures that the Jellyfin settings are correctly updated in SickChill's configuration.
sickchill/oldbeard/show_queue.py (1)
  • 749-751: The addition of Jellyfin notifier functionality is correctly implemented and follows the pattern used by other notifiers such as Kodi, Plex, and Emby. This ensures consistency in the way SickChill handles library updates across different media servers. However, it's important to ensure that the jellyfin_notifier object is properly initialized and available in the notifiers module, as this code assumes its presence and readiness to use.

Ensure that the jellyfin_notifier object is correctly set up in the notifiers module and that it has a method update_library that accepts a show object as its parameter. This is crucial for the integration to work as expected without causing runtime errors.

sickchill/gui/slick/views/layouts/main.mako (1)
  • 204-206: The conditional block for displaying the "Update Jellyfin" link is correctly implemented and follows the pattern used for other services like PLEX and KODI. This ensures consistency across the application and maintains a clean user interface by only showing relevant options.

However, for future maintainability, consider abstracting the condition checks for service configuration (like settings.USE_JELLYFIN, settings.JELLYFIN_HOST, and settings.JELLYFIN_APIKEY) into a helper function or method. This approach can simplify the template code and centralize the logic for determining if a service is configured, making it easier to update or extend in the future.

sickchill/oldbeard/postProcessor.py (3)
  • 1209-1211: The addition of Jellyfin library update functionality is correctly implemented by calling notifiers.jellyfin_notifier.update_library(episode_object.show) within the process method. This ensures that the Jellyfin library is updated whenever a new episode is processed, aligning with the behavior for other notifiers like Kodi, Plex, and Emby. The method call is appropriately placed within the try-except block that handles notification and library update operations, ensuring that any exceptions raised by the Jellyfin notifier do not halt the post-processing workflow.
  • 1209-1211: The guessit_findit function provides an alternative way to parse file names using the guessit library, falling back to the traditional NameParser if necessary. This approach enhances the flexibility and accuracy of parsing, especially for complex or non-standard file names. However, ensure that the guessit library's behavior aligns closely with SickChill's requirements for parsing show names and episodes. It might be beneficial to add more detailed logging or error handling around the guessit parsing to help diagnose parsing issues.
  • 1206-1214: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [1-1211]

Throughout the file, there are several instances where string formatting could be modernized to use f-strings, introduced in Python 3.6. F-strings provide a more readable and concise way to format strings compared to the older .format() method. For example, replace _("File {directory} doesn't exist, did unrar fail?").format(directory=self.directory) with f"File {self.directory} doesn't exist, did unrar fail?". Consider refactoring these instances to use f-strings for improved readability.

sickchill/gui/slick/css/style.css (2)
  • 349-352: The CSS for .menu-icon-jellyfin correctly sets the background image and size for the Jellyfin menu icon. This ensures consistency with other notifier icons in the UI.
  • 2094-2097: The CSS for .icon-notifiers-jellyfin properly defines the background image and size for the Jellyfin notifier icon, aligning with the visual style of other notifier icons.
sickchill/views/home.py (3)
  • 263-266: The method haveJELLYFIN correctly checks if Jellyfin is enabled in the settings. This is a straightforward static method that returns a boolean value based on the settings.USE_JELLYFIN flag.
  • 561-569: The method testJELLYFIN properly handles the testing of Jellyfin notifications. It correctly retrieves and sanitizes user input before calling the test_notify method on the jellyfin_notifier. This method follows good practices for handling external input and provides clear feedback to the user based on the result of the test notification.
  • 1511-1526: The method updateJELLYFIN is implemented to trigger an update in the Jellyfin library, optionally for a specific show. It correctly checks for the presence of a show object and calls the update_library method on the jellyfin_notifier. The method also handles user feedback appropriately by displaying a notification message based on the outcome of the update operation.
sickchill/start.py (2)
  • 58-58: Adding Jellyfin to the configuration sections is a necessary step for integrating Jellyfin as a notifier option. This change correctly follows the pattern established by other notifiers like Emby, Growl, etc.
  • 1371-1375: The configuration for Jellyfin is correctly added to the save_config function, ensuring that Jellyfin settings are persisted across application restarts. This aligns with the handling of other notifier configurations.
sickchill/gui/slick/views/config_notifications.mako (1)
  • 560-621: The Jellyfin integration section has been added correctly, following the structure and conventions used for other services in the file. The use of Mako template syntax, HTML form elements, and SickChill settings variables is consistent with the rest of the file. The inclusion of a test button (id="testJELLYFIN") and the use of the checked function to reflect the current configuration state are best practices for user interface design in this context.

sickchill/start.py Show resolved Hide resolved
sickchill/start.py Show resolved Hide resolved
sickchill/settings.py Show resolved Hide resolved
sickchill/gui/slick/js/core.js Show resolved Hide resolved
sickchill/oldbeard/postProcessor.py Show resolved Hide resolved
@speedfreak01 speedfreak01 marked this pull request as ready for review March 7, 2024 01:11
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 61b9f1c and c328f20.
Files ignored due to path filters (1)
  • sickchill/gui/slick/js/core.min.js is excluded by: !**/*.min.js
Files selected for processing (2)
  • sickchill/oldbeard/notifiers/init.py (2 hunks)
  • sickchill/views/home.py (4 hunks)
Files skipped from review as they are similar to previous changes (2)
  • sickchill/oldbeard/notifiers/init.py
  • sickchill/views/home.py

@miigotu
Copy link
Contributor

miigotu commented Mar 8, 2024

Man coderabbit can be a pain sometimes lol. Thanks for this.

@miigotu miigotu merged commit 0270f92 into SickChill:develop Mar 8, 2024
10 of 11 checks passed
@speedfreak01 speedfreak01 deleted the feature/jellyfin-notifierV2 branch June 8, 2024 08:27
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.

3 participants