Skip to content

base

Type Aliases:

  • IndexerLike

    Type alias for anything that can resolve to an Indexer.

Classes:

log module-attribute

log = getLogger(__name__)

IndexerLike

IndexerLike = str | type[Indexer] | Indexer

Type alias for anything that can resolve to an Indexer.

This includes:

  • A string identifier or plugin namespace of this indexer.
  • A class type subclassing Indexer.
  • An instance of an Indexer.

CacheIndexer

CacheIndexer(*, force: bool = True, **kwargs: Any)

Bases: Indexer

Indexer interface with cache storage logic.

Methods:

  • asource

    Load one or more input files as an [AudioNode][vs.AudioNode] using the indexer.

  • ensure_obj

    Ensure that the input is a indexer instance, resolving it if necessary.

  • from_param

    Resolve and return an Indexer type from a given input (string, type, or instance).

  • get_cache_path
  • has_audio

    Whether this indexer supports audio sourcing.

  • has_video

    Whether this indexer supports video sourcing.

  • normalize_filenames
  • source

    Load one or more input files as a [VideoNode][vs.VideoNode] using the indexer.

  • source_func

Attributes:

Source code in vssource/indexers/base.py
57
58
59
60
61
def __init__(self, *, force: bool = True, **kwargs: Any) -> None:
    super().__init__()

    self.force = force
    self.indexer_kwargs = kwargs

force instance-attribute

force = force

indexer_kwargs instance-attribute

indexer_kwargs = kwargs

asource

asource(
    file: SPathLike | Iterable[SPathLike],
    *,
    track: int = -1,
    sample_rate: int | None = None,
    channels: Sequence[int] | None = None,
    bits: int | None = None,
    **kwargs: Any,
) -> AudioNode

Load one or more input files as an [AudioNode][vs.AudioNode] using the indexer.

Source code in vssource/indexers/base.py
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
@inject_self
def asource(
    self,
    file: SPathLike | Iterable[SPathLike],
    *,
    track: int = -1,
    sample_rate: int | None = None,
    channels: Sequence[int] | None = None,
    bits: int | None = None,
    **kwargs: Any,
) -> vs.AudioNode:
    """
    Load one or more input files as an [AudioNode][vs.AudioNode] using the indexer.
    """
    if not self.has_audio:
        raise CustomRuntimeError(f"{self.__class__.__name__} does not support audio indexing!", self.asource)

    nfiles = self.normalize_filenames(file)
    call_kwargs = self.indexer_kwargs | kwargs
    if self._audio_track_arg_name not in call_kwargs and track is not None:
        call_kwargs[self._audio_track_arg_name] = track

    clips = [self._asource_file(f.to_str(), **call_kwargs) for f in nfiles]
    clip = clips[0] if len(clips) == 1 else core.std.AudioSplice(clips)

    if sample_rate is not None or channels is not None or bits is not None:
        clip = core.std.AudioResample(clip, samplerate=sample_rate, channels=channels, bits=bits)

    return clip

ensure_obj classmethod

ensure_obj(
    indexer: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExcept | None = None,
) -> Self

Ensure that the input is a indexer instance, resolving it if necessary.

Parameters:

  • indexer

    (str | type[Self] | Self | None, default: None ) –

    Indexer identifier (string, class, or instance). Plugin namespace is also supported.

  • func_except

    (FuncExcept | None, default: None ) –

    Function returned for custom error handling.

Returns:

  • Self

    Indexer instance.

Source code in vssource/indexers/base.py
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
@classmethod
def ensure_obj(
    cls, indexer: str | type[Self] | Self | None = None, /, func_except: FuncExcept | None = None
) -> Self:
    """
    Ensure that the input is a indexer instance, resolving it if necessary.

    Args:
        indexer: Indexer identifier (string, class, or instance). Plugin namespace is also supported.
        func_except: Function returned for custom error handling.

    Returns:
        Indexer instance.
    """
    return _base_ensure_obj(cls, indexer, func_except)

