diff --git a/server/szurubooru/func/images.py b/server/szurubooru/func/images.py index e135d182..602f3bd0 100644 --- a/server/szurubooru/func/images.py +++ b/server/szurubooru/func/images.py @@ -28,6 +28,9 @@ class Image: def __init__(self, content: bytes) -> None: self.content = content self._reload_info() + if self.info["format"]["format_name"] == "swf": + self.content = self.swf_to_png() + self._reload_info() @property def width(self) -> int: @@ -60,10 +63,7 @@ class Image: "png", "-", ] - if ( - "duration" in self.info["format"] - and self.info["format"]["format_name"] != "swf" - ): + if "duration" in self.info["format"]: duration = float(self.info["format"]["duration"]) if duration > 3: cli = [ @@ -76,6 +76,19 @@ class Image: self.content = content self._reload_info() + def swf_to_png(self) -> bytes: + return self._execute( + [ + "--silent", + "-g", + "gl", + "--", + "{path}", + "-", + ], + program="exporter", + ) + def to_png(self) -> bytes: return self._execute( [ @@ -315,7 +328,7 @@ class Image: ) assert "format" in self.info assert "streams" in self.info - if len(self.info["streams"]) < 1: + if len(self.info["streams"]) < 1 and self.info["format"]["format_name"] != "swf": logger.warning("The video contains no video streams.") raise errors.ProcessingError( "The video contains no video streams."