127 lines
4.2 KiB
Markdown
127 lines
4.2 KiB
Markdown
# ChatGPT Shared Chat Exporter
|
|
|
|
Export a public ChatGPT shared conversation link to a clean Markdown file.
|
|
|
|
The exporter reads the structured conversation data embedded in ChatGPT share pages, then writes the visible user/assistant conversation path as Markdown with clean metadata tables.
|
|
|
|
## Features
|
|
|
|
- exports public `https://chatgpt.com/share/...` links
|
|
- preserves Markdown-formatted message content, including headings, lists, code blocks, and tables
|
|
- includes conversation metadata such as title, source URL, conversation ID, timestamps, and model slug
|
|
- includes per-message metadata such as author, message ID, created/updated time, status, channel, recipient, model, request ID, and turn ID
|
|
- records uploaded image/file metadata such as name, MIME type, size, dimensions, and source pointer
|
|
- converts Markdown exports to clean PDF files
|
|
- supports RTL PDF layout for Persian/Arabic chats
|
|
- supports custom PDF font family, font file, font size, page size, and margins
|
|
- can include hidden/system/internal nodes when requested
|
|
|
|
## Requirements
|
|
|
|
- Python 3.9 or newer
|
|
- network access to `chatgpt.com` for live exports
|
|
|
|
## Quick Start
|
|
|
|
Run directly from the repository:
|
|
|
|
```bash
|
|
python3 main.py "https://chatgpt.com/share/YOUR_SHARE_ID"
|
|
```
|
|
|
|
By default, exports are written to `exports/`, which is ignored by Git so private chat content is not committed accidentally.
|
|
|
|
## Install Locally
|
|
|
|
```bash
|
|
python3 -m pip install -e .
|
|
chatgpt-share-exporter "https://chatgpt.com/share/YOUR_SHARE_ID"
|
|
```
|
|
|
|
This installs the PDF dependencies too.
|
|
|
|
## Options
|
|
|
|
```bash
|
|
chatgpt-share-exporter URL --timezone UTC
|
|
chatgpt-share-exporter URL --include-hidden
|
|
chatgpt-share-exporter URL --all-nodes
|
|
chatgpt-share-exporter URL --stdout
|
|
chatgpt-share-exporter URL -o my_exports --overwrite
|
|
```
|
|
|
|
- `--timezone`: format message times in `local`, `UTC`, or an IANA timezone like `Asia/Tehran`
|
|
- `--include-hidden`: include system/internal messages that ChatGPT normally hides
|
|
- `--all-nodes`: export every mapping node, including non-selected branches
|
|
- `--stdout`: print Markdown instead of writing a file
|
|
- `--overwrite`: replace the default output file instead of creating a numbered copy
|
|
- `--html-file`: parse an already downloaded share page instead of fetching the URL
|
|
- `--timeout`: set the download timeout in seconds
|
|
|
|
## Convert Exports To PDF
|
|
|
|
Convert every Markdown export in `exports/`:
|
|
|
|
```bash
|
|
chatgpt-share-exporter pdf exports
|
|
```
|
|
|
|
or use the dedicated command:
|
|
|
|
```bash
|
|
chatgpt-export-to-pdf exports
|
|
```
|
|
|
|
Generate an RTL PDF:
|
|
|
|
```bash
|
|
chatgpt-share-exporter pdf exports --rtl
|
|
```
|
|
|
|
Use a custom font and size:
|
|
|
|
```bash
|
|
chatgpt-share-exporter pdf exports \
|
|
--font-family Vazirmatn \
|
|
--font-path ./fonts/Vazirmatn-Regular.ttf \
|
|
--font-size 14
|
|
```
|
|
|
|
PDF options:
|
|
|
|
- `--direction auto|ltr|rtl`: choose PDF text direction. Default: `auto`
|
|
- `--rtl`: shortcut for `--direction rtl`
|
|
- `--ltr`: shortcut for `--direction ltr`
|
|
- `--font-family`: preferred body font family. Default: `Vazirmatn`
|
|
- `--font-path`: explicit `.ttf` or `.otf` font file path
|
|
- `--font-size`: base font size in points. Default: `14`
|
|
- `--page-size A4|Letter`: PDF page size. Default: `A4`
|
|
- `--margin-mm`: page margin in millimeters. Default: `16`
|
|
- `--recursive`: convert Markdown files in nested export directories
|
|
- `--overwrite`: replace existing PDF files
|
|
|
|
Generated PDFs are written to `pdf_exports/`, which is ignored by Git.
|
|
|
|
For best Persian output, install Vazirmatn locally or pass its font file with `--font-path`. If Vazirmatn is not installed, the converter searches for common system fallbacks such as Arial Unicode, Tahoma, DejaVu Sans, and Noto Arabic fonts.
|
|
|
|
## Development
|
|
|
|
Run tests:
|
|
|
|
```bash
|
|
python3 -m unittest discover -s tests
|
|
```
|
|
|
|
Run a syntax check:
|
|
|
|
```bash
|
|
python3 -m py_compile main.py chatgpt_share_exporter.py chatgpt_pdf_converter.py tests/test_exporter.py tests/test_pdf_converter.py
|
|
```
|
|
|
|
## Notes
|
|
|
|
- Only public ChatGPT shared links are supported.
|
|
- If ChatGPT returns a browser challenge instead of the shared chat HTML, the exporter cannot parse that response.
|
|
- ChatGPT may change its share-page format; the parser is tested against the current embedded React Router payload and a fallback `__NEXT_DATA__` payload.
|
|
- This project is not affiliated with OpenAI.
|