from_param classmethod

from_param(
    indexer: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExcept | None = None,
) -> type[Self]

Resolve and return an Indexer type from a given input (string, type, or instance).

Parameters:

  • indexer

    (str | type[Self] | Self | None, default: None ) –

    Indexer identifier (string, class, or instance). Plugin namespace is also supported.

  • func_except

    (FuncExcept | None, default: None ) –

    Function returned for custom error handling.

Returns:

Source code in vssource/indexers/base.py
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
@classmethod
def from_param(
    cls, indexer: str | type[Self] | Self | None = None, /, func_except: FuncExcept | None = None
) -> type[Self]:
    """
    Resolve and return an Indexer type from a given input (string, type, or instance).

    Args:
        indexer: Indexer identifier (string, class, or instance). Plugin namespace is also supported.
        func_except: Function returned for custom error handling.

    Returns:
        Resolved indexer type.
    """
    return _base_from_param(cls, indexer, func_except)

get_cache_path staticmethod

get_cache_path(
    source_path: SPathLike,
    ext: str | None = None,
    track: int | None = None,
    is_audio: bool = False,
) -> SPath
Source code in vssource/indexers/base.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
@staticmethod
def get_cache_path(
    source_path: SPathLike,
    ext: str | None = None,
    track: int | None = None,
    is_audio: bool = False,
) -> SPath:
    source_file = SPath(source_path).resolve()
    hashed_path = hashlib.blake2s(source_file.to_str().encode("utf-8"), digest_size=4).hexdigest()
    cache_filename = f"{source_file.name}_{hashed_path}"

    if is_audio and ext:
        tr_suffix = f"_a{track if track is not None else 0}"
        cache_filename = f"{cache_filename}{tr_suffix}"

    if ext:
        cache_filename = f"{cache_filename}.{ext.lstrip('.')}"

    storage = _get_indexer_cache_storage()
    return storage.get_file(cache_filename)

has_audio classmethod

has_audio() -> bool

Whether this indexer supports audio sourcing.

Source code in vssource/indexers/base.py
69
70
71
72
73
@classproperty
@classmethod
def has_audio(cls) -> bool:
    """Whether this indexer supports audio sourcing."""
    return getattr(cls, "_asource_func", None) is not None

has_video classmethod

has_video() -> bool

Whether this indexer supports video sourcing.

Source code in vssource/indexers/base.py
63
64
65
66
67
@classproperty
@classmethod
def has_video(cls) -> bool:
    """Whether this indexer supports video sourcing."""
    return getattr(cls, "_source_func", None) is not None

normalize_filenames classmethod

normalize_filenames(file: SPathLike | Iterable[SPathLike]) -> list[SPath]
Source code in vssource/indexers/base.py
187
188
189
190
191
192
193
194
195
196
197
@classmethod
def normalize_filenames(cls, file: SPathLike | Iterable[SPathLike]) -> list[SPath]:
    files = list[SPath]()

    for f in to_arr(file):
        if str(f).startswith("file:///"):
            f = str(f)[8::]

        files.append(SPath(f))

    return files

source

source(
    file: SPathLike | Iterable[SPathLike],
    bits: int | None = 32,
    *,
    matrix: MatrixLike | None = None,
    transfer: TransferLike | None = None,
    primaries: PrimariesLike | None = None,
    chroma_location: ChromaLocation | None = None,
    color_range: RangeLike | None = None,
    field_based: FieldBasedLike | None = None,
    idx_props: bool = True,
    ref: VideoNode | None = None,
    name: str | None = None,
    **kwargs: Any,
) -> VideoNode

Load one or more input files as a [VideoNode][vs.VideoNode] using the indexer.

The returned clip is passed through initialize_clip to apply bit depth conversion and frame props initialization.

