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