Skip to content

Commit

Permalink
Merge pull request #50 from Muddyblack/25-mediadataeditor-add-video-f…
Browse files Browse the repository at this point in the history
…iles-support

video files working STABLE
  • Loading branch information
Muddyblack authored Jan 13, 2024
2 parents a43a0eb + 6683eca commit 143a5c0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ saves/
exiftool.exe
TEST*
*.old*

temp/

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
25 changes: 22 additions & 3 deletions MetaDataEditor/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from PyQt5.QtCore import Qt, QSettings
from PyQt5.QtGui import QMovie, QPixmap, QIcon

from moviepy.editor import VideoFileClip

from custom_widgets import TagWidget

Expand All @@ -31,6 +32,11 @@
DARKMODE_SYTLE_SHEET = f"{SCRIPT_DIR_PATH}/darkmode_style.qss"
LIGHTMODE_SYTLE_SHEET = f"{SCRIPT_DIR_PATH}/lightmode_style.qss"

TEMP_PATH = f"{SCRIPT_DIR_PATH}/temp"
if not os.path.exists(TEMP_PATH):
os.makedirs(TEMP_PATH)
TEMP_Thumbnail_PATH = f"{TEMP_PATH}/thumbnail.jpg"

IMAGE_FORMATS = "Images (*.png *.jpg *.jpeg *.bmp *.gif)"
VIDEO_FORMATS = "Videos (*.mp4 *.avi *.mkv *.flv *.mov)"

Expand Down Expand Up @@ -217,11 +223,15 @@ def save_file(self):
break

options = QFileDialog.Options()
file_extension = os.path.splitext(self.image_path)[1].lower()
file_format = (
VIDEO_FORMATS if file_extension in VIDEO_FORMATS else IMAGE_FORMATS
)
file_dialog = QFileDialog.getSaveFileName(
self,
"Save Image",
"Save File",
f"{self.image_path}",
f"{IMAGE_FORMATS};;{VIDEO_FORMATS}",
f"{file_format}",
options=options,
)

Expand Down Expand Up @@ -262,7 +272,16 @@ def display_file(self, image_path):
self.image_label.setMovie(self.movie)
self.movie.start()
else:
pixmap = QPixmap(image_path)
thumbnail_path = image_path
file_extension = os.path.splitext(self.image_path)[1].lower()
if file_extension in VIDEO_FORMATS.lower():
print("video")
clip = VideoFileClip(image_path)
clip.save_frame(TEMP_Thumbnail_PATH, t="00:00:01")
clip.close()
thumbnail_path = TEMP_Thumbnail_PATH

pixmap = QPixmap(thumbnail_path)
pixmap = pixmap.scaled(
self.image_label.width(), self.height(), Qt.KeepAspectRatio
)
Expand Down
6 changes: 6 additions & 0 deletions MetaDataEditor/image_metadata_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ def write_metadata(image_path, out_path, metadata=None):
cmd.append("-overwrite_original")
elif os.path.exists(out_path):
os.remove(out_path)
logging.info(
"immage path: %s with metadata: %s and output: %s",
image_path,
metadata,
out_path,
)
try:
subprocess.run(
cmd,
Expand Down
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ google-auth
google-auth-oauthlib
google-auth-httplib2
google-api-python-client
Pillow
Pylint
pillow
moviepy
pylint
pyqt5

0 comments on commit 143a5c0

Please sign in to comment.