Source code in vssource/indexers/base.py
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
@inject_self
def source(
    self,
    file: SPathLike | Iterable[SPathLike],
    bits: int | None = 32,
    *,
    matrix: MatrixLike | None = None,
    transfer: TransferLike | None = None,
    primaries: PrimariesLike | None = None,
    chroma_location: ChromaLocation | None = None,
    color_range: RangeLike | None = None,
    field_based: FieldBasedLike | None = None,
    idx_props: bool = True,
    ref: vs.VideoNode | None = None,
    name: str | None = None,
    **kwargs: Any,
) -> vs.VideoNode:
    """
    Load one or more input files as a [VideoNode][vs.VideoNode] using the indexer.

    The returned clip is passed through [initialize_clip][vstools.initialize_clip] to apply bit depth conversion
    and frame props initialization.
    """
    if not self.has_video:
        raise CustomRuntimeError(f"{self.__class__.__name__} does not support video indexing!", self.source)

    nfiles = self.normalize_filenames(file)
    clips = [self._source_file(f.to_str(), **self.indexer_kwargs | kwargs) for f in nfiles]
    clip = clips[0] if len(clips) == 1 else core.std.Splice(clips)
    clip = initialize_clip(clip, bits, matrix, transfer, primaries, chroma_location, color_range, field_based)

    if idx_props:
        clip = clip.std.SetFrameProps(IdxFilePath=[f.to_str() for f in nfiles], Idx=self.__class__.__name__)

    if name:
        clip = clip.std.SetFrameProps(Name=name)

    if ref:
        clip = match_clip(clip, ref, length=True)

    return clip

source_func classmethod

source_func(path: SPathLike, **kwargs: Any) -> VideoNode
Source code in vssource/indexers/base.py
179
180
181
182
183
184
185
@classmethod
@deprecated(
    "`source_func` is deprecated and will be removed in a future version. Use `source` instead.",
    category=DeprecationWarning,
)
def source_func(cls, path: SPathLike, **kwargs: Any) -> vs.VideoNode:
    return cls._source_file(path, **kwargs)

ExternalIndexer

ExternalIndexer(
    *,
    bin_path: SPathLike | MissingT = MISSING,
    ext: str | MissingT = MISSING,
    force: bool = True,
    default_out_folder: SPathLike | Literal[False] | None = None,
    **kwargs: Any,
)

Bases: Indexer

Methods:

Attributes:

Source code in vssource/indexers/base.py
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
def __init__(
    self,
    *,
    bin_path: SPathLike | MissingT = MISSING,
    ext: str | MissingT = MISSING,
    force: bool = True,
    default_out_folder: SPathLike | Literal[False] | None = None,
    **kwargs: Any,
) -> None:
    super().__init__(force=force, **kwargs)

    if bin_path is MISSING:
        bin_path = self._bin_path

    if ext is MISSING:
        ext = self._ext

    self.bin_path = SPath(bin_path)
    self.ext = ext
    self.default_out_folder = default_out_folder

bin_path instance-attribute

bin_path = SPath(bin_path)

default_out_folder instance-attribute

default_out_folder = default_out_folder

ext instance-attribute

ext = ext

force instance-attribute

force = force

indexer_kwargs instance-attribute

indexer_kwargs = kwargs

asource

asource(
    file: SPathLike | Iterable[SPathLike],
    *,
    track: int = -1,
    sample_rate: int | None = None,
    channels: Sequence[int] | None = None,
    bits: int | None = None,
    **kwargs: Any,
) -> AudioNode

Load one or more input files as an [AudioNode][vs.AudioNode] using the indexer.

Source code in vssource/indexers/base.py
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
@inject_self
@override
def asource(
    self,
    file: SPathLike | Iterable[SPathLike],
    *,
    track: int = -1,
    sample_rate: int | None = None,
    channels: Sequence[int] | None = None,
    bits: int | None = None,
    **kwargs: Any,
) -> vs.AudioNode:
    if not self.has_audio:
        raise CustomRuntimeError(f"{self.__class__.__name__} does not support audio indexing!", self.asource)

    index_files = self.index(self.normalize_filenames(file))

    return super().asource(
        index_files,
        track=track,
        sample_rate=sample_rate,
        channels=channels,
        bits=bits,
        **kwargs,
    )

