Compare commits
	
		
			1 Commits
		
	
	
		
			master
			...
			7699bdd305
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 7699bdd305 | 
@@ -6,9 +6,7 @@ import random
 | 
				
			|||||||
import requests
 | 
					import requests
 | 
				
			||||||
import os
 | 
					import os
 | 
				
			||||||
import pyszuru
 | 
					import pyszuru
 | 
				
			||||||
 | 
					from PIL import Image, ImageSequence, UnidentifiedImageError
 | 
				
			||||||
from PIL import Image
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from epd.epd_config import palArr, epdArr, EPD_TYPES
 | 
					from epd.epd_config import palArr, epdArr, EPD_TYPES
 | 
				
			||||||
@@ -29,7 +27,7 @@ highest_post = next(booru.search_post("sort:id type:image", page_size=1))
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
post = None
 | 
					post = None
 | 
				
			||||||
while post is None:
 | 
					while post is None:
 | 
				
			||||||
    random_id = random.randint(0, highest_post.id_)
 | 
					    random_id = 10455  # For testing, always use ID=10455 which is a gif
 | 
				
			||||||
    temp_post = booru.getPost(random_id)
 | 
					    temp_post = booru.getPost(random_id)
 | 
				
			||||||
    if temp_post and temp_post.mime.startswith("image/") and temp_post.content:
 | 
					    if temp_post and temp_post.mime.startswith("image/") and temp_post.content:
 | 
				
			||||||
        post = temp_post
 | 
					        post = temp_post
 | 
				
			||||||
@@ -57,7 +55,7 @@ while not image_downloaded:
 | 
				
			|||||||
        img.close()
 | 
					        img.close()
 | 
				
			||||||
        image_downloaded = True
 | 
					        image_downloaded = True
 | 
				
			||||||
        print("[DEBUG] Image successfully verified.")
 | 
					        print("[DEBUG] Image successfully verified.")
 | 
				
			||||||
    except (PIL.UnidentifiedImageError, requests.exceptions.RequestException) as e:
 | 
					    except (UnidentifiedImageError, requests.exceptions.RequestException) as e:
 | 
				
			||||||
        print(
 | 
					        print(
 | 
				
			||||||
            f"[ERROR] Failed to process downloaded file (Error: {e}). Retrying with a new post..."
 | 
					            f"[ERROR] Failed to process downloaded file (Error: {e}). Retrying with a new post..."
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
@@ -67,7 +65,7 @@ while not image_downloaded:
 | 
				
			|||||||
        # Find a new post
 | 
					        # Find a new post
 | 
				
			||||||
        post = None
 | 
					        post = None
 | 
				
			||||||
        while post is None:
 | 
					        while post is None:
 | 
				
			||||||
            random_id = random.randint(0, highest_post.id_)
 | 
					            random_id = 10455  # For testing, always use ID=10455 which is a gif
 | 
				
			||||||
            temp_post = booru.getPost(random_id)
 | 
					            temp_post = booru.getPost(random_id)
 | 
				
			||||||
            if temp_post and temp_post.mime.startswith("image/") and temp_post.content:
 | 
					            if temp_post and temp_post.mime.startswith("image/") and temp_post.content:
 | 
				
			||||||
                post = temp_post
 | 
					                post = temp_post
 | 
				
			||||||
@@ -81,6 +79,13 @@ while not image_downloaded:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    # Process and upload
 | 
					    # Process and upload
 | 
				
			||||||
    img = Image.open("image.jpg")
 | 
					    img = Image.open("image.jpg")
 | 
				
			||||||
 | 
					    if post.mime == "image/gif":
 | 
				
			||||||
 | 
					        # Seek to a random frame
 | 
				
			||||||
 | 
					        random_frame_index = random.randint(0, img.n_frames - 1)
 | 
				
			||||||
 | 
					        print(f"[DEBUG] Detected GIF, selecting frame: {random_frame_index}")
 | 
				
			||||||
 | 
					        img.seek(random_frame_index)
 | 
				
			||||||
 | 
					        # Convert the frame to an RGB image to discard GIF palette and alpha for processing
 | 
				
			||||||
 | 
					        img = img.convert("RGB")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Get configuration from environment variables
 | 
					# Get configuration from environment variables
 | 
				
			||||||
try:
 | 
					try:
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user