3030from PIL import Image
3131
3232from common .decoded_thumbnails import get_decoded_thumbnail_url
33- from common .thumbnails import delete_image_thumbnail , get_image_thumbnail_url
33+ from common .thumbnails import (
34+ delete_image_thumbnail ,
35+ get_image_thumbnail_path ,
36+ get_image_thumbnail_url ,
37+ )
3438
3539
3640def get_disk_usage (path : Path ) -> Dict [str , Union [int , str ]]:
@@ -119,6 +123,35 @@ def get_image_dimensions(image_path: str) -> Tuple[Any, ...]:
119123 return (None , None )
120124
121125
126+ def build_recording_snapshot_info (snapshot_file : Path ) -> Optional [Dict [str , Any ]]:
127+ """Build snapshot and generated-thumbnail metadata for a recording."""
128+ if not snapshot_file .exists () or not snapshot_file .is_file ():
129+ return None
130+
131+ width , height = get_image_dimensions (str (snapshot_file ))
132+ thumbnail_url = get_image_thumbnail_url (snapshot_file , "/recordings" )
133+ thumbnail_info = None
134+
135+ if thumbnail_url :
136+ thumbnail_path = get_image_thumbnail_path (snapshot_file )
137+ if thumbnail_path .exists () and thumbnail_path .is_file ():
138+ thumbnail_info = {
139+ "filename" : thumbnail_path .name ,
140+ "url" : thumbnail_url ,
141+ "size" : thumbnail_path .stat ().st_size ,
142+ }
143+
144+ return {
145+ "filename" : snapshot_file .name ,
146+ "url" : f"/recordings/{ snapshot_file .name } " ,
147+ "thumbnail_url" : thumbnail_url ,
148+ "thumbnail" : thumbnail_info ,
149+ "size" : snapshot_file .stat ().st_size ,
150+ "width" : width ,
151+ "height" : height ,
152+ }
153+
154+
122155def parse_transcription_metadata (transcription_file_path : str ) -> Dict [str , Any ]:
123156 """
124157 Parse metadata from a transcription file header.
@@ -469,23 +502,15 @@ async def filebrowser_request_routing(sio, cmd, data, logger, sid):
469502 continue
470503
471504 data_stat = data_file .stat ()
505+ meta_stat = meta_file .stat ()
472506 metadata = parse_sigmf_metadata (str (meta_file ))
473507
474508 # Check if recording is in progress
475509 is_recording_in_progress = metadata .get ("recording_in_progress" , False )
476510
477511 # Check for waterfall snapshot
478512 snapshot_file = recordings_dir / f"{ base_name } .png"
479- snapshot_info = None
480- if snapshot_file .exists ():
481- width , height = get_image_dimensions (str (snapshot_file ))
482- snapshot_info = {
483- "filename" : snapshot_file .name ,
484- "url" : f"/recordings/{ snapshot_file .name } " ,
485- "thumbnail_url" : get_image_thumbnail_url (snapshot_file , "/recordings" ),
486- "width" : width ,
487- "height" : height ,
488- }
513+ snapshot_info = build_recording_snapshot_info (snapshot_file )
489514
490515 processed_items .append (
491516 {
@@ -494,6 +519,7 @@ async def filebrowser_request_routing(sio, cmd, data, logger, sid):
494519 "data_file" : data_file .name ,
495520 "meta_file" : meta_file .name ,
496521 "data_size" : data_stat .st_size ,
522+ "meta_size" : meta_stat .st_size ,
497523 "created" : datetime .fromtimestamp (
498524 data_stat .st_ctime , timezone .utc
499525 ).isoformat (),
@@ -935,6 +961,7 @@ async def filebrowser_request_routing(sio, cmd, data, logger, sid):
935961
936962 # Get file stats
937963 data_stat = data_file .stat ()
964+ meta_stat = meta_file .stat ()
938965
939966 # Parse metadata
940967 metadata = parse_sigmf_metadata (str (meta_file ))
@@ -944,22 +971,14 @@ async def filebrowser_request_routing(sio, cmd, data, logger, sid):
944971
945972 # Check for waterfall snapshot
946973 snapshot_file = recordings_dir / f"{ base_name } .png"
947- snapshot_info = None
948- if snapshot_file .exists ():
949- width , height = get_image_dimensions (str (snapshot_file ))
950- snapshot_info = {
951- "filename" : snapshot_file .name ,
952- "url" : f"/recordings/{ snapshot_file .name } " ,
953- "thumbnail_url" : get_image_thumbnail_url (snapshot_file , "/recordings" ),
954- "width" : width ,
955- "height" : height ,
956- }
974+ snapshot_info = build_recording_snapshot_info (snapshot_file )
957975
958976 recording = {
959977 "name" : base_name ,
960978 "data_file" : data_file .name ,
961979 "meta_file" : meta_file .name ,
962980 "data_size" : data_stat .st_size ,
981+ "meta_size" : meta_stat .st_size ,
963982 "created" : datetime .fromtimestamp (data_stat .st_ctime , timezone .utc ).isoformat (),
964983 "modified" : datetime .fromtimestamp (
965984 data_stat .st_mtime , timezone .utc
@@ -993,6 +1012,7 @@ async def filebrowser_request_routing(sio, cmd, data, logger, sid):
9931012
9941013 # Get file stats
9951014 data_stat = data_file .stat ()
1015+ meta_stat = meta_file .stat ()
9961016
9971017 # Parse metadata
9981018 metadata = parse_sigmf_metadata (str (meta_file ))
@@ -1002,22 +1022,14 @@ async def filebrowser_request_routing(sio, cmd, data, logger, sid):
10021022
10031023 # Check for waterfall snapshot
10041024 snapshot_file = recordings_dir / f"{ recording_name } .png"
1005- snapshot_info = None
1006- if snapshot_file .exists ():
1007- width , height = get_image_dimensions (str (snapshot_file ))
1008- snapshot_info = {
1009- "filename" : snapshot_file .name ,
1010- "url" : f"/recordings/{ snapshot_file .name } " ,
1011- "thumbnail_url" : get_image_thumbnail_url (snapshot_file , "/recordings" ),
1012- "width" : width ,
1013- "height" : height ,
1014- }
1025+ snapshot_info = build_recording_snapshot_info (snapshot_file )
10151026
10161027 recording = {
10171028 "name" : recording_name ,
10181029 "data_file" : data_file .name ,
10191030 "meta_file" : meta_file .name ,
10201031 "data_size" : data_stat .st_size ,
1032+ "meta_size" : meta_stat .st_size ,
10211033 "created" : datetime .fromtimestamp (data_stat .st_ctime , timezone .utc ).isoformat (),
10221034 "modified" : datetime .fromtimestamp (data_stat .st_mtime , timezone .utc ).isoformat (),
10231035 "metadata" : metadata ,
0 commit comments