@@ -56,7 +56,7 @@ def parse_filename(file_name):
5656 # https://github.com/sven337/ReolinkLinux/wiki/Figuring-out-the-file-names#file-name-structure
5757 pattern = r'.*?Mp4Record_(\d{4}-\d{2}-\d{2})_Rec[MS](\d)(\d)_(DST)?(\d{8})_(\d{6})_(\d{6})'
5858 v3_suffix = r'.*_(\w{4,8})_(\w{4,8})\.mp4'
59- v9_suffix = r'.*_(\d)_(\w{7})(\w{7})_(\w{4 ,8})\.mp4'
59+ v9_suffix = r'.*_(\d)_(\w{7})(\w{7})_(\w{1 ,8})\.mp4'
6060 match = re .match (pattern , file_name )
6161
6262 out = {}
@@ -375,8 +375,28 @@ def add_video(self, video_path):
375375 # Find a potentially pre-existing channel0 item for this datetime, if so, add as a child
376376 # This lets channel1 appear as a child, but also main & sub videos appear in the same group
377377 channel_0_item = self .find_channel_0_item (start_datetime )
378+
378379 if channel_0_item :
379- channel_0_item .addChild (video_item )
380+ # Check if the current item is a main stream and the existing channel_0_item is a sub stream
381+ if "RecM" in base_file_name and "RecS" in channel_0_item .text (1 ):
382+ # Make the current main stream item the new parent
383+ new_parent = video_item
384+ # Move all children of the sub stream item to the new main stream item
385+ while channel_0_item .childCount () > 0 :
386+ child = channel_0_item .takeChild (0 )
387+ new_parent .addChild (child )
388+ # Remove the old sub stream item
389+ parent = channel_0_item .parent ()
390+ if parent :
391+ parent .removeChild (channel_0_item )
392+ else :
393+ index = self .video_tree .indexOfTopLevelItem (channel_0_item )
394+ self .video_tree .takeTopLevelItem (index )
395+ # Add the new main stream item as a top-level item
396+ self .video_tree .addTopLevelItem (new_parent )
397+ else :
398+ # If it's not a main stream replacing a sub stream, add as a child as before
399+ channel_0_item .addChild (video_item )
380400 else :
381401 self .video_tree .addTopLevelItem (video_item )
382402
@@ -424,6 +444,7 @@ def on_download_complete(self, video_path, success):
424444 item = self .find_item_by_path (os .path .basename (video_path ))
425445 if not item :
426446 print (f"on_download_complete { video_path } did not find item?!" )
447+ return
427448 item .setForeground (1 , QBrush (QColor (0 , 0 , 0 ))) # Black color for normal text
428449 font = item .font (1 )
429450 font .setItalic (False )
@@ -592,7 +613,7 @@ def signal_handler(sig, frame):
592613 signal .signal (signal .SIGINT , signal_handler )
593614
594615 parser = argparse .ArgumentParser (description = "Reolink Video Review GUI" )
595- parser .add_argument ('--sub ' , action = 'store_true' , help = "Search for sub channel instead of main channel" )
616+ parser .add_argument ('--main ' , action = 'store_true' , help = "Search for main channel instead of sub channel" )
596617 parser .add_argument ('files' , nargs = '*' , help = "Optional video file names to process" )
597618 args = parser .parse_args ()
598619
@@ -609,7 +630,7 @@ def signal_handler(sig, frame):
609630 start = dt .combine (dt .now (), dt .min .time ())
610631 end = dt .now ()
611632
612- streamtype = 'sub' if args .sub else 'main'
633+ streamtype = 'sub' if not args .main else 'main'
613634 processed_motions = cam .get_motion_files (start = start , end = end , streamtype = streamtype , channel = 0 )
614635 processed_motions += cam .get_motion_files (start = start , end = end , streamtype = streamtype , channel = 1 )
615636
0 commit comments