Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def add_file(self, filepath):
path, filename = os.path.split(filepath)
# Add file into project
app = get_app()
_ = get_app()._tr
# Check for this path in our existing project data
file = File.get(path=filepath)
# If this file is already found, exit
if file:
return
# Load filepath in libopenshot clip object (which will try multiple readers to open it)
clip = openshot.Clip(filepath)
# Get the JSON for the clip's internal reader
try:
reader = clip.Reader()
file_data = json.loads(reader.Json())
# Determine media type
if file_data["has_video"] and not is_image(file_data):
file_data["media_type"] = "video"
def addClip(self, data, position):
# Get app object
app = get_app()
# Search for matching file in project data (if any)
file_id = data[0]
file = File.get(id=file_id)
if not file:
# File not found, do nothing
return
if (file.data["media_type"] == "video" or file.data["media_type"] == "image"):
# Determine thumb path
thumb_path = os.path.join(info.THUMBNAIL_PATH, "%s.png" % file.data["id"])
else:
# Audio file
thumb_path = os.path.join(info.PATH, "images", "AudioThumbnail.png")
# Get file name
path, filename = os.path.split(file.data["path"])
# Convert path to the correct relative path (based on this folder)
def add_file(self, filepath):
path, filename = os.path.split(filepath)
# Add file into project
app = get_app()
_ = get_app()._tr
# Check for this path in our existing project data
file = File.get(path=filepath)
# If this file is already found, exit
if file:
return
# Load filepath in libopenshot clip object (which will try multiple readers to open it)
clip = openshot.Clip(filepath)
# Get the JSON for the clip's internal reader
try:
reader = clip.Reader()
file_data = json.loads(reader.Json())
# Set media type
file_data["media_type"] = "image"
# Get clip path
xml_file_id = clip_element.getElementsByTagName("file")[0].getAttribute("id")
clip_path = ""
if clip_element.getElementsByTagName("pathurl"):
clip_path = clip_element.getElementsByTagName("pathurl")[0].childNodes[0].nodeValue
else:
# Skip clipitem if no clippath node found
# This usually happens for linked audio clips (which OpenShot combines audio and thus ignores this)
continue
clip_path, is_modified, is_skipped = find_missing_file(clip_path)
if is_skipped:
continue
# Check for this path in our existing project data
file = File.get(path=clip_path)
# Load filepath in libopenshot clip object (which will try multiple readers to open it)
clip_obj = openshot.Clip(clip_path)
if not file:
# Get the JSON for the clip's internal reader
try:
reader = clip_obj.Reader()
file_data = json.loads(reader.Json())
# Determine media type
if file_data["has_video"] and not is_image(file_data):
file_data["media_type"] = "video"
elif file_data["has_video"] and is_image(file_data):
file_data["media_type"] = "image"
elif file_data["has_audio"] and not file_data["has_video"]:
# Path is expected to have 3 matched components (third is optional though)
# /thumbnails/FILE-ID/FRAME-NUMBER/ or
# /thumbnails/FILE-ID/FRAME-NUMBER/path/
self.send_response_only(200)
else:
self.send_error(404)
return
# Get URL parts
file_id = url_output.group('file_id')
file_frame = int(url_output.group('file_frame'))
only_path = url_output.group('only_path')
try:
# Look up file data
file = File.get(id=file_id)
# Ensure file location is an absolute path
file_path = file.absolute_path()
except AttributeError:
# Couldn't match file ID
self.send_error(404)
return
# Send headers
if not only_path:
self.send_header('Content-type', 'image/png')
else:
self.send_header('Content-type', 'text/html')
self.end_headers()
# Locate thumbnail
def actionAdd_to_Timeline_trigger(self, event):
# Loop through selected files
f = None
files = []
for file_id in self.selected_files:
# Find matching file
files.append(File.get(id=file_id))
# Get current position of playhead
fps = get_app().project.get(["fps"])
fps_float = float(fps["num"]) / float(fps["den"])
pos = (self.preview_thread.player.Position() - 1) / fps_float
# show window
from windows.add_to_timeline import AddToTimeline
win = AddToTimeline(files, pos)
# Run the dialog event loop - blocking interaction on this window during this time
result = win.exec_()
if result == QDialog.Accepted:
log.info('confirmed')
else:
log.info('canceled')
def actionDuplicateTitle_trigger(self, event):
# Get selected svg title file
selected_file_id = self.selected_files[0]
file = File.get(id=selected_file_id)
file_path = file.data.get("path")
# show dialog for editing title
from windows.title_editor import TitleEditor
win = TitleEditor(file_path, duplicate=True)
# Run the dialog event loop - blocking interaction on this window during that time
result = win.exec_()
def actionDuplicateTitle_trigger(self, event):
# Get selected svg title file
selected_file_id = self.selected_files[0]
file = File.get(id=selected_file_id)
file_path = file.data.get("path")
# show dialog for editing title
from windows.title_editor import TitleEditor
win = TitleEditor(file_path, duplicate=True)
# Run the dialog event loop - blocking interaction on this window during that time
result = win.exec_()