#!/usr/bin/env bash # Listing reel from a link: the photos and facts of a public listing page # (Zillow, Realtor.com, Redfin or FurnishedFinder) become the photo reel. The # read is 2 credits, bringing the photos in is free, each small photo # sharpened is 2 credits, and the final is 15 credits for each started 10 # seconds (a 30-second reel: 45). The Preview is free. # The calls of the page https://api.oneupai.com/docs/recipes/listing-from-link, # in its order, as one program. # # export ONEUP_API_KEY="oneup_live_…" # your Builder key # bash run.sh "https://www.zillow.com/homedetails/…" # # Needs curl, jq and uuidgen. ONEUP_BASE_URL changes the host (default # https://api.oneupai.com). Every answer is printed as it arrives. set -euo pipefail : "${ONEUP_API_KEY:?Set ONEUP_API_KEY to your API key first}" API=${ONEUP_BASE_URL:-https://api.oneupai.com} LISTING=${1:?Give the listing page address as the first argument} # One API call; the answer is printed and kept in OUT. A refusal stops here. api() { local method=$1 path=$2 shift 2 OUT=$(curl -sS -X "$method" "$API$path" \ -H "Authorization: Bearer $ONEUP_API_KEY" \ -H "Content-Type: application/json" "$@") echo "$OUT" if ! echo "$OUT" | jq -e 'type == "object" and (has("error") | not)' > /dev/null; then echo "refused: $method $path" >&2 exit 1 fi } # Waits for a queued job (every 2 s for 30 s, then every 5 s) and leaves its # result in OUT. wait_for() { local start=$SECONDS api GET "/v1/queue/status/$1" until echo "$OUT" | jq -e '.status == "COMPLETED" or .status == "FAILED"' > /dev/null; do if [ $((SECONDS - start)) -lt 30 ]; then sleep 2; else sleep 5; fi api GET "/v1/queue/status/$1" done api GET "/v1/queue/result/$1" } # Starts a render, waits for it, and leaves the finished render in OUT. render() { api POST /v1/renders -H "Idempotency-Key: $(uuidgen)" \ -d "$(jq -n --arg p "$PROJECT" --arg v "$VERSION" --arg k "$1" \ '{alias: "oneup/render-timeline", project_id: $p, version_id: $v, kind: $k}')" local id id=$(echo "$OUT" | jq -r .render_id) until echo "$OUT" | jq -e '.status == "COMPLETED" or .status == "FAILED"' > /dev/null; do sleep 5 api GET "/v1/renders/$id" done } # 1. Read the listing (2 credits; the same retry key within 15 minutes # returns the first answer without a charge). api POST /v1/run/oneup/web-read-listing -H "Idempotency-Key: $(uuidgen)" \ -d "$(jq -n --arg u "$LISTING" '{url: $u}')" LISTING_ANSWER=$OUT ADDRESS=$(echo "$LISTING_ANSWER" | jq -r .output.facts.address) DETAILS=$(echo "$LISTING_ANSWER" | jq -r '.output.facts | "\(.price) · \(.beds) bd · \(.baths) ba"') # 2. Bring the photos into your account (free; within an hour of the read). api POST /v1/uploads/from-extraction -d "$(echo "$LISTING_ANSWER" | jq -c \ '{extraction_id: .output.extraction_id, urls: [.output.photos[].url][:40]}')" IMPORTED=$OUT # 3. Sharpen each photo whose shorter side is under 1080 pixels (2 credits # each), and use the sharper copy in its place. SMALL=$(echo "$LISTING_ANSWER" | jq -c \ '[.output.photos[] | select(((.width // 1080) < 1080) or ((.height // 1080) < 1080)) | .url]') PHOTOS='[]' while read -r item; do [ -n "$item" ] || continue url=$(echo "$item" | jq -r .url) source=$(echo "$item" | jq -r .upload_id) if echo "$SMALL" | jq -e --arg u "$url" 'any(.[]; . == $u)' > /dev/null; then api POST /v1/queue/submit/oneup/image-upscale -H "Idempotency-Key: $(uuidgen)" \ -d "$(echo "$item" | jq -c '{image_url: .file_url}')" wait_for "$(echo "$OUT" | jq -r .ticket)" source=$(echo "$OUT" | jq -r '.assets[0].asset_id') fi PHOTOS=$(echo "$PHOTOS" | jq -c --arg id "$source" '. + [$id]') done <<< "$(echo "$IMPORTED" | jq -c '.uploads[]')" if [ "$(echo "$PHOTOS" | jq length)" = 0 ]; then echo "no photo could be brought in" >&2 exit 1 fi # 4. The photo reel: each photo 3 s with a push-in or a pan, 0.4 s crossfades, # a 4-second closing card, the address and price over the opening. api POST /v1/projects -d '{"agent_slug": "oneup/render-timeline"}' PROJECT=$(echo "$OUT" | jq -r .project_id) TIMELINE=$(jq -n --argjson photos "$PHOTOS" --arg address "$ADDRESS" --arg details "$DETAILS" ' { v: "1.1", output: {aspect: "9:16", resolution: 1080, fps: 30, container: "mp4"}, segments: ([$photos | to_entries[] | { id: "p\(.key + 1)", source: {"$asset": .value}, duration: 3000, effects: [if .key % 2 == 0 then {op: "kenburns", from: {x: 0.5, y: 0.5, zoom: 1}, to: {x: 0.5, y: 0.5, zoom: 1.18}, ease: "ease_in_out"} else {op: "kenburns", from: {x: 0.58, y: 0.5, zoom: 1.18}, to: {x: 0.42, y: 0.5, zoom: 1.18}, ease: "ease_in_out"} end], transition_out: {op: "crossfade", duration: 400} }] + [{id: "card", source: {"$asset": $photos[-1]}, duration: 4000, effects: [{op: "fade", from: 1, to: 0, duration: 600}]}]), overlays: [ {id: "t1", kind: "text", content: $address, style: "lower_third", position: "middle", range: {from: 0, to: 3000}, enter: {op: "fade", duration: 250}, exit: {op: "fade", duration: 200}}, {id: "t2", kind: "text", content: $details, style: "lower_third", position: "bottom", range: {from: 0, to: 3000}} ] }') api PUT "/v1/projects/$PROJECT/timeline" -d "$(jq -n --argjson t "$TIMELINE" '{timeline: $t}')" VERSION=$(echo "$OUT" | jq -r .version_id) # 5. A free Preview, then the final, then the MP4's link (good for an hour). render preview render final api GET "/v1/queue/result/$(echo "$OUT" | jq -r .ticket)"