Skip to content

Commit bf2dedf

Browse files
committed
refactor
1 parent 1c44951 commit bf2dedf

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

src/ffmpeg_media_type/utils/ffmpeg.py

+11-19
Original file line numberDiff line numberDiff line change
@@ -249,25 +249,17 @@ def animated_webp_support(func: Callable[[str], FFProbeInfo]) -> Callable[[str],
249249
def wrapper(uri: str) -> FFProbeInfo:
250250
probe_info = func(uri)
251251
if probe_info.streams[0].height == 0 and probe_info.streams[0].width == 0 and probe_info.format.format_name == "webp_pipe":
252-
if not uri.startswith("http"):
253-
webpmux_command = ["webpmux", "-get", "frame", "1", uri, "-o", uri]
254-
call(webpmux_command)
255-
return func(uri)
256-
257-
parsed_uri = urlparse(uri)
258-
259-
path = parsed_uri.path
260-
file = os.path.basename(path)
261-
_, file_ext = os.path.splitext(file)
262-
263-
response = requests.get(uri)
264-
response.raise_for_status()
265-
266-
with tempfile.NamedTemporaryFile(mode="wb", suffix=file_ext, delete=True) as f:
267-
f.write(response.content)
268-
webpmux_command = ["webpmux", "-get", "frame", "1", f.name, "-o", f.name]
269-
call(webpmux_command)
270-
return func(f.name)
252+
if uri.startswith("http"):
253+
response = requests.get(uri)
254+
response.raise_for_status()
255+
with tempfile.NamedTemporaryFile(mode="wb", suffix=".webp", delete=False) as f:
256+
f.write(response.content)
257+
uri = f.name
258+
259+
assert os.path.exists(uri)
260+
webpmux_command = ["webpmux", "-get", "frame", "1", uri, "-o", uri]
261+
call(webpmux_command)
262+
return func(uri)
271263
return probe_info
272264

273265
return wrapper

0 commit comments

Comments
 (0)