Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving projects doesn't add .vcp extension, loading project doesn't work without .vcp extension #375

Open
thp opened this issue Apr 11, 2023 · 2 comments

Comments

@thp
Copy link

thp commented Apr 11, 2023

When saving projects, the ".vcp" extension isn't added automatically.
When loading projects, selecting a file without a ".vcp" extension does nothing.

Steps to reproduce:

  1. Open a video file
  2. Add some cuts
  3. Save project file, inserting "asdf" into the filename field (don't add the ".vcp" extension)
  4. Close vidcutter and open again
  5. Load project file, selecting "asdf" as the file

Expected result:

  • The project file is loaded, independent of file name extension
  • (Alternatively, the ".vcp" extension is added to the filename on save if it isn't there already)

Actual result:

  • Project file isn't loaded

VidCutter version: 6.0.5.1 Flatpak

@thp
Copy link
Author

thp commented Apr 11, 2023

For the loading part, it seems like it uses the file extension to distinguish between file types (vidcutter/vidcutter.py):

            project_type = info.suffix()
...
                    if project_type == 'vcp' and linenum == 1:
                        self.loadMedia(line)
...

One quick workaround would be to assume that an extension-less file is a .vcp file:

diff --git a/vidcutter/videocutter.py b/vidcutter/videocutter.py
index 98e5553..7082f7c 100644
--- a/vidcutter/videocutter.py
+++ b/vidcutter/videocutter.py
@@ -832,7 +832,7 @@ class VideoCutter(QWidget):
                 self.lastFolder = QFileInfo(project_file).absolutePath()
             file = QFile(project_file)
             info = QFileInfo(file)
-            project_type = info.suffix()
+            project_type = info.suffix() or 'vcp'
             if not file.open(QFile.ReadOnly | QFile.Text):
                 QMessageBox.critical(self.parent, 'Open project file',
                                      'Cannot read project file {0}:\n\n{1}'.format(project_file, file.errorString()))

However, this wouldn't work if the file name contains a "." (as then info.suffix() would return some weird value).

Possibly better:

diff --git a/vidcutter/videocutter.py b/vidcutter/videocutter.py
index 98e5553..237f927 100644
--- a/vidcutter/videocutter.py
+++ b/vidcutter/videocutter.py
@@ -833,6 +833,9 @@ class VideoCutter(QWidget):
             file = QFile(project_file)
             info = QFileInfo(file)
             project_type = info.suffix()
+            if project_type not in self.project_files:
+                # Assume .vcp file if the file extension is missing or invalid
+                project_type = 'vcp'
             if not file.open(QFile.ReadOnly | QFile.Text):
                 QMessageBox.critical(self.parent, 'Open project file',
                                      'Cannot read project file {0}:\n\n{1}'.format(project_file, file.errorString()))

@thp
Copy link
Author

thp commented Apr 11, 2023

For the saving part, seems like it should work with the filter alone, but it doesn't work for me (Flatpak/Linux).

A naive solution (which most likely has sandboxing restrictions) would be to just append the extension if it's missing:

diff --git a/vidcutter/videocutter.py b/vidcutter/videocutter.py
index 98e5553..46b13ba 100644
--- a/vidcutter/videocutter.py
+++ b/vidcutter/videocutter.py
@@ -934,6 +937,9 @@ class VideoCutter(QWidget):
                 filter=self.projectFilters(True),
                 initialFilter='VidCutter Project (*.vcp)',
                 options=self.getFileDialogOptions())
+        if ptype == 'VidCutter Project (*.vcp)' and not project_save.endswith('.vcp'):
+            # Add extension, will probably not work with sandboxing
+            project_save += '.vcp'
         if project_save is not None and len(project_save.strip()):
             file = QFile(project_save)
             if not file.open(QFile.WriteOnly | QFile.Text):

According to this SO thread you might need to use setDefaultSuffix() on a QFileDialog you create yourself, sidestepping the QFileDialog.getSaveFileName() static method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant