Skip to content

Commit af5ec21

Browse files
bazilinskyyclaude
andcommitted
Downloader: wait while a listed drive is not mounted, not readable or shows less than half its videos (2026-11-16: crowd-tue-5 dropped off and 29 of its videos were downloaded again onto crowd-tue-3)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 16a3569 commit af5ec21

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

‎tools/download_videos.py‎

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,26 @@ def present(folders):
9999
return have
100100

101101

102+
def unseen(folders, before):
103+
"""The folders whose videos cannot be seen now, with why: under /media on a drive that is not mounted, not
104+
readable, or holding less than half the videos it held at the last look (2026-11-16: crowd-tue-5 dropped off for
105+
a while, its 38k videos looked missing and 29 were downloaded again onto crowd-tue-3). Also returns how many videos
106+
each folder holds now, for the next look."""
107+
gone, now = [], {}
108+
for d in dict.fromkeys(folders):
109+
if not mounted(d):
110+
gone.append((d, 'drive not mounted'))
111+
continue
112+
try:
113+
now[d] = sum(1 for f in os.listdir(d) if f.endswith('.mp4')) if os.path.isdir(d) else 0
114+
except OSError as e:
115+
gone.append((d, f'not readable ({e.strerror})'))
116+
continue
117+
if before.get(d, 0) >= 100 and now[d] < before[d] / 2:
118+
gone.append((d, f'{now[d]} videos, {before[d]} at the last look'))
119+
return gone, now
120+
121+
102122
def mounted(folder):
103123
"""False for a folder under /media whose drive is not mounted (it would fill the system disk instead)."""
104124
parts = os.path.abspath(folder).split(os.sep)
@@ -176,7 +196,7 @@ def main():
176196
per_hour, done_at = setting('download_per_hour', 30), []
177197
log(f'drives in order: {drives} (each until {reserve} GB is left); file server first: {use_ftp}')
178198
h = None
179-
checked, todo, streak, wait = 0.0, [], 0, BLOCKED_S
199+
checked, todo, streak, wait, counts = 0.0, [], 0, BLOCKED_S, {}
180200
try:
181201
with open(FAILED) as f:
182202
failed = {v: t for v, t in json.load(f).items() if time.time() - t < RETRY_S}
@@ -192,6 +212,15 @@ def main():
192212
pass
193213
while True:
194214
if time.time() - checked >= CHECK_S or not todo:
215+
gone, now = unseen(list(folders) + list(drives), counts)
216+
if gone: # its videos would look missing and be downloaded again: wait until it is back
217+
log('waiting an hour, videos not visible in: ' + '; '.join(f'{d} ({why})' for d, why in gone))
218+
if args.dry_run or args.once:
219+
return
220+
report(status, drives, state='a drive is missing', current=None, until=time.time() + CHECK_S)
221+
time.sleep(CHECK_S)
222+
continue
223+
counts.update(now)
195224
checked, have = time.time(), present(list(folders) + list(drives))
196225
todo = [v for v in mapping_videos() if v not in have and time.time() - failed.get(v, 0) > RETRY_S]
197226
log(f'{len(todo)} videos to download')

0 commit comments

Comments
 (0)