fix: refresh expired Baidu sessions and fingerprint legacy UI assets
This commit is contained in:
+18
-20
@@ -111,26 +111,24 @@ class Archive:
|
||||
except (PermissionError, OSError):
|
||||
self.error = '无法核对录制中文件,暂缓恢复旧片段'; return
|
||||
owners = self.a.setting('recording_legacy_owners',{})
|
||||
recovered = 0
|
||||
for root_key, root in self.roots().items():
|
||||
for p in sorted(root.rglob('*.mp4')):
|
||||
if recovered >= 100: return
|
||||
if p.is_symlink() or not NAME.fullmatch(p.name): continue
|
||||
relative = str(p.relative_to(root))
|
||||
with self.a.LOCK:
|
||||
if self.a.DB.execute('SELECT 1 FROM recording_archive WHERE root=? AND path=?',(root_key,relative)).fetchone(): continue
|
||||
try:
|
||||
if str(p) in opened or time.time()-p.stat().st_mtime < 60: continue
|
||||
match = re.fullmatch('cam_('+ID+')_main',p.parent.name)
|
||||
if not match: continue
|
||||
camera = match[1]
|
||||
family = p.parent.parent.name if re.fullmatch(ID,p.parent.parent.name) else owners.get(camera,'')
|
||||
before = self.fingerprint(p)
|
||||
result = subprocess.run(['ffprobe','-v','error','-show_entries','format=duration','-of','json',str(p)],capture_output=True,timeout=15,check=True)
|
||||
duration = float(json.loads(result.stdout)['format']['duration'])
|
||||
if self.fingerprint(p) != before: continue
|
||||
self.enqueue(root_key,relative,family,camera,duration); recovered += 1
|
||||
except (OSError,ValueError,KeyError,subprocess.SubprocessError): continue
|
||||
candidates = [(p.name,root_key,root,p) for root_key,root in self.roots().items() for p in root.rglob('*.mp4')]
|
||||
for _, root_key, root, p in sorted(candidates):
|
||||
if p.is_symlink() or not NAME.fullmatch(p.name): continue
|
||||
relative = str(p.relative_to(root))
|
||||
with self.a.LOCK:
|
||||
if self.a.DB.execute('SELECT 1 FROM recording_archive WHERE root=? AND path=?',(root_key,relative)).fetchone(): continue
|
||||
try:
|
||||
if str(p) in opened or time.time()-p.stat().st_mtime < 60: continue
|
||||
match = re.fullmatch('cam_('+ID+')_main',p.parent.name)
|
||||
if not match: continue
|
||||
camera = match[1]
|
||||
family = p.parent.parent.name if re.fullmatch(ID,p.parent.parent.name) else owners.get(camera,'')
|
||||
before = self.fingerprint(p)
|
||||
result = subprocess.run(['ffprobe','-v','error','-show_entries','format=duration','-of','json',str(p)],capture_output=True,timeout=15,check=True)
|
||||
duration = float(json.loads(result.stdout)['format']['duration'])
|
||||
if self.fingerprint(p) != before: continue
|
||||
self.enqueue(root_key,relative,family,camera,duration)
|
||||
except (OSError,ValueError,KeyError,subprocess.SubprocessError): continue
|
||||
|
||||
def update(self, key, **values):
|
||||
with self.a.LOCK, self.a.DB:
|
||||
|
||||
Reference in New Issue
Block a user