A Python library and command-line tool for downloading media files from Safie cameras
Project description
Safie Media File Downloader
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
httpxfor HTTP requests
CLI Tool (Optional)
clickfor command-line interfacepython-dateutilfor 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
- Update the version in
pyproject.toml - Create and push a new tag:
git tag v0.1.0 git push origin v0.1.0
- Create a new release on GitHub using the tag
- The GitHub Actions workflow will automatically build and publish to PyPI
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96c40a0c053897bc732ebb1c9cce3b02f34d014a54ec8b05b7287e498acf7f1b
|
|
| MD5 |
84aab459252aeca67062fca8fdbc0c36
|
|
| BLAKE2b-256 |
3f7f3600bceba6c32a2210bbb989d4726cfe4a45159c3d9c342b3973a166d649
|
Provenance
The following attestation bundles were made for safie_mediafile-0.1.5.tar.gz:
Publisher:
deploy.yml on syundo0730/safie-mediafile
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
safie_mediafile-0.1.5.tar.gz -
Subject digest:
96c40a0c053897bc732ebb1c9cce3b02f34d014a54ec8b05b7287e498acf7f1b - Sigstore transparency entry: 203491966
- Sigstore integration time:
-
Permalink:
syundo0730/safie-mediafile@39f1b9e6cd89cb101f3fac23c562e1a31b4603fc -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/syundo0730
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy.yml@39f1b9e6cd89cb101f3fac23c562e1a31b4603fc -
Trigger Event:
push
-
Statement type:
File details
Details for the file safie_mediafile-0.1.5-py3-none-any.whl.
File metadata
- Download URL: safie_mediafile-0.1.5-py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f0d7193c387d07ba8dbfd25be79a45d45e27faf5be510dc311f0e7d2905da00
|
|
| MD5 |
24298290043bb1dd545ef643f8fa421c
|
|
| BLAKE2b-256 |
8c1f4907eb5b3179d98be8678a4101248700161e56dac232d08213512256d8f7
|
Provenance
The following attestation bundles were made for safie_mediafile-0.1.5-py3-none-any.whl:
Publisher:
deploy.yml on syundo0730/safie-mediafile
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
safie_mediafile-0.1.5-py3-none-any.whl -
Subject digest:
1f0d7193c387d07ba8dbfd25be79a45d45e27faf5be510dc311f0e7d2905da00 - Sigstore transparency entry: 203491967
- Sigstore integration time:
-
Permalink:
syundo0730/safie-mediafile@39f1b9e6cd89cb101f3fac23c562e1a31b4603fc -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/syundo0730
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy.yml@39f1b9e6cd89cb101f3fac23c562e1a31b4603fc -
Trigger Event:
push
-
Statement type: