← Back to team overview

openshot.bugs team mailing list archive

[Bug 538558] Re: absolute paths in .osp

 

Could anyone try this?
The basic idea is that when you open a .osp project, we check if project location has changed. If it is the case, we check if resources location have moved with the project or if they are still in the original location. 
Special care is taken for files with %d in the name (image sequences).*

Emmanuel

classes/open_project.py line 74 (in bzr 1.4.3alpha1)
============USE===============
        #check project files still exist in the same location
        missing_files = ""
        items = project_object.project_folder.items
        
        # Just in case the project was moved
        new_project_path = "/".join(file_path.split('/')[:-1])
        
        for item in items:
            if isinstance(item, files.OpenShotFile):
                # Try auto path recovery in case the project was moved: Assume that resources were moved too, preserving relative paths
                if project_object.folder != new_project_path:
                    
                    # project moved. Update files if resources moved or disapeared from prevouse path
                    if item.name.startswith(project_object.folder):
                        # File could be relative path
                        new_path = item.name.replace(project_object.folder, new_project_path)
                        if check_if_file_exist(new_path):
                            # The file exist relatively to the new project location. Update path
                            item.name = new_path
                        elif not check_if_file_exist(item.name):
                            # The file disapeard from previouse location. Considere that it was 
                            # intended to be moved with the project file but relative new path is wrong.
                            # Update path
                            item.name = new_path
                        else:
                            # The file is not in the new location, and still in the old one.
                            # Keep the old one. This would generate absolute path.
                            pass 
                        
                    else:
                        # This file was absolute path anyway
                        pass
                        
                if not check_if_file_exist(item.name):
                    missing_files += item.name + "\n"
        
        # If project has moved since last edition: update internal path
        project_object.folder =  new_project_path
        
        if missing_files:
            messagebox.show("OpenShot", _("The following file(s) no longer exist.") + "\n\n" + missing_files)

============== additional function =================

def check_if_file_exist(item_name):
    """Same idea as os.path.exist, but handle openshot special filenames"""
    if "%" not in item_name:
        return os.path.exists(item_name) 
    
    # We have a sequence file with %d in the path
    path = os.path.dirname(item_name)
    file_name = item_name.split(os.path.sep)[-1]
    head = file_name.split("%d")[0]
    tail = file_name.split("%d")[1]
    
    if not os.path.exists(path):
        return False
    
    for f in os.listdir(path):
        if f.startswith(head) and f.endswith(tail):
            return True
    
    # We did not find any item matching the resource path
    return False
    
==============END===============

-- 
You received this bug notification because you are a member of OpenShot
Bugs, which is subscribed to OpenShot Video Editor.
https://bugs.launchpad.net/bugs/538558

Title:
  absolute paths in .osp

Status in OpenShot Video Editor:
  Triaged

Bug description:
  Hi,

  I have opened .osp file with text editor and seems like paths to media files in project are absolute.
  It will be great to use relative from .osp file paths to media files.

  It should be much easy to move(send) clip sources and  project file to
  another location

To manage notifications about this bug go to:
https://bugs.launchpad.net/openshot/+bug/538558/+subscriptions