ScriptCollection 4.4.61__py3-none-any.whl → 4.4.62__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ScriptCollection/Executables.py +14 -0
- ScriptCollection/GeneralUtilities.py +92 -0
- ScriptCollection/ScriptCollectionCore.py +1 -1
- {scriptcollection-4.4.61.dist-info → scriptcollection-4.4.62.dist-info}/METADATA +1 -1
- {scriptcollection-4.4.61.dist-info → scriptcollection-4.4.62.dist-info}/RECORD +8 -8
- {scriptcollection-4.4.61.dist-info → scriptcollection-4.4.62.dist-info}/WHEEL +1 -1
- {scriptcollection-4.4.61.dist-info → scriptcollection-4.4.62.dist-info}/entry_points.txt +1 -0
- {scriptcollection-4.4.61.dist-info → scriptcollection-4.4.62.dist-info}/top_level.txt +0 -0
ScriptCollection/Executables.py
CHANGED
|
@@ -185,6 +185,20 @@ def ShowMissingFiles() -> int:
|
|
|
185
185
|
return 0
|
|
186
186
|
|
|
187
187
|
|
|
188
|
+
def CheckMediaFile() -> int:
|
|
189
|
+
parser = argparse.ArgumentParser(description='Checks whether a media-file (for example mp4 or mkv) can be played completely. Exit-code 0 if and only if no inconsistency was found.')
|
|
190
|
+
parser.add_argument('file', help='Media-file to check')
|
|
191
|
+
parser.add_argument('--decode', action='store_true', help='Additionally decodes all video- and audio-streams completely (slow)')
|
|
192
|
+
args = parser.parse_args()
|
|
193
|
+
findings = GeneralUtilities.get_media_file_inconsistencies(args.file, args.decode)
|
|
194
|
+
for finding in findings:
|
|
195
|
+
GeneralUtilities.write_message_to_stderr(finding)
|
|
196
|
+
if 0 < len(findings):
|
|
197
|
+
return 1
|
|
198
|
+
GeneralUtilities.write_message_to_stdout(f"No inconsistencies found in '{args.file}'.")
|
|
199
|
+
return 0
|
|
200
|
+
|
|
201
|
+
|
|
188
202
|
def ExtractPDFPages() -> int:
|
|
189
203
|
parser = argparse.ArgumentParser(description='Extract pages from PDF-file')
|
|
190
204
|
parser.add_argument('file', help='Input file')
|
|
@@ -1356,6 +1356,98 @@ class GeneralUtilities:
|
|
|
1356
1356
|
exit_code = process.wait()
|
|
1357
1357
|
return (exit_code, stdout, stderr)
|
|
1358
1358
|
|
|
1359
|
+
media_check_tolerance_in_seconds: float = 2.0
|
|
1360
|
+
|
|
1361
|
+
@staticmethod
|
|
1362
|
+
@check_arguments
|
|
1363
|
+
def __run_media_tool(tool: str, arguments: list[str]) -> tuple[int, str, str]:
|
|
1364
|
+
result = GeneralUtilities.run_program_simple(tool, arguments)
|
|
1365
|
+
return (result[0], result[1].decode("utf-8", errors="replace"), result[2].decode("utf-8", errors="replace"))
|
|
1366
|
+
|
|
1367
|
+
@staticmethod
|
|
1368
|
+
@check_arguments
|
|
1369
|
+
def __read_media_packets(file: str) -> tuple[list[str], dict[int, list[tuple[float, float]]]]:
|
|
1370
|
+
"""Reads all packets of the file (so the whole file is demuxed) and returns the problems reported by ffprobe and the list of (start, duration) in seconds of the packets per stream-index."""
|
|
1371
|
+
result = GeneralUtilities.__run_media_tool("ffprobe", ["-v", "error", "-show_entries", "packet=stream_index,pts_time,dts_time,duration_time", "-of", "compact=p=0", file])
|
|
1372
|
+
problems: list[str] = []
|
|
1373
|
+
if result[0] != 0 or result[2].strip():
|
|
1374
|
+
problems.append(f"Reading all packets of the file failed (exit-code: {result[0]}): {result[2].strip()}")
|
|
1375
|
+
packets: dict[int, list[tuple[float, float]]] = {}
|
|
1376
|
+
for line in GeneralUtilities.string_to_lines(result[1]):
|
|
1377
|
+
if not line.strip():
|
|
1378
|
+
continue
|
|
1379
|
+
values = dict(part.split("=", 1) for part in line.split("|") if "=" in part)
|
|
1380
|
+
start = values.get("pts_time", "N/A")
|
|
1381
|
+
if start == "N/A":
|
|
1382
|
+
start = values.get("dts_time", "N/A")
|
|
1383
|
+
if start == "N/A":
|
|
1384
|
+
continue
|
|
1385
|
+
duration = values.get("duration_time", "N/A")
|
|
1386
|
+
packets.setdefault(int(values["stream_index"]), []).append((float(start), 0.0 if duration == "N/A" else float(duration)))
|
|
1387
|
+
return (problems, packets)
|
|
1388
|
+
|
|
1389
|
+
@staticmethod
|
|
1390
|
+
@check_arguments
|
|
1391
|
+
def get_media_file_inconsistencies(file: str, decode: bool) -> list[str]:
|
|
1392
|
+
"""Checks whether a media-file (for example mp4 or mkv) can be played completely. Returns the found inconsistencies; an empty list means that none was found.
|
|
1393
|
+
Checked are: The container is readable, it declares a duration, every video- and audio-stream contains packets, starts and ends in line with the declared duration
|
|
1394
|
+
(tolerance: media_check_tolerance_in_seconds) and has no gap longer than that tolerance. If decode is true then all video- and audio-streams are additionally decoded completely (slow).
|
|
1395
|
+
This function needs ffprobe (and ffmpeg if decode is true)."""
|
|
1396
|
+
GeneralUtilities.assert_file_exists(file)
|
|
1397
|
+
GeneralUtilities.assert_condition(GeneralUtilities.tool_is_available("ffprobe"), "ffprobe is not available.")
|
|
1398
|
+
GeneralUtilities.assert_condition(not decode or GeneralUtilities.tool_is_available("ffmpeg"), "ffmpeg is not available.")
|
|
1399
|
+
if os.path.getsize(file) == 0:
|
|
1400
|
+
return ["The file is empty."]
|
|
1401
|
+
tolerance = GeneralUtilities.media_check_tolerance_in_seconds
|
|
1402
|
+
|
|
1403
|
+
probe = GeneralUtilities.__run_media_tool("ffprobe", ["-v", "error", "-show_format", "-show_streams", "-of", "json", file])
|
|
1404
|
+
if probe[0] != 0 or probe[2].strip():
|
|
1405
|
+
return [f"The container is not readable (exit-code: {probe[0]}): {probe[2].strip()}"]
|
|
1406
|
+
info = json.loads(probe[1])
|
|
1407
|
+
media_format: dict = info.get("format", {})
|
|
1408
|
+
streams = [stream for stream in info.get("streams", []) if stream.get("codec_type") in ("video", "audio") and not stream.get("disposition", {}).get("attached_pic", 0)]
|
|
1409
|
+
if len(streams) == 0:
|
|
1410
|
+
return ["The file contains no video- or audio-stream."]
|
|
1411
|
+
if "duration" not in media_format:
|
|
1412
|
+
return ["The container does not declare a duration, so completeness can not be verified."]
|
|
1413
|
+
declared_duration = float(media_format["duration"])
|
|
1414
|
+
declared_start = float(media_format.get("start_time", 0))
|
|
1415
|
+
|
|
1416
|
+
findings: list[str] = []
|
|
1417
|
+
problems, packets = GeneralUtilities.__read_media_packets(file)
|
|
1418
|
+
findings.extend(problems)
|
|
1419
|
+
for stream in streams:
|
|
1420
|
+
index = int(stream["index"])
|
|
1421
|
+
name = f"{stream['codec_type']}-stream {index} ({stream.get('codec_name', 'unknown')})"
|
|
1422
|
+
stream_packets = sorted(packets.get(index, []))
|
|
1423
|
+
if len(stream_packets) == 0:
|
|
1424
|
+
findings.append(f"The {name} contains no packets.")
|
|
1425
|
+
continue
|
|
1426
|
+
first_start = stream_packets[0][0]
|
|
1427
|
+
end = max(start+duration for start, duration in stream_packets)
|
|
1428
|
+
if declared_start+tolerance < first_start:
|
|
1429
|
+
findings.append(f"The {name} starts {first_start-declared_start:.1f}s after the start of the file.")
|
|
1430
|
+
if end < declared_start+declared_duration-tolerance:
|
|
1431
|
+
findings.append(f"The {name} contains only {end-declared_start:.1f}s of the declared {declared_duration:.1f}s.")
|
|
1432
|
+
if declared_start+declared_duration+tolerance < end:
|
|
1433
|
+
findings.append(f"The {name} is longer ({end-declared_start:.1f}s) than the declared {declared_duration:.1f}s.")
|
|
1434
|
+
gaps = [(stream_packets[i][0], stream_packets[i+1][0]-(stream_packets[i][0]+stream_packets[i][1])) for i in range(len(stream_packets)-1)]
|
|
1435
|
+
gaps = [gap for gap in gaps if tolerance < gap[1]]
|
|
1436
|
+
if 0 < len(gaps):
|
|
1437
|
+
findings.append(f"The {name} has {len(gaps)} gap(s) longer than {tolerance:.1f}s, the first one of {gaps[0][1]:.1f}s after {gaps[0][0]:.1f}s.")
|
|
1438
|
+
|
|
1439
|
+
if decode:
|
|
1440
|
+
decoded = GeneralUtilities.__run_media_tool("ffmpeg", ["-v", "error", "-nostdin", "-i", file, "-map", "0:v?", "-map", "0:a?", "-f", "null", "-"])
|
|
1441
|
+
if decoded[0] != 0 or decoded[2].strip():
|
|
1442
|
+
findings.append(f"Decoding failed (exit-code: {decoded[0]}): {decoded[2].strip()}")
|
|
1443
|
+
return findings
|
|
1444
|
+
|
|
1445
|
+
@staticmethod
|
|
1446
|
+
@check_arguments
|
|
1447
|
+
def assert_media_file_is_consistent(file: str, decode: bool) -> None:
|
|
1448
|
+
findings = GeneralUtilities.get_media_file_inconsistencies(file, decode)
|
|
1449
|
+
GeneralUtilities.assert_condition(len(findings) == 0, f"The media-file '{file}' is inconsistent: "+" ".join(findings))
|
|
1450
|
+
|
|
1359
1451
|
@staticmethod
|
|
1360
1452
|
@check_arguments
|
|
1361
1453
|
def assert_file_exists(file: str,message=None) -> None:
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
ScriptCollection/ArbTranslationsOrganizer.py,sha256=3TO4fjkYADcHGyUXdiQk-RtfCxtf9ojuBS3CbZtgXBE,12218
|
|
2
2
|
ScriptCollection/CertificateUpdater.py,sha256=yZc7KESc1F_Mc6HP2UfLmNHRc2MvtVqp0t60J_CqY3s,9755
|
|
3
|
-
ScriptCollection/Executables.py,sha256=
|
|
4
|
-
ScriptCollection/GeneralUtilities.py,sha256=
|
|
3
|
+
ScriptCollection/Executables.py,sha256=EncTPUCKoq3uTKbobr1TIiVF8JF7LnIyqPDrTYm1wqA,78317
|
|
4
|
+
ScriptCollection/GeneralUtilities.py,sha256=kW6y52rdD-dJrjCtIgsdwYinz6FtclGj-xc_4tL1MUg,80022
|
|
5
5
|
ScriptCollection/HTTPMaintenanceOverheadHelper.py,sha256=TToNtyO1XzsMbBsTBf3o0xgOK0v4Jf03qw2Z0xb2nCk,2007
|
|
6
6
|
ScriptCollection/ProcessesRunner.py,sha256=wtNFdmj9klETTIDUSE90vaR5ClEX4V7dgJNVbp9_wi0,1381
|
|
7
7
|
ScriptCollection/ProgramRunnerBase.py,sha256=eZenpiIFW1dhvSVCG7cfBs5hO4_KLlOxR7oXoSxUDmk,2286
|
|
@@ -11,7 +11,7 @@ ScriptCollection/ProgramRunnerSudo.py,sha256=vwKq-MOcqsgiKhSf-MBUDBC_UyaU8evP3Ro
|
|
|
11
11
|
ScriptCollection/RepositoryDiagramGenerator.py,sha256=K_u2NW_p4ozdWD50irJEkkcDVa70TcUJpZN63TeXSLw,7092
|
|
12
12
|
ScriptCollection/RepositoryHistoryAnalyzer.py,sha256=u9141B9D-Kef-9uo3yR7BXKUMzIKLVsesnYk7H-cWm4,6157
|
|
13
13
|
ScriptCollection/SCLog.py,sha256=Fjf8Pdi63cXHGMxL_aI6A0dwGm7QIfrv3czjvpSUlaM,4705
|
|
14
|
-
ScriptCollection/ScriptCollectionCore.py,sha256=
|
|
14
|
+
ScriptCollection/ScriptCollectionCore.py,sha256=YSIqH23aVKMeUyu18FHHNwtwbdtm4pGIqlTj49zBVeE,310633
|
|
15
15
|
ScriptCollection/TestKind.py,sha256=jqLJwNvQeyea7SZf-UFzMC9pM0znv4do7FIC1xq8u9M,1672
|
|
16
16
|
ScriptCollection/UnassignedVariablesCheck.py,sha256=8xNcp1D5HeOLO1a1NEerq2TsnpFhw7yzYPkaay-oisY,3804
|
|
17
17
|
ScriptCollection/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -73,8 +73,8 @@ ScriptCollection/TFCPS/Rust/TFCPS_CodeUnitSpecific_Rust.py,sha256=yyjWPMHQjPLkML
|
|
|
73
73
|
ScriptCollection/TFCPS/Rust/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
74
74
|
ScriptCollection/TFCPS/TypeScript/TFCPS_CodeUnitSpecific_TypeScript.py,sha256=ILVhJHvwG5TvPBBqSvyACYb7W9QnWrJpxKgHu8IQu4g,9249
|
|
75
75
|
ScriptCollection/TFCPS/TypeScript/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
76
|
-
scriptcollection-4.4.
|
|
77
|
-
scriptcollection-4.4.
|
|
78
|
-
scriptcollection-4.4.
|
|
79
|
-
scriptcollection-4.4.
|
|
80
|
-
scriptcollection-4.4.
|
|
76
|
+
scriptcollection-4.4.62.dist-info/METADATA,sha256=0-mbbh4L_E0TTmiKevWfM-_-55hOjn5wUg5WEMYkx7M,8032
|
|
77
|
+
scriptcollection-4.4.62.dist-info/WHEEL,sha256=16fc_9Rp854SLcdhaDEjr0u65p0e3FhZxihNgcnCE98,91
|
|
78
|
+
scriptcollection-4.4.62.dist-info/entry_points.txt,sha256=WlLvtCVRFHws2E4rf4a_W62j3YeSeu5RBVTBPlVBcZs,6198
|
|
79
|
+
scriptcollection-4.4.62.dist-info/top_level.txt,sha256=hY2hOVH0V0Ce51WB76zKkIWTUNwMUdHo4XDkR2vYVwg,17
|
|
80
|
+
scriptcollection-4.4.62.dist-info/RECORD,,
|
|
@@ -6,6 +6,7 @@ scbuildcodeunitsc = ScriptCollection.Executables:BuildCodeUnitsC
|
|
|
6
6
|
sccalculatebitcoinblockhash = ScriptCollection.Executables:CalculateBitcoinBlockHash
|
|
7
7
|
scchangefileextension = ScriptCollection.Executables:ChangeFileExtensions
|
|
8
8
|
scchangehashofprogram = ScriptCollection.Executables:ChangeHashOfProgram
|
|
9
|
+
sccheckmediafile = ScriptCollection.Executables:CheckMediaFile
|
|
9
10
|
sccheckpythonast = ScriptCollection.Executables:CheckPythonAst
|
|
10
11
|
sccleantoolscache = ScriptCollection.Executables:CleanToolsCache
|
|
11
12
|
scconvertgitrepositorytobarerepository = ScriptCollection.Executables:ConvertGitRepositoryToBareRepository
|
|
File without changes
|