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.4.tar.gz (41.8 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.4-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: safie_mediafile-0.1.4.tar.gz
  • Upload date:
  • Size: 41.8 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.4.tar.gz
Algorithm Hash digest
SHA256 97b2e035b6e107498e09fbb3f4cdc4c96405e5df15a67de4aca22afa58bc21a3
MD5 a94e032a0d3aca3391d13dd6e0b1ea23
BLAKE2b-256 6534d6563ecbfe09216fc1026a7ee12755aced8484ce8e838ed223fa0c275651

See more details on using hashes here.

Provenance

The following attestation bundles were made for safie_mediafile-0.1.4.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.4-py3-none-any.whl.

File metadata

File hashes

Hashes for safie_mediafile-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2a4dffe2744068b569e0e49eea7e915745c0db85987aec5ca739eb96817fbb8d
MD5 3ef3d4d8cf659adf2c8b24f6838985b1
BLAKE2b-256 b686ea2e006cf6cb67929215fc58be3a01297fadb6017e600061855f7ba4fcfc

See more details on using hashes here.

Provenance

The following attestation bundles were made for safie_mediafile-0.1.4-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