ozmartian / vidcutter

A modern yet simple multi-platform video cutter and joiner.
GNU General Public License v3.0
1.77k stars 137 forks source link

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

Open thp opened 1 year ago

thp commented 1 year ago

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:

Actual result:

VidCutter version: 6.0.5.1 Flatpak

thp commented 1 year ago

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 commented 1 year ago

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.