Git Product home page Git Product logo

pyatemapi's Introduction

PyATEMAPI

Python Blackmagic Design ATEM REST API

Purpose

To provide a web API for interfacing with ATEM Switchers. The API is designed to be as simple as possible and to be as flexible as possible.

Why build a web API for ATEM?

This API allows developers to interact with ATEM Switchers without having to write desktop code. Instead, developers can now interact with an ATEM through the browser using simple web APIs with Javascript.

Roadmap / Features

  • Fully Documented in Postman
  • Web Example
  • Get tally data
  • Fade to black
  • Trigger Cut
  • Trigger auto transition
  • Set preview
  • Set program
  • DSK Tie
  • DSK Cut
  • Ping switcher
  • Upload / manage media pool
  • Audio control
  • Tested using ATEM Television Studio HD
  • Docker Image
  • Support for options from env or config file
  • Support for multiple switchers
  • CI/CD Testing with GitHub Actions (will probably require creating or updating a more fully featured mocking tool like PyATEMSim but with better support)

Usage

Clone PyATEMAPI to your machine by running:

git clone https://github.com/mackenly/PyATEMAPI.git

Install the required packages by running:

pip install -r requirements.txt

While in the directory of the project, run server.py to start the server. Pass in as parameters the IP address of the ATEM switcher and a simple passphrase for basic authentication. If running on native python, best practice is to read these variables in with the read command in Linux/Mac or the Read-Host command in Windows:

Linux/Mac

read -s PASSPHRASE
read SERVER_IP
python3 server.py

Windows

$securedValue = Read-Host "Passphrase" -AsSecureString
$bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($securedValue)
$env:PASSPHRASE = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bstr)
$env:SERVER_IP = Read-Host "Atem Device IP"
python server.py

NOTE: Some versions of powershell support Read-Host "Password" -MaskInput as well, which would reduce the above command to simply:

$env:PASSPHRASE = Read-Host "Passphrase" -MaskInput
$env:SERVER_IP = Read-Host "Atem Device IP"
python server.py

Use Command Line Arguments

Alternatively you can use the --ip and --passphrase command line options though these will result in the passphrase being in plaintext in command line history logs such as .bash_history, other Linux/Mac shell histories, or $env:APPDATA\Microsoft\Windows\PowerShell\PSReadLine in Windows.

python server.py --ip 127.0.0.1 --passphrase Password1

After starting the server, you can use the web API to interact with the ATEM Switcher.

Testing

If you would like to test this API, you can use a tool called PyATEMSim. In the directory of the simulator, simply run python atem_server.py and you will be able to interact with the simulated ATEM switcher's provided IP and port via this API. This simulator doesn't provide all the functionality of a real switcher and seems to have issues with input numbers, so don't rely on it for important testing.

Documentation

The API documentation is available through Postman at https://documenter.getpostman.com/view/19380446/UzQpvT1y.

Demo

To demonstrate and test the API, a basic web controller example is provided. To run the example, enter the web-example directory, modify the constant at the top of script.js with the values you're using to run the server, and then open the index.html file in a browser.

Docker

The application can be run via docker. This can be built using the repository defined container definition or using the DockerHub registered container.

Create an ENV file

The atem device ip and passphrase for the API will be pulled from environment variables. To do this we'll need to create and env file called .env which will be used by our docker and docker-compose instructions later. Just create the .env file and edit it to have the following variables:

SERVER_IP=192.168.1.42
PASSPHRASE=MySecretPassword

Run from DockerHub

You can run the application from the built images in DockerHub.

docker run -d -p 5555:5555 --env-file=.env mackenly/pyatemapi:latest

Run with docker-compose

docker-compose up -d

You can also explicitly define the path to the env file if you are managing multiple configurations:

docker-compose --env-file .env_alt up -d

You can then bring the service down with a standard docker-compose down command:

docker-compose down

Build and run Docker container from source

docker build -t pyatemapi .
docker run -d -p 5555:5555 --env-file=.env pyatemapi

Contributing

Contributions are welcome. Please open an issue or pull request on mackenly/PyATEMAPI.

License

The MIT License (MIT)

pyatemapi's People

Contributors

dependabot[bot] avatar mackenly avatar nuvious avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

pyatemapi's Issues

Timetable for media upload

Hello. I'm trying to create a simple way to create a simple graphic and push it up to the ATEM media pool. I can handle the graphics side but need help on the pushing to the ATEM side. I was wondering if you had any idea on timetable for adding the media upload capability? I'm a programmer myself and so might be able to be of some assistance although I have very little knowledge in Python. Thank you.

Address CWE-214 weakness in implementation (that I submitted a while back)

At the moment, the ATEM device IP and passphrase for the server are submitted via command line arguments. In a non-docker environment this would have the passphrase appear in .bash_history, other shell histories, and potentially process logs. In a docker or kubernetes context this would have the passphrase visible in the logs. This is more a risk in a non-container context since in a container context if someone has access to kubernetes/docker logs they can likely also inspect environment variables too.

Here's an example of the problematic output:

$> docker run --rm -it -p 5555:5555 --env-file=.env mackenly/pyatemapi:latest
+ SERVER_IP=192.168.1.42
+ PASSPHRASE=mysecretpassphrase
+ python server.py 192.168.1.42 mysecretpassphrase
22:33:42.266 INFO     Initializing switcher
22:33:42.266 INFO     Starting connection with ATEM switcher on 192.168.1.42
22:33:42.267 INFO     Connecting for the first time
22:33:42.267 INFO     Waiting for connection
22:33:42.268 INFO     Sending HELLO packet
22:33:42.277 INFO     Connected to switcher

As mentioned this is enumerated in CWE-214 (https://cwe.mitre.org/data/definitions/214.html) and is resolved by moving the variable retrieval into the python code. I will submit a PR for this shortly that maintains backwards compatibility.

NOTE: Additionally, there's a bug in the docker-compose file that prevents picking up the environment variables so I'll fix that too.

Create a docker image.

Would like to create a docker image. Will submit a PR for one myself with docker/kubernetes deployment examples. I'm a homelab nerd so most of my container stuff is running in docker on kubernetes now so figured I'd take the work that I've been doing and incorporate it.

Again, PR to come.

change to real json

Is it possible to change de return json? Now I get a False instead of false. And I get a ' instead of "

for example:
from: {'source': 1, 'preview': False, 'program': False}
to: {"source": 1, "preview": false, "program": false}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.