Skip to content

Development

kavinthangavel edited this page Apr 23, 2025 · 6 revisions

๐Ÿ’ป Development Guide

This document provides information for developers who want to contribute to Media Player Scrobbler for SIMKL.

๐Ÿ“‚ Project Structure

simkl-movie-tracker/
โ”œโ”€โ”€ docs/                    # Documentation
โ”œโ”€โ”€ simkl_mps/         # Main package
โ”‚   โ”œโ”€โ”€ __init__.py          # Package initialization
โ”‚   โ”œโ”€โ”€ backlog_cleaner.py   # Handles offline queue
โ”‚   โ”œโ”€โ”€ cli.py               # Command-line interface
โ”‚   โ”œโ”€โ”€ main.py              # Application entry point
โ”‚   โ”œโ”€โ”€ media_cache.py       # Movie info caching
โ”‚   โ”œโ”€โ”€ media_tracker.py     # Main tracking coordination
โ”‚   โ”œโ”€โ”€ monitor.py           # Window monitoring
โ”‚   โ”œโ”€โ”€ movie_scrobbler.py   # Movie tracking and Simkl integration
โ”‚   โ”œโ”€โ”€ service_manager.py   # System service management
โ”‚   โ”œโ”€โ”€ service_runner.py    # Background service implementation
โ”‚   โ”œโ”€โ”€ simkl_api.py         # Simkl API interactions
โ”‚   โ”œโ”€โ”€ tray_app.py          # System tray application
โ”‚   โ”œโ”€โ”€ window_detection.py  # Cross-platform window detection
โ”‚   โ”œโ”€โ”€ players/             # Media player integrations
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”‚   โ”œโ”€โ”€ mpc.py           # MPC-HC/BE integration
โ”‚   โ”‚   โ”œโ”€โ”€ mpv.py           # MPV integration
โ”‚   โ”‚   โ”œโ”€โ”€ potplayer.py     # PotPlayer integration
โ”‚   โ”‚   โ””โ”€โ”€ vlc.py           # VLC integration
โ”‚   โ””โ”€โ”€ utils/               # Utility functions and constants
โ”œโ”€โ”€ tests/                   # Test suite
โ”œโ”€โ”€ .gitignore               # Git ignore patterns
โ”œโ”€โ”€ pyproject.toml           # Project metadata and dependencies
โ”œโ”€โ”€ README.md                # Project overview
โ””โ”€โ”€ LICENSE                  # License information

๐Ÿš€ Development Setup

  1. Clone the repository:

    git clone https://github.com/kavinthangavel/simkl-movie-tracker.git
    cd simkl-movie-tracker
  2. Set up the development environment:

    # Using Poetry (recommended)
    poetry install --with dev
    
    # Or using pip
    pip install -e ".[dev]"
  3. Set up pre-commit hooks (optional):

    pre-commit install

๐Ÿงช Running Tests

# Run tests with pytest
poetry run pytest

# Run tests with coverage
poetry run pytest --cov=simkl_mps

# Run specific test file
poetry run pytest tests/test_specific_file.py

๐Ÿ“ Code Style

This project follows PEP 8 style guidelines. Use flake8 to check your code:

poetry run flake8 simkl_mps

โž• Adding a New Media Player

To add support for a new media player:

  1. Create a new file in the players/ directory (e.g., simkl_mps/players/new_player.py)
  2. Implement a class that follows the player integration interface:
    class NewPlayerIntegration:
        def __init__(self):
            # Initialize player connection
            pass
            
        def get_position_duration(self, process_name=None):
            # Return (position_seconds, duration_seconds) tuple or (None, None)
            pass
  3. Add the player to players/__init__.py
  4. Update window detection to recognize the player in window_detection.py

๐Ÿ“ฆ Building and Publishing

# Build distribution packages
poetry build

# Publish to PyPI (requires credentials)
poetry publish

๐Ÿ”„ Pull Request Process

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes and commit them: git commit -m 'Add amazing feature'
  4. Push to the branch: git push origin feature/amazing-feature
  5. Open a Pull Request against the main repository

๐Ÿ”‘ API Access

For development, you can use the default client ID or register your own:

  1. Go to https://simkl.com/settings/developer/
  2. Create a new application
  3. Set the redirect URL to urn:ietf:wg:oauth:2.0:oob
  4. Use the client ID in your development environment:
    SIMKL_CLIENT_ID=your_client_id
    

๐Ÿ” Debugging Tips

  • Use the --debug flag to enable detailed logging: simkl-mps start --debug
  • Check logs in the application data directory
  • Use Python's debugger (pdb) or an IDE like PyCharm or VS Code for step-by-step debugging
  • Test player integration separately using the player-specific test scripts

๐Ÿ—๏ธ Architecture Overview

Media Player Scrobbler for SIMKL uses a modular architecture:

  1. ๐ŸชŸ Window Detection Layer: Platform-specific code to detect media player windows
  2. ๐ŸŽฎ Media Player Integration Layer: Interfaces with specific players to get playback information
  3. ๐ŸŽฌ Movie Identification Layer: Parses titles and identifies movies via Simkl API
  4. ๐Ÿ“Š Progress Tracking Layer: Monitors playback and determines completion
  5. ๐Ÿ”Œ Simkl API Layer: Handles authentication and scrobbling to Simkl

This separation allows for easy maintenance and extension of individual components.

Architecture Diagram

graph TD
    A[Window Detection] -->|Active Windows| B[Player Recognition]
    B -->|Window Info| C[Title Extraction]
    C -->|Movie Title| D[guessit Parser]
    D -->|Parsed Info| E[Simkl Search]
    E -->|Movie ID| F[Progress Tracker]
    F -->|Position Updates| G{Completion Check}
    G -->|>80%| H[Mark as Watched]
    G -->|<80%| F
    
    I[Player Integration] -->|Position Data| F
    J[OS-specific APIs] --> A
    
    style A fill:#d5f5e3,stroke:#333,stroke-width:2px
    style H fill:#f9d5e5,stroke:#333,stroke-width:2px
    style I fill:#d5eef7,stroke:#333,stroke-width:2px
    style J fill:#f7dc6f,stroke:#333,stroke-width:2px
Loading

Clone this wiki locally