Esempio n. 1
0
    def get_destination_data(self):
        if not self.task:
            raise Exception('Unable to fetch destination data. Task has not been set!')
        if not self.settings:
            raise Exception('Unable to fetch destination data. Task settings has not been set!')

        # Get container extension
        container = containers.grab_module(self.settings.out_container)
        container_extension = container.container_extension()

        return prepare_file_destination_data(self.task.abspath, container_extension)
Esempio n. 2
0
    def set_destination_data(self):
        # Fetch the file's name without the file extension (this is going to be reset)
        file_name_without_extension = os.path.splitext(
            self.source['basename'])[0]

        # Get container extension
        container = containers.grab_module(self.settings.OUT_CONTAINER)
        container_extension = container.container_extension()

        # Set destination dict
        basename = "{}.{}".format(file_name_without_extension,
                                  container_extension)
        abspath = os.path.join(self.source['dirname'], basename)
        self.destination = {'basename': basename, 'abspath': abspath}
Esempio n. 3
0
    def set_cache_path(self):
        # Fetch the file's name without the file extension (this is going to be reset)
        file_name_without_extension = os.path.splitext(
            self.source['basename'])[0]

        # Get container extension
        container = containers.grab_module(self.settings.OUT_CONTAINER)
        container_extension = container.container_extension()

        # Parse an output cache path
        out_folder = "unmanic_file_conversion-{}".format(time.time())
        out_file = "{}-{}.{}".format(file_name_without_extension, time.time(),
                                     container_extension)
        self.cache_path = os.path.join(self.settings.CACHE_PATH, out_folder,
                                       out_file)
Esempio n. 4
0
def prepare_file_destination_data(pathname, out_container):
    basename = os.path.basename(pathname)
    dirname = os.path.dirname(os.path.abspath(pathname))
    # Fetch the file's name without the file extension (this is going to be reset)
    file_name_without_extension = os.path.splitext(basename)[0]

    # Get container extension
    container = containers.grab_module(out_container)
    container_extension = container.container_extension()

    # Set destination dict
    basename = "{}.{}".format(file_name_without_extension, container_extension)
    abspath = os.path.join(dirname, basename)
    file_data = {'basename': basename, 'abspath': abspath}

    return file_data
Esempio n. 5
0
    def set_cache_path(self):
        if not self.task:
            raise Exception('Unable to set cache path. Task has not been set!')
        # Fetch the file's name without the file extension (this is going to be reset)
        split_file_name = os.path.splitext(self.source.basename)
        file_name_without_extension = split_file_name[0]

        # Get container extension
        container = containers.grab_module(self.settings.out_container)
        container_extension = container.container_extension()

        # Parse an output cache path
        out_folder = "unmanic_file_conversion-{}".format(time.time())
        out_file = "{}-{}.{}".format(file_name_without_extension, time.time(), container_extension)
        cache_directory = os.path.join(self.settings.cache_path, out_folder)
        cache_path = os.path.join(cache_directory, out_file)
        if self.task:
            self.task.cache_path = cache_path
Esempio n. 6
0
    def setup_test_task(self, pathname):
        # Create a new task and set the source
        self.test_task = task.Task(self.data_queues["logging"].get_logger("Task"))

        # Fill test_task with data
        from unmanic.libs import common
        source_data = common.fetch_file_data_by_path(pathname)
        self.test_task.create_task_by_absolute_path(os.path.abspath(pathname), self.settings, source_data)

        # Get container extension
        if self.settings.get_keep_original_container():
            split_file_name = os.path.splitext(os.path.basename(pathname))
            container_extension = split_file_name[1].lstrip('.')
        else:
            from unmanic.libs.unffmpeg import containers
            container = containers.grab_module(self.settings.get_out_container())
            container_extension = container.container_extension()

        destination_data = task.prepare_file_destination_data(os.path.abspath(pathname), container_extension)
        self.test_task.set_destination_data(destination_data)
        self.test_task.set_cache_path()