Skip to content

Standardize environment variable naming with backwards compatibility#229

Merged
McCloudS merged 1 commit intoMcCloudS:mainfrom
darkspadez:feature/standardize-environment-variables
Aug 27, 2025
Merged

Standardize environment variable naming with backwards compatibility#229
McCloudS merged 1 commit intoMcCloudS:mainfrom
darkspadez:feature/standardize-environment-variables

Conversation

@darkspadez
Copy link
Contributor

Pull Request: Standardize Environment Variable Naming with Backwards Compatibility

Overview

This PR standardizes environment variable naming throughout the codebase while maintaining full backwards compatibility. The inconsistent naming patterns (some with underscores, some without) have been unified under a clear, logical convention.

Problem

The current environment variables use inconsistent naming patterns:

  • With underscores: WHISPER_MODEL, TRANSCRIBE_DEVICE, SKIP_LANG_CODES
  • Without underscores: PLEXTOKEN, JELLYFINSERVER, PROCADDEDMEDIA, NAMESUBLANG

This inconsistency creates confusion for users and makes the codebase harder to maintain.

Solution

New Naming Convention

  • Format: UPPERCASE_WITH_UNDERSCORES
  • Logical Grouping: Variables grouped by functionality with consistent prefixes
  • Backwards Compatibility: All legacy names continue to work seamlessly

Key Implementation

  1. Helper Function: Added get_env_with_fallback() for seamless migration
  2. Comprehensive Documentation: Added detailed explanation of naming convention and migration guide
  3. Zero Breaking Changes: Existing configurations continue to work without modification

Environment Variable Mappings

Server Integration

PLEX_TOKEN          ← PLEXTOKEN
PLEX_SERVER         ← PLEXSERVER  
JELLYFIN_TOKEN      ← JELLYFINTOKEN
JELLYFIN_SERVER     ← JELLYFINSERVER

Processing Control

PROCESS_ADDED_MEDIA     ← PROCADDEDMEDIA
PROCESS_MEDIA_ON_PLAY   ← PROCMEDIAONPLAY
WEBHOOK_PORT            ← WEBHOOKPORT

Subtitle Configuration

SUBTITLE_LANGUAGE_NAME                    ← NAMESUBLANG
SKIP_IF_EXTERNAL_SUBTITLES_EXIST         ← SKIPIFEXTERNALSUB
SKIP_IF_INTERNAL_SUBTITLES_LANGUAGE      ← SKIPIFINTERNALSUBLANG
SKIP_IF_TARGET_SUBTITLES_EXIST           ← SKIP_IF_TO_TRANSCRIBE_SUB_ALREADY_EXIST
SKIP_SUBTITLE_LANGUAGES                  ← SKIP_LANG_CODES
SKIP_IF_AUDIO_LANGUAGES                  ← SKIP_IF_AUDIO_TRACK_IS
SKIP_ONLY_SUBGEN_SUBTITLES               ← ONLY_SKIP_IF_SUBGEN_SUBTITLE
SKIP_IF_NO_LANGUAGE_BUT_SUBTITLES_EXIST  ← SKIP_IF_LANGUAGE_IS_NOT_SET_BUT_SUBTITLES_EXIST

Migration Strategy

  • Seamless: Both old and new names work simultaneously
  • Priority: New names take precedence when both are set
  • Gradual: Users can migrate at their own pace
  • Documentation: Clear migration guide included in code

Testing

  • ✅ All 15 environment variable mappings tested
  • ✅ Precedence logic verified (new names override old names)
  • ✅ Fallback logic verified (old names work when new names not set)
  • ✅ Type conversions tested (boolean, integer)
  • ✅ Syntax validation passed
  • ✅ Default values work when neither name is set

Benefits

  1. Consistency: All variables follow the same naming pattern
  2. Maintainability: Logical groupings make code easier to understand
  3. User-Friendly: Clear, descriptive names reduce configuration errors
  4. Future-Proof: Established convention for new variables
  5. Zero Disruption: Existing setups continue working without changes

Files Changed

  • subgen.py: Environment variable declarations and documentation

Breaking Changes

None - Full backwards compatibility maintained.

Migration Timeline

  • Immediate: New names available for use
  • Ongoing: Users can gradually adopt new names
  • Future: Legacy names may be deprecated in future major versions (with advance notice)

This PR provides a solid foundation for consistent environment variable management while ensuring zero disruption to existing users.

