Added some functionality so we can modify the size of the playing video
This commit is contained in:
@@ -47,8 +47,14 @@ DEFAULT_SETTINGS = {
|
||||
'card_style': 'flat', # 'flat' | 'elevated' | 'bordered'
|
||||
'corner_radius': 'rounded', # 'sharp' | 'rounded' | 'pill'
|
||||
'library_path': '', # '' = use COURSES_LIBRARY_PATH/--library-path default
|
||||
'video_width': '', # '' = responsive full-width; else last dragged size, in px
|
||||
'video_height': '',
|
||||
}
|
||||
|
||||
# Bounds for the persisted video player size, to reject garbage values
|
||||
# without capping how big/small someone can reasonably drag it.
|
||||
VIDEO_SIZE_BOUNDS = {'video_width': (200, 4000), 'video_height': (120, 3000)}
|
||||
|
||||
# Allowed values for every setting except accent_color (validated separately
|
||||
# as a hex string). Anything outside these sets is rejected/ignored on save.
|
||||
SETTINGS_CHOICES = {
|
||||
@@ -91,6 +97,9 @@ def load_settings() -> Dict[str, Any]:
|
||||
# Lenient on load (directory may be transiently
|
||||
# unavailable at startup) - only validated on save.
|
||||
settings[key] = value
|
||||
elif key in VIDEO_SIZE_BOUNDS:
|
||||
if value == '' or (isinstance(value, int) and not isinstance(value, bool)):
|
||||
settings[key] = value
|
||||
elif key in SETTINGS_CHOICES and value in SETTINGS_CHOICES[key]:
|
||||
settings[key] = value
|
||||
except (json.JSONDecodeError, OSError) as e:
|
||||
@@ -109,6 +118,18 @@ def save_settings(new_settings: Dict[str, Any]) -> Dict[str, Any]:
|
||||
if value and not os.path.isdir(value):
|
||||
raise ValueError(f"Directory not found: {value}")
|
||||
current[key] = value
|
||||
elif key in VIDEO_SIZE_BOUNDS:
|
||||
if value in (None, ''):
|
||||
current[key] = ''
|
||||
continue
|
||||
try:
|
||||
num = int(value)
|
||||
except (TypeError, ValueError):
|
||||
raise ValueError(f"{key} must be a number")
|
||||
lo, hi = VIDEO_SIZE_BOUNDS[key]
|
||||
if not (lo <= num <= hi):
|
||||
raise ValueError(f"{key} must be between {lo} and {hi}")
|
||||
current[key] = num
|
||||
elif key in SETTINGS_CHOICES and value in SETTINGS_CHOICES[key]:
|
||||
current[key] = value
|
||||
os.makedirs(DATA_DIR, exist_ok=True)
|
||||
|
||||
Reference in New Issue
Block a user