pyPhotoFrameCast is a Python script that turns your Chromecast device into a digital photo frame. It continuously casts a slideshow of photos from a local directory to a selected Chromecast. This script is ideal for a Raspberry Pi or other single-board computers, allowing you to easily display your favorite memories on any screen with a Chromecast.
- Customizable Slideshow: Display photos from a specified folder and all its subdirectories.
- Configurable Settings: Easily adjust the Chromecast device name and the time window for the slideshow.
- Remote Management: Control the script remotely via a web browser to initiate a graceful shutdown.
- Device Discovery: Quickly find the names of all available Chromecast devices on your network.
- Error Handling: The script includes robust error handling to manage connection issues and ensure a smooth experience.
The script operates in two main parts:
- HTTP Server: A lightweight HTTP server is started on your local machine (e.g., Raspberry Pi). This server hosts the photo files, making them accessible via a local URL.
- Chromecast Caster: The main loop of the script connects to your Chromecast device and sequentially casts each photo from the local HTTP server. It shuffles the photo list to ensure a random order.
Before you begin, ensure you have the following installed on your device:
- Python 3.x
pychromecastlibrary: You can install it withpip install pychromecast.
All settings are managed in the config.py file. Edit this file to match your setup:
# config.py
from datetime import datetime
class PhotoFrameConfig:
# Root directory where your photos are stored.
PHOTOSBASEDIR = "/media/usb/share/samba/photoframe"
# Port of the HTTP server.
PORT = 8088
# IP address of the device running the script. You can run the script with -i to find this.
IP = "192.168.1.2"
# Friendly name of your Chromecast device. Run the script with -d to find it.
CASTDEVICE = "Livingroom Hub"
# Start and end time for the script to be active.
START_TIME = datetime.today().replace(hour=17, minute=59, second=0, microsecond=0)
END_TIME = datetime.today().replace(hour=20, minute=30, second=0, microsecond=0)
# Number of seconds to display each photo.
TIMEDELAY = 20Open your terminal and navigate to the directory containing the script.
List available Chromecast devices:
Use the -d or --devices flag to find the exact friendly name of your Chromecast device.
python3 pyPhotoFrameCast.py --devicesFind your device's IP address:
Use the -i or --ip flag to get your local IP address. This is needed for the IP setting in config.py.
python3 pyPhotoFrameCast.py --ipStart the slideshow:
Run the script without any flags to start the slideshow.
python3 pyPhotoFrameCast.pyRun in non-verbose mode:
To silence the output, use the -nv or --no-verbose flag. This is useful when running the script as a background service.
python3 pyPhotoFrameCast.py --no-verboseTo stop the script from a web browser, first run it with the -k or --kill flag to get the shutdown URL:
python3 pyPhotoFrameCast.py --killThis will output a URL like http://192.168.1.2:8088/kill. Whenever you need, simply visit this URL in a web browser (e.g. create a bookmark in your phone), and the script will gracefully shut down.