def stop_and_remove_splitter_thread(self, video_id):
        """
        Stops and removes the DasherSplitterThread of a specific video.

        This method check if there's a DasherSplitterThread running for a specific video, which is
        given as parameter. If the thread is still running, this method stops it and updates
        the database information, marking the thread as Failure. If the thread is not running,
        then this method checks the return code of the thread to mark the state in the DB as
        "Failure" or "Finished" depending on its value.
        :param video_id: Id of the video.
        :return:
            - NotExistingResource, if there's no video with such id.
            - ValueError, if the given id is not a valid video id.
        """
        LOGGER.info("Removing dasher splitter thread from VideoThreadsManager: [video_id={}]".
                    format(video_id))
        try:
            GenericValidator.validate_id(video_id)
            d_thread = VideoThreadsRepository.get_instance().get_dasher_splitter_thread(video_id)
            video = Video.objects(id=video_id).first()
            if video is None:
                raise NotExistingResource("No video with such id")
            # 1) If the thread is running,we stop it and mark it as failure in the db.
            if d_thread['thread'].is_alive():
                d_thread['thread'].exit()
                video.update(set__splitter_status=ProcessStatus.FAILURE.value)
            # 2) If the thread finished, we check the return code and update the db.
            elif d_thread['thread'].code != 0:
                video.update(set__splitter_status=ProcessStatus.FAILURE.value)
            else:
                video.update(set__splitter_status=ProcessStatus.FINISHED.value)
            VideoThreadsRepository.get_instance().remove_dasher_splitter_thread(video_id=video_id)
            LOGGER.info(
                "Sucessfully removed dasher splitter thread from VideoThreadsManager: [video_id={}]".
                format(video_id))
        except Exception as ex:
            LOGGER.error("Error removing DashterSplitterThread: ")
            raise ex
    def split_video(self, video_id):
        """

        :param video_id:
        :return:
        """
        LOGGER.info("Splitting video in fragments: [id={}]".format(video_id))
        try:
            GenericValidator.validate_id(video_id)
            video = Video.objects(id=video_id).first()
            if video is None:
                raise NotExistingResource("No video with such id.")
            video_path = video['video_path']
            t_splitter = DasherSplitterThread(video_path=video_path)
            t_splitter.start()
            VideoThreadsManager.get_instance().add_dasher_splitter_thread(
                d_thread=t_splitter, video_id=video_id)
        except ValueError as ve:
            LOGGER.exception("Error validating video path: ")
            raise ve
        except Exception as ex:
            LOGGER.exception("Error trying to split video: ")
            raise ex
    def create_video_thumbs(self, video_id):
        """

        :param video_id:
        :return:
        """
        LOGGER.info("Creating thumbs for video: [id={}]".format(video_id))
        try:
            GenericValidator.validate_id(video_id)
            video = Video.objects(id=video_id).first()
            if video is None:
                raise NotExistingResource("No video with such id.")
            video_path = video['video_path']
            t_thumbs_creator = ThumbsCreatorThread(video_path=video_path)
            t_thumbs_creator.start()
            VideoThreadsManager.get_instance().add_thumbs_thread(
                t_thread=t_thumbs_creator, video_id=video_id)
        except ValueError as ve:
            LOGGER.exception("Error validating video path: ")
            raise ve
        except Exception as ex:
            LOGGER.exception("Error trying to create thumbs for video: ")
            raise ex
    def get_mixed_video_path(self, video_id):
        """

        :param video_id:
        :return:
        """
        LOGGER.info("Geeting mixed video path [video_id={}]".format(video_id))
        try:
            video = Video.objects(id=video_id).first()
            if video is None:
                raise NotExistingResource("There's no video with such id.")
            if not video['mixed'] or not video['mixed_video_path']:
                raise IllegalResourceState("The video is no mixed yet.")
            LOGGER.info(
                "Mixed video path retrieved: [video_id={}, path={}]".format(
                    video_id, video['mixed_video_path']))
            return video['mixed_video_path']
        except ValueError as ve:
            LOGGER.exception("Error validating video id: ")
            raise ve
        except Exception as ex:
            LOGGER.exception("Error getting mixed video: ")
            raise ex
Example #5
0
    def get_session(self, session_id):
        """
        Retrieves and returns the session identified with the given id.

        This method check if there's a session in the database with the provided id. If so, the
        information of the session is returned in a dictionary. If not, the method raises a
        IllegalSessionStateException.
        :return: Dictionary containing the information of the session identified with the id given
        as parameter.
        :raises:
        - NotExistingResource, if there's no session with such id.
        - ValueError, if the provided id is not a valid id.
        """
        LOGGER.info("Retrieveing session: [id={}].".format(session_id))
        GenericValidator.validate_id(session_id)
        session = RumbaSession.objects(id=session_id).first()
        if session is None:
            raise NotExistingResource("There's no session with such id.")
        LOGGER.info(
            "Session successfully retrieved: [id={}]".format(session_id))
        LOGGER.debug("Session information: {}".format(session))
        view_sess = MongoHelper.to_dict(session)
        view_sess.pop('folder_url')
        return view_sess