class Client: def __init__(self, config: ConfigurationFile): self.config = config self.database = Database(self.config.db_file) self.organizer = Organizer(self.config, self.config.db_file) self.downloader = Downloader(self.config.db_file, self.organizer, self.config) self.tracker = Tracker(self.config.db_file, self.downloader, self.config.update_period) self.tracker.start() self.downloader.start() self.organizer.start() def add_tvshow(self, tvshow_id: int): tvshow_name = showrss.get_name(tvshow_id) self.database.put_tvshow(TVShow(tvshow_id, tvshow_name)) def remove_tvshow(self, tvshow_id: int): self.database.remove_tvshow(tvshow_id) def list_tvshows(self): return self.database.tvshows() def list_episodes(self, state: EpisodeState = None): return self.database.episodes(state) def download_progress(self): return self.downloader.downloads() def exit(self): self.tracker.stop() self.downloader.stop()
def start(self): """ Starts a new downloader session. The downloader must be started in order to be able to check for completed episodes and organize them using the organizer assign to it. Starting the downloader also restarts downloading all episodes marked as DOWNLOADING. """ self._stopped.clear() database = Database(self.database_file) # restart downloading all episodes marked as DOWNLOADING for episode in database.episodes(EpisodeState.DOWNLOADING): self.download(episode) # manage completed episodes periodically self._thread = Timer(self.config.download_check_period, self.manage_downloads) self._thread.start()
def start(self): database = Database(self.database_file) # restore all episodes marked as downloaded for episode in database.episodes(EpisodeState.DOWNLOADED): self.store(episode)