ensure_obj classmethod

ensure_obj(
    indexer: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExcept | None = None,
) -> Self

Ensure that the input is a indexer instance, resolving it if necessary.

Parameters:

  • indexer

    (str | type[Self] | Self | None, default: None ) –

    Indexer identifier (string, class, or instance). Plugin namespace is also supported.

  • func_except

    (FuncExcept | None, default: None ) –

    Function returned for custom error handling.

Returns:

  • Self

    Indexer instance.

Source code in vssource/indexers/base.py
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
@classmethod
def ensure_obj(
    cls, indexer: str | type[Self] | Self | None = None, /, func_except: FuncExcept | None = None
) -> Self:
    """
    Ensure that the input is a indexer instance, resolving it if necessary.

    Args:
        indexer: Indexer identifier (string, class, or instance). Plugin namespace is also supported.
        func_except: Function returned for custom error handling.

    Returns:
        Indexer instance.
    """
    return _base_ensure_obj(cls, indexer, func_except)

file_corrupted

file_corrupted(index_path: SPath) -> None
Source code in vssource/indexers/base.py
388
389
390
391
392
393
394
395
def file_corrupted(self, index_path: SPath) -> None:
    if self.force:
        try:
            index_path.unlink()
        except OSError:
            raise CustomRuntimeError("Index file corrupted, tried to delete it and failed.", self.__class__)
    else:
        raise CustomRuntimeError("Index file corrupted! Delete it and retry.", self.__class__)

from_param classmethod

from_param(
    indexer: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExcept | None = None,
) -> type[Self]

Resolve and return an Indexer type from a given input (string, type, or instance).

Parameters:

  • indexer

    (str | type[Self] | Self | None, default: None ) –

    Indexer identifier (string, class, or instance). Plugin namespace is also supported.

  • func_except

    (FuncExcept | None, default: None ) –

    Function returned for custom error handling.

Returns:

Source code in vssource/indexers/base.py
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
@classmethod
def from_param(
    cls, indexer: str | type[Self] | Self | None = None, /, func_except: FuncExcept | None = None
) -> type[Self]:
    """
    Resolve and return an Indexer type from a given input (string, type, or instance).

    Args:
        indexer: Indexer identifier (string, class, or instance). Plugin namespace is also supported.
        func_except: Function returned for custom error handling.

    Returns:
        Resolved indexer type.
    """
    return _base_from_param(cls, indexer, func_except)

get_cmd abstractmethod

get_cmd(files: list[SPath], output: SPath) -> list[str]

Returns the indexer command

Source code in vssource/indexers/base.py
295
296
297
298
299
@abstractmethod
def get_cmd(self, files: list[SPath], output: SPath) -> list[str]:
    """
    Returns the indexer command
    """

get_file_idx_path

get_file_idx_path(folder: SPath, file_hash: str, file_name: SPathLike) -> SPath
Source code in vssource/indexers/base.py
450
451
452
453
454
455
def get_file_idx_path(self, folder: SPath, file_hash: str, file_name: SPathLike) -> SPath:
    f_name = SPath(file_name).stem
    current_indexer = SPath(self._bin_path).name
    filename = f"{file_hash}_{f_name}_{current_indexer}"

    return self.get_idx_file_path(PackageStorage(folder, package_name=__name__).get_file(filename))

get_files_hash classmethod

get_files_hash(files: list[SPath]) -> str
Source code in vssource/indexers/base.py
469
470
471
472
473
@classmethod
def get_files_hash(cls, files: list[SPath]) -> str:
    length = sum(file.stat().st_size for file in files)
    to_hash = length.to_bytes(32, "little") + cls.get_joined_names(files).encode()
    return hashlib.md5(to_hash).hexdigest()

get_idx_file_path