- Add get_env_with_fallback() helper function for seamless migration
- Implement consistent UPPERCASE_WITH_UNDERSCORES naming convention
- Group variables by logical categories (PLEX_*, JELLYFIN_*, PROCESS_*, SKIP_*, etc.)
- Maintain full backwards compatibility with legacy variable names
- Add comprehensive documentation explaining new naming convention

New standardized names with backwards compatibility:
- PLEX_TOKEN (was PLEXTOKEN)
- PLEX_SERVER (was PLEXSERVER)
- JELLYFIN_TOKEN (was JELLYFINTOKEN)
- JELLYFIN_SERVER (was JELLYFINSERVER)
- PROCESS_ADDED_MEDIA (was PROCADDEDMEDIA)
- PROCESS_MEDIA_ON_PLAY (was PROCMEDIAONPLAY)
- SUBTITLE_LANGUAGE_NAME (was NAMESUBLANG)
- WEBHOOK_PORT (was WEBHOOKPORT)
- SKIP_IF_EXTERNAL_SUBTITLES_EXIST (was SKIPIFEXTERNALSUB)
- SKIP_IF_TARGET_SUBTITLES_EXIST (was SKIP_IF_TO_TRANSCRIBE_SUB_ALREADY_EXIST)
- SKIP_IF_INTERNAL_SUBTITLES_LANGUAGE (was SKIPIFINTERNALSUBLANG)
- SKIP_SUBTITLE_LANGUAGES (was SKIP_LANG_CODES)
- SKIP_IF_AUDIO_LANGUAGES (was SKIP_IF_AUDIO_TRACK_IS)
- SKIP_ONLY_SUBGEN_SUBTITLES (was ONLY_SKIP_IF_SUBGEN_SUBTITLE)
- SKIP_IF_NO_LANGUAGE_BUT_SUBTITLES_EXIST (was SKIP_IF_LANGUAGE_IS_NOT_SET_BUT_SUBTITLES_EXIST)

Migration is seamless - both old and new names work simultaneously.
New names take precedence when both are set.

Tested: All mappings, type conversions, precedence logic, and syntax validation.
Copy link
Owner

@McCloudS McCloudS left a comment

Choose a reason for hiding this comment

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

Let's give it a shot. I've meant to clean up the names, just got paralyzed with the decision space since I've had the variables for so long. Can you update the readme table to have the updated names?

@McCloudS McCloudS merged commit 723dccb into McCloudS:main Aug 27, 2025
github-actions bot pushed a commit that referenced this pull request Aug 27, 2025
…229)

- Add get_env_with_fallback() helper function for seamless migration
- Implement consistent UPPERCASE_WITH_UNDERSCORES naming convention
- Group variables by logical categories (PLEX_*, JELLYFIN_*, PROCESS_*, SKIP_*, etc.)
- Maintain full backwards compatibility with legacy variable names
- Add comprehensive documentation explaining new naming convention

New standardized names with backwards compatibility:
- PLEX_TOKEN (was PLEXTOKEN)
- PLEX_SERVER (was PLEXSERVER)
- JELLYFIN_TOKEN (was JELLYFINTOKEN)
- JELLYFIN_SERVER (was JELLYFINSERVER)
- PROCESS_ADDED_MEDIA (was PROCADDEDMEDIA)
- PROCESS_MEDIA_ON_PLAY (was PROCMEDIAONPLAY)
- SUBTITLE_LANGUAGE_NAME (was NAMESUBLANG)
- WEBHOOK_PORT (was WEBHOOKPORT)
- SKIP_IF_EXTERNAL_SUBTITLES_EXIST (was SKIPIFEXTERNALSUB)
- SKIP_IF_TARGET_SUBTITLES_EXIST (was SKIP_IF_TO_TRANSCRIBE_SUB_ALREADY_EXIST)
- SKIP_IF_INTERNAL_SUBTITLES_LANGUAGE (was SKIPIFINTERNALSUBLANG)
- SKIP_SUBTITLE_LANGUAGES (was SKIP_LANG_CODES)
- SKIP_IF_AUDIO_LANGUAGES (was SKIP_IF_AUDIO_TRACK_IS)
- SKIP_ONLY_SUBGEN_SUBTITLES (was ONLY_SKIP_IF_SUBGEN_SUBTITLE)
- SKIP_IF_NO_LANGUAGE_BUT_SUBTITLES_EXIST (was SKIP_IF_LANGUAGE_IS_NOT_SET_BUT_SUBTITLES_EXIST)

Migration is seamless - both old and new names work simultaneously.
New names take precedence when both are set.

Tested: All mappings, type conversions, precedence logic, and syntax validation.
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