@@ -173,6 +173,7 @@ def __init__(self, config, keybindings, ui=True, external=False):
173173 self .keybindings = {key : (val ,) if not isinstance (val , tuple ) else val for key , val in keybindings .items ()}
174174 if self .default_color == - 1 :
175175 self .default_color = 0
176+ self .external = external
176177 if external :
177178 signal .signal (signal .SIGINT , self .sigint_handler )
178179 self .ascii_palette_len = len (self .ascii_palette ) - 1
@@ -200,6 +201,7 @@ def sigint_handler(self, _signum, _frame):
200201 """Handling Ctrl-C event"""
201202 self .stop_playback ()
202203 time .sleep (1 )
204+ terminal_utils .leave_tui ()
203205 sys .exit () # failsafe
204206
205207
@@ -546,7 +548,7 @@ def play_youtube(self, url):
546548 logger .warning ("Cant play youtube link, yt-dlp path is invalid" )
547549
548550
549- def play (self , path ):
551+ def play (self , path , hint = None ):
550552 """Select runner based on file type"""
551553 if not path :
552554 return
@@ -573,6 +575,8 @@ def play(self, path):
573575 self .play_video (path )
574576 else :
575577 mime = get_mime (path ).split ("/" )
578+ if hint :
579+ mime = [hint , None ]
576580 if mime [0 ] == "image" :
577581 if mime [1 ] == "gif" :
578582 self .media_type = "gif"
@@ -591,6 +595,8 @@ def play(self, path):
591595 else :
592596 logger .warning (f"Unsupported media format: { mime } " )
593597 self .run = False
598+ if self .external :
599+ sys .exit (f"Unsupported media format: { mime } " )
594600 while self .run : # dont exit when video ends
595601 time .sleep (0.2 )
596602 except Exception as e :
@@ -708,7 +714,7 @@ def wait_input(self):
708714 self .control_codes (104 )
709715
710716
711- def ascii_runner (path , config , keybindings ):
717+ def runner (path , config , keybindings ):
712718 """Main function"""
713719 path = os .path .expanduser (path )
714720 if not os .path .exists (path ):
0 commit comments