get_idx_file_path(path: SPath) -> SPath
Source code in vssource/indexers/base.py
385
386
def get_idx_file_path(self, path: SPath) -> SPath:
    return path.with_suffix(f".{self.ext}")

get_info abstractmethod

get_info(index_path: SPath, file_idx: int = 0) -> IndexFileType

Returns info about the indexing file

Source code in vssource/indexers/base.py
301
302
303
304
305
@abstractmethod
def get_info(self, index_path: SPath, file_idx: int = 0) -> IndexFileType:
    """
    Returns info about the indexing file
    """

get_joined_names classmethod

get_joined_names(files: list[SPath]) -> str
Source code in vssource/indexers/base.py
457
458
459
@classmethod
def get_joined_names(cls, files: list[SPath]) -> str:
    return "_".join([file.name for file in files])

get_out_folder

get_out_folder(
    output_folder: SPathLike | Literal[False] | None = None,
    file: SPath | None = None,
) -> SPath
Source code in vssource/indexers/base.py
372
373
374
375
376
377
378
379
380
381
382
383
def get_out_folder(
    self, output_folder: SPathLike | Literal[False] | None = None, file: SPath | None = None
) -> SPath:
    if output_folder is None:
        return SPath(file).get_folder() if file else self.get_out_folder(False)

    if not output_folder:
        from tempfile import gettempdir

        return SPath(gettempdir())

    return SPath(output_folder)

get_video_idx_path

get_video_idx_path(
    folder: SPath, file_hash: str, file_name: SPathLike
) -> SPath
Source code in vssource/indexers/base.py
443
444
445
446
447
448
@deprecated(
    "`get_video_idx_path` is deprecated and will be removed in a future version. Use `get_file_idx_path` instead.",
    category=DeprecationWarning,
)
def get_video_idx_path(self, folder: SPath, file_hash: str, file_name: SPathLike) -> SPath:
    return self.get_file_idx_path(folder, file_hash, file_name)

get_videos_hash classmethod

get_videos_hash(files: list[SPath]) -> str
Source code in vssource/indexers/base.py
461
462
463
464
465
466
467
@classmethod
@deprecated(
    "`get_videos_hash` is deprecated and will be removed in a future version. Use `get_files_hash` instead.",
    category=DeprecationWarning,
)
def get_videos_hash(cls, files: list[SPath]) -> str:
    return cls.get_files_hash(files)

has_audio classmethod

has_audio() -> bool

Whether this indexer supports audio sourcing.

Source code in vssource/indexers/base.py
69
70
71
72
73
@classproperty
@classmethod
def has_audio(cls) -> bool:
    """Whether this indexer supports audio sourcing."""
    return getattr(cls, "_asource_func", None) is not None

has_video classmethod

has_video() -> bool

Whether this indexer supports video sourcing.

Source code in vssource/indexers/base.py
63
64
65
66
67
@classproperty
@classmethod
def has_video(cls) -> bool:
    """Whether this indexer supports video sourcing."""
    return getattr(cls, "_source_func", None) is not None

index

index(
    files: Sequence[SPath],
    force: bool = False,
    split_files: bool = False,
    output_folder: SPathLike | Literal[False] | None = None,
    *cmd_args: str,
) -> list[SPath]
Source code in vssource/indexers/base.py
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
def index(
    self,
    files: Sequence[SPath],
    force: bool = False,
    split_files: bool = False,
    output_folder: SPathLike | Literal[False] | None = None,
    *cmd_args: str,
) -> list[SPath]:
    if len(unique_folders := list({f.get_folder().to_str() for f in files})) > 1:
        return [
            c
            for s in (
                self.index(
                    [f for f in files if f.get_folder().to_str() == folder], force, split_files, output_folder
                )
                for folder in unique_folders
            )
            for c in s
        ]

    dest_folder = self.get_out_folder(output_folder, files[0])

    files = sorted(set(files))

    hash_str = self.get_files_hash(files)

    def _index(files: list[SPath], output: SPath) -> None:
        if output.is_file():
            if output.stat().st_size == 0 or force:
                output.unlink()
            else:
                return self.update_video_filenames(output, files)
        return self._run_index(files, output, cmd_args)

    if not split_files:
        output = self.get_file_idx_path(dest_folder, hash_str, "JOINED" if len(files) > 1 else "SINGLE")
        _index(files, output)
        return [output]

    outputs = [self.get_file_idx_path(dest_folder, hash_str, file.name) for file in files]

    for file, output in zip(files, outputs):
        _index([file], output)

    return outputs

