Fix pre-existing player issues: edit upload paths, playlist sync, DPI, console
src/edit_popup.py: pass and reproduce the server-side edited-media layout
('edited_media/<media_id>/') when saving an edit, falling back to the flat
folder when no media id is available, so uploads land where the server expects.
src/get_playlists_v2.py: preserve every server field (audio, muted, description,
id, position, ...) when rewriting playlist items, instead of rebuilding fixed
dicts that silently dropped them. Web-link items keep their original http(s) url
and are never downloaded.
windows/pyi_runtime_hook.py: declare per-monitor DPI awareness before SDL/Kivy
initialise, so on a scaled display the window is not virtualised to a smaller
resolution (which left a black strip and mis-scaled media).
windows/build_win.bat: optional code signing step for PCs with Smart App Control
enabled, driven by KIWY_SIGN_PFX / KIWY_SIGN_PFX_PASSWORD or a local
kiwy_signing.pfx.
windows/build.spec, windows/README_WINDOWS_BUILD.md, windows/development-track.md:
build notes and manifest updates.
This commit is contained in:
+75
-13
@@ -82,11 +82,17 @@ class DrawingLayer(Widget):
|
||||
|
||||
class EditPopup(Popup):
|
||||
"""Popup for editing/annotating images"""
|
||||
def __init__(self, player_instance, image_path, user_card_data=None, **kwargs):
|
||||
def __init__(self, player_instance, image_path, user_card_data=None,
|
||||
media_id=None, original_filename=None, **kwargs):
|
||||
super(EditPopup, self).__init__(**kwargs)
|
||||
self.player = player_instance
|
||||
self.image_path = image_path
|
||||
self.user_card_data = user_card_data # Store card data to send to server on save
|
||||
# Server naming context: which media item (id) is being edited and what
|
||||
# its original file name is on the server. The server stores edited
|
||||
# media under 'edited_media/<media_id>/', so we must reproduce that.
|
||||
self.media_id = media_id
|
||||
self.original_filename = original_filename # server-side file_name
|
||||
|
||||
# Auto-close timer (5 minutes)
|
||||
self.auto_close_timeout = 300 # 5 minutes in seconds
|
||||
@@ -259,8 +265,15 @@ class EditPopup(Popup):
|
||||
def save_image(self, instance):
|
||||
"""Save the edited image"""
|
||||
try:
|
||||
# Create edited_media directory if it doesn't exist
|
||||
edited_dir = os.path.join(self.player.base_dir, 'media', 'edited_media')
|
||||
# Edited media is stored on the server under
|
||||
# 'edited_media/<media_id>/'. Reproduce that subfolder locally so
|
||||
# the upload naming matches what the server expects. Fall back to
|
||||
# the flat 'edited_media/' folder when no media_id is available.
|
||||
edited_base = os.path.join(self.player.base_dir, 'media', 'edited_media')
|
||||
if self.media_id is not None:
|
||||
edited_dir = os.path.join(edited_base, str(self.media_id))
|
||||
else:
|
||||
edited_dir = edited_base
|
||||
os.makedirs(edited_dir, exist_ok=True)
|
||||
|
||||
# Get original filename
|
||||
@@ -310,8 +323,22 @@ class EditPopup(Popup):
|
||||
# Overwrite the file
|
||||
shutil.copy2(output_path, self.image_path)
|
||||
|
||||
# Force file system sync to ensure data is written to disk
|
||||
os.sync()
|
||||
# Force file system sync to ensure data is written to disk.
|
||||
# NOTE: os.sync() is Linux-only and raises AttributeError on
|
||||
# Windows — that used to abort the whole pipeline before the
|
||||
# metadata/upload steps. Use a cross-platform fsync that is
|
||||
# best-effort and can never break the save/upload flow.
|
||||
try:
|
||||
if hasattr(os, 'sync'):
|
||||
os.sync()
|
||||
else:
|
||||
with open(output_path, 'rb') as _f:
|
||||
try:
|
||||
os.fsync(_f.fileno())
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as _sync_err:
|
||||
Logger.warning(f"EditPopup: File sync skipped ({_sync_err})")
|
||||
|
||||
# Verify the overwrite
|
||||
new_size = os.path.getsize(self.image_path)
|
||||
@@ -326,9 +353,15 @@ class EditPopup(Popup):
|
||||
self.ids.top_toolbar.opacity = 1
|
||||
self.ids.right_sidebar.opacity = 1
|
||||
|
||||
# Create and save metadata
|
||||
json_filename = self._save_metadata(edited_dir, new_name, base_name,
|
||||
new_version if version_match else 1, output_filename)
|
||||
# Create and save metadata. This runs in its own guarded
|
||||
# block so that a failure here cannot silently stop the
|
||||
# upload — the two steps are intentionally decoupled.
|
||||
json_filename = None
|
||||
try:
|
||||
json_filename = self._save_metadata(edited_dir, new_name, base_name,
|
||||
new_version if version_match else 1, output_filename)
|
||||
except Exception as meta_err:
|
||||
Logger.error(f"EditPopup: Metadata save failed: {meta_err}")
|
||||
|
||||
# Upload to server in background (continues after popup closes)
|
||||
upload_thread = threading.Thread(
|
||||
@@ -414,6 +447,14 @@ class EditPopup(Popup):
|
||||
'version': version,
|
||||
'user_card_data': self.user_card_data # Card data from reader (or None)
|
||||
}
|
||||
# Include the server-side file name and media id so the server can
|
||||
# attach the edit to the correct media item.
|
||||
if self.original_filename:
|
||||
metadata['original_filename'] = self.original_filename
|
||||
else:
|
||||
metadata['original_filename'] = os.path.basename(self.image_path)
|
||||
if self.media_id is not None:
|
||||
metadata['media_id'] = self.media_id
|
||||
|
||||
# Save metadata JSON
|
||||
json_filename = f"{new_name}_metadata.json"
|
||||
@@ -444,16 +485,37 @@ class EditPopup(Popup):
|
||||
Logger.warning("EditPopup: Missing server URL or auth code (upload skipped)")
|
||||
return False
|
||||
|
||||
# Load metadata from file
|
||||
with open(metadata_path, 'r') as meta_file:
|
||||
metadata = json.load(meta_file)
|
||||
# Load metadata from file (or build it in memory if the metadata
|
||||
# file was not written — the upload must still go through).
|
||||
metadata = None
|
||||
if metadata_path and os.path.exists(metadata_path):
|
||||
try:
|
||||
with open(metadata_path, 'r') as meta_file:
|
||||
metadata = json.load(meta_file)
|
||||
except Exception as e:
|
||||
Logger.warning(f"EditPopup: Could not read metadata file: {e}")
|
||||
if not metadata:
|
||||
metadata = {
|
||||
'time_of_modification': datetime.now().isoformat(),
|
||||
'original_name': os.path.basename(image_path),
|
||||
'new_name': os.path.basename(image_path),
|
||||
'version': 1,
|
||||
'user_card_data': self.user_card_data,
|
||||
}
|
||||
if self.original_filename:
|
||||
metadata['original_filename'] = self.original_filename
|
||||
if self.media_id is not None:
|
||||
metadata['media_id'] = self.media_id
|
||||
|
||||
# Prepare upload URL - send to the original file endpoint
|
||||
upload_url = f"{server_url}/api/player-edit-media"
|
||||
headers = {'Authorization': f'Bearer {auth_code}'}
|
||||
|
||||
# Add the original filename to metadata so server knows which file was edited
|
||||
metadata['original_filename'] = os.path.basename(metadata['original_path'])
|
||||
# Ensure the original filename (server-side name) is present so the
|
||||
# server knows which file was edited. Prefer the media context we
|
||||
# captured when the edit popup opened.
|
||||
if not metadata.get('original_filename'):
|
||||
metadata['original_filename'] = os.path.basename(metadata.get('original_path', image_path))
|
||||
|
||||
# Disable SSL verification for self-signed certificates (like main code does)
|
||||
# Note: This is NOT recommended for production with untrusted servers
|
||||
|
||||
Reference in New Issue
Block a user