Skip to content

Commit

Permalink
bugfix: 'Merge Videos' tab should accept multiple files at a time
Browse files Browse the repository at this point in the history
  • Loading branch information
taseikyo committed Mar 16, 2020
1 parent 42ed150 commit e2e30da
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 16 deletions.
20 changes: 20 additions & 0 deletions ffmpeg-helper/ffmpeg-helper/mwin.ui
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,16 @@
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="clear_video_files_btn">
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>Clear</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="select_video_files_btn">
<property name="minimumSize">
Expand Down Expand Up @@ -338,6 +348,16 @@
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="clear_va_files_btn">
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>Clear</string>
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="select_va_files_btn">
<property name="minimumSize">
Expand Down
71 changes: 55 additions & 16 deletions ffmpeg-helper/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@
DURATION_MODE = 0
ENDTIME_MODE = 1

ALLOW_VIDEO_TYPE = ["mp4", "avi", "mkv", "ts", "rmvb", "rm", "mov"]
ALLOW_VIDEO_TYPE = [
"mp4",
"avi",
"mkv",
"ts",
"rmvb",
"rm",
"mov",
]
ALLOW_AUDIO_TYPE = ["m4a", "mp3", "acc", "wav", "flac"]


Expand Down Expand Up @@ -50,31 +58,41 @@ def dragEnterEvent(self, e):
if self.tabWidget.currentIndex() in (0, 1)
else ALLOW_VIDEO_TYPE + ALLOW_AUDIO_TYPE
)
_, ext = os.path.splitext(e.mimeData().text())
if ext[1:] in allow_type:
e.accept()
else:
e.ignore()
for file in e.mimeData().urls():
_, ext = os.path.splitext(file.toLocalFile())
if ext[1:] in allow_type:
e.accept()
else:
e.ignore()

def dropEvent(self, e):
# e.mimeData().text() = file:///F:videio/xxx.mp4
filename = e.mimeData().text()[8:]
tab_index = self.tabWidget.currentIndex()
if tab_index == 0:
# process one file at a time
self.cut_file_path = filename
self.filename_label.setText(os.path.basename(filename))
self.log_edit.setPlainText("")
elif tab_index == 1:
row = self.merge_video_table.rowCount()
if row == 0:
self.merge_video_table.setRowCount(0)
self.merge_video_table.setColumnCount(1)
self.merge_video_table.setHorizontalHeaderLabels(["Merge Filenames"])
self.merge_video_table.horizontalHeader().setStretchLastSection(True)
self.merge_files_path.append(filename)
self.merge_video_table.insertRow(row)
self.merge_video_table.setItem(row, 0, QTableWidgetItem(filename))
# process multiple files at a time
for file in e.mimeData().urls():
filename = file.toLocalFile()
row = self.merge_video_table.rowCount()
if row == 0:
self.merge_video_table.setRowCount(0)
self.merge_video_table.setColumnCount(1)
self.merge_video_table.setHorizontalHeaderLabels(
["Merge Filenames"]
)
self.merge_video_table.horizontalHeader().setStretchLastSection(
True
)
self.merge_files_path.append(filename)
self.merge_video_table.insertRow(row)
self.merge_video_table.setItem(row, 0, QTableWidgetItem(filename))
else:
# process one audio and video file at a time
row = self.merge_va_table.rowCount()
if row == 0:
self.merge_va_table.setRowCount(0)
Expand Down Expand Up @@ -206,6 +224,16 @@ def on_select_video_files_btn_clicked(self):
print(files[x])
self.merge_video_table.setItem(x, 0, QTableWidgetItem(files[x]))

@pyqtSlot()
def on_clear_video_files_btn_clicked(self):
self.merge_files_path = []

self.merge_video_table.clearContents()
self.merge_video_table.setRowCount(0)
self.merge_video_table.setColumnCount(1)
self.merge_video_table.setHorizontalHeaderLabels(["Merge Filenames"])
self.merge_video_table.horizontalHeader().setStretchLastSection(True)

@pyqtSlot()
def on_start_merge_video_btn_clicked(self):
if not self.merge_files_path or len(self.merge_files_path) < 2:
Expand Down Expand Up @@ -275,6 +303,17 @@ def on_select_va_files_btn_clicked(self):
print(files[x])
self.merge_va_table.setItem(x, 0, QTableWidgetItem(files[x]))

@pyqtSlot()
def on_clear_va_files_btn_clicked(self):
self.merge_video_path = ""
self.merge_audio_path = ""

self.merge_va_table.clearContents()
self.merge_va_table.setRowCount(0)
self.merge_va_table.setColumnCount(1)
self.merge_va_table.setHorizontalHeaderLabels(["Merge Filenames"])
self.merge_va_table.horizontalHeader().setStretchLastSection(True)

@pyqtSlot()
def on_start_merge_va_btn_clicked(self):
if self.merge_va_table.rowCount() < 2:
Expand Down Expand Up @@ -319,7 +358,7 @@ def __init__(self, cmd):
def run(self):
try:
p = subprocess.Popen(
self.cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
self.cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
)
for line in iter(p.stdout.readline, b""):
try:
Expand Down

0 comments on commit e2e30da

Please sign in to comment.