Metadata-Version: 2.4
Name: wayback2warc
Version: 0.1.3
Summary: WARC exporter for the Wayback Machine
Author-email: tmctmt <tmctmt@proton.me>
License: MIT License
        
        Copyright (c) 2026 tmctmt
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Keywords: Internet Archive,Wayback Machine,WARC
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Intended Audience :: System Administrators
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Topic :: Utilities
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: httpx[socks]==0.28.1
Requires-Dist: tqdm==4.67.3
Requires-Dist: warcio==1.8.1
Dynamic: license-file

# wayback2warc
![PyPI - Version](https://img.shields.io/pypi/v/wayback2warc)

A CLI tool that exports captures from the Wayback Machine and packs them into WARC files.

```
usage: wayback2warc [-h] [-c COLLAPSE] [-f FILTER] [-m] [-p PROXY] [-t THREADS] [-w WARC_SIZE] url [prefix]

positional arguments:
  url                   *.example.org or example.org/*
  prefix                output path prefix

options:
  -h, --help            show this help message and exit
  -c, --collapse COLLAPSE
                        dedupe records based on returned key
  -f, --filter FILTER   filter records based on returned boolean
  -m, --meta            dump cdx metadata into stdout
  -p, --proxy PROXY     url formatted proxy, can be a single value or a file
  -t, --threads THREADS
                        concurrent downloads (default: 2)
  -w, --warc-size WARC_SIZE
                        max size of produced warc files in MB (default: 1024)
```

## Install
`pip install wayback2warc`

## Usage

Download all subdomains, all pages, and all captures for a domain:

`wayback2warc '*.example.org'`

Download all pages and all captures for a prefix:

`wayback2warc 'example.org/*'`

Download all captures for a single page:

`wayback2warc 'example.org'`

Download all pages but only a yearly capture of each:

`wayback2warc 'example.org/*' --collapse 'lambda m: (m.urlkey, m.timestamp[:4])'`

## Filtering and collapsing
This tool implements filtering/collapsing functionality on the client-side rather than relying on the CDX server to do so.
This is a necessity due to the way CDX paging works, but on the bright side it allows for much more granular queries.

Instead of a query language, lambda functions are used to narrow down captures for downloading.
A [CaptureMetadata](https://github.com/tmctmt/wayback2warc/blob/main/wayback2warc.py#L28) instance is passed to both functions, and the returned value is used as a key for collapsing, or as a boolean for filtering.

Collapse captures by URL excluding query:
`--collapse 'lambda m: m.urlkey.split("?")[0]'`

Filter captures before 2020 and exclude images:
`--filter 'lambda m: m.timestamp < "2020" and "image/" not in m.mimetype'`

## WARC records
The generated WARC files use per-record GZIP compression. Request records are not included. Response record payloads are always saved uncompressed with a `Content-Length` header, any `Content-Encoding` or `Transfer-Encoding` headers are stripped. Headers and status-lines are reconstructed on a best-effort basis, but the capitalization and order of headers may differ from the original capture. The HTTP version is always set to HTTP/1.1.
