Cleanup: move utility to create a frame path into a static method

Add PlayRenderedAnim._frame_path_with_number_char since mixing
this logic inline made the code harder to follow.
This commit is contained in:
Campbell Barton 2022-02-15 16:50:08 +11:00
parent c146d75808
commit fa7bd4c069
1 changed files with 18 additions and 15 deletions

View File

@ -44,6 +44,23 @@ class PlayRenderedAnim(Operator):
bl_label = "Play Rendered Animation"
bl_options = {'REGISTER'}
@staticmethod
def _frame_path_with_number_char(rd, ch, **kwargs):
# Replace the number with `ch`.
# NOTE: make an api call for this would be nice, however this isn't needed in many places.
file_a = rd.frame_path(frame=0, **kwargs)
frame_tmp = 9
file_b = rd.frame_path(frame=frame_tmp, **kwargs)
while len(file_a) == len(file_b):
frame_tmp = (frame_tmp * 10) + 9
file_b = rd.frame_path(frame=frame_tmp, **kwargs)
file_b = rd.frame_path(frame=int(frame_tmp / 10), **kwargs)
return ("".join((c if file_b[i] == c else ch) for i, c in enumerate(file_a)))
def execute(self, context):
import os
import subprocess
@ -71,21 +88,7 @@ class PlayRenderedAnim(Operator):
player_path = guess_player_path(preset)
if is_movie is False and preset in {'FRAMECYCLER', 'RV', 'MPLAYER'}:
# replace the number with '#'
file_a = rd.frame_path(frame=0, view=view_suffix)
# TODO, make an api call for this
frame_tmp = 9
file_b = rd.frame_path(frame=frame_tmp, view=view_suffix)
while len(file_a) == len(file_b):
frame_tmp = (frame_tmp * 10) + 9
file_b = rd.frame_path(frame=frame_tmp, view=view_suffix)
file_b = rd.frame_path(frame=int(frame_tmp / 10), view=view_suffix)
file = ("".join((c if file_b[i] == c else "#")
for i, c in enumerate(file_a)))
del file_a, file_b, frame_tmp
file = PlayRenderedAnim._frame_path_with_number_char(rd, "#", view=view_suffix)
file = bpy.path.abspath(file) # expand '//'
else:
path_valid = True