forked from telegramdesktop/tdesktop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse_video_json.py
More file actions
76 lines (62 loc) · 1.9 KB
/
parse_video_json.py
File metadata and controls
76 lines (62 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env python3
import json
import sys
import os
def get_video_attr(attributes):
for attr in attributes:
if 'w' in attr and 'h' in attr and 'duration' in attr:
return attr
return None
def format_duration(seconds):
if seconds is None: return "N/A"
mins = int(seconds // 60)
secs = seconds % 60
return f"{mins:02d}:{secs:05.2f} ({seconds:.2f}s)"
def print_doc(doc, label):
mime = doc.get('mime_type', 'unknown')
# Filter for actual video files
if not mime.startswith('video/'):
return
attr = get_video_attr(doc.get('attributes', []))
if not attr:
return
w = attr.get('w', '?')
h = attr.get('h', '?')
dur = attr.get('duration')
codec = attr.get('video_codec') or "none/original"
size_mb = doc.get('size', 0) / (1024 * 1024)
print(f"--- {label} ---")
print(f" Resolution: {w}x{h} ({h}p)")
print(f" Duration: {format_duration(dur)}")
print(f" Codec: {codec}")
print(f" Mime: {mime}")
print(f" File Size: {size_mb:.2f} MB")
print()
def main():
if len(sys.argv) < 2:
print("Usage: ./parse_video_json.py <file.json>")
sys.exit(1)
path = sys.argv[1]
if not os.path.exists(path):
print(f"Error: {path} not found")
sys.exit(1)
with open(path, 'r', encoding='utf-8') as f:
data = json.load(f)
media = data.get('media', {})
doc = media.get('document')
if not doc:
print("No media document found in JSON.")
return
# 1. Main Document
print_doc(doc, "ATTRIBUTES (Original)")
# 2. Alt Documents
alts = media.get('alt_documents', [])
if alts:
print(f"--- ALT DOCUMENTS ({len(alts)} entries) ---")
print()
for i, alt in enumerate(alts):
print_doc(alt, f"Alt #{i+1}")
else:
print("No alt_documents found.")
if __name__ == "__main__":
main()