Fix API compatibility and session handling, add logout support#60
Open
Shi-553 wants to merge 16 commits intoniconicolibs:mainfrom
Open
Fix API compatibility and session handling, add logout support#60Shi-553 wants to merge 16 commits intoniconicolibs:mainfrom
Shi-553 wants to merge 16 commits intoniconicolibs:mainfrom
Conversation
added 15 commits
August 7, 2025 14:04
- Remove sample_items field that is no longer provided by API - Remove is_following field that is no longer available in responses This cleanup eliminates unused properties that were causing model validation issues with the current API response format.
- Add Host header to GET and POST requests based on URL netloc - Import urlparse to extract hostname from URLs - Ensures proper HTTP/1.1 compliance and compatibility with proxies/CDNs This change improves request handling by providing proper Host header information that some servers and proxy configurations require.
Change 'type' to 'types' parameter name to match API specification. This fixes video search functionality that was failing due to incorrect parameter naming in NVAPI requests.
- Clear user_session cookies when login validation fails - Prevents stale session data from causing authentication issues - Ensures clean state after failed login attempts This improvement handles edge cases where invalid session cookies could persist and interfere with subsequent login attempts.
- Add logout() method to NicoNico class for clean session termination - Call NicoNico logout endpoint and clear session cookies - Reset authentication state (logined=False, premium=False) - Add appropriate logging for logout success and failure cases This completes the authentication lifecycle management by providing a proper way to terminate user sessions.
…annel information
- Change owner field type from WatchOwner to WatchOwner | None in WatchData
- Add null checks in download functions to handle cases where owner is None
- Provide fallback values ('Unknown' for name, '0' for id) when owner is None
- Changed position_sec type from float to float | None - Added default value None for position_sec field - Fixes validation error when API returns None for positionSec
- Add optional headers parameter to get() method for custom headers - Update docstring to document the new parameter - This enables Video Tags API v2 functionality that requires X-Tag-Edit-Key header - Maintains backward compatibility by making headers parameter optional
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We will submit pull requests for each feature that has been implemented for MusicAssistant's niconico provider.
This pull request introduces several improvements and fixes across the NicoNico API wrapper, focusing on better API compatibility, enhanced data modeling, and improved session management. The most important changes include updates to tag and owner data models for better type safety, improvements to session handling (including logout support), and compatibility fixes for the latest API endpoints.
API compatibility and session management:
logoutmethod to theNicoNicoclass to properly log out users, clear session data, and update authentication state. Also ensured session cookies are cleared on failed login attempts for robust session handling. [1] [2]getandpostmethods inniconico.pyto set theHostheader dynamically from the request URL, improving HTTP request compatibility. [1] [2] [3] [4]getfunction.Data model improvements:
watch.pyto use explicit types, including new models forWatchOwnerChannel,WatchOwnerLive, andWatchTagItem, and updated theWatchOwner,WatchTag, andWatchDataclasses to use these types or allowNonevalues where appropriate. [1] [2] [3] [4] [5] [6]UserRelationshipsandUserMylistItemmodels to use proper default values and field aliases for improved parsing and correctness. [1] [2]API endpoint and usage fixes:
Updated video tag retrieval to use the v2 API endpoint (v1 is no longer available), which now requires an edit_key header for tag operations. [1] [2]
Corrected video search query parameter from type (non-functional) to types to ensure proper API compatibility.
Robustness improvements:
ownerdata may be missing by providing fallback values. [1] [2] [3]