Fix import csv and update edit
parent
24c6f12402
commit
c43d1b3f35
|
@ -14,7 +14,7 @@ def install_module(module_name, package_name=None):
|
|||
except ModuleNotFoundError:
|
||||
print(f'Installing Module {module_name} ....')
|
||||
|
||||
subprocess.call([sys.executable, '-m', 'ensurepip'])
|
||||
subprocess.call([sys.executable, '-m', 'ensurepip', '--upgrade'])
|
||||
subprocess.call([sys.executable, '-m', 'pip', 'install', package_name or module_name])
|
||||
|
||||
module = importlib.import_module(module_name)
|
||||
|
|
|
@ -86,6 +86,7 @@ class VSETB_OT_import_files(Operator):
|
|||
|
||||
import_edit : BoolProperty(name='', default=True)
|
||||
edit: EnumProperty(name='', items=lambda s, c: EDITS)
|
||||
match_by : EnumProperty(name='Match By', items=[('NAME', 'Name', ''), ('INDEX', 'Index', '')])
|
||||
|
||||
import_movie : BoolProperty(name='', default=False)
|
||||
movie: EnumProperty(name='', items=lambda s, c: MOVIES)
|
||||
|
@ -108,19 +109,23 @@ class VSETB_OT_import_files(Operator):
|
|||
col = layout.column(align=True)
|
||||
col.operator('import.auto_select_files', text='Auto Select')
|
||||
|
||||
row = self.layout.row(heading="Import Edit", align=True)
|
||||
row = layout.row(heading="Import Edit", align=True)
|
||||
row.prop(self, 'import_edit')
|
||||
sub = row.row(align=True)
|
||||
sub.active = self.import_edit
|
||||
sub.prop(self, 'edit')
|
||||
row = layout.row(align=True)
|
||||
row.prop(self, 'match_by', expand=True)
|
||||
|
||||
row = self.layout.row(heading="Import Movie", align=True)
|
||||
layout.separator()
|
||||
|
||||
row = layout.row(heading="Import Movie", align=True)
|
||||
row.prop(self, 'import_movie')
|
||||
sub = row.row()
|
||||
sub.active = self.import_movie
|
||||
sub.prop(self, 'movie')
|
||||
|
||||
row = self.layout.row(heading="Import Sound", align=True)
|
||||
row = layout.row(heading="Import Sound", align=True)
|
||||
row.prop(self, 'import_sound')
|
||||
sub = row.row()
|
||||
sub.active = self.import_sound
|
||||
|
@ -159,7 +164,7 @@ class VSETB_OT_import_files(Operator):
|
|||
if self.import_edit:
|
||||
print(f'[>.] Loading Edit from: {str(edit_filepath)}')
|
||||
|
||||
import_edit(edit_filepath, adapter="cmx_3600")
|
||||
import_edit(edit_filepath, adapter="cmx_3600", match_by=self.match_by)
|
||||
|
||||
if self.import_movie:
|
||||
print(f'[>.] Loading Movie from: {str(movie_filepath)}')
|
||||
|
|
|
@ -106,8 +106,12 @@ class VSETB_OT_spreadsheet_from_file(Operator):
|
|||
def execute(self, context):
|
||||
scn = context.scene
|
||||
project = get_scene_settings().active_project
|
||||
spreadsheet = project.spreadsheet_import
|
||||
|
||||
import_cells = project.spreadsheet_import.cells
|
||||
separator = spreadsheet.separator.replace('\\n', '\n').replace('\\t', '\t').replace('\\r', '\r')
|
||||
delimiter = spreadsheet.delimiter.replace('\\n', '\n').replace('\\t', '\t').replace('\\r', '\r')
|
||||
|
||||
import_cells = spreadsheet.cells
|
||||
import_cells.clear()
|
||||
|
||||
if not self.filepath:
|
||||
|
@ -121,8 +125,8 @@ class VSETB_OT_spreadsheet_from_file(Operator):
|
|||
filepath = Path(self.filepath)
|
||||
|
||||
if filepath.suffix.lower() == '.csv':
|
||||
with open(filepath, newline='\n') as csvfile:
|
||||
rows = list(csv.reader(csvfile))
|
||||
with open(filepath, newline=separator) as csvfile:
|
||||
rows = list(csv.reader(csvfile, delimiter=delimiter))
|
||||
|
||||
elif filepath.suffix.lower() == '.xlsx':
|
||||
try:
|
||||
|
@ -144,6 +148,8 @@ class VSETB_OT_spreadsheet_from_file(Operator):
|
|||
|
||||
rows = [r for r in rows if any(r)]
|
||||
|
||||
print('rows', rows)
|
||||
|
||||
cell_types = project.get_cell_types()
|
||||
for cell_name in rows[0]:
|
||||
if not cell_name:
|
||||
|
@ -338,7 +344,7 @@ class VSETB_OT_import_spreadsheet(Operator):
|
|||
cell_types = project.get_cell_types()
|
||||
cell_names = {k: spreadsheet.cells[k].import_name for k in header if k}
|
||||
|
||||
separator = spreadsheet.separator.replace('\\n', '\n').replace('\\t', '\t').replace('\\r', '\r')
|
||||
#separator = spreadsheet.separator.replace('\\n', '\n').replace('\\t', '\t').replace('\\r', '\r')
|
||||
|
||||
shot_strips = get_strips('Shots')
|
||||
|
||||
|
|
|
@ -255,13 +255,15 @@ def render_strip(strip, output):
|
|||
scn.frame_current = scene_current
|
||||
scn.render.filepath = render_path
|
||||
|
||||
def import_edit(filepath, adapter="cmx_3600", channel='Shots'):
|
||||
def import_edit(filepath, adapter="cmx_3600", channel='Shots', match_by='name'):
|
||||
opentimelineio = install_module('opentimelineio')
|
||||
|
||||
from opentimelineio.schema import Clip
|
||||
|
||||
scn = bpy.context.scene
|
||||
sequencer = scn.sequence_editor.sequences
|
||||
strips = get_strips(channel='Shots')
|
||||
shot_channel = get_channel_index('Shots')
|
||||
|
||||
edl = Path(filepath)
|
||||
try:
|
||||
|
@ -276,6 +278,9 @@ def import_edit(filepath, adapter="cmx_3600", channel='Shots'):
|
|||
scn.frame_start = (
|
||||
0 if timeline.global_start_time is None else timeline.global_start_time
|
||||
)
|
||||
|
||||
# Get all video clips only
|
||||
clips = []
|
||||
for track in timeline.tracks:
|
||||
for child in track.each_child(shallow_search=True):
|
||||
|
||||
|
@ -285,41 +290,56 @@ def import_edit(filepath, adapter="cmx_3600", channel='Shots'):
|
|||
|
||||
# FIXME Exclude Audio for now
|
||||
if any(child.name.lower().endswith(ext) for ext in SOUND_SUFFIXES):
|
||||
channel = get_channel_index('Audio')
|
||||
continue
|
||||
|
||||
channel = get_channel_index('Shots')
|
||||
frame_start = opentimelineio.opentime.to_frames(
|
||||
child.range_in_parent().start_time)
|
||||
clips.append(child)
|
||||
|
||||
frame_end = frame_start + opentimelineio.opentime.to_frames(
|
||||
child.range_in_parent().duration)
|
||||
clips.sort(key=lambda x: x.range_in_parent().start_time)
|
||||
|
||||
#try:
|
||||
strip = next((s for s in sequencer if s.vsetb_strip_settings.source_name == child.name), None)
|
||||
if strip:
|
||||
if frame_start != strip.frame_final_start or frame_end !=strip.frame_final_end:
|
||||
print(f'The strip {strip.name} is updated with new range')
|
||||
#self.report({'INFO'}, f'The strip {strip.name} is updated with new range')
|
||||
|
||||
strip.frame_final_start = frame_start
|
||||
strip.frame_final_end = frame_end
|
||||
else:
|
||||
strip = sequencer.new_effect(
|
||||
name=child.name,
|
||||
type='COLOR',
|
||||
channel=channel,
|
||||
frame_start=frame_start,
|
||||
frame_end=frame_end,
|
||||
)
|
||||
for i, clip in enumerate(clips):
|
||||
|
||||
strip.blend_alpha = 0.0
|
||||
strip.select = False
|
||||
strip.vsetb_strip_settings.source_name = child.name
|
||||
frame_start = opentimelineio.opentime.to_frames(
|
||||
clip.range_in_parent().start_time)
|
||||
|
||||
#except Exception as e:
|
||||
# print('e: ', e)
|
||||
# continue
|
||||
frame_end = frame_start + opentimelineio.opentime.to_frames(
|
||||
clip.range_in_parent().duration)
|
||||
|
||||
strip = None
|
||||
|
||||
if match_by.lower() == 'name':
|
||||
strip = next((s for s in strips if s.vsetb_strip_settings.source_name == clip.name), None)
|
||||
elif match_by.lower() == 'index':
|
||||
try:
|
||||
strip = strips[i]
|
||||
except IndexError:
|
||||
print(f'No strip found for {clip.name}')
|
||||
|
||||
if strip:
|
||||
if frame_start != strip.frame_final_start or frame_end !=strip.frame_final_end:
|
||||
print(f'The strip {strip.name} is updated with new range')
|
||||
#self.report({'INFO'}, f'The strip {strip.name} is updated with new range')
|
||||
|
||||
strip.frame_final_start = frame_start
|
||||
strip.frame_final_end = frame_end
|
||||
|
||||
else:
|
||||
print('Create a new strip')
|
||||
strip = sequencer.new_effect(
|
||||
name=clip.name,
|
||||
type='COLOR',
|
||||
channel=shot_channel,
|
||||
frame_start=frame_start,
|
||||
frame_end=frame_end,
|
||||
)
|
||||
|
||||
strip.blend_alpha = 0.0
|
||||
strip.select = False
|
||||
strip.vsetb_strip_settings.source_name = clip.name
|
||||
|
||||
#except Exception as e:
|
||||
# print('e: ', e)
|
||||
# continue
|
||||
|
||||
scn.frame_end = frame_end-1
|
||||
return timeline
|
||||
|
|
Loading…
Reference in New Issue