normalize_filenames classmethod

normalize_filenames(file: SPathLike | Iterable[SPathLike]) -> list[SPath]
Source code in vssource/indexers/base.py
187
188
189
190
191
192
193
194
195
196
197
@classmethod
def normalize_filenames(cls, file: SPathLike | Iterable[SPathLike]) -> list[SPath]:
    files = list[SPath]()

    for f in to_arr(file):
        if str(f).startswith("file:///"):
            f = str(f)[8::]

        files.append(SPath(f))

    return files

source

source(
    file: SPathLike | Iterable[SPathLike],
    bits: int | None = 32,
    *,
    matrix: MatrixLike | None = None,
    transfer: TransferLike | None = None,
    primaries: PrimariesLike | None = None,
    chroma_location: ChromaLocation | None = None,
    color_range: RangeLike | None = None,
    field_based: FieldBasedLike | None = None,
    idx_props: bool = True,
    **kwargs: Any,
) -> VideoNode

Load one or more input files as a [VideoNode][vs.VideoNode] using the indexer.

The returned clip is passed through initialize_clip to apply bit depth conversion and frame props initialization.

Source code in vssource/indexers/base.py
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
@inject_self
@override
def source(
    self,
    file: SPathLike | Iterable[SPathLike],
    bits: int | None = 32,
    *,
    matrix: MatrixLike | None = None,
    transfer: TransferLike | None = None,
    primaries: PrimariesLike | None = None,
    chroma_location: ChromaLocation | None = None,
    color_range: RangeLike | None = None,
    field_based: FieldBasedLike | None = None,
    idx_props: bool = True,
    **kwargs: Any,
) -> vs.VideoNode:
    if not self.has_video:
        raise CustomRuntimeError(f"{self.__class__.__name__} does not support video indexing!", self.source)

    index_files = self.index(self.normalize_filenames(file))

    return super().source(
        index_files,
        bits,
        matrix=matrix,
        transfer=transfer,
        primaries=primaries,
        chroma_location=chroma_location,
        color_range=color_range,
        field_based=field_based,
        idx_props=idx_props,
        **kwargs,
    )

source_func classmethod

source_func(path: SPathLike, **kwargs: Any) -> VideoNode
Source code in vssource/indexers/base.py
179
180
181
182
183
184
185
@classmethod
@deprecated(
    "`source_func` is deprecated and will be removed in a future version. Use `source` instead.",
    category=DeprecationWarning,
)
def source_func(cls, path: SPathLike, **kwargs: Any) -> vs.VideoNode:
    return cls._source_file(path, **kwargs)

update_video_filenames

update_video_filenames(index_path: SPath, filepaths: list[SPath]) -> None

Update filepaths recorded inside index file if moved. Default is a no-op.

Source code in vssource/indexers/base.py
367
368
369
370
def update_video_filenames(self, index_path: SPath, filepaths: list[SPath]) -> None:
    """
    Update filepaths recorded inside index file if moved. Default is a no-op.
    """

Indexer

Indexer(*, force: bool = True, **kwargs: Any)

Bases: ABC

Abstract indexer interface for video and audio node sourcing.

Methods:

  • asource

    Load one or more input files as an [AudioNode][vs.AudioNode] using the indexer.

  • ensure_obj

    Ensure that the input is a indexer instance, resolving it if necessary.

  • from_param

    Resolve and return an Indexer type from a given input (string, type, or instance).

  • has_audio

    Whether this indexer supports audio sourcing.

  • has_video

    Whether this indexer supports video sourcing.

  • normalize_filenames
  • source

    Load one or more input files as a [VideoNode][vs.VideoNode] using the indexer.

  • source_func

