archive_methods.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. import os
  2. from typing import Dict, List, Tuple, Optional
  3. from collections import defaultdict
  4. from datetime import datetime
  5. from .schema import Link, ArchiveResult
  6. from .index import (
  7. write_link_index,
  8. patch_links_index,
  9. load_json_link_index,
  10. )
  11. from .config import (
  12. CURL_BINARY,
  13. GIT_BINARY,
  14. WGET_BINARY,
  15. YOUTUBEDL_BINARY,
  16. FETCH_FAVICON,
  17. FETCH_TITLE,
  18. FETCH_WGET,
  19. FETCH_WGET_REQUISITES,
  20. FETCH_PDF,
  21. FETCH_SCREENSHOT,
  22. FETCH_DOM,
  23. FETCH_WARC,
  24. FETCH_GIT,
  25. FETCH_MEDIA,
  26. SUBMIT_ARCHIVE_DOT_ORG,
  27. TIMEOUT,
  28. MEDIA_TIMEOUT,
  29. GIT_DOMAINS,
  30. VERSION,
  31. WGET_USER_AGENT,
  32. CHECK_SSL_VALIDITY,
  33. COOKIES_FILE,
  34. CURL_VERSION,
  35. WGET_VERSION,
  36. CHROME_VERSION,
  37. GIT_VERSION,
  38. YOUTUBEDL_VERSION,
  39. WGET_AUTO_COMPRESSION,
  40. )
  41. from .util import (
  42. enforce_types,
  43. domain,
  44. extension,
  45. without_query,
  46. without_fragment,
  47. fetch_page_title,
  48. is_static_file,
  49. TimedProgress,
  50. chmod_file,
  51. wget_output_path,
  52. chrome_args,
  53. run, PIPE, DEVNULL,
  54. )
  55. from .logs import (
  56. log_link_archiving_started,
  57. log_link_archiving_finished,
  58. log_archive_method_started,
  59. log_archive_method_finished,
  60. )
  61. class ArchiveError(Exception):
  62. def __init__(self, message, hints=None):
  63. super().__init__(message)
  64. self.hints = hints
  65. @enforce_types
  66. def archive_link(link: Link, link_dir: Optional[str]=None) -> Link:
  67. """download the DOM, PDF, and a screenshot into a folder named after the link's timestamp"""
  68. ARCHIVE_METHODS = (
  69. ('title', should_fetch_title, fetch_title),
  70. ('favicon', should_fetch_favicon, fetch_favicon),
  71. ('wget', should_fetch_wget, fetch_wget),
  72. ('pdf', should_fetch_pdf, fetch_pdf),
  73. ('screenshot', should_fetch_screenshot, fetch_screenshot),
  74. ('dom', should_fetch_dom, fetch_dom),
  75. ('git', should_fetch_git, fetch_git),
  76. ('media', should_fetch_media, fetch_media),
  77. ('archive_org', should_fetch_archive_dot_org, archive_dot_org),
  78. )
  79. link_dir = link_dir or link.link_dir
  80. try:
  81. is_new = not os.path.exists(link_dir)
  82. if is_new:
  83. os.makedirs(link_dir)
  84. link = load_json_link_index(link, link_dir=link_dir)
  85. log_link_archiving_started(link, link_dir, is_new)
  86. link = link.overwrite(updated=datetime.now())
  87. stats = {'skipped': 0, 'succeeded': 0, 'failed': 0}
  88. for method_name, should_run, method_function in ARCHIVE_METHODS:
  89. try:
  90. if method_name not in link.history:
  91. link.history[method_name] = []
  92. if should_run(link, link_dir):
  93. log_archive_method_started(method_name)
  94. result = method_function(link=link, link_dir=link_dir)
  95. link.history[method_name].append(result)
  96. stats[result.status] += 1
  97. log_archive_method_finished(result)
  98. else:
  99. stats['skipped'] += 1
  100. except Exception as e:
  101. raise Exception('Exception in archive_methods.fetch_{}(Link(url={}))'.format(
  102. method_name,
  103. link.url,
  104. )) from e
  105. # print(' ', stats)
  106. # If any changes were made, update the link index json and html
  107. write_link_index(link, link_dir=link.link_dir)
  108. was_changed = stats['succeeded'] or stats['failed']
  109. if was_changed:
  110. patch_links_index(link)
  111. log_link_archiving_finished(link, link.link_dir, is_new, stats)
  112. except KeyboardInterrupt:
  113. try:
  114. write_link_index(link, link_dir=link.link_dir)
  115. except:
  116. pass
  117. raise
  118. except Exception as err:
  119. print(' ! Failed to archive link: {}: {}'.format(err.__class__.__name__, err))
  120. raise
  121. return link
  122. ### Archive Method Functions
  123. @enforce_types
  124. def should_fetch_title(link: Link, link_dir: Optional[str]=None) -> bool:
  125. # if link already has valid title, skip it
  126. if link.title and not link.title.lower().startswith('http'):
  127. return False
  128. if is_static_file(link.url):
  129. return False
  130. return FETCH_TITLE
  131. @enforce_types
  132. def fetch_title(link: Link, link_dir: Optional[str]=None, timeout: int=TIMEOUT) -> ArchiveResult:
  133. """try to guess the page's title from its content"""
  134. output = None
  135. cmd = [
  136. CURL_BINARY,
  137. link.url,
  138. '|',
  139. 'grep',
  140. '<title>',
  141. ]
  142. status = 'succeeded'
  143. timer = TimedProgress(timeout, prefix=' ')
  144. try:
  145. output = fetch_page_title(link.url, timeout=timeout, progress=False)
  146. if not output:
  147. raise ArchiveError('Unable to detect page title')
  148. except Exception as err:
  149. status = 'failed'
  150. output = err
  151. finally:
  152. timer.end()
  153. return ArchiveResult(
  154. cmd=cmd,
  155. pwd=link_dir,
  156. cmd_version=CURL_VERSION,
  157. output=output,
  158. status=status,
  159. **timer.stats,
  160. )
  161. @enforce_types
  162. def should_fetch_favicon(link: Link, link_dir: Optional[str]=None) -> bool:
  163. if os.path.exists(os.path.join(link_dir, 'favicon.ico')):
  164. return False
  165. return FETCH_FAVICON
  166. @enforce_types
  167. def fetch_favicon(link: Link, link_dir: Optional[str]=None, timeout: int=TIMEOUT) -> ArchiveResult:
  168. """download site favicon from google's favicon api"""
  169. output = 'favicon.ico'
  170. cmd = [
  171. CURL_BINARY,
  172. '--max-time', str(timeout),
  173. '--location',
  174. '--output', output,
  175. *(() if CHECK_SSL_VALIDITY else ('--insecure',)),
  176. 'https://www.google.com/s2/favicons?domain={}'.format(domain(link.url)),
  177. ]
  178. status = 'succeeded'
  179. timer = TimedProgress(timeout, prefix=' ')
  180. try:
  181. run(cmd, stdout=PIPE, stderr=PIPE, cwd=link_dir, timeout=timeout)
  182. chmod_file(output, cwd=link_dir)
  183. except Exception as err:
  184. status = 'failed'
  185. output = err
  186. finally:
  187. timer.end()
  188. return ArchiveResult(
  189. cmd=cmd,
  190. pwd=link_dir,
  191. cmd_version=CURL_VERSION,
  192. output=output,
  193. status=status,
  194. **timer.stats,
  195. )
  196. @enforce_types
  197. def should_fetch_wget(link: Link, link_dir: Optional[str]=None) -> bool:
  198. output_path = wget_output_path(link)
  199. if output_path and os.path.exists(os.path.join(link_dir, output_path)):
  200. return False
  201. return FETCH_WGET
  202. @enforce_types
  203. def fetch_wget(link: Link, link_dir: Optional[str]=None, timeout: int=TIMEOUT) -> ArchiveResult:
  204. """download full site using wget"""
  205. if FETCH_WARC:
  206. warc_dir = os.path.join(link_dir, 'warc')
  207. os.makedirs(warc_dir, exist_ok=True)
  208. warc_path = os.path.join('warc', str(int(datetime.now().timestamp())))
  209. # WGET CLI Docs: https://www.gnu.org/software/wget/manual/wget.html
  210. output = None
  211. cmd = [
  212. WGET_BINARY,
  213. # '--server-response', # print headers for better error parsing
  214. '--no-verbose',
  215. '--adjust-extension',
  216. '--convert-links',
  217. '--force-directories',
  218. '--backup-converted',
  219. '--span-hosts',
  220. '--no-parent',
  221. '-e', 'robots=off',
  222. '--restrict-file-names=unix',
  223. '--timeout={}'.format(timeout),
  224. *(() if FETCH_WARC else ('--timestamping',)),
  225. *(('--warc-file={}'.format(warc_path),) if FETCH_WARC else ()),
  226. *(('--page-requisites',) if FETCH_WGET_REQUISITES else ()),
  227. *(('--user-agent={}'.format(WGET_USER_AGENT),) if WGET_USER_AGENT else ()),
  228. *(('--load-cookies', COOKIES_FILE) if COOKIES_FILE else ()),
  229. *(('--compression=auto',) if WGET_AUTO_COMPRESSION else ()),
  230. *((() if CHECK_SSL_VALIDITY else ('--no-check-certificate', '--no-hsts'))),
  231. link.url,
  232. ]
  233. status = 'succeeded'
  234. timer = TimedProgress(timeout, prefix=' ')
  235. try:
  236. result = run(cmd, stdout=PIPE, stderr=PIPE, cwd=link_dir, timeout=timeout)
  237. output = wget_output_path(link)
  238. # parse out number of files downloaded from last line of stderr:
  239. # "Downloaded: 76 files, 4.0M in 1.6s (2.52 MB/s)"
  240. output_tail = [
  241. line.strip()
  242. for line in (result.stdout + result.stderr).decode().rsplit('\n', 3)[-3:]
  243. if line.strip()
  244. ]
  245. files_downloaded = (
  246. int(output_tail[-1].strip().split(' ', 2)[1] or 0)
  247. if 'Downloaded:' in output_tail[-1]
  248. else 0
  249. )
  250. # Check for common failure cases
  251. if result.returncode > 0 and files_downloaded < 1:
  252. hints = (
  253. 'Got wget response code: {}.'.format(result.returncode),
  254. *output_tail,
  255. )
  256. if b'403: Forbidden' in result.stderr:
  257. raise ArchiveError('403 Forbidden (try changing WGET_USER_AGENT)', hints)
  258. if b'404: Not Found' in result.stderr:
  259. raise ArchiveError('404 Not Found', hints)
  260. if b'ERROR 500: Internal Server Error' in result.stderr:
  261. raise ArchiveError('500 Internal Server Error', hints)
  262. raise ArchiveError('Got an error from the server', hints)
  263. except Exception as err:
  264. status = 'failed'
  265. output = err
  266. finally:
  267. timer.end()
  268. return ArchiveResult(
  269. cmd=cmd,
  270. pwd=link_dir,
  271. cmd_version=WGET_VERSION,
  272. output=output,
  273. status=status,
  274. **timer.stats,
  275. )
  276. @enforce_types
  277. def should_fetch_pdf(link: Link, link_dir: Optional[str]=None) -> bool:
  278. if is_static_file(link.url):
  279. return False
  280. if os.path.exists(os.path.join(link_dir, 'output.pdf')):
  281. return False
  282. return FETCH_PDF
  283. @enforce_types
  284. def fetch_pdf(link: Link, link_dir: Optional[str]=None, timeout: int=TIMEOUT) -> ArchiveResult:
  285. """print PDF of site to file using chrome --headless"""
  286. output = 'output.pdf'
  287. cmd = [
  288. *chrome_args(TIMEOUT=timeout),
  289. '--print-to-pdf',
  290. link.url,
  291. ]
  292. status = 'succeeded'
  293. timer = TimedProgress(timeout, prefix=' ')
  294. try:
  295. result = run(cmd, stdout=PIPE, stderr=PIPE, cwd=link_dir, timeout=timeout)
  296. if result.returncode:
  297. hints = (result.stderr or result.stdout).decode()
  298. raise ArchiveError('Failed to print PDF', hints)
  299. chmod_file('output.pdf', cwd=link_dir)
  300. except Exception as err:
  301. status = 'failed'
  302. output = err
  303. finally:
  304. timer.end()
  305. return ArchiveResult(
  306. cmd=cmd,
  307. pwd=link_dir,
  308. cmd_version=CHROME_VERSION,
  309. output=output,
  310. status=status,
  311. **timer.stats,
  312. )
  313. @enforce_types
  314. def should_fetch_screenshot(link: Link, link_dir: Optional[str]=None) -> bool:
  315. if is_static_file(link.url):
  316. return False
  317. if os.path.exists(os.path.join(link_dir, 'screenshot.png')):
  318. return False
  319. return FETCH_SCREENSHOT
  320. @enforce_types
  321. def fetch_screenshot(link: Link, link_dir: Optional[str]=None, timeout: int=TIMEOUT) -> ArchiveResult:
  322. """take screenshot of site using chrome --headless"""
  323. output = 'screenshot.png'
  324. cmd = [
  325. *chrome_args(TIMEOUT=timeout),
  326. '--screenshot',
  327. link.url,
  328. ]
  329. status = 'succeeded'
  330. timer = TimedProgress(timeout, prefix=' ')
  331. try:
  332. result = run(cmd, stdout=PIPE, stderr=PIPE, cwd=link_dir, timeout=timeout)
  333. if result.returncode:
  334. hints = (result.stderr or result.stdout).decode()
  335. raise ArchiveError('Failed to take screenshot', hints)
  336. chmod_file(output, cwd=link_dir)
  337. except Exception as err:
  338. status = 'failed'
  339. output = err
  340. finally:
  341. timer.end()
  342. return ArchiveResult(
  343. cmd=cmd,
  344. pwd=link_dir,
  345. cmd_version=CHROME_VERSION,
  346. output=output,
  347. status=status,
  348. **timer.stats,
  349. )
  350. @enforce_types
  351. def should_fetch_dom(link: Link, link_dir: Optional[str]=None) -> bool:
  352. if is_static_file(link.url):
  353. return False
  354. if os.path.exists(os.path.join(link_dir, 'output.html')):
  355. return False
  356. return FETCH_DOM
  357. @enforce_types
  358. def fetch_dom(link: Link, link_dir: Optional[str]=None, timeout: int=TIMEOUT) -> ArchiveResult:
  359. """print HTML of site to file using chrome --dump-html"""
  360. output = 'output.html'
  361. output_path = os.path.join(link_dir, output)
  362. cmd = [
  363. *chrome_args(TIMEOUT=timeout),
  364. '--dump-dom',
  365. link.url
  366. ]
  367. status = 'succeeded'
  368. timer = TimedProgress(timeout, prefix=' ')
  369. try:
  370. with open(output_path, 'w+') as f:
  371. result = run(cmd, stdout=f, stderr=PIPE, cwd=link_dir, timeout=timeout)
  372. if result.returncode:
  373. hints = result.stderr.decode()
  374. raise ArchiveError('Failed to fetch DOM', hints)
  375. chmod_file(output, cwd=link_dir)
  376. except Exception as err:
  377. status = 'failed'
  378. output = err
  379. finally:
  380. timer.end()
  381. return ArchiveResult(
  382. cmd=cmd,
  383. pwd=link_dir,
  384. cmd_version=CHROME_VERSION,
  385. output=output,
  386. status=status,
  387. **timer.stats,
  388. )
  389. @enforce_types
  390. def should_fetch_git(link: Link, link_dir: Optional[str]=None) -> bool:
  391. if is_static_file(link.url):
  392. return False
  393. if os.path.exists(os.path.join(link_dir, 'git')):
  394. return False
  395. is_clonable_url = (
  396. (domain(link.url) in GIT_DOMAINS)
  397. or (extension(link.url) == 'git')
  398. )
  399. if not is_clonable_url:
  400. return False
  401. return FETCH_GIT
  402. @enforce_types
  403. def fetch_git(link: Link, link_dir: Optional[str]=None, timeout: int=TIMEOUT) -> ArchiveResult:
  404. """download full site using git"""
  405. output = 'git'
  406. output_path = os.path.join(link_dir, 'git')
  407. os.makedirs(output_path, exist_ok=True)
  408. cmd = [
  409. GIT_BINARY,
  410. 'clone',
  411. '--mirror',
  412. '--recursive',
  413. *(() if CHECK_SSL_VALIDITY else ('-c', 'http.sslVerify=false')),
  414. without_query(without_fragment(link.url)),
  415. ]
  416. status = 'succeeded'
  417. timer = TimedProgress(timeout, prefix=' ')
  418. try:
  419. result = run(cmd, stdout=PIPE, stderr=PIPE, cwd=output_path, timeout=timeout + 1)
  420. if result.returncode == 128:
  421. # ignore failed re-download when the folder already exists
  422. pass
  423. elif result.returncode > 0:
  424. hints = 'Got git response code: {}.'.format(result.returncode)
  425. raise ArchiveError('Failed git download', hints)
  426. except Exception as err:
  427. status = 'failed'
  428. output = err
  429. finally:
  430. timer.end()
  431. return ArchiveResult(
  432. cmd=cmd,
  433. pwd=link_dir,
  434. cmd_version=GIT_VERSION,
  435. output=output,
  436. status=status,
  437. **timer.stats,
  438. )
  439. @enforce_types
  440. def should_fetch_media(link: Link, link_dir: Optional[str]=None) -> bool:
  441. if is_static_file(link.url):
  442. return False
  443. if os.path.exists(os.path.join(link_dir, 'media')):
  444. return False
  445. return FETCH_MEDIA
  446. @enforce_types
  447. def fetch_media(link: Link, link_dir: Optional[str]=None, timeout: int=MEDIA_TIMEOUT) -> ArchiveResult:
  448. """Download playlists or individual video, audio, and subtitles using youtube-dl"""
  449. output = 'media'
  450. output_path = os.path.join(link_dir, 'media')
  451. os.makedirs(output_path, exist_ok=True)
  452. cmd = [
  453. YOUTUBEDL_BINARY,
  454. '--write-description',
  455. '--write-info-json',
  456. '--write-annotations',
  457. '--yes-playlist',
  458. '--write-thumbnail',
  459. '--no-call-home',
  460. '--no-check-certificate',
  461. '--user-agent',
  462. '--all-subs',
  463. '--extract-audio',
  464. '--keep-video',
  465. '--ignore-errors',
  466. '--geo-bypass',
  467. '--audio-format', 'mp3',
  468. '--audio-quality', '320K',
  469. '--embed-thumbnail',
  470. '--add-metadata',
  471. *(() if CHECK_SSL_VALIDITY else ('--no-check-certificate',)),
  472. link.url,
  473. ]
  474. status = 'succeeded'
  475. timer = TimedProgress(timeout, prefix=' ')
  476. try:
  477. result = run(cmd, stdout=PIPE, stderr=PIPE, cwd=output_path, timeout=timeout + 1)
  478. chmod_file(output, cwd=link_dir)
  479. if result.returncode:
  480. if (b'ERROR: Unsupported URL' in result.stderr
  481. or b'HTTP Error 404' in result.stderr
  482. or b'HTTP Error 403' in result.stderr
  483. or b'URL could be a direct video link' in result.stderr
  484. or b'Unable to extract container ID' in result.stderr):
  485. # These happen too frequently on non-media pages to warrant printing to console
  486. pass
  487. else:
  488. hints = (
  489. 'Got youtube-dl response code: {}.'.format(result.returncode),
  490. *result.stderr.decode().split('\n'),
  491. )
  492. raise ArchiveError('Failed to download media', hints)
  493. except Exception as err:
  494. status = 'failed'
  495. output = err
  496. finally:
  497. timer.end()
  498. return ArchiveResult(
  499. cmd=cmd,
  500. pwd=link_dir,
  501. cmd_version=YOUTUBEDL_VERSION,
  502. output=output,
  503. status=status,
  504. **timer.stats,
  505. )
  506. @enforce_types
  507. def should_fetch_archive_dot_org(link: Link, link_dir: Optional[str]=None) -> bool:
  508. if is_static_file(link.url):
  509. return False
  510. if os.path.exists(os.path.join(link_dir, 'archive.org.txt')):
  511. # if open(path, 'r').read().strip() != 'None':
  512. return False
  513. return SUBMIT_ARCHIVE_DOT_ORG
  514. @enforce_types
  515. def archive_dot_org(link: Link, link_dir: Optional[str]=None, timeout: int=TIMEOUT) -> ArchiveResult:
  516. """submit site to archive.org for archiving via their service, save returned archive url"""
  517. output = 'archive.org.txt'
  518. archive_org_url = None
  519. submit_url = 'https://web.archive.org/save/{}'.format(link.url)
  520. cmd = [
  521. CURL_BINARY,
  522. '--location',
  523. '--head',
  524. '--user-agent', 'ArchiveBox/{} (+https://github.com/pirate/ArchiveBox/)'.format(VERSION), # be nice to the Archive.org people and show them where all this ArchiveBox traffic is coming from
  525. '--max-time', str(timeout),
  526. *(() if CHECK_SSL_VALIDITY else ('--insecure',)),
  527. submit_url,
  528. ]
  529. status = 'succeeded'
  530. timer = TimedProgress(timeout, prefix=' ')
  531. try:
  532. result = run(cmd, stdout=PIPE, stderr=DEVNULL, cwd=link_dir, timeout=timeout)
  533. content_location, errors = parse_archive_dot_org_response(result.stdout)
  534. if content_location:
  535. archive_org_url = 'https://web.archive.org{}'.format(content_location[0])
  536. elif len(errors) == 1 and 'RobotAccessControlException' in errors[0]:
  537. archive_org_url = None
  538. # raise ArchiveError('Archive.org denied by {}/robots.txt'.format(domain(link.url)))
  539. elif errors:
  540. raise ArchiveError(', '.join(errors))
  541. else:
  542. raise ArchiveError('Failed to find "content-location" URL header in Archive.org response.')
  543. except Exception as err:
  544. status = 'failed'
  545. output = err
  546. finally:
  547. timer.end()
  548. if not isinstance(output, Exception):
  549. # instead of writing None when archive.org rejects the url write the
  550. # url to resubmit it to archive.org. This is so when the user visits
  551. # the URL in person, it will attempt to re-archive it, and it'll show the
  552. # nicer error message explaining why the url was rejected if it fails.
  553. archive_org_url = archive_org_url or submit_url
  554. with open(os.path.join(link_dir, output), 'w', encoding='utf-8') as f:
  555. f.write(archive_org_url)
  556. chmod_file('archive.org.txt', cwd=link_dir)
  557. output = archive_org_url
  558. return ArchiveResult(
  559. cmd=cmd,
  560. pwd=link_dir,
  561. cmd_version=CURL_VERSION,
  562. output=output,
  563. status=status,
  564. **timer.stats,
  565. )
  566. @enforce_types
  567. def parse_archive_dot_org_response(response: bytes) -> Tuple[List[str], List[str]]:
  568. # Parse archive.org response headers
  569. headers: Dict[str, List[str]] = defaultdict(list)
  570. # lowercase all the header names and store in dict
  571. for header in response.splitlines():
  572. if b':' not in header or not header.strip():
  573. continue
  574. name, val = header.decode().split(':', 1)
  575. headers[name.lower().strip()].append(val.strip())
  576. # Get successful archive url in "content-location" header or any errors
  577. content_location = headers['content-location']
  578. errors = headers['x-archive-wayback-runtime-error']
  579. return content_location, errors