def _create_player_from_selected(self) -> None: """Creates player(s) based on the selected items and adds to the queue. If the active menu is the feed menu, then this will create players for all episodes in the selected feed. If the active menu is the episode menu, this will simply create a single player. This method will not clear the queue prior to adding the new player(s), nor will it play the episodes after running. """ if self._active_window == 0: feed = self._feed_menu.item if feed is not None: for episode in self._display.database.episodes(feed): player = Player.create_instance( self._display.AVAILABLE_PLAYERS, str(episode), episode.get_playable(), episode) self._display.queue.add(player) elif self._active_window == 1: episode = self._episode_menu.item if episode is not None: player = Player.create_instance( self._display.AVAILABLE_PLAYERS, str(episode), episode.get_playable(), episode) self._display.queue.add(player)
def main(): # instantiate DataFile-based objects config = Config() feeds = Feeds() # update fields in help menu text for field in config: if "{%s}" % field in castero.__help__: castero.__help__ = \ castero.__help__.replace( "{%s}" % field, config[field].ljust(9) ) elif "{%s|" % field in castero.__help__: field2 = castero.__help__.split("{%s|" % field)[1].split("}")[0] castero.__help__ = \ castero.__help__.replace( "{%s|%s}" % (field, field2), ("%s or %s" % (config[field], config[field2])).ljust(9) ) # check if user is running the client with an info flag info_flags = {'help': ['-h', '--help'], 'version': ['-v', '--version']} if sys.argv[len(sys.argv) - 1] in info_flags['help']: print(castero.__help__) sys.exit(0) elif sys.argv[len(sys.argv) - 1] in info_flags['version']: print(castero.__version__) sys.exit(0) # check whether dependencies are met Player.check_dependencies() # instantiate the display object stdscr = curses.initscr() display = Display(stdscr, config, feeds) display.clear() display.update_parent_dimensions() # check if we need to start reloading if helpers.is_true(config['reload_on_start']): reload_thread = threading.Thread(target=feeds.reload, args=[display]) reload_thread.start() # run initial display operations display.display() display.update() display.refresh() # core loop for the client running = True while running: display.display() display.update() display.refresh() char = display.getch() if char != -1: running = display.handle_input(char) sys.exit(0)
def main(): # check if user is running the client with -h or --help flag help_flags = ['-h', '--help'] if sys.argv[len(sys.argv) - 1] in help_flags: print(castero.__help__) sys.exit(0) # check whether dependencies are met Player.check_dependencies() config = Config() feeds = Feeds() stdscr = curses.initscr() display = Display(stdscr, config, feeds) display.clear() display.update_parent_dimensions() if config['reload_on_start'] in ['True', 'true', '1']: t = threading.Thread(target=feeds.reload, args=[display]) t.start() running = True while running: display.display() display.update() display.refresh() c = display.getch() if c != -1: running = display.handle_input(c) sys.exit(0)
def _restore_queue(self) -> None: """Recreate players in queue from the database.""" for episode in self.database.queue(): player = Player.create_instance(self.AVAILABLE_PLAYERS, str(episode), episode.get_playable(), episode) self.queue.add(player)
def main(): # check if user is running the client with an info flag info_flags = {'help': ['-h', '--help'], 'version': ['-v', '--version']} if sys.argv[len(sys.argv) - 1] in info_flags['help']: print(castero.__help__) sys.exit(0) elif sys.argv[len(sys.argv) - 1] in info_flags['version']: print(castero.__version__) sys.exit(0) # check whether dependencies are met Player.check_dependencies() # instantiate DataFile-based objects config = Config() feeds = Feeds() # instantiate the display object stdscr = curses.initscr() display = Display(stdscr, config, feeds) display.clear() display.update_parent_dimensions() # check if we need to start reloading if helpers.is_true(config['reload_on_start']): reload_thread = threading.Thread(target=feeds.reload, args=[display]) reload_thread.start() # core loop for the client running = True while running: display.display() display.update() display.refresh() char = display.getch() if char != -1: running = display.handle_input(char) sys.exit(0)
def _create_player_from_selected(self) -> None: """Creates player(s) based on the selected items and adds to the queue. If the active menu is the feed menu, then this will create players for all episodes in the selected feed. If the active menu is the episode menu, this will simply create a single player. This method will not clear the queue prior to adding the new player(s), nor will it play the episodes after running. """ feed_index = self._feed_menu.selected_index feed = self._feeds.at(feed_index) if self._active_window == 0: if feed is not None: for episode in feed.episodes: player = Player(str(episode), episode.get_playable()) self._queue.add(player) elif self._active_window == 1: episode_index = self._episode_menu.selected_index if feed is not None: episode = feed.episodes[episode_index] player = Player(str(episode), episode.get_playable()) self._queue.add(player)
from castero.episode import Episode from castero.feed import Feed from castero.player import Player from castero.queue import Queue my_dir = os.path.dirname(os.path.realpath(__file__)) feed = Feed(file=my_dir + "/feeds/valid_basic.xml") episode = Episode(feed, title="episode title", description="episode description", link="episode link", pubdate="episode pubdate", copyright="episode copyright", enclosure="episode enclosure") player1 = Player("MLK Dream", my_dir + "/media/MLK_Dream_10s.mp3", episode) player2 = Player("MLK Dream", my_dir + "/media/MLK_Dream_10s.mp3", episode) player3 = Player("MLK Dream", my_dir + "/media/MLK_Dream_10s.mp3", episode) queue = Queue(mock.MagicMock()) queue.add(player1) queue.add(player2) def get_queue_perspective(display): """Retrieve the Queue perspective. Args: display: the display containing the loaded perspective Returns: Queue: the loaded Queue perspective
def test_player_create_instance_dep_error_indirect(): Config.data = {'player': ''} SomePlayer.check_dependencies.side_effect = PlayerDependencyError() with pytest.raises(PlayerDependencyError): Player.create_instance(available_players, "t", "p", episode) assert SomePlayer.check_dependencies.call_count == 1
def test_player_create_instance_success_indirect(): Config.data = {'player': ''} Player.create_instance(available_players, "t", "p", episode) SomePlayer.check_dependencies.assert_called = 2 SomePlayer.assert_called_with("t", "p", episode)
def test_player_create_instance_success_direct(): Config.data = {'player': 'someplayer'} Player.create_instance(available_players, "t", "p", episode) assert SomePlayer.check_dependencies.call_count == 1 SomePlayer.assert_called_with("t", "p", episode)