Skip to main content

A Python library and command-line tool for downloading media files from Safie cameras

Project description

Safie Media File Downloader

Lint and Test PyPI - Python Version GitHub License

A Python library and command-line tool for downloading media files from Safie cameras.

Installation

Library with CLI Tool

If you also want to use the command-line tool:

pip install "safie-mediafile[cli]"

Library Only

If you want to use only the library functionality:

pip install safie-mediafile

Usage

Command Line Interface

You can download media files using either the device serial number or device name:

# Using serial number
safie-mediafile --serial 201055433 2024-03-22T10:00:00Z 2024-03-22T11:00:00Z --api-token YOUR_API_TOKEN

# Using device name
safie-mediafile --name "Camera Name" 2024-03-22T10:00:00Z 2024-03-22T11:00:00Z --api-token YOUR_API_TOKEN

# Specifying an output file path
safie-mediafile --serial 201055433 2024-03-22T10:00:00Z 2024-03-22T11:00:00Z --output-path output.mp4 --api-token YOUR_API_TOKEN

You can also set the API token using the SAFIE_TOKEN environment variable:

# Set API token as an environment variable
export SAFIE_TOKEN=YOUR_API_TOKEN
safie-mediafile --serial 201055433 2024-03-22T10:00:00Z 2024-03-22T11:00:00Z

Note: The command-line interface is only available if you install the package with the cli extra.

Python API

import asyncio
from datetime import datetime
from safie_mediafile import find_device_id, create_and_download_mediafile

async def download_media():
    # Set up time (ISO 8601 format)
    start = datetime.fromisoformat("2024-03-22T10:00:00+09:00")
    end = datetime.fromisoformat("2024-03-22T11:00:00+09:00")

    # Get device ID (search by serial number or name)
    device_id = await find_device_id(
        api_token="your_api_token",
        serial="201055433",  # or name="Camera Name" (use either one)
    )

    # Create and download media file
    with open("output.mp4", "wb") as f:
        await create_and_download_mediafile(
            device_id=device_id,
            start_time=start,
            end_time=end,
            file=f,  # file object opened in binary mode
            api_token="your_api_token",
        )

if __name__ == "__main__":
    asyncio.run(download_media())

Requirements

Core Library

  • Python 3.8 or later
  • httpx for HTTP requests

CLI Tool (Optional)

  • click for command-line interface
  • python-dateutil for timezone handling

Development

Setup Development Environment

# Clone the repository
git clone https://github.com/syundo0730/safie-mediafile.git
cd safie-mediafile

# Install uv if not already installed
# For macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

# Install development dependencies using uv
uv pip install -e ".[dev,cli]"

Running Tests

# Run all tests
uv run pytest

# Run tests with coverage
uv run pytest --cov=safie_mediafile tests/

Code Quality

# Run linter
uv run ruff check .

# Run type checker
uv run mypy safie_mediafile

Releasing

This package uses GitHub Actions to automatically build and publish to PyPI when a new release is created.

Release Process

  1. Update the version in pyproject.toml
  2. Create and push a new tag:
    git tag v0.1.0
    git push origin v0.1.0
    
  3. Create a new release on GitHub using the tag
  4. The GitHub Actions workflow will automatically build and publish to PyPI

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

safie_mediafile-0.1.5.tar.gz (43.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

safie_mediafile-0.1.5-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file safie_mediafile-0.1.5.tar.gz.

File metadata

  • Download URL: safie_mediafile-0.1.5.tar.gz
  • Upload date:
  • Size: 43.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for safie_mediafile-0.1.5.tar.gz
Algorithm Hash digest
SHA256 96c40a0c053897bc732ebb1c9cce3b02f34d014a54ec8b05b7287e498acf7f1b
MD5 84aab459252aeca67062fca8fdbc0c36
BLAKE2b-256 3f7f3600bceba6c32a2210bbb989d4726cfe4a45159c3d9c342b3973a166d649

See more details on using hashes here.

Provenance

The following attestation bundles were made for safie_mediafile-0.1.5.tar.gz:

Publisher: deploy.yml on syundo0730/safie-mediafile

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file safie_mediafile-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for safie_mediafile-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 1f0d7193c387d07ba8dbfd25be79a45d45e27faf5be510dc311f0e7d2905da00
MD5 24298290043bb1dd545ef643f8fa421c
BLAKE2b-256 8c1f4907eb5b3179d98be8678a4101248700161e56dac232d08213512256d8f7

See more details on using hashes here.

Provenance

The following attestation bundles were made for safie_mediafile-0.1.5-py3-none-any.whl:

Publisher: deploy.yml on syundo0730/safie-mediafile

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page