I’ve just pushed an update (v4.4) to the Mini-Pi Media Server that introduces automated cloud syncing. You can now drop video files into a specific Google Drive folder (Video folder) from another PC and have your Pi Zero 2W automatically download them and refresh the MiniDLNA library every 30 minutes.
How it Works
The integration uses Rclone, an open-source command-line program to manage cloud storage. I’ve wrapped the logic into a new interactive setup script (rclone-setup.sh) to keep the process "headless-friendly."
Key Features of the Update:
- Automated Sync: The system checks your Google Drive every 30 minutes.
- Smart Refresh: The
minidlnaservice only restarts if the script detects a change in the file count—saving CPU cycles on the Pi Zero. - Permission Management: Automatically fixes file permissions (
755) and ownership (www-data) after every sync so files are immediately playable. - Background Service: Once configured, it runs as a systemd service, meaning it starts automatically on boot and checks every 30 minutes.
The Setup Workflow
I designed the bash script to be a step-by-step wizard. Here is the process for users:
- Software Prep: The script installs Rclone and sets up the local directory structure at
/var/lib/minidlna/Video/Web. - Folder Mapping: Users provide a specific Google Drive Folder ID. This keeps the sync scoped to just your "Video" folder rather than your entire drive.
- Headless Auth: Since the Pi Zero usually runs without a browser, the script allows you to paste an authentication token generated via
rclone authorizefrom another machine. - The "Set and Forget" Service: The script generates a systemd unit file that handles the timing and the sync logic.
So where do synchronised media files go ?
Running this script creates a Web folder within the Video folder, your media is synchronised there.
Minidlna, samba and apache will show the media files in this directory.
Technical Snippet: The Sync Logic
The heart of the sync is this one-liner executed by the service that runs every 30 minutes :-
Rclone-sync systemd service
The script has been designed to fail silently if no internet availability.
So this scirpt will not crash if the pi is running away from an internet connection (ethernet unplugged).
When next connected to the home network, the sync service will run at the next 30 minute slot, connect and just sync again.
Unattended, automatic - just the way things should be.
Why Google Drive?
While I love local storage, the Pi Zero could just sync new media and with media scraper at 5am will download the movie art and synopsis for the movie.
So where does it sync media to ?
Every 30 minutes a rclone-sync service runs and checks with your local copy of the web folder and pulls down any different media files that you have locally from your google drive Video folder.
Other updates:-
A couple of optimisations for the WiFi access point on a Pi 5 to get the speed faster when connected via WiFi access point (which should get faster as firmware updates to the wifi chip are released).
Updated the mini-pi-setup.sh script to include the google drive setup synchronisation
NOTE: the mkv conversion to mp4 overnight system task will NOT work on media files in the Web (synchronised) folder. They are left as is from whatever is synchronised.
____________________________________________________________________
☁️ Google Drive Sync User Guide
Prerequisites
- A Google Drive account is obviously needed.
- A PC/Laptop with a web browser to perform the initial authentication.
- Sudo access on your Mini-Pi.
Step 1: Prepare your Google Drive
Before running the script, you need to identify the specific 'Video' folder you want to sync.
- Open Google Drive in your web browser.
- Create a new folder named "Video" (or any name you prefer).
- Open that folder. Look at the URL in your browser's address bar.
- Copy the Folder ID. This is the long string of random letters and numbers at the end of the URL (after the last
/).- Example:
https://drive.google.com/drive/u/0/folders/1abc123_XYZ-789_ID_HERE
- Example:
In the example above the '1abc123_XYZ-789_ID_HERE' is the Folder ID you need to copy and paste, your folder id will be a different code.
Step 2: Either run the mini-pi-setup.sh script OR run rclone-setup.sh
Access your Mini-Pi via SSH and launch the script:
Select Option 1 ([Setup]): This installs Rclone, creates the local directories at /var/lib/minidlna/Video/Web, and asks you to paste the Folder ID you copied in Step 1
- Since the Pi is "headless" (no browser), you must authorize it from another computer.
- On your PC, visit
- rclone.org/commands/rclone_authorize/ or run
rclone authorize "drive"in a terminal. - Follow the Google login prompts.
- Copy the resulting JSON code block (the text between
{and}) and paste it into the script prompt on your Pi.
Step 3: Enable the Background Service
Once configured, you need to tell the Pi to start syncing automatically.
- Select Option 3 ([Start]): This creates a systemd service that runs in the background.
- Sync Frequency: The server will now check for new files every 30 minutes.
- Automatic Refresh: If the script finds new files, it will automatically restart the MiniDLNA service so your new media appears on your TV immediately.
Step 4: Maintenance & Logs
If you want to see the sync in action or troubleshoot, use Option 4 ([View]) in the script menu. This pulls the real-time logs from the system service, showing you which files are being downloaded or deleted.
Pro Tip: To delete a movie from your Pi, just delete it from your Google Drive folder. The script uses --delete-during, which keeps your Pi storage perfectly mirrored to your cloud folder.
You can download / upgrade by running the following on the Raspberry Pi (either SSH into the Pi or on the actual Pi) :-
wget -qO- https://raw.githubusercontent.com/diddy-boy/mini-pi-media-server/main/install.sh | bash
diddy
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.