mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-21 21:22:11 -03:00
- Added support for importing recipes via image upload or URL input in the ImportManager. - Implemented toggle functionality to switch between upload and URL modes, updating the UI accordingly. - Enhanced error handling for missing fields and invalid URLs during the import process. - Updated the RecipeRoutes to analyze images from both uploaded files and URLs, returning appropriate metadata. - Improved the import modal UI to accommodate new input methods and provide clearer user feedback.
42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
import requests
|
|
import tempfile
|
|
import re
|
|
from bs4 import BeautifulSoup
|
|
|
|
def download_twitter_image(url):
|
|
"""Download image from a URL containing twitter:image meta tag
|
|
|
|
Args:
|
|
url (str): The URL to download image from
|
|
|
|
Returns:
|
|
str: Path to downloaded temporary image file
|
|
"""
|
|
try:
|
|
# Download page content
|
|
response = requests.get(url)
|
|
response.raise_for_status()
|
|
|
|
# Parse HTML
|
|
soup = BeautifulSoup(response.text, 'html.parser')
|
|
|
|
# Find twitter:image meta tag
|
|
meta_tag = soup.find('meta', attrs={'property': 'twitter:image'})
|
|
if not meta_tag:
|
|
return None
|
|
|
|
image_url = meta_tag['content']
|
|
|
|
# Download image
|
|
image_response = requests.get(image_url)
|
|
image_response.raise_for_status()
|
|
|
|
# Save to temp file
|
|
with tempfile.NamedTemporaryFile(delete=False, suffix='.jpg') as temp_file:
|
|
temp_file.write(image_response.content)
|
|
return temp_file.name
|
|
|
|
except Exception as e:
|
|
print(f"Error downloading twitter image: {e}")
|
|
return None
|