Attributes:

Source code in vssource/indexers/base.py
57
58
59
60
61
def __init__(self, *, force: bool = True, **kwargs: Any) -> None:
    super().__init__()

    self.force = force
    self.indexer_kwargs = kwargs

force instance-attribute

force = force

indexer_kwargs instance-attribute

indexer_kwargs = kwargs

asource

asource(
    file: SPathLike | Iterable[SPathLike],
    *,
    track: int = -1,
    sample_rate: int | None = None,
    channels: Sequence[int] | None = None,
    bits: int | None = None,
    **kwargs: Any,
) -> AudioNode

Load one or more input files as an [AudioNode][vs.AudioNode] using the indexer.

Source code in vssource/indexers/base.py
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
@inject_self
def asource(
    self,
    file: SPathLike | Iterable[SPathLike],
    *,
    track: int = -1,
    sample_rate: int | None = None,
    channels: Sequence[int] | None = None,
    bits: int | None = None,
    **kwargs: Any,
) -> vs.AudioNode:
    """
    Load one or more input files as an [AudioNode][vs.AudioNode] using the indexer.
    """
    if not self.has_audio:
        raise CustomRuntimeError(f"{self.__class__.__name__} does not support audio indexing!", self.asource)

    nfiles = self.normalize_filenames(file)
    call_kwargs = self.indexer_kwargs | kwargs
    if self._audio_track_arg_name not in call_kwargs and track is not None:
        call_kwargs[self._audio_track_arg_name] = track

    clips = [self._asource_file(f.to_str(), **call_kwargs) for f in nfiles]
    clip = clips[0] if len(clips) == 1 else core.std.AudioSplice(clips)

    if sample_rate is not None or channels is not None or bits is not None:
        clip = core.std.AudioResample(clip, samplerate=sample_rate, channels=channels, bits=bits)

    return clip

ensure_obj classmethod

ensure_obj(
    indexer: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExcept | None = None,
) -> Self

Ensure that the input is a indexer instance, resolving it if necessary.

Parameters:

  • indexer

    (str | type[Self] | Self | None, default: None ) –

    Indexer identifier (string, class, or instance). Plugin namespace is also supported.

  • func_except

    (FuncExcept | None, default: None ) –

    Function returned for custom error handling.

Returns:

  • Self

    Indexer instance.

Source code in vssource/indexers/base.py
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
@classmethod
def ensure_obj(
    cls, indexer: str | type[Self] | Self | None = None, /, func_except: FuncExcept | None = None
) -> Self:
    """
    Ensure that the input is a indexer instance, resolving it if necessary.

    Args:
        indexer: Indexer identifier (string, class, or instance). Plugin namespace is also supported.
        func_except: Function returned for custom error handling.

    Returns:
        Indexer instance.
    """
    return _base_ensure_obj(cls, indexer, func_except)

from_param classmethod

from_param(
    indexer: str | type[Self] | Self | None = None,
    /,
    func_except: FuncExcept | None = None,
) -> type[Self]

Resolve and return an Indexer type from a given input (string, type, or instance).

Parameters:

  • indexer

    (str | type[Self] | Self | None, default: None ) –

    Indexer identifier (string, class, or instance). Plugin namespace is also supported.

  • func_except

    (FuncExcept | None, default: None ) –

    Function returned for custom error handling.

Returns:

Source code in vssource/indexers/base.py
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
@classmethod
def from_param(
    cls, indexer: str | type[Self] | Self | None = None, /, func_except: FuncExcept | None = None
) -> type[Self]:
    """
    Resolve and return an Indexer type from a given input (string, type, or instance).

    Args:
        indexer: Indexer identifier (string, class, or instance). Plugin namespace is also supported.
        func_except: Function returned for custom error handling.

    Returns:
        Resolved indexer type.
    """
    return _base_from_param(cls, indexer, func_except)

