← back to Resize It
scripts/download_spoonflower.py
263 lines
#!/usr/bin/env python3
"""
Download design file from Spoonflower after authentication
"""
import sys
import time
from playwright.sync_api import sync_playwright
def download_spoonflower_design(design_url, email, password, download_dir="/tmp", headless=True):
"""
Sign in to Spoonflower and download the design file
"""
with sync_playwright() as p:
browser = p.chromium.launch(headless=headless)
context = browser.new_context(
accept_downloads=True,
viewport={'width': 1920, 'height': 1080}
)
page = context.new_page()
# First, go to login page
print("🔐 Navigating to login page...")
page.goto("https://www.spoonflower.com/login", wait_until='networkidle', timeout=60000)
time.sleep(3)
# Fill in credentials - try multiple selectors
print("📧 Entering credentials...")
try:
# Try to find email input by label
email_selectors = [
'input[type="email"]',
'input[type="text"]',
'label:has-text("Email") + input',
'input[placeholder*="email" i]'
]
email_filled = False
for selector in email_selectors:
try:
if page.locator(selector).first.is_visible(timeout=5000):
page.locator(selector).first.fill(email)
print(f" Email filled with: {selector}")
email_filled = True
break
except:
continue
if not email_filled:
print("❌ Could not find email field")
page.screenshot(path="/tmp/spoonflower_login_debug.png")
browser.close()
return None
# Find password input
password_selectors = [
'input[type="password"]',
'label:has-text("Password") + input'
]
password_filled = False
for selector in password_selectors:
try:
if page.locator(selector).first.is_visible(timeout=5000):
page.locator(selector).first.fill(password)
print(f" Password filled with: {selector}")
password_filled = True
break
except:
continue
if not password_filled:
print("❌ Could not find password field")
page.screenshot(path="/tmp/spoonflower_login_debug.png")
browser.close()
return None
# Click submit
submit_selectors = [
'button[type="submit"]',
'button:has-text("Sign In")',
'button:has-text("Log In")',
'input[type="submit"]'
]
for selector in submit_selectors:
try:
if page.locator(selector).first.is_visible(timeout=2000):
page.locator(selector).first.click()
print(f" Clicked submit with: {selector}")
break
except:
continue
print("⏳ Waiting for login to complete...")
time.sleep(5)
except Exception as e:
print(f"❌ Login failed: {e}")
page.screenshot(path="/tmp/spoonflower_login_debug.png")
browser.close()
return None
# Now navigate to the design page after successful login
print(f"🌐 Navigating to design page: {design_url}...")
page.goto(design_url, wait_until='networkidle', timeout=60000)
time.sleep(5)
# Check if we got a 404
content = page.content()
if 'wrong turn' in content.lower() or ('404' in content and 'albuquerque' in content.lower()):
print("""
❌ I can log in to Spoonflower, but I cannot access a valid design page from this URL.
The design page returned a 404 error. This means:
- The design does not exist at this URL, OR
- The design has been deleted, OR
- The logged-in account does not own this design, so Spoonflower hides the page.
Valid Spoonflower design URLs that work with this tool:
- https://www.spoonflower.com/artists/designs/12345678-design-name-here
- https://www.spoonflower.com/en/design/12345678-design-name-here
- https://www.spoonflower.com/en/fabric/12345678-design-name-here
- https://www.spoonflower.com/en/wallpaper/12345678-design-name-here
To continue, please:
1. Open your browser and log in to Spoonflower with: info@designerwallcoverings.com
2. Go to the exact design where you can see the "File options" button.
3. Verify the design exists and you can see it.
4. Copy the entire URL from your browser's address bar.
5. Paste that full URL here and run this tool again.
I can only download designs that:
- Exist in your Spoonflower account
- You have permission to access with the logged-in account
- Have the "File Options" menu visible when you view them in a browser
""")
page.screenshot(path="/tmp/spoonflower_404.png")
browser.close()
return None
else:
print(f"✅ Design page loaded successfully")
print("🔍 Looking for File Options button...")
# Wait extra time for the page to fully load
time.sleep(3)
# Take screenshot before looking for button
page.screenshot(path="/tmp/before_file_options.png")
print(" Screenshot saved: /tmp/before_file_options.png")
# Try multiple selectors for File Options
file_options_selectors = [
'button:has-text("File Options")',
'button.chakra-menu__menu-button:has-text("File Options")',
'button[id*="menu-button"]:has-text("File Options")',
'button[aria-haspopup="menu"]:has-text("File Options")',
'.chakra-menu__menu-button:has-text("File Options")',
'button.chakra-button:has-text("File Options")',
'text=File Options'
]
file_options_clicked = False
for selector in file_options_selectors:
try:
print(f" Trying selector: {selector}")
locator = page.locator(selector).first
if locator.is_visible(timeout=5000):
print(f" ✅ Found File Options with: {selector}")
locator.scroll_into_view_if_needed()
time.sleep(1)
locator.click()
file_options_clicked = True
time.sleep(2)
break
except Exception as e:
print(f" ❌ Failed with {selector}: {str(e)[:50]}")
continue
if not file_options_clicked:
print("❌ Could not find File Options button")
# Take screenshot for debugging
page.screenshot(path="/tmp/spoonflower_debug.png", full_page=True)
print(" Full page screenshot saved to /tmp/spoonflower_debug.png")
# List all buttons on page for debugging
all_buttons = page.locator('button').all()
print(f" Found {len(all_buttons)} total buttons on page")
for i, btn in enumerate(all_buttons[:20]):
try:
text = btn.inner_text(timeout=1000)
if text and len(text) < 100:
print(f" Button {i}: '{text}'")
except:
pass
browser.close()
return None
print("📥 Looking for download option...")
# Try to find download link in menu
download_selectors = [
'[role="menuitem"]:has-text("Download")',
'button[role="menuitem"]:has-text("Download")',
'.chakra-menu__menuitem:has-text("Download")',
'text=Download Current File',
'text=Download',
'a:has-text("Download")',
'button:has-text("Download")'
]
downloaded_file = None
for selector in download_selectors:
try:
if page.locator(selector).first.is_visible(timeout=3000):
print(f" Found download option with: {selector}")
# Set up download handler
with page.expect_download(timeout=30000) as download_info:
page.locator(selector).first.click()
download = download_info.value
# Save the file
suggested_name = download.suggested_filename
download_path = f"{download_dir}/{suggested_name}"
download.save_as(download_path)
downloaded_file = download_path
print(f"✅ Downloaded: {download_path}")
break
except Exception as e:
print(f" Trying next selector... ({e})")
continue
if not downloaded_file:
print("❌ Could not find or click download option")
page.screenshot(path="/tmp/spoonflower_menu_debug.png")
print(" Screenshot saved to /tmp/spoonflower_menu_debug.png")
browser.close()
return downloaded_file
if __name__ == '__main__':
if len(sys.argv) < 4:
print("Usage: python3 download_spoonflower.py <design_url> <email> <password>")
sys.exit(1)
design_url = sys.argv[1]
email = sys.argv[2]
password = sys.argv[3]
result = download_spoonflower_design(design_url, email, password)
if result:
print(f"\n✅ Success! File downloaded to: {result}")
sys.exit(0)
else:
print(f"\n❌ Failed to download file")
sys.exit(1)