diff --git a/trackma/engine.py b/trackma/engine.py index 81df0edd..87ad8534 100644 --- a/trackma/engine.py +++ b/trackma/engine.py @@ -817,7 +817,7 @@ def _add_show_to_library(self, library, library_cache, rescan, fullpath, filenam return library, library_cache - def get_episode_path(self, show, episode): + def get_episode_path(self, show, episode, error_on_fail=True): """ This function returns the full path of the requested episode from the requested show. """ @@ -828,7 +828,9 @@ def get_episode_path(self, show, episode): if showid not in library: raise utils.EngineError('Show not in library.') if episode not in library[showid]: - raise utils.EngineError('Episode not in library.') + if error_on_fail: + raise utils.EngineError('Episode not in library.') + return return library[showid][episode] @@ -854,7 +856,7 @@ def play_random(self): ep = self.play_episode(show) return (show, ep) - def play_episode(self, show, playep=0): + def play_episode(self, show, playep=0, playto=0): """ Does a local search in the hard disk (in the folder specified by the config file) for the specified episode (**playep**) for the specified **show**. @@ -865,10 +867,21 @@ def play_episode(self, show, playep=0): if not self.mediainfo.get('can_play'): raise utils.EngineError('Operation not supported by current site or mediatype.') + eps = re.split('-', str(playep)) + if len(eps) > 1: + if eps[0] != '': + playep = eps[0] + else: + playep = 0 + if eps[1] != '': + playto = eps[1] + else: + playto = show['total'] try: playep = int(playep) + playto = int(playto) except ValueError: - raise utils.EngineError('Episode must be numeric.') + raise utils.EngineError('Episode[s] must be numeric or with optional range (eg: 1-3, -3, or - to play all unseen episodes)') if show: playing_next = False @@ -876,17 +889,26 @@ def play_episode(self, show, playep=0): playep = show['my_progress'] + 1 playing_next = True - if show['total'] and playep > show['total']: - raise utils.EngineError('Episode beyond limits.') + if not playto or playto < playep: + playto = playep + + if show['total']: + if playep > show['total']: + raise utils.EngineError('Episode beyond limits.') + if playto > show['total']: + self.msg.info(self.name, "Play to %i is beyond limits of show %s. Defaulting to total episodes of %s" % (playto, show['title'], show['total'])) + playto = show['total'] self.msg.info(self.name, "Getting %s %s from library..." % (show['title'], playep)) - filename = self.get_episode_path(show, playep) endep = playep - if filename: + if self.get_episode_path(show, playep): self.msg.info(self.name, 'Found. Starting player...') arg_list = shlex.split(self.config['player']) - arg_list.append(filename) + for episode in range(playep, playto+1): + ep = self.get_episode_path(show, episode, error_on_fail=False) + if ep: + arg_list.append(ep) try: with open(os.devnull, 'wb') as DEVNULL: subprocess.Popen(arg_list, stdout=DEVNULL, stderr=DEVNULL) diff --git a/trackma/ui/cli.py b/trackma/ui/cli.py index 5705d7df..4e6d8f30 100644 --- a/trackma/ui/cli.py +++ b/trackma/ui/cli.py @@ -78,7 +78,7 @@ class Trackma_cmd(cmd.Cmd): 'add': 1, 'del': 1, 'delete': 1, - 'play': (1, 2), + 'play': (1, 3), 'openfolder': 1, 'update': (1, 2), 'score': 2, @@ -498,6 +498,7 @@ def do_play(self, args): :param show Episode index or title. :optparam ep Episode number. Assume next if not specified. + :optparam playto Episode number to play to in range. :usage play [episode number] """ try: @@ -508,8 +509,11 @@ def do_play(self, args): # otherwise play the next episode not watched yet if len(args) > 1: episode = args[1] + playto = episode + if len(args) > 2: + playto = args[2] - self.engine.play_episode(show, episode) + self.engine.play_episode(show, episode, playto) except utils.TrackmaError as e: self.display_error(e) diff --git a/trackma/ui/curses.py b/trackma/ui/curses.py index a37f1c5a..d21385f8 100644 --- a/trackma/ui/curses.py +++ b/trackma/ui/curses.py @@ -354,7 +354,7 @@ def do_play(self): item = self._get_selected_item() if item: show = self.engine.get_show_info(item.showid) - self.ask('[Play] Episode # to play: ', self.play_request, show['my_progress']+1) + self.ask('[Play] Episodes to play (eg: 1, 1-3 or - to play all unseen): ', self.play_request, show['my_progress']+1) def do_openfolder(self): item = self._get_selected_item()