JustPaste
HomeCategoriesAboutDonateContactTerms of UsePrivacy Policy
JustPaste

Free online notepad — write and share instantly

Navigate

  • Home
  • Timeline
  • Categories

Info

  • About
  • Donate
  • Contact

Legal

  • Terms of Use
  • Privacy Policy

© 2026 JustPaste.app. All rights reserved.

Made with ♥ by JustPaste

Ggg | JustPaste.app
15 days ago2 views
👨‍💻Programming

Ggg

# 1. Install Homebrew (if you don't already have it)
# https://brew.sh

# 2. Install Python dependencies
pip3 install requests watchdog

# 3. Create project folder
mkdir -p ~/bunny-auto-sync/upload
cd ~/bunny-auto-sync

# 4. Create config file
cat > config.py << 'EOF'
API_KEY = "YOUR_BUNNY_API_KEY"
LIBRARY_ID = "YOUR_BUNNY_LIBRARY_ID"
WATCH_FOLDER = "/Users/$USER/bunny-auto-sync/upload"
EOF

# 5. Create uploader script
cat > uploader.py << 'EOF'
import os
import time
import requests
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
from config import API_KEY, LIBRARY_ID, WATCH_FOLDER

API_BASE = "https://video.bunnycdn.com/library"

def create_video(title):
    url = f"{API_BASE}/{LIBRARY_ID}/videos"
    headers = {"AccessKey": API_KEY}
    response = requests.post(url, headers=headers, json={"title": title})
    response.raise_for_status()
    return response.json()["guid"]

def upload_video(video_id, file_path):
    url = f"{API_BASE}/{LIBRARY_ID}/videos/{video_id}"
    headers = {"AccessKey": API_KEY}
    with open(file_path, "rb") as f:
        response = requests.put(url, headers=headers, data=f)
    response.raise_for_status()

class VideoHandler(FileSystemEventHandler):
    def on_created(self, event):
        if event.is_directory:
            return

        if not event.src_path.lower().endswith((".mp4", ".mov", ".mkv", ".webm")):
            return

        # Wait briefly so file copy completes
        time.sleep(5)

        filename = os.path.basename(event.src_path)
        title = os.path.splitext(filename)[0]

        print(f"Uploading: {filename}")

        try:
            video_id = create_video(title)
            upload_video(video_id, event.src_path)
            print(f"Uploaded successfully: {title} ({video_id})")
        except Exception as e:
            print(f"Upload failed for {filename}: {e}")

if __name__ == "__main__":
    print(f"Watching folder: {WATCH_FOLDER}")
    os.makedirs(WATCH_FOLDER, exist_ok=True)

    observer = Observer()
    observer.schedule(VideoHandler(), WATCH_FOLDER, recursive=False)
    observer.start()

    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()

    observer.join()
EOF

# 6. Edit config.py and replace:
#    YOUR_BUNNY_API_KEY
#    YOUR_BUNNY_LIBRARY_ID
nano config.py

# 7. Start the watcher
python3 uploader.py

# 8. From now on, copy any video into this folder:
#    ~/bunny-auto-sync/upload
# and it will automatically upload to your Bunny Stream library.
← Back to timeline