From 43fb2a0378775fee70d6d3f9971d3cc1d5ee5a16 Mon Sep 17 00:00:00 2001 From: Michael Lazar Date: Wed, 13 Jul 2016 01:19:16 -0700 Subject: [PATCH] Added terminal mode, fixed mime handler for gifv --- rtv/mime_handlers.py | 4 ++-- rtv/terminal.py | 42 ++++++++++++++++++++++++++---------------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/rtv/mime_handlers.py b/rtv/mime_handlers.py index 2571d5d..d3e827b 100644 --- a/rtv/mime_handlers.py +++ b/rtv/mime_handlers.py @@ -117,7 +117,7 @@ class GifvMIMEParser(BaseMIMEParser): @staticmethod def get_mimetype(url): modified_url = url[:-4] + 'webm' - return modified_url, 'image/webm' + return modified_url, 'video/webm' class RedditUploadsMIMEParser(BaseMIMEParser): @@ -190,4 +190,4 @@ parsers = [ RedditUploadsMIMEParser, YoutubeMIMEParser, GifvMIMEParser, - BaseMIMEParser] \ No newline at end of file + BaseMIMEParser] diff --git a/rtv/terminal.py b/rtv/terminal.py index 115532d..7ff2b45 100644 --- a/rtv/terminal.py +++ b/rtv/terminal.py @@ -316,7 +316,7 @@ class Terminal(object): if not self.config['enable_media']: return self.open_browser(url) - command = None + command, entry = None, None for parser in mime_handlers.parsers: if parser.pattern.match(url): modified_url, content_type = parser.get_mimetype(url) @@ -335,23 +335,33 @@ class Terminal(object): break - with self.loader('Opening page in a new window', delay=0): - args = [command] - _logger.info('Running command: %s', args) - # Non-blocking, run with a full shell to support pipes - p = subprocess.Popen( - args, shell=True, universal_newlines=True, - stdout=subprocess.PIPE, stderr=subprocess.PIPE) - # Wait a little while to make sure that the command doesn't exit - # with an error. This isn't perfect, but it should be good enough - # to catch invalid commands. - time.sleep(1.0) - code = p.poll() - if code is not None and code != 0: - stdout, stderr = p.communicate() - _logger.warning(stderr) + args = [command] + _logger.info('Running command: %s', args) + + if 'needsterminal' in entry: + with self.suspend(): + # Blocking, pause rtv until the process returns + p = subprocess.Popen(args, shell=True) + code = p.wait() + if code != 0: raise exceptions.BrowserError( 'Program exited with status=%s' % code) + else: + with self.loader('Opening page in a new window', delay=0): + # Non-blocking, run with a full shell to support pipes + p = subprocess.Popen( + args, shell=True, universal_newlines=True, + stdout=subprocess.PIPE, stderr=subprocess.PIPE) + # Wait a little while to make sure that the command doesn't + # exit with an error. This isn't perfect, but it should be good + # enough to catch invalid commands. + time.sleep(1.0) + code = p.poll() + if code is not None and code != 0: + stdout, stderr = p.communicate() + _logger.warning(stderr) + raise exceptions.BrowserError( + 'Program exited with status=%s' % code) def open_browser(self, url): """