Skip to content
This repository was archived by the owner on May 2, 2026. It is now read-only.

feat(auth): Allow non-interactive Anilist authentication#175

Merged
Benexl merged 5 commits intoviu-media:masterfrom
komposer-aml:fix/auth-input-mac
Dec 30, 2025
Merged

feat(auth): Allow non-interactive Anilist authentication#175
Benexl merged 5 commits intoviu-media:masterfrom
komposer-aml:fix/auth-input-mac

Conversation

@komposer-aml
Copy link
Copy Markdown
Contributor

This enhances the anilist auth command by allowing the authentication token to be provided directly as an argument or from a file. This provides a non-interactive way to authenticate, which is useful for scripting or for users who have issues with the interactive browser-based flow.

The auth command now accepts an optional token_input argument.

  • If the argument is a valid file path, the token is read from the file.
  • Otherwise, the argument is treated as the token itself.
  • If no argument is provided, the command falls back to the previous interactive method.

The README is also updated to document these new authentication options.

This commit also includes:

  • test: Unit tests for the new authentication logic (test_auth.py) and for the mapper fix (test_mapper.py).
  • fix(api): A fix in the Anilist API mapper to handle potentially missing data in the API response, making it more robust.
  • style: Minor code style and formatting fixes throughout the codebase.

This enhances the `anilist auth` command by allowing the authentication token to be provided directly as an argument or from a file. This provides a non-interactive way to authenticate, which is useful for scripting or for users who have issues with the interactive browser-based flow.

The `auth` command now accepts an optional `token_input` argument.
- If the argument is a valid file path, the token is read from the file.
- Otherwise, the argument is treated as the token itself.
- If no argument is provided, the command falls back to the previous interactive method.

The README is also updated to document these new authentication options.

This commit also includes:
- `test`: Unit tests for the new authentication logic (``test_auth.py``) and for the mapper fix (``test_mapper.py``).
- `fix(api)`: A fix in the Anilist API mapper to handle potentially missing data in the API response, making it more robust.
- `style`: Minor code style and formatting fixes throughout the codebase.
@komposer-aml
Copy link
Copy Markdown
Contributor Author

Including screenshots of the fix working
invalid cases
valid .txt input case

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances the anilist auth command to support non-interactive authentication by allowing tokens to be provided directly as arguments or from files, useful for scripting and automation. The changes also include a robustness fix for the AniList API mapper and various code style improvements.

  • Added non-interactive authentication support with token from argument or file
  • Fixed potential null reference issues in AniList API response mapper
  • Improved code formatting consistency across provider files

Reviewed changes

Copilot reviewed 8 out of 12 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
viu_media/cli/commands/anilist/commands/auth.py Enhanced authentication command to accept token as argument or file path, refactored token retrieval into separate function
viu_media/libs/media_api/anilist/mapper.py Added defensive null checks for data and Viewer fields to handle missing API response data
tests/cli/commands/anilist/commands/test_auth.py Added comprehensive unit tests for new authentication methods (direct token, file-based, empty file scenarios)
tests/libs/media_api/anilist/test_mapper.py Added tests for mapper edge cases including missing data and viewer keys
viu_media/libs/provider/anime/animepahe/provider.py Minor formatting fix for trailing comma in headers dictionary
viu_media/libs/provider/anime/animepahe/mappers.py Reformatted multi-line Server return statement
viu_media/libs/provider/anime/animepahe/constants.py Updated string concatenation to use double quotes consistently
viu_media/cli/cli.py Fixed spacing around assignment operator
README.md Updated authentication documentation to mention new token input options
tests/cli/commands/anilist/init.py Added empty init file for test package structure
tests/libs/init.py Added empty init file for test package structure
tests/libs/media_api/init.py Added empty init file for test package structure
tests/libs/media_api/anilist/init.py Added empty init file for test package structure

Comment thread viu_media/cli/commands/anilist/commands/auth.py
Comment thread viu_media/cli/commands/anilist/commands/auth.py
Comment on lines +21 to +23
except Exception as e:
feedback.error(f"Error reading token from file: {e}")
return None
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

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

The broad exception handler catches all exceptions, which could mask unexpected errors. Consider catching specific exceptions (e.g., PermissionError, OSError, UnicodeDecodeError) to provide more helpful error messages to users.

Suggested change
except Exception as e:
feedback.error(f"Error reading token from file: {e}")
return None
except (OSError, PermissionError) as e:
feedback.error(f"Error reading token from file '{path}': {e}")
return None
except UnicodeDecodeError as e:
feedback.error(f"Token file '{path}' is not valid text: {e}")
return None

Copilot uses AI. Check for mistakes.
Comment thread tests/cli/commands/anilist/commands/test_auth.py Outdated
Comment on lines +21 to +23
except Exception as e:
feedback.error(f"Error reading token from file: {e}")
return None
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

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

Missing test coverage for the file read error path. Consider adding a test case that simulates a file read exception (e.g., permission error) to ensure the error handling works correctly.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Should be implemented. Not going to be implemented by me though

Comment on lines 97 to 100
if not token:
feedback.error("Login cancelled.")
if not token_input:
feedback.error("Login cancelled.")
return
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

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

Missing test coverage for the case when a user cancels the interactive token prompt (returns None or empty string). Consider adding a test where selector.ask returns None to ensure the "Login cancelled." message is shown correctly.

Copilot uses AI. Check for mistakes.
Comment thread viu_media/cli/commands/anilist/commands/auth.py Outdated
Copy link
Copy Markdown
Collaborator

@Benexl Benexl left a comment

Choose a reason for hiding this comment

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

cool

@Benexl
Copy link
Copy Markdown
Collaborator

Benexl commented Dec 30, 2025

yoh @komposer-aml just fix the pyright errors and will be good to go

Updated mock data in `test_to_generic_user_profile_success` to conform to `AnilistViewerData` requirements.
Adjusted type annotations in tests with intentionally malformed data to `Any` to prevent pyright errors, ensuring proper validation of error handling.
komposer-aml and others added 2 commits December 29, 2025 23:44
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Benexl Benexl merged commit f684f56 into viu-media:master Dec 30, 2025
2 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants