Skip to content

Fix API compatibility and session handling, add logout support#60

Open
Shi-553 wants to merge 16 commits intoniconicolibs:mainfrom
Shi-553:pr/core-infrastructure-fixes
Open

Fix API compatibility and session handling, add logout support#60
Shi-553 wants to merge 16 commits intoniconicolibs:mainfrom
Shi-553:pr/core-infrastructure-fixes

Conversation

@Shi-553
Copy link

@Shi-553 Shi-553 commented Aug 16, 2025

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:

  • Added a logout method to the NicoNico class 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]
  • Updated the get and post methods in niconico.py to set the Host header dynamically from the request URL, improving HTTP request compatibility. [1] [2] [3] [4]
  • We have made it possible to specify headers in the get function.

Data model improvements:

  • Refined several data models in watch.py to use explicit types, including new models for WatchOwnerChannel, WatchOwnerLive, and WatchTagItem, and updated the WatchOwner, WatchTag, and WatchData classes to use these types or allow None values where appropriate. [1] [2] [3] [4] [5] [6]
  • Updated UserRelationships and UserMylistItem models 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:

  • Ensured download paths for storyboards and videos handle cases where owner data may be missing by providing fallback values. [1] [2] [3]

Shi-553 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.
- 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
@Shi-553 Shi-553 changed the title Core infrastructure fixes Fix Core infrastructure Aug 16, 2025
- 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
@Shi-553 Shi-553 marked this pull request as ready for review August 16, 2025 08:40
@Shi-553 Shi-553 changed the title Fix Core infrastructure Fix API compatibility and session handling, add logout support Aug 16, 2025
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.

1 participant