Manar55 commited on
Commit
332fa67
·
verified ·
1 Parent(s): ea0375f

Deploy 4930839

Browse files
Files changed (3) hide show
  1. app.py +7 -1
  2. route/metadata_check.py +265 -0
  3. templates/ts-gps.js +53 -8
app.py CHANGED
@@ -824,7 +824,13 @@ def gps_endpoint():
824
  try:
825
  with os.fdopen(fd, "wb") as out:
826
  f.save(out)
827
- return jsonify(gps_extractor.extract(path, ext))
 
 
 
 
 
 
828
  except Exception as e:
829
  print(f"[gps] failed: {e}", flush=True)
830
  return jsonify({"found": False})
 
824
  try:
825
  with os.fdopen(fd, "wb") as out:
826
  f.save(out)
827
+ out = gps_extractor.extract(path, ext)
828
+ try:
829
+ import metadata_check
830
+ out["meta"] = metadata_check.check(path, ext, out)
831
+ except Exception as e:
832
+ print(f"[metadata] failed: {e}", flush=True)
833
+ return jsonify(out)
834
  except Exception as e:
835
  print(f"[gps] failed: {e}", flush=True)
836
  return jsonify({"found": False})
route/metadata_check.py ADDED
@@ -0,0 +1,265 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Metadata consistency checks for photos and videos.
3
+
4
+ Reads the capture device, dates and software from EXIF (photos) or the
5
+ container tags (videos) and cross-checks them:
6
+ - capture date earlier than the device's release date
7
+ - capture date in the future
8
+ - "modified" date earlier than the capture date
9
+ - GPS clock (UTC) disagreeing with the camera clock
10
+ - time-zone offset far from the GPS longitude
11
+ - editing software / re-encoder recorded in the file
12
+
13
+ Metadata can be stripped or rewritten, so every finding is an indicator to
14
+ weigh, not proof on its own.
15
+ """
16
+ import json
17
+ import re
18
+ import subprocess
19
+ from datetime import datetime, timedelta, timezone
20
+
21
+ import gps_extractor
22
+
23
+ # Release dates (first retail availability). Used only to flag a capture date
24
+ # that is clearly earlier than the device existed (30-day margin).
25
+ _IPHONE = {
26
+ "iphone": "2007-06-29", "iphone 3g": "2008-07-11", "iphone 3gs": "2009-06-19", "iphone 4": "2010-06-24",
27
+ "iphone 4s": "2011-10-14", "iphone 5": "2012-09-21", "iphone 5c": "2013-09-20", "iphone 5s": "2013-09-20",
28
+ "iphone 6": "2014-09-19", "iphone 6 plus": "2014-09-19", "iphone 6s": "2015-09-25", "iphone 6s plus": "2015-09-25",
29
+ "iphone se": "2016-03-31", "iphone 7": "2016-09-16", "iphone 7 plus": "2016-09-16", "iphone 8": "2017-09-22",
30
+ "iphone 8 plus": "2017-09-22", "iphone x": "2017-11-03", "iphone xs": "2018-09-21", "iphone xs max": "2018-09-21",
31
+ "iphone xr": "2018-10-26", "iphone 11": "2019-09-20", "iphone 11 pro": "2019-09-20", "iphone 11 pro max": "2019-09-20",
32
+ "iphone se (2nd generation)": "2020-04-24", "iphone 12": "2020-10-23", "iphone 12 pro": "2020-10-23",
33
+ "iphone 12 mini": "2020-11-13", "iphone 12 pro max": "2020-11-13", "iphone 13": "2021-09-24",
34
+ "iphone 13 mini": "2021-09-24", "iphone 13 pro": "2021-09-24", "iphone 13 pro max": "2021-09-24",
35
+ "iphone se (3rd generation)": "2022-03-18", "iphone 14": "2022-09-16", "iphone 14 plus": "2022-10-07",
36
+ "iphone 14 pro": "2022-09-16", "iphone 14 pro max": "2022-09-16", "iphone 15": "2023-09-22",
37
+ "iphone 15 plus": "2023-09-22", "iphone 15 pro": "2023-09-22", "iphone 15 pro max": "2023-09-22",
38
+ "iphone 16": "2024-09-20", "iphone 16 plus": "2024-09-20", "iphone 16 pro": "2024-09-20",
39
+ "iphone 16 pro max": "2024-09-20", "iphone 16e": "2025-02-28", "iphone 17": "2025-09-19",
40
+ "iphone air": "2025-09-19", "iphone 17 pro": "2025-09-19", "iphone 17 pro max": "2025-09-19",
41
+ }
42
+ # Samsung model codes (prefix of e.g. "SM-S918B") -> (name, release date)
43
+ _SAMSUNG = {
44
+ "SM-G950": ("Galaxy S8", "2017-04-21"), "SM-G955": ("Galaxy S8+", "2017-04-21"),
45
+ "SM-N950": ("Galaxy Note8", "2017-09-15"), "SM-G960": ("Galaxy S9", "2018-03-16"),
46
+ "SM-G965": ("Galaxy S9+", "2018-03-16"), "SM-N960": ("Galaxy Note9", "2018-08-24"),
47
+ "SM-G970": ("Galaxy S10e", "2019-03-08"), "SM-G973": ("Galaxy S10", "2019-03-08"),
48
+ "SM-G975": ("Galaxy S10+", "2019-03-08"), "SM-N970": ("Galaxy Note10", "2019-08-23"),
49
+ "SM-N975": ("Galaxy Note10+", "2019-08-23"), "SM-N976": ("Galaxy Note10+ 5G", "2019-08-23"),
50
+ "SM-G980": ("Galaxy S20", "2020-03-06"), "SM-G981": ("Galaxy S20 5G", "2020-03-06"),
51
+ "SM-G985": ("Galaxy S20+", "2020-03-06"), "SM-G986": ("Galaxy S20+ 5G", "2020-03-06"),
52
+ "SM-G988": ("Galaxy S20 Ultra", "2020-03-06"), "SM-N980": ("Galaxy Note20", "2020-08-21"),
53
+ "SM-N981": ("Galaxy Note20 5G", "2020-08-21"), "SM-N985": ("Galaxy Note20 Ultra", "2020-08-21"),
54
+ "SM-N986": ("Galaxy Note20 Ultra 5G", "2020-08-21"), "SM-G991": ("Galaxy S21", "2021-01-29"),
55
+ "SM-G996": ("Galaxy S21+", "2021-01-29"), "SM-G998": ("Galaxy S21 Ultra", "2021-01-29"),
56
+ "SM-G990": ("Galaxy S21 FE", "2022-01-11"), "SM-S901": ("Galaxy S22", "2022-02-25"),
57
+ "SM-S906": ("Galaxy S22+", "2022-02-25"), "SM-S908": ("Galaxy S22 Ultra", "2022-02-25"),
58
+ "SM-F721": ("Galaxy Z Flip4", "2022-08-26"), "SM-F936": ("Galaxy Z Fold4", "2022-08-26"),
59
+ "SM-S911": ("Galaxy S23", "2023-02-17"), "SM-S916": ("Galaxy S23+", "2023-02-17"),
60
+ "SM-S918": ("Galaxy S23 Ultra", "2023-02-17"), "SM-A346": ("Galaxy A34", "2023-03-24"),
61
+ "SM-A546": ("Galaxy A54", "2023-03-24"), "SM-F731": ("Galaxy Z Flip5", "2023-08-11"),
62
+ "SM-F946": ("Galaxy Z Fold5", "2023-08-11"), "SM-S921": ("Galaxy S24", "2024-01-31"),
63
+ "SM-S926": ("Galaxy S24+", "2024-01-31"), "SM-S928": ("Galaxy S24 Ultra", "2024-01-31"),
64
+ "SM-A356": ("Galaxy A35", "2024-03-15"), "SM-A556": ("Galaxy A55", "2024-03-15"),
65
+ "SM-F741": ("Galaxy Z Flip6", "2024-07-24"), "SM-F956": ("Galaxy Z Fold6", "2024-07-24"),
66
+ "SM-S931": ("Galaxy S25", "2025-02-07"), "SM-S936": ("Galaxy S25+", "2025-02-07"),
67
+ "SM-S938": ("Galaxy S25 Ultra", "2025-02-07"),
68
+ }
69
+ _PIXEL = {
70
+ "pixel": "2016-10-20", "pixel xl": "2016-10-20", "pixel 2": "2017-10-19", "pixel 2 xl": "2017-10-19",
71
+ "pixel 3": "2018-10-18", "pixel 3 xl": "2018-10-18", "pixel 3a": "2019-05-07", "pixel 3a xl": "2019-05-07",
72
+ "pixel 4": "2019-10-24", "pixel 4 xl": "2019-10-24", "pixel 4a": "2020-08-20", "pixel 5": "2020-10-29",
73
+ "pixel 6": "2021-10-28", "pixel 6 pro": "2021-10-28", "pixel 6a": "2022-07-28", "pixel 7": "2022-10-13",
74
+ "pixel 7 pro": "2022-10-13", "pixel 7a": "2023-05-10", "pixel 8": "2023-10-12", "pixel 8 pro": "2023-10-12",
75
+ "pixel 8a": "2024-05-14", "pixel 9": "2024-08-22", "pixel 9 pro": "2024-08-22", "pixel 9 pro xl": "2024-08-22",
76
+ "pixel 9a": "2025-04-10", "pixel 10": "2025-08-28", "pixel 10 pro": "2025-08-28", "pixel 10 pro xl": "2025-08-28",
77
+ }
78
+ _EDITORS = re.compile(r"photoshop|lightroom|gimp|snapseed|picsart|canva|facetune|pixlr|affinity|capture one|"
79
+ r"luminar|vsco|meitu|capcut|inshot|premiere|after effects|final cut|davinci|imovie|kinemaster|"
80
+ r"filmora|vn video|adobe", re.I)
81
+ _REENCODERS = re.compile(r"handbrake|lavf|ffmpeg|libx264|x264", re.I)
82
+
83
+
84
+ def device_release(make, model):
85
+ """(display name, release date) or (None, None)."""
86
+ if not model:
87
+ return None, None
88
+ m = re.sub(r"\s+", " ", str(model)).strip()
89
+ low = m.lower()
90
+ if low in _IPHONE:
91
+ return m, _IPHONE[low]
92
+ if low.startswith("pixel"):
93
+ k = low.replace("google ", "")
94
+ if k in _PIXEL:
95
+ return m, _PIXEL[k]
96
+ code = re.match(r"(SM-[A-Z]\d{3})", m.upper())
97
+ if code and code.group(1) in _SAMSUNG:
98
+ name, d = _SAMSUNG[code.group(1)]
99
+ return f"{name} ({m})", d
100
+ return None, None
101
+
102
+
103
+ def _parse_dt(text, offset=None):
104
+ """EXIF "YYYY:MM:DD HH:MM:SS" or ISO 8601 -> datetime (aware if an offset is known)."""
105
+ if not text:
106
+ return None
107
+ t = str(text).strip().replace("\x00", "")
108
+ try:
109
+ if re.match(r"^\d{4}:\d{2}:\d{2} \d{2}:\d{2}:\d{2}", t):
110
+ dt = datetime.strptime(t[:19], "%Y:%m:%d %H:%M:%S")
111
+ else:
112
+ t2 = t.replace("Z", "+00:00")
113
+ t2 = re.sub(r"([+-]\d{2})(\d{2})$", r"\1:\2", t2)
114
+ dt = datetime.fromisoformat(t2[:32])
115
+ except ValueError:
116
+ return None
117
+ if dt.year < 1990:
118
+ return None
119
+ if dt.tzinfo is None and offset:
120
+ m = re.match(r"^([+-])(\d{2}):?(\d{2})$", str(offset).strip())
121
+ if m:
122
+ sign = 1 if m.group(1) == "+" else -1
123
+ dt = dt.replace(tzinfo=timezone(sign * timedelta(hours=int(m.group(2)), minutes=int(m.group(3)))))
124
+ return dt
125
+
126
+
127
+ def _fmt(dt):
128
+ if not dt:
129
+ return None
130
+ s = dt.strftime("%Y-%m-%d %H:%M:%S")
131
+ if dt.tzinfo is not None:
132
+ off = dt.utcoffset().total_seconds() / 3600.0
133
+ s += f" (UTC{off:+.0f})" if off == int(off) else f" (UTC{off:+.1f})"
134
+ return s
135
+
136
+
137
+ def _photo_meta(path):
138
+ from PIL import Image
139
+ try:
140
+ try:
141
+ import pillow_heif
142
+ pillow_heif.register_heif_opener()
143
+ except Exception:
144
+ pass
145
+ with Image.open(path) as img:
146
+ exif = img.getexif()
147
+ if not exif:
148
+ return {}
149
+ ex = exif.get_ifd(0x8769) or {}
150
+ gps = exif.get_ifd(0x8825) or {}
151
+ except Exception:
152
+ return {}
153
+ meta = {
154
+ "make": str(exif.get(271, "") or "").strip("\x00 ") or None,
155
+ "model": str(exif.get(272, "") or "").strip("\x00 ") or None,
156
+ "software": str(exif.get(305, "") or "").strip("\x00 ") or None,
157
+ "captured": _parse_dt(ex.get(36867) or ex.get(36868), ex.get(36881) or ex.get(36880)),
158
+ "modified": _parse_dt(exif.get(306), ex.get(36880) or ex.get(36881)),
159
+ "lens": str(ex.get(42036, "") or "").strip("\x00 ") or None,
160
+ }
161
+ try:
162
+ if 29 in gps and 7 in gps:
163
+ h, mi, s = (gps_extractor._ratio(x) for x in gps[7])
164
+ d = datetime.strptime(str(gps[29]).strip("\x00 "), "%Y:%m:%d")
165
+ meta["gps_time"] = d.replace(tzinfo=timezone.utc) + timedelta(hours=h, minutes=mi, seconds=s)
166
+ except Exception:
167
+ pass
168
+ return meta
169
+
170
+
171
+ def _video_meta(path):
172
+ try:
173
+ out = subprocess.run(["ffprobe", "-v", "quiet", "-print_format", "json", "-show_format", "-show_streams", path],
174
+ capture_output=True, timeout=30).stdout
175
+ info = json.loads(out or b"{}")
176
+ except Exception:
177
+ return {}
178
+ tags = {}
179
+ for t in [info.get("format", {}).get("tags", {})] + [s.get("tags", {}) for s in info.get("streams", [])]:
180
+ for k, v in (t or {}).items():
181
+ tags.setdefault(k.lower(), v)
182
+ local = _parse_dt(tags.get("com.apple.quicktime.creationdate"))
183
+ utc = _parse_dt(tags.get("creation_time"))
184
+ if utc is not None and utc.tzinfo is None:
185
+ utc = utc.replace(tzinfo=timezone.utc)
186
+ return {
187
+ "make": tags.get("com.apple.quicktime.make") or tags.get("com.android.manufacturer") or tags.get("make"),
188
+ "model": tags.get("com.apple.quicktime.model") or tags.get("com.android.model") or tags.get("model"),
189
+ "software": tags.get("com.apple.quicktime.software") or tags.get("software") or tags.get("encoder"),
190
+ "captured": local or utc,
191
+ "container_time": utc if local else None,
192
+ }
193
+
194
+
195
+ def _finding(level, ar, en):
196
+ return {"level": level, "ar": ar, "en": en}
197
+
198
+
199
+ def check(path, ext, gps=None):
200
+ is_video = ext in gps_extractor.VIDEO_EXTS
201
+ meta = _video_meta(path) if is_video else _photo_meta(path)
202
+ findings = []
203
+ now = datetime.now(timezone.utc)
204
+
205
+ def aware(dt):
206
+ return dt if dt is None or dt.tzinfo else dt.replace(tzinfo=timezone.utc)
207
+
208
+ cap = meta.get("captured")
209
+ name, rel = device_release(meta.get("make"), meta.get("model"))
210
+ if cap and rel:
211
+ rel_d = datetime.strptime(rel, "%Y-%m-%d")
212
+ if cap.replace(tzinfo=None) < rel_d - timedelta(days=30):
213
+ findings.append(_finding("high",
214
+ f"تاريخ الالتقاط ({cap:%Y-%m-%d}) أقدم من تاريخ صدور الجهاز {name} ({rel}) — تعارض يشير إلى تعديل التاريخ أو بيانات الجهاز.",
215
+ f"Capture date ({cap:%Y-%m-%d}) is earlier than the release of {name} ({rel}) — suggests the date or device data was altered."))
216
+ if cap and aware(cap) > now + timedelta(days=1):
217
+ findings.append(_finding("high", f"تاريخ الالتقاط ({cap:%Y-%m-%d}) في المستقبل.",
218
+ f"Capture date ({cap:%Y-%m-%d}) is in the future."))
219
+ mod = meta.get("modified")
220
+ if cap and mod:
221
+ if aware(mod) < aware(cap) - timedelta(minutes=2):
222
+ findings.append(_finding("medium", "تاريخ التعديل أقدم من تاريخ الالتقاط — ترتيب غير منطقي للتواريخ.",
223
+ "The modified date is earlier than the capture date — the dates are out of order."))
224
+ elif aware(mod) - aware(cap) > timedelta(minutes=5):
225
+ findings.append(_finding("info", f"عُدِّل الملف بعد التقاطه بمدة ({_fmt(mod)}).",
226
+ f"The file was modified some time after capture ({_fmt(mod)})."))
227
+ gt = meta.get("gps_time")
228
+ if cap and gt:
229
+ if cap.tzinfo is not None:
230
+ if abs((cap - gt).total_seconds()) > 10 * 60:
231
+ findings.append(_finding("medium", "توقيت GPS لا يطابق توقيت الكاميرا (فرق أكثر من 10 دقائق).",
232
+ "The GPS clock does not match the camera clock (more than 10 minutes apart)."))
233
+ elif abs((cap.replace(tzinfo=timezone.utc) - gt).total_seconds()) > 15 * 3600:
234
+ findings.append(_finding("medium", "توقيت GPS يختلف عن توقيت الكاميرا بأكثر مما يفسّره فرق التوقيت.",
235
+ "The GPS clock differs from the camera clock by more than a time-zone difference explains."))
236
+ ct = meta.get("container_time")
237
+ if cap and ct and cap.tzinfo is not None and abs((cap - ct).total_seconds()) > 10 * 60:
238
+ findings.append(_finding("medium", "تاريخ إنشاء المقطع المسجّل في الحاوية يختلف عن تاريخ التصوير — غالبًا أُعيد حفظ المقطع أو تصديره.",
239
+ "The container creation time differs from the recording date — the video was likely re-saved or exported."))
240
+ if gps and gps.get("found") and cap is not None and cap.tzinfo is not None:
241
+ off = cap.utcoffset().total_seconds() / 3600.0
242
+ if abs(off - gps["lon"] / 15.0) > 3.5:
243
+ findings.append(_finding("info", "فرق التوقيت المسجّل لا يتوافق مع موقع GPS الجغرافي.",
244
+ "The recorded time-zone offset does not fit the GPS location."))
245
+ sw = meta.get("software") or ""
246
+ if sw and _EDITORS.search(sw):
247
+ findings.append(_finding("medium", f"البيانات تذكر برنامج تحرير: {sw}",
248
+ f"The metadata names editing software: {sw}"))
249
+ elif sw and _REENCODERS.search(sw):
250
+ findings.append(_finding("info", f"أُعيد ترميز الملف ({sw}) — يحدث عادةً عند التحويل أو الرفع على المنصات، ويُزيل غالبًا بيانات الجهاز الأصلية.",
251
+ f"The file was re-encoded ({sw}) — common after conversion or platform upload, and it usually removes the original device data."))
252
+
253
+ has_meta = any(meta.get(k) for k in ("make", "model", "captured", "software"))
254
+ level = "none" if not has_meta else ("inconsistent" if any(f["level"] in ("high", "medium") for f in findings)
255
+ else "consistent")
256
+ return {
257
+ "status": level,
258
+ "device": " ".join(x for x in (meta.get("make"), meta.get("model")) if x) or None,
259
+ "device_release": rel,
260
+ "captured": _fmt(cap),
261
+ "modified": _fmt(mod),
262
+ "gps_time": _fmt(gt),
263
+ "software": sw or None,
264
+ "findings": findings,
265
+ }
templates/ts-gps.js CHANGED
@@ -11,15 +11,28 @@
11
  var PIN = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">' +
12
  '<path d="M12 22s7-6.2 7-12a7 7 0 0 0-14 0c0 5.8 7 12 7 12z"/><circle cx="12" cy="10" r="2.5"/></svg>';
13
 
 
 
14
  var css = document.createElement('style');
15
  css.textContent =
16
  '#ts-gps{position:fixed;bottom:58px;left:14px;z-index:99998;font:12.5px system-ui,Segoe UI,Tahoma,sans-serif;display:none}' +
 
 
 
 
 
 
 
 
 
 
17
  '#ts-gps button.main{display:flex;align-items:center;gap:7px;border-radius:999px;padding:7px 13px;border:1px solid #2a3f66;' +
18
  'background:rgba(15,27,51,.92);color:#64748b;cursor:default;font:inherit;box-shadow:0 4px 14px rgba(0,0,0,.3)}' +
19
- '#ts-gps.on button.main{color:#fff;background:#15803d;border-color:#22c55e;cursor:pointer;animation:tsGpsGlow 1.8s ease-in-out infinite}' +
20
  '#ts-gps.wait button.main{color:#93c5fd}' +
 
21
  '@keyframes tsGpsGlow{0%,100%{box-shadow:0 0 0 0 rgba(34,197,94,.55)}50%{box-shadow:0 0 0 8px rgba(34,197,94,0)}}' +
22
- '#ts-gps .pop{display:none;position:absolute;bottom:44px;left:0;min-width:240px;background:#0f1b33;color:#e2e8f0;' +
23
  'border:1px solid #2a3f66;border-radius:12px;padding:12px;box-shadow:0 8px 24px rgba(0,0,0,.45)}' +
24
  '#ts-gps .pop.open{display:block}#ts-gps .pop a,#ts-gps .pop button{display:block;width:100%;margin-top:8px;padding:9px;border-radius:9px;' +
25
  'text-align:center;text-decoration:none;font:inherit;font-weight:700;border:1px solid #334155;background:#1e293b;color:#e2e8f0;cursor:pointer;box-sizing:border-box}' +
@@ -29,15 +42,19 @@
29
 
30
  var box = document.createElement('div');
31
  box.id = 'ts-gps';
32
- box.innerHTML = '<div class="pop"></div><button class="main" type="button">' + PIN + '<span></span></button>';
 
 
33
  function mount() { if (!document.body.contains(box)) document.body.appendChild(box); }
34
  if (document.body) mount(); else document.addEventListener('DOMContentLoaded', mount);
35
- var btn = box.querySelector('button.main'), label = btn.querySelector('span'), pop = box.querySelector('.pop');
 
36
 
37
  function place() { // same side as the status pill
38
  var s = document.getElementById('ts-status');
39
- if (s && s.style.right && s.style.right !== 'auto') { box.style.right = '14px'; box.style.left = 'auto'; pop.style.left = 'auto'; pop.style.right = '0'; }
40
- else { box.style.left = '14px'; box.style.right = 'auto'; pop.style.right = 'auto'; pop.style.left = '0'; }
 
41
  if (!s) box.style.bottom = '14px';
42
  }
43
 
@@ -50,9 +67,36 @@
50
  label.textContent = state.wait ? T('جارٍ فحص الموقع…', 'Checking location…')
51
  : state.found ? T('يوجد موقع جغرافي', 'Location found') : T('لا يوجد موقع جغرافي', 'No location data');
52
  btn.title = state.name || '';
53
- if (!state.found) pop.classList.remove('open');
 
 
 
 
 
 
 
54
  }
55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  btn.addEventListener('click', function () {
57
  if (!state || !state.found) return;
58
  var g = state;
@@ -66,7 +110,8 @@
66
  '<div style="font-size:11px;opacity:.65;margin-top:8px;line-height:1.5">' +
67
  T('الموقع مأخوذ من بيانات الملف، ويمكن تعديله أو حذفه بسهولة، فلا يُعدّ دليلًا قاطعًا بمفرده.',
68
  'Taken from the file metadata, which can be edited or removed, so it is not conclusive on its own.') + '</div>';
69
- pop.classList.toggle('open');
 
70
  });
71
  pop.addEventListener('click', function (e) {
72
  if (e.target.hasAttribute('data-copy') && state && state.found) {
 
11
  var PIN = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">' +
12
  '<path d="M12 22s7-6.2 7-12a7 7 0 0 0-14 0c0 5.8 7 12 7 12z"/><circle cx="12" cy="10" r="2.5"/></svg>';
13
 
14
+ var DOC = '<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">' +
15
+ '<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><path d="M14 2v6h6"/><path d="M9 13h6M9 17h4"/></svg>';
16
  var css = document.createElement('style');
17
  css.textContent =
18
  '#ts-gps{position:fixed;bottom:58px;left:14px;z-index:99998;font:12.5px system-ui,Segoe UI,Tahoma,sans-serif;display:none}' +
19
+ '#ts-gps .stack{display:flex;flex-direction:column;gap:8px;align-items:flex-start;direction:ltr}' +
20
+ '#ts-gps[dir=rtl] .stack>button{direction:rtl}' +
21
+ '#ts-gps button.meta.ok{color:#bfdbfe;border-color:#3b82f6}' +
22
+ '#ts-gps button.meta.bad{color:#fff;background:#b45309;border-color:#f59e0b;cursor:pointer;animation:tsMetaGlow 1.8s ease-in-out infinite}' +
23
+ '#ts-gps button.meta.ok,#ts-gps button.meta.bad{cursor:pointer}' +
24
+ '@keyframes tsMetaGlow{0%,100%{box-shadow:0 0 0 0 rgba(245,158,11,.55)}50%{box-shadow:0 0 0 8px rgba(245,158,11,0)}}' +
25
+ '#ts-gps .row{display:flex;justify-content:space-between;gap:10px;padding:4px 0;border-bottom:1px solid #1e2b45;font-size:12px}' +
26
+ '#ts-gps .row b{font-weight:600;opacity:.7}#ts-gps .row span{text-align:end;direction:ltr;unicode-bidi:plaintext}' +
27
+ '#ts-gps .f{display:flex;gap:8px;margin-top:8px;font-size:12px;line-height:1.55}' +
28
+ '#ts-gps .f i{flex:0 0 8px;height:8px;border-radius:50%;margin-top:5px}' +
29
  '#ts-gps button.main{display:flex;align-items:center;gap:7px;border-radius:999px;padding:7px 13px;border:1px solid #2a3f66;' +
30
  'background:rgba(15,27,51,.92);color:#64748b;cursor:default;font:inherit;box-shadow:0 4px 14px rgba(0,0,0,.3)}' +
31
+ '#ts-gps.on button.main.loc{color:#fff;background:#15803d;border-color:#22c55e;cursor:pointer;animation:tsGpsGlow 1.8s ease-in-out infinite}' +
32
  '#ts-gps.wait button.main{color:#93c5fd}' +
33
+ '#ts-gps .pop{max-width:min(340px,calc(100vw - 28px));max-height:60vh;overflow:auto}' +
34
  '@keyframes tsGpsGlow{0%,100%{box-shadow:0 0 0 0 rgba(34,197,94,.55)}50%{box-shadow:0 0 0 8px rgba(34,197,94,0)}}' +
35
+ '#ts-gps .pop{display:none;position:absolute;bottom:calc(100% + 8px);left:0;min-width:240px;background:#0f1b33;color:#e2e8f0;' +
36
  'border:1px solid #2a3f66;border-radius:12px;padding:12px;box-shadow:0 8px 24px rgba(0,0,0,.45)}' +
37
  '#ts-gps .pop.open{display:block}#ts-gps .pop a,#ts-gps .pop button{display:block;width:100%;margin-top:8px;padding:9px;border-radius:9px;' +
38
  'text-align:center;text-decoration:none;font:inherit;font-weight:700;border:1px solid #334155;background:#1e293b;color:#e2e8f0;cursor:pointer;box-sizing:border-box}' +
 
42
 
43
  var box = document.createElement('div');
44
  box.id = 'ts-gps';
45
+ box.innerHTML = '<div class="pop"></div><div class="stack">' +
46
+ '<button class="main meta" type="button">' + DOC + '<span></span></button>' +
47
+ '<button class="main loc" type="button">' + PIN + '<span></span></button></div>';
48
  function mount() { if (!document.body.contains(box)) document.body.appendChild(box); }
49
  if (document.body) mount(); else document.addEventListener('DOMContentLoaded', mount);
50
+ var btn = box.querySelector('button.loc'), label = btn.querySelector('span'), pop = box.querySelector('.pop');
51
+ var mbtn = box.querySelector('button.meta'), mlabel = mbtn.querySelector('span'), popFor = null;
52
 
53
  function place() { // same side as the status pill
54
  var s = document.getElementById('ts-status');
55
+ var stack = box.querySelector('.stack');
56
+ if (s && s.style.right && s.style.right !== 'auto') { box.style.right = '14px'; box.style.left = 'auto'; pop.style.left = 'auto'; pop.style.right = '0'; stack.style.alignItems = 'flex-end'; }
57
+ else { box.style.left = '14px'; box.style.right = 'auto'; pop.style.right = 'auto'; pop.style.left = '0'; stack.style.alignItems = 'flex-start'; }
58
  if (!s) box.style.bottom = '14px';
59
  }
60
 
 
67
  label.textContent = state.wait ? T('جارٍ فحص الموقع…', 'Checking location…')
68
  : state.found ? T('يوجد موقع جغرافي', 'Location found') : T('لا يوجد موقع جغرافي', 'No location data');
69
  btn.title = state.name || '';
70
+ var m = state.meta;
71
+ mbtn.className = 'main meta' + (m ? (m.status === 'inconsistent' ? ' bad' : (m.status === 'consistent' ? ' ok' : '')) : '');
72
+ mbtn.style.display = state.wait ? 'none' : '';
73
+ var nf = m && m.findings ? m.findings.filter(function (f) { return f.level !== 'info'; }).length : 0;
74
+ mlabel.textContent = !m || m.status === 'none' ? T('لا توجد بيانات وصفية للجهاز', 'No device metadata')
75
+ : m.status === 'inconsistent' ? T('تعارض في البيانات الوصفية (' + nf + ')', 'Metadata conflict (' + nf + ')')
76
+ : T('البيانات الوصفية: لا تعارض ظاهر', 'Metadata: no conflict found');
77
+ if (!state.found && popFor === 'loc') pop.classList.remove('open');
78
  }
79
 
80
+ function esc(t) { return String(t == null ? '' : t).replace(/[&<>"]/g, function (c) { return { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]; }); }
81
+ mbtn.addEventListener('click', function () {
82
+ var m = state && state.meta;
83
+ if (!m || m.status === 'none') return;
84
+ if (popFor === 'meta' && pop.classList.contains('open')) { pop.classList.remove('open'); return; }
85
+ var rows = [[T('الجهاز', 'Device'), m.device], [T('تاريخ صدور الجهاز', 'Device release'), m.device_release],
86
+ [T('تاريخ الالتقاط', 'Captured'), m.captured], [T('تاريخ التعديل', 'Modified'), m.modified],
87
+ [T('توقيت GPS', 'GPS time'), m.gps_time], [T('البرنامج', 'Software'), m.software]];
88
+ var h = '<div style="font-weight:700;margin-bottom:6px">' + T('تدقيق البيانات الوصفية', 'Metadata check') + '</div>';
89
+ rows.forEach(function (r) { if (r[1]) h += '<div class="row"><b>' + r[0] + '</b><span>' + esc(r[1]) + '</span></div>'; });
90
+ var col = { high: '#ef4444', medium: '#f59e0b', info: '#60a5fa' };
91
+ if (m.findings && m.findings.length) m.findings.forEach(function (f) {
92
+ h += '<div class="f"><i style="background:' + col[f.level] + '"></i><div>' + esc(en() ? f.en : f.ar) + '</div></div>'; });
93
+ else h += '<div class="f"><i style="background:#22c55e"></i><div>' + T('لم يُرصد تعارض بين التواريخ والجهاز والموقع.', 'No conflict was found between the dates, device and location.') + '</div></div>';
94
+ h += '<div style="font-size:11px;opacity:.65;margin-top:10px;line-height:1.5">' +
95
+ T('البيانات الوصفية يمكن تعديلها أو حذفها، فغياب التعارض لا يُثبت الأصالة، ووجوده مؤشر يستدعي التحقق.',
96
+ 'Metadata can be edited or removed: no conflict does not prove authenticity, and a conflict is an indicator to verify.') + '</div>';
97
+ pop.innerHTML = h; popFor = 'meta'; pop.classList.add('open');
98
+ });
99
+
100
  btn.addEventListener('click', function () {
101
  if (!state || !state.found) return;
102
  var g = state;
 
110
  '<div style="font-size:11px;opacity:.65;margin-top:8px;line-height:1.5">' +
111
  T('الموقع مأخوذ من بيانات الملف، ويمكن تعديله أو حذفه بسهولة، فلا يُعدّ دليلًا قاطعًا بمفرده.',
112
  'Taken from the file metadata, which can be edited or removed, so it is not conclusive on its own.') + '</div>';
113
+ if (popFor === 'loc' && pop.classList.contains('open')) pop.classList.remove('open');
114
+ else { popFor = 'loc'; pop.classList.add('open'); }
115
  });
116
  pop.addEventListener('click', function (e) {
117
  if (e.target.hasAttribute('data-copy') && state && state.found) {