Exemplo n.º 1
0
    def store(self, episode: Episode):
        """
        Stores the given episode in its respective store directory and
        renames it to its store filename according to the configurator
        assigned with the organizer.

        :param episode: episode to be store.
        """
        downloaded_dir = self.config.episode_downloaded_dir(episode)
        video_file = videofiles.find_episode_file(downloaded_dir)

        # create the store directory
        store_dir = self.config.episode_store_dir(episode)
        os.makedirs(store_dir, exist_ok=True)

        # build episode path from its store directory, filename and the video
        # file extension
        filename = self.config.episode_filename(episode)
        extension = os.path.splitext(video_file)[1]
        complete_filename = filename + extension
        store_path = os.path.join(store_dir, complete_filename)
        video_path = os.path.join(downloaded_dir, video_file)

        # TODO: implement the moving in a separate thread
        # the move should be done in a separate thread because it will work
        # as a copy (very slow) if the destination folder is not in the same
        # filesystem
        self._move_episode_file(video_path, store_path)
        # episode must be only marked as STORED after finishing moving the
        # episode file
        database = Database(self.database_file)
        database.set_state(episode, EpisodeState.STORED)
Exemplo n.º 2
0
    def _store_episode(self, episode: Episode):
        """
        Stores the given episode through the organizer assign to the downloader.
        Before storing the episode, it is marked as DOWNLOADED.

        :param episode: episode to store.
        """
        database = Database(self.database_file)
        database.set_state(episode, EpisodeState.DOWNLOADED)
        self.organizer.store(episode)
Exemplo n.º 3
0
 def _download_episodes(self, database: Database, *episodes):
     for episode in episodes:
         database.put_episode(episode)
         database.set_state(episode, EpisodeState.DOWNLOADING)
         self.downloader.download(episode)