has_audio classmethod

has_audio() -> bool

Whether this indexer supports audio sourcing.

Source code in vssource/indexers/base.py
69
70
71
72
73
@classproperty
@classmethod
def has_audio(cls) -> bool:
    """Whether this indexer supports audio sourcing."""
    return getattr(cls, "_asource_func", None) is not None

has_video classmethod

has_video() -> bool

Whether this indexer supports video sourcing.

Source code in vssource/indexers/base.py
63
64
65
66
67
@classproperty
@classmethod
def has_video(cls) -> bool:
    """Whether this indexer supports video sourcing."""
    return getattr(cls, "_source_func", None) is not None

normalize_filenames classmethod

normalize_filenames(file: SPathLike | Iterable[SPathLike]) -> list[SPath]
Source code in vssource/indexers/base.py
187
188
189
190
191
192
193
194
195
196
197
@classmethod
def normalize_filenames(cls, file: SPathLike | Iterable[SPathLike]) -> list[SPath]:
    files = list[SPath]()

    for f in to_arr(file):
        if str(f).startswith("file:///"):
            f = str(f)[8::]

        files.append(SPath(f))

    return files

source

source(
    file: SPathLike | Iterable[SPathLike],
    bits: int | None = 32,
    *,
    matrix: MatrixLike | None = None,
    transfer: TransferLike | None = None,
    primaries: PrimariesLike | None = None,
    chroma_location: ChromaLocation | None = None,
    color_range: RangeLike | None = None,
    field_based: FieldBasedLike | None = None,
    idx_props: bool = True,
    ref: VideoNode | None = None,
    name: str | None = None,
    **kwargs: Any,
) -> VideoNode

Load one or more input files as a [VideoNode][vs.VideoNode] using the indexer.

The returned clip is passed through initialize_clip to apply bit depth conversion and frame props initialization.

Source code in vssource/indexers/base.py
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
@inject_self
def source(
    self,
    file: SPathLike | Iterable[SPathLike],
    bits: int | None = 32,
    *,
    matrix: MatrixLike | None = None,
    transfer: TransferLike | None = None,
    primaries: PrimariesLike | None = None,
    chroma_location: ChromaLocation | None = None,
    color_range: RangeLike | None = None,
    field_based: FieldBasedLike | None = None,
    idx_props: bool = True,
    ref: vs.VideoNode | None = None,
    name: str | None = None,
    **kwargs: Any,
) -> vs.VideoNode:
    """
    Load one or more input files as a [VideoNode][vs.VideoNode] using the indexer.

    The returned clip is passed through [initialize_clip][vstools.initialize_clip] to apply bit depth conversion
    and frame props initialization.
    """
    if not self.has_video:
        raise CustomRuntimeError(f"{self.__class__.__name__} does not support video indexing!", self.source)

    nfiles = self.normalize_filenames(file)
    clips = [self._source_file(f.to_str(), **self.indexer_kwargs | kwargs) for f in nfiles]
    clip = clips[0] if len(clips) == 1 else core.std.Splice(clips)
    clip = initialize_clip(clip, bits, matrix, transfer, primaries, chroma_location, color_range, field_based)

    if idx_props:
        clip = clip.std.SetFrameProps(IdxFilePath=[f.to_str() for f in nfiles], Idx=self.__class__.__name__)

    if name:
        clip = clip.std.SetFrameProps(Name=name)

    if ref:
        clip = match_clip(clip, ref, length=True)

    return clip

source_func classmethod

source_func(path: SPathLike, **kwargs: Any) -> VideoNode
Source code in vssource/indexers/base.py
179
180
181
182
183
184
185
@classmethod
@deprecated(
    "`source_func` is deprecated and will be removed in a future version. Use `source` instead.",
    category=DeprecationWarning,
)
def source_func(cls, path: SPathLike, **kwargs: Any) -> vs.VideoNode:
    return cls._source_file(path, **kwargs)