110
111
112
113
114
115
116
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234 | @copy_signature(_source_func)
def source(
filepath: SPathLike | Sequence[SPathLike] | Generator[SPathLike, None, None] | None = None,
bits: int | None = None, *,
matrix: MatrixT | None = None,
transfer: TransferT | None = None,
primaries: PrimariesT | None = None,
chroma_location: ChromaLocationT | None = None,
color_range: ColorRangeT | None = None,
field_based: FieldBasedT | None = None,
ref: vs.VideoNode | None = None,
film_thr: float = 99.0,
name: str | Literal[False] = False,
**kwargs: Any
) -> vs.VideoNode | source_func:
if filepath is None:
return partial( # type: ignore
source, bits=bits if bits is not None else filepath, matrix=matrix, transfer=transfer, primaries=primaries,
chroma_location=chroma_location, color_range=color_range, field_based=field_based, ref=ref,
film_thr=film_thr, name=name, **kwargs
)
clip = None
film_thr = float(min(100, film_thr))
filepath, file = parse_video_filepath(filepath)
props = dict[str, Any]()
to_skip = to_arr(kwargs.get('_to_skip', []))
if file.ext is IndexingType.LWI:
clip = LSMAS.source_func(filepath, **kwargs)
elif file.file_type is FileType.IMAGE:
clip = IMWRI.source_func(filepath, **kwargs)
else:
try:
if DGIndexNV in to_skip:
raise RuntimeError
try:
from pymediainfo import MediaInfo # type: ignore
except ImportError:
...
else:
tracks = MediaInfo.parse(filepath, parse_speed=0.25).video_tracks
if tracks:
trackmeta = tracks[0].to_data()
video_format = trackmeta.get("format")
if video_format is not None:
video_fmt = str(video_format).strip().lower()
if video_fmt == 'ffv1':
raise RuntimeError
bitdepth = trackmeta.get('bit_depth')
if bitdepth is not None and video_fmt == 'avc' and int(bitdepth) > 8:
raise RuntimeError
indexer, filepath_dgi = DGIndexNV(), SPath(filepath)
if filepath_dgi.suffix != '.dgi':
filepath_dgi = next(iter(indexer.index([filepath_dgi], False, False)))
idx_info = indexer.get_info(filepath_dgi, 0).footer
props |= dict(DgiFieldOp=0, DgiOrder=idx_info.order, DgiFilm=idx_info.film)
indexer_kwargs = dict[str, Any]()
if idx_info.film >= film_thr:
indexer_kwargs |= dict(fieldop=1)
props |= dict(DgiFieldOp=1, _FieldBased=0)
clip = indexer.source_func(filepath_dgi, **indexer_kwargs)
except (RuntimeError, AttributeError, FileNotFoundError):
indexers = list[type[Indexer]]([LSMAS, D2VWitch, DGIndex])
try:
from vspreview import is_preview
best_last = is_preview()
except BaseException:
best_last = False
if best_last:
indexers.append(BestSource)
else:
indexers.insert(0, BestSource)
for indexerr in indexers:
if indexerr in to_skip:
continue
try:
clip = indexerr.source(filepath, bits=bits)
break
except Exception as e:
if 'bgr0 is not supported' in str(e):
try:
clip = indexerr.source(filepath, format='rgb24', bits=bits)
break
except Exception:
...
if clip is None:
raise CustomRuntimeError(f'None of the indexers you have installed work on this file! "{filepath}"')
props |= dict(IdxFilePath=str(filepath))
if name:
props |= dict(Name=name)
clip = clip.std.SetFrameProps(**props)
if ref:
clip = match_clip(clip, ref, length=file.file_type is FileType.IMAGE)
return initialize_clip(
clip, bits, matrix=matrix, transfer=transfer,
primaries=primaries, chroma_location=chroma_location,
color_range=color_range, field_based=field_based
)
|