pinterest-dl 2.3.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.yardopts +7 -0
- data/CHANGELOG.md +33 -0
- data/README.md +174 -145
- data/bin/pinterest-dl +1 -162
- data/lib/pinterest-dl.rb +9 -1
- data/lib/pinterest_dl/api.rb +47 -22
- data/lib/pinterest_dl/board.rb +38 -45
- data/lib/pinterest_dl/cli.rb +455 -0
- data/lib/pinterest_dl/client.rb +53 -200
- data/lib/pinterest_dl/configuration.rb +77 -24
- data/lib/pinterest_dl/cookie_jar.rb +318 -0
- data/lib/pinterest_dl/downloader.rb +735 -46
- data/lib/pinterest_dl/errors.rb +129 -15
- data/lib/pinterest_dl/extractors/image.rb +60 -9
- data/lib/pinterest_dl/extractors/pin_data.rb +158 -32
- data/lib/pinterest_dl/extractors/video.rb +42 -10
- data/lib/pinterest_dl/media_validator.rb +110 -0
- data/lib/pinterest_dl/models.rb +169 -0
- data/lib/pinterest_dl/paginator.rb +81 -0
- data/lib/pinterest_dl/progress_bar.rb +195 -4
- data/lib/pinterest_dl/search.rb +30 -44
- data/lib/pinterest_dl/security.rb +208 -0
- data/lib/pinterest_dl/session.rb +65 -0
- data/lib/pinterest_dl/transport.rb +326 -0
- data/lib/pinterest_dl/tui/app.rb +498 -0
- data/lib/pinterest_dl/tui/download_queue.rb +423 -0
- data/lib/pinterest_dl/tui/icons.rb +113 -0
- data/lib/pinterest_dl/tui/preview.rb +674 -0
- data/lib/pinterest_dl/tui/renderer.rb +738 -0
- data/lib/pinterest_dl/tui/state.rb +190 -0
- data/lib/pinterest_dl/tui/terminal.rb +281 -0
- data/lib/pinterest_dl/tui/theme.rb +318 -0
- data/lib/pinterest_dl/tui.rb +53 -0
- data/lib/pinterest_dl/version.rb +1 -1
- metadata +21 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 06f9da770a1496d3fc28b544aeb6fbdcce51f8813e37fe8e86b63d914da6c9aa
|
|
4
|
+
data.tar.gz: 309c75d2cc74400c3c2b253384a1e2685016df132fe97d7d0e8e13795e4e6dc0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 22c2c1e6615127d0e88632819557b52f6ff8c6c1e79dcda1a5fa6c02ec28832906e3a14f8107304840d321eb4dc39ce8a67e4125d4ebf02f3bd01c827ecd9194
|
|
7
|
+
data.tar.gz: a162d41d166663d1387af18ce04a011b55a8c6b776ec34e3b1542efa98863eee5a0c3e978560672f2b41e640e9479e70a137d2b8069bfa6851eeb61eceaa8a78
|
data/.yardopts
ADDED
data/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,39 @@
|
|
|
3
3
|
All notable changes to this project are documented here.
|
|
4
4
|
This project follows [Semantic Versioning](https://semver.org/).
|
|
5
5
|
|
|
6
|
+
## [2.5.0]
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
- Interactive terminal UI (`pinterest-dl tui` or running `pinterest-dl` in an interactive terminal) with gallery browsing, category filtering, configurable search result limits (`1`–`200`), right-panel quality selector, full mouse support, and multi-select batch downloading.
|
|
10
|
+
- Multi-protocol HD image preview pipeline with automatic detection for Kitty Graphics Protocol (Kitty, Ghostty, WezTerm, Konsole), iTerm2 Inline Images (iTerm2, Tabby, Hyper, Warp), Sixel (Windows Terminal, Foot, mlterm, Contour), `ueberzugpp` X11 overlays, and 24-bit half-block fallback (`ffmpeg`, ImageMagick, `chafa`, Pillow, `djpeg`).
|
|
11
|
+
- Automatic proxy (`HTTPS_PROXY`/`HTTP_PROXY`/`ALL_PROXY`) and `cookies.txt` detection for zero-config TUI startup, full multi-byte UTF-8 keyboard support, and auto-clearing completed download queue entries.
|
|
12
|
+
|
|
13
|
+
## [2.4.0]
|
|
14
|
+
|
|
15
|
+
### Security
|
|
16
|
+
- Added `PinterestDL::Security` with strict URL/host validation, SSRF protection against private, loopback, link-local, and metadata IP ranges (`SSRFError`), and rejection of embedded URL credentials.
|
|
17
|
+
- Added `PinterestDL::CookieJar` preserving `Domain`, `Path`, `Secure`, `HttpOnly`, and `Expires`/`Max-Age` attributes and strictly preventing cookies from being sent to CDN (`*.pinimg.com`), shortener (`pin.it`), or external hosts.
|
|
18
|
+
- Cross-domain redirects are now validated against trusted hosts (`RedirectError`) and strip sensitive headers (`Cookie`, `Authorization`, `X-CSRFToken`) when crossing security domains.
|
|
19
|
+
- Added `PinterestDL::MediaValidator` to verify HTTP `Content-Type` headers and binary file signatures (JPEG, PNG, GIF, WebP, MP4, WebM) and reject HTML/JSON error pages disguised as media (`InvalidMediaError`).
|
|
20
|
+
- Enforced configurable maximum download file size (`config.max_file_size`, default 500 MB, or `--max-size` on the CLI) with `FileTooLargeError`.
|
|
21
|
+
- Logger output automatically redacts cookies, CSRF tokens, session IDs, and proxy passwords.
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
- `PinterestDL::Session` (`PinterestDL.session`) for fully isolated per-client configuration and cookie jars without global state interference.
|
|
25
|
+
- `PinterestDL::Transport` layer with exponential backoff and random jitter (`retry_jitter`, `max_retry_wait`), plus full support for both integer and HTTP-date `Retry-After` headers.
|
|
26
|
+
- `PinterestDL::Paginator` for unified cursor/bookmark pagination across `Search` and `Board`, with duplicate bookmark cycle detection and `Enumerable` support.
|
|
27
|
+
- `PinterestDL::Pin` and `PinterestDL::DownloadReport` models supporting both object-oriented methods and Hash `[]`/`dig` access.
|
|
28
|
+
- Resumable downloads (`Range: bytes=N-` with HTTP `206 Partial Content`) via `resume: true` and `--resume`/`--no-resume`.
|
|
29
|
+
- Download speed throttling (`max_speed:` / `--max-speed`, e.g. `500K`, `2M`), batch URL deduplication (`deduplicate: true`), smart filename collision handling (`collision_strategy: :rename`), and disk space / write-permission error handling (`DiskSpaceError`).
|
|
30
|
+
- Live byte-level `ProgressBar` showing percentage, received/total bytes, download speed, ETA, and media type badge (`[IMAGE]` / `[VIDEO]`), with `--no-progress` and `--non-interactive` flags.
|
|
31
|
+
- Extracted CLI logic into `PinterestDL::CLI` (`lib/pinterest_dl/cli.rb`) with `--format text|json|csv|quiet`, `--json`, `--images-only`, `--videos-only`, and actionable error hints.
|
|
32
|
+
- Expanded error hierarchy: `ForbiddenError` (distinct from `RateLimitError`), `TimeoutError`, `ConnectionError`, `SSLError`, `RedirectError`, `SSRFError`, `InvalidResponseError`, `FileTooLargeError`, `IncompleteDownloadError`, `InvalidMediaError`, and `DiskSpaceError`.
|
|
33
|
+
|
|
34
|
+
### Fixed
|
|
35
|
+
- `Extractors::PinData.best_image_url` now ranks image variants by resolution area and bucket priority instead of relying on hash insertion order.
|
|
36
|
+
- Added support for `__NEXT_DATA__`, `window.__INITIAL_STATE__`, `srcset`, and `<video>`/`<source>` fallbacks when extracting media from HTML.
|
|
37
|
+
- Fixed race conditions and thread exception propagation in `Downloader#download_batch`, and verified `Content-Length` to detect truncated downloads (`IncompleteDownloadError`).
|
|
38
|
+
|
|
6
39
|
## [2.3.0]
|
|
7
40
|
|
|
8
41
|
### Added
|
data/README.md
CHANGED
|
@@ -1,29 +1,23 @@
|
|
|
1
1
|
# pinterest-dl
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
**Extract direct image and video URLs from Pinterest pins, search pins, fetch board contents, and download media from Ruby or the command line.**
|
|
4
4
|
|
|
5
5
|
[](https://rubygems.org/gems/pinterest-dl)
|
|
6
|
-
[](https://rubygems.org/gems/pinterest-dl)
|
|
7
6
|
[](https://github.com/monji024/pinterest-dl/actions/workflows/ci.yml)
|
|
8
7
|
[](LICENSE)
|
|
9
|
-
[](https://www.ruby-lang.org/)
|
|
10
9
|
|
|
11
|
-
|
|
10
|
+
Pinterest does not provide a public API for resolving direct media URLs from pin links, paginating public boards, or downloading pin media in bulk. `pinterest-dl` extracts direct `i.pinimg.com` and `v.pinimg.com` media URLs from pin pages and Pinterest's web resource endpoints, with zero runtime gem dependencies.
|
|
12
11
|
|
|
13
|
-
> **
|
|
14
|
-
> (Yeah, because even in 2026 Pinterest still gives you the middle finger on clean APIs.)
|
|
12
|
+
> **Network note:** Users in regions where Pinterest is restricted may need an HTTP/HTTPS proxy (`--proxy` or `config.proxy`).
|
|
15
13
|
|
|
16
|
-
|
|
14
|
+
## Features
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
-
|
|
21
|
-
- **
|
|
22
|
-
-
|
|
23
|
-
- **Downloads** a URL or a whole batch in parallel (multi-threaded, written to `.part` files first so interrupted runs don't leave broken files on disk).
|
|
24
|
-
- Supports **authenticated requests** via raw cookie strings or a Netscape `cookies.txt` file, for boards/pins that require a logged-in session.
|
|
25
|
-
- Raises **specific, catchable exceptions** (`NotFoundError`, `RateLimitError`, `NetworkError`, ...) instead of returning `nil` or printing to stdout.
|
|
26
|
-
- Ships a **CLI** (`pinterest-dl`) for one-off use from the shell.
|
|
16
|
+
- **Direct media extraction**: Resolves original or resized image URLs (`originals`, `1200x`, `736x`, `564x`, `474x`, `236x`) and highest-resolution `.mp4` video URLs from pin URLs, country subdomains, and `pin.it` short links.
|
|
17
|
+
- **Search and boards**: Queries Pinterest search and board/section feeds with automatic cursor pagination, duplicate pin filtering, and embedded HTML fallback.
|
|
18
|
+
- **Reliable downloading**: Streams files to temporary `.part` files with atomic rename on completion, validated HTTP `206 Partial Content` (`Content-Range`) and `416` resume support, `Content-Type` and magic-byte verification, configurable file-size caps, bandwidth throttling, and multi-threaded batch workers.
|
|
19
|
+
- **Security by default**: Blocks SSRF against loopback/private/link-local addresses, scopes cookies strictly to Pinterest domains (never leaking session cookies to CDN or third-party hosts), strips sensitive headers on cross-domain redirects, and redacts tokens/cookies from logs.
|
|
20
|
+
- **Isolated sessions**: Supports both global configuration (`PinterestDL.configure`) and independent per-client instances (`PinterestDL.session`).
|
|
27
21
|
|
|
28
22
|
## Installation
|
|
29
23
|
|
|
@@ -31,192 +25,227 @@ Pinterest doesn't give you a clean, official API for getting a direct media URL
|
|
|
31
25
|
gem install pinterest-dl
|
|
32
26
|
```
|
|
33
27
|
|
|
34
|
-
Or add
|
|
28
|
+
Or add to your `Gemfile`:
|
|
35
29
|
|
|
36
30
|
```ruby
|
|
37
31
|
gem 'pinterest-dl'
|
|
38
32
|
```
|
|
39
33
|
|
|
40
|
-
|
|
34
|
+
Requires Ruby **3.0 or newer** (no external runtime dependencies).
|
|
41
35
|
|
|
42
|
-
|
|
43
|
-
require 'pinterest-dl'
|
|
36
|
+
## Quick Start
|
|
44
37
|
|
|
45
|
-
|
|
46
|
-
PinterestDL.get_image_url('https://www.pinterest.com/pin/1234567890123456789/')
|
|
47
|
-
# => "https://i.pinimg.com/originals/aa/bb/cc/aabbcc...jpg"
|
|
38
|
+
### Interactive TUI
|
|
48
39
|
|
|
49
|
-
|
|
50
|
-
PinterestDL.get_video_url('https://www.pinterest.com/pin/1234567890123456789/')
|
|
51
|
-
# => "https://v.pinimg.com/videos/mc/720p/aa/bb/cc/aabbcc....mp4"
|
|
40
|
+
Launch the interactive terminal interface with gallery browsing, live previews, quality selection, mouse controls, and batch downloading:
|
|
52
41
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
path: 'downloads/pin.jpg'
|
|
57
|
-
)
|
|
42
|
+
```bash
|
|
43
|
+
pinterest-dl tui
|
|
44
|
+
# or simply run `pinterest-dl` in an interactive terminal
|
|
58
45
|
```
|
|
59
46
|
|
|
60
|
-
|
|
47
|
+
Proxy environment variables (`HTTPS_PROXY`, `HTTP_PROXY`, `ALL_PROXY`) and local `cookies.txt` files are detected automatically.
|
|
61
48
|
|
|
62
|
-
|
|
49
|
+
**Image preview rendering** depends on your terminal's graphics support:
|
|
50
|
+
- **Full-resolution native images (recommended):** Works out of the box in **Kitty**, **Ghostty**, **WezTerm**, **Konsole** (Kitty Graphics Protocol), **iTerm2** / **Tabby** / **Hyper** / **Warp** (iTerm2 Inline Images), and **Windows Terminal** / **Foot** / **mlterm** / **Contour** (Sixel with `chafa` or `img2sixel`).
|
|
51
|
+
- **Standard X11 terminals (GNOME Terminal, Pop!_OS Terminal, XFCE4 Terminal, Alacritty):** Require `ueberzugpp` for native unpixelated overlays. Without `ueberzugpp`, standard text-only terminals automatically fall back to 24-bit half-block previews (via `ffmpeg`, ImageMagick, `chafa`, Pillow, or `djpeg`).
|
|
63
52
|
|
|
64
|
-
|
|
65
|
-
url = PinterestDL.get_image_url('https://www.pinterest.com/pin/example/')
|
|
66
|
-
|
|
67
|
-
# Pick a specific size bucket
|
|
68
|
-
url = PinterestDL.get_image_url('https://www.pinterest.com/pin/example/', quality: :"736x")
|
|
69
|
-
# quality can be :originals, :"1200x", :"736x", :"564x", :"474x", :"236x"
|
|
53
|
+
#### Optional: Install `ueberzugpp` on Ubuntu / Pop!_OS
|
|
70
54
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
55
|
+
```bash
|
|
56
|
+
echo 'deb http://download.opensuse.org/repositories/home:/justkidding/xUbuntu_26.04/ /' | sudo tee /etc/apt/sources.list.d/home:justkidding.list
|
|
57
|
+
curl -fsSL https://download.opensuse.org/repositories/home:justkidding/xUbuntu_26.04/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/home_justkidding.gpg > /dev/null
|
|
58
|
+
sudo apt update
|
|
59
|
+
sudo apt install ueberzugpp
|
|
76
60
|
```
|
|
77
61
|
|
|
78
|
-
|
|
62
|
+
*(Replace `xUbuntu_26.04` with `xUbuntu_24.04` or `xUbuntu_22.04` for earlier Ubuntu or Pop!_OS releases.)*
|
|
79
63
|
|
|
80
|
-
|
|
81
|
-
results = PinterestDL.search('nature landscape', limit: 10)
|
|
82
|
-
# => [{ id: "...", pin_url: "...", title: "...", description: "...", creator: "...", image_url: "...", video_url: nil }, ...]
|
|
64
|
+
### CLI
|
|
83
65
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
66
|
+
```bash
|
|
67
|
+
# Print direct image or video URL
|
|
68
|
+
pinterest-dl image https://www.pinterest.com/pin/1234567890123456789/
|
|
69
|
+
pinterest-dl video https://pin.it/3vYQ7zmM5
|
|
87
70
|
|
|
88
|
-
|
|
89
|
-
|
|
71
|
+
# Download a pin image or video to disk (displays live progress bar)
|
|
72
|
+
pinterest-dl image https://www.pinterest.com/pin/1234567890123456789/ -o pin.jpg
|
|
73
|
+
pinterest-dl video https://pin.it/3vYQ7zmM5 -o video.mp4
|
|
90
74
|
|
|
91
|
-
|
|
92
|
-
|
|
75
|
+
# Inspect both image and video URLs as JSON
|
|
76
|
+
pinterest-dl media https://www.pinterest.com/pin/1234567890123456789/
|
|
93
77
|
|
|
94
|
-
|
|
78
|
+
# Search pins and download 50 results using 6 worker threads
|
|
79
|
+
pinterest-dl search "architectural photography" -n 50 -j 6 -o ./downloads
|
|
80
|
+
|
|
81
|
+
# Download only videos from a board, skipping existing files
|
|
82
|
+
pinterest-dl board https://www.pinterest.com/username/board-name/ --videos-only -n 100 -s -o ./videos
|
|
95
83
|
```
|
|
96
84
|
|
|
97
|
-
###
|
|
85
|
+
### Ruby Library
|
|
98
86
|
|
|
99
87
|
```ruby
|
|
100
|
-
|
|
101
|
-
pins = PinterestDL.board('https://www.pinterest.com/username/board-name/', limit: 100)
|
|
88
|
+
require 'pinterest-dl'
|
|
102
89
|
|
|
103
|
-
#
|
|
104
|
-
|
|
90
|
+
# Extract direct URLs
|
|
91
|
+
image_url = PinterestDL.get_image_url('https://www.pinterest.com/pin/1234567890123456789/')
|
|
92
|
+
video_url = PinterestDL.get_video_url('https://www.pinterest.com/pin/1234567890123456789/')
|
|
93
|
+
media = PinterestDL.get_media('https://www.pinterest.com/pin/1234567890123456789/', quality: :'736x')
|
|
94
|
+
# => { image_url: "https://i.pinimg.com/736x/...", video_url: nil }
|
|
105
95
|
|
|
106
|
-
#
|
|
107
|
-
|
|
96
|
+
# Download a single file
|
|
97
|
+
PinterestDL.download(image_url, path: 'downloads/pin.jpg', resume: true)
|
|
108
98
|
```
|
|
109
99
|
|
|
110
|
-
|
|
100
|
+
## Library Usage
|
|
101
|
+
|
|
102
|
+
### Isolated Sessions
|
|
103
|
+
|
|
104
|
+
Use `PinterestDL.session` when running multiple configurations or accounts concurrently without mutating `PinterestDL.config`:
|
|
111
105
|
|
|
112
106
|
```ruby
|
|
113
|
-
|
|
114
|
-
|
|
107
|
+
session = PinterestDL.session(
|
|
108
|
+
cookies: File.expand_path('~/cookies.txt'),
|
|
109
|
+
quality: :'1200x',
|
|
110
|
+
concurrency: 6,
|
|
111
|
+
max_speed: '2M'
|
|
112
|
+
)
|
|
115
113
|
|
|
116
|
-
|
|
117
|
-
|
|
114
|
+
pins = session.board('https://www.pinterest.com/username/board-name/', limit: 50)
|
|
115
|
+
report = session.download_batch(pins, dir: './downloads', collision_strategy: :rename)
|
|
116
|
+
```
|
|
118
117
|
|
|
119
|
-
|
|
120
|
-
urls = PinterestDL.search_images('mountains', limit: 40)
|
|
121
|
-
result = PinterestDL.download_batch(urls, dir: './downloads', concurrency: 6, overwrite: false)
|
|
118
|
+
### Search and Boards
|
|
122
119
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
PinterestDL.
|
|
126
|
-
|
|
127
|
-
|
|
120
|
+
```ruby
|
|
121
|
+
# Search returns an Array of pin hashes ({ id:, pin_url:, title:, description:, creator:, image_url:, video_url: })
|
|
122
|
+
pins = PinterestDL.search('minimalist poster', limit: 25, type: :all)
|
|
123
|
+
image_urls = PinterestDL.search_images('sunset', limit: 10)
|
|
124
|
+
video_urls = PinterestDL.search_videos('motion graphics', limit: 5)
|
|
125
|
+
|
|
126
|
+
# Fetch pins from a board or board section
|
|
127
|
+
board_pins = PinterestDL.board('https://www.pinterest.com/username/board-name/', limit: 100)
|
|
128
|
+
section_pins = PinterestDL.board('https://www.pinterest.com/username/board-name/section-slug/', limit: 50)
|
|
128
129
|
```
|
|
129
130
|
|
|
130
|
-
###
|
|
131
|
+
### Batch Downloading & Collision Strategies
|
|
131
132
|
|
|
132
|
-
|
|
133
|
+
`download_batch` accepts an array of URLs or pin hashes and returns a `PinterestDL::DownloadReport` (which supports both method access like `report.succeeded` and Hash access like `report[:succeeded]`):
|
|
133
134
|
|
|
134
135
|
```ruby
|
|
135
|
-
PinterestDL.
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
136
|
+
urls = PinterestDL.search_images('mountains', limit: 40)
|
|
137
|
+
|
|
138
|
+
report = PinterestDL.download_batch(
|
|
139
|
+
urls,
|
|
140
|
+
dir: './downloads',
|
|
141
|
+
concurrency: 4,
|
|
142
|
+
resume: true,
|
|
143
|
+
deduplicate: true,
|
|
144
|
+
collision_strategy: :rename # :rename, :skip, or :overwrite
|
|
145
|
+
) do |done, total, url|
|
|
146
|
+
warn "Progress: #{done}/#{total} (#{url})"
|
|
139
147
|
end
|
|
148
|
+
|
|
149
|
+
puts "Succeeded: #{report.succeeded.size}"
|
|
150
|
+
puts "Skipped: #{report.skipped.size}"
|
|
151
|
+
puts "Failed: #{report.failed.size}"
|
|
152
|
+
puts "Bytes: #{report.bytes_downloaded}"
|
|
140
153
|
```
|
|
141
154
|
|
|
142
|
-
###
|
|
155
|
+
### Configuration
|
|
143
156
|
|
|
144
157
|
```ruby
|
|
145
158
|
PinterestDL.configure do |c|
|
|
146
|
-
c.
|
|
147
|
-
c.
|
|
148
|
-
c.
|
|
149
|
-
c.
|
|
150
|
-
c.
|
|
151
|
-
c.
|
|
152
|
-
c.
|
|
153
|
-
c.
|
|
154
|
-
c.
|
|
155
|
-
c.
|
|
156
|
-
c.
|
|
157
|
-
c.
|
|
159
|
+
c.cookies = File.expand_path('~/cookies.txt') # or 'sessionid=...; csrftoken=...'
|
|
160
|
+
c.quality = :originals # :originals, :"1200x", :"736x", :"564x", :"474x", :"236x"
|
|
161
|
+
c.open_timeout = 10 # seconds
|
|
162
|
+
c.read_timeout = 20 # seconds
|
|
163
|
+
c.write_timeout = 20 # seconds
|
|
164
|
+
c.max_retries = 3 # retries on transient network / 429 / 5xx errors
|
|
165
|
+
c.retry_wait = 1.0 # base backoff in seconds
|
|
166
|
+
c.max_retry_wait = 30.0 # maximum backoff cap in seconds
|
|
167
|
+
c.retry_jitter = 0.25 # random jitter ratio added to backoff
|
|
168
|
+
c.rate_limit_interval = 0.5 # minimum seconds between requests
|
|
169
|
+
c.concurrency = 4 # worker threads for download_batch
|
|
170
|
+
c.overwrite = true # overwrite existing files when collision_strategy is not set
|
|
171
|
+
c.resume = true # resume partial .part files via HTTP Range
|
|
172
|
+
c.deduplicate = true # skip duplicate URLs within a batch
|
|
173
|
+
c.collision_strategy = :rename # :rename, :skip, or :overwrite
|
|
174
|
+
c.max_file_size = 500 * 1024 * 1024 # 500 MB cap per file
|
|
175
|
+
c.max_speed = nil # e.g. '500K' or '2M' per worker
|
|
176
|
+
c.verify_content_type = true # reject HTML/JSON error responses and empty payloads
|
|
177
|
+
c.proxy = nil # HTTP/HTTPS proxy URL (defaults to HTTPS_PROXY / HTTP_PROXY)
|
|
178
|
+
c.max_cache_entries = 256 # LRU cache size for GET requests
|
|
158
179
|
end
|
|
159
180
|
```
|
|
160
181
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
182
|
+
## CLI Reference
|
|
183
|
+
|
|
184
|
+
```text
|
|
185
|
+
Usage:
|
|
186
|
+
pinterest-dl image URL [-q QUALITY] [-o PATH] [options]
|
|
187
|
+
pinterest-dl video URL [-o PATH] [options]
|
|
188
|
+
pinterest-dl media URL [-q QUALITY] [options]
|
|
189
|
+
pinterest-dl search QUERY [-n LIMIT] [-t TYPE] [-q QUALITY] [-j JOBS] [-o DIR] [options]
|
|
190
|
+
pinterest-dl board URL [-n LIMIT] [-t TYPE] [-q QUALITY] [-j JOBS] [-o DIR] [options]
|
|
191
|
+
|
|
192
|
+
Options:
|
|
193
|
+
-o, --output PATH File or directory to save downloaded media (omit to print direct URL)
|
|
194
|
+
-n, --limit N Max number of results or files to download (default 25)
|
|
195
|
+
-t, --type TYPE Filter media type: all, image, video, pin (default all)
|
|
196
|
+
--images-only Shortcut for --type image
|
|
197
|
+
--videos-only Shortcut for --type video
|
|
198
|
+
-q, --quality Q Image quality: originals, 1200x, 736x, 564x, 474x, 236x
|
|
199
|
+
-c, --cookies STR|FILE Cookie header string or Netscape cookies.txt file path
|
|
200
|
+
-j, --jobs N Parallel download workers for batch downloads (default 4)
|
|
201
|
+
-s, --skip-existing Skip files that already exist on disk
|
|
202
|
+
--resume Resume partially downloaded .part files (default true)
|
|
203
|
+
--no-resume Restart interrupted downloads from scratch
|
|
204
|
+
--max-size BYTES Maximum allowed file size (e.g. 100M, 500M)
|
|
205
|
+
--max-speed RATE Throttle download speed per worker (e.g. 500K, 2M)
|
|
206
|
+
--format FMT Output report format: text, json, csv, quiet (default text)
|
|
207
|
+
--json Output results and summary in JSON format
|
|
208
|
+
--no-progress Disable live progress bar output
|
|
209
|
+
--non-interactive Run without interactive terminal animations or prompts
|
|
210
|
+
--proxy URL HTTP/HTTPS proxy URL
|
|
211
|
+
--timeout SEC Network read/open timeout in seconds
|
|
212
|
+
--retries N Max retries on transient failures (default 3)
|
|
213
|
+
-v, --verbose Enable debug logging
|
|
214
|
+
--version Print version and exit
|
|
215
|
+
-h, --help Show this help
|
|
183
216
|
```
|
|
184
217
|
|
|
185
|
-
|
|
218
|
+
## Error Handling
|
|
186
219
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
220
|
+
All library exceptions inherit from `PinterestDL::Error < StandardError` and expose `#url`, `#status_code`, and `#cause_error`:
|
|
221
|
+
|
|
222
|
+
| Exception Class | Cause |
|
|
223
|
+
| :--- | :--- |
|
|
224
|
+
| `PinterestDL::NotFoundError` | Pin, board, section, or media URL was not found (`404` or missing media). |
|
|
225
|
+
| `PinterestDL::AuthenticationError` | HTTP `401` — authentication cookies are required. |
|
|
226
|
+
| `PinterestDL::ForbiddenError` | HTTP `403` — request blocked by Pinterest (invalid CSRF/cookies or IP restriction). |
|
|
227
|
+
| `PinterestDL::RateLimitError` | HTTP `429` — rate limited (`#retry_after` contains server hint when present). |
|
|
228
|
+
| `PinterestDL::RangeNotSatisfiableError` | HTTP `416` — requested byte range is outside the remote resource size. |
|
|
229
|
+
| `PinterestDL::TimeoutError` | Connection, read, or write timeout after retries. |
|
|
230
|
+
| `PinterestDL::ConnectionError` | Socket reset, DNS failure, or dropped connection. |
|
|
231
|
+
| `PinterestDL::RedirectError` | Redirect loop, missing `Location`, or untrusted cross-domain redirect target. |
|
|
232
|
+
| `PinterestDL::InvalidURLError` / `SSRFError` | Malformed URL, non-Pinterest host, embedded credentials, or blocked private/loopback IP. |
|
|
233
|
+
| `PinterestDL::InvalidResponseError` | Malformed JSON or invalid HTTP `206` `Content-Range` header. |
|
|
234
|
+
| `PinterestDL::FileTooLargeError` | Remote `Content-Length` or streamed bytes exceeded `max_file_size`. |
|
|
235
|
+
| `PinterestDL::IncompleteDownloadError` | Stream ended before receiving the declared `Content-Length` / `Content-Range`. |
|
|
236
|
+
| `PinterestDL::InvalidMediaError` | Server returned `text/html` / `application/json` instead of media. |
|
|
237
|
+
| `PinterestDL::DiskSpaceError` | Insufficient disk space (`ENOSPC`) or non-writable target directory (`EACCES`/`EROFS`). |
|
|
201
238
|
|
|
202
|
-
|
|
239
|
+
## Development & Testing
|
|
203
240
|
|
|
204
|
-
|
|
241
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for development instructions.
|
|
205
242
|
|
|
206
243
|
```bash
|
|
207
244
|
bundle install
|
|
208
|
-
bundle exec rake test
|
|
209
|
-
bundle exec rake rubocop
|
|
210
|
-
bundle exec rake # both (default task)
|
|
245
|
+
bundle exec rake test
|
|
246
|
+
bundle exec rake rubocop
|
|
211
247
|
```
|
|
212
248
|
|
|
213
|
-
## Links
|
|
214
|
-
|
|
215
|
-
- [RubyGems](https://rubygems.org/gems/pinterest-dl)
|
|
216
|
-
- [GitHub](https://github.com/monji024/pinterest-dl)
|
|
217
|
-
- [Changelog](CHANGELOG.md)
|
|
218
|
-
- [Issue tracker](https://github.com/monji024/pinterest-dl/issues)
|
|
219
|
-
|
|
220
249
|
## License
|
|
221
250
|
|
|
222
|
-
WTFPL — [monji024](https://github.com/monji024)
|
|
251
|
+
[WTFPL](LICENSE) — [monji024](https://github.com/monji024)
|
data/bin/pinterest-dl
CHANGED
|
@@ -2,166 +2,5 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require_relative '../lib/pinterest-dl'
|
|
5
|
-
require 'optparse'
|
|
6
5
|
|
|
7
|
-
|
|
8
|
-
<<~USAGE
|
|
9
|
-
pinterest-dl v#{PinterestDL::VERSION}
|
|
10
|
-
|
|
11
|
-
Usage:
|
|
12
|
-
pinterest-dl image URL [-q QUALITY] [-o FILE]
|
|
13
|
-
pinterest-dl video URL [-o FILE]
|
|
14
|
-
pinterest-dl media URL [-q QUALITY]
|
|
15
|
-
pinterest-dl search QUERY [-n LIMIT] [-t TYPE] [-q QUALITY] [-j JOBS] [-o DIR]
|
|
16
|
-
pinterest-dl board URL [-n LIMIT] [-t TYPE] [-q QUALITY] [-j JOBS] [-o DIR]
|
|
17
|
-
|
|
18
|
-
Options:
|
|
19
|
-
-o, --output PATH File (image/video) or directory (search/board) to save to
|
|
20
|
-
-n, --limit N Max number of results (search/board), default 25
|
|
21
|
-
-t, --type TYPE What to collect in search/board: all, image, video, pin (default all)
|
|
22
|
-
-q, --quality Q Image quality: originals, 1200x, 736x, 564x, 474x, 236x (default originals)
|
|
23
|
-
-c, --cookies STR|FILE Cookie header string or Netscape cookies.txt file path
|
|
24
|
-
-j, --jobs N Parallel download workers for batch downloads (default 4)
|
|
25
|
-
-s, --skip-existing Skip files that already exist on disk
|
|
26
|
-
--proxy URL HTTP/HTTPS proxy URL
|
|
27
|
-
--timeout SEC Network read/open timeout in seconds
|
|
28
|
-
--retries N Max retries on transient failures (default 3)
|
|
29
|
-
-v, --verbose Enable debug logging
|
|
30
|
-
--version Print version and exit
|
|
31
|
-
-h, --help Show this help
|
|
32
|
-
USAGE
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
options = {
|
|
36
|
-
limit: 25,
|
|
37
|
-
quality: :originals,
|
|
38
|
-
type: :all,
|
|
39
|
-
jobs: 4,
|
|
40
|
-
skip_existing: false,
|
|
41
|
-
verbose: false
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
parser = OptionParser.new do |opts|
|
|
45
|
-
opts.on('-o PATH', '--output PATH') { |v| options[:output] = v }
|
|
46
|
-
opts.on('-n N', '--limit N', Integer) { |v| options[:limit] = v }
|
|
47
|
-
opts.on('-t T', '--type T') { |v| options[:type] = v.to_sym }
|
|
48
|
-
opts.on('-q Q', '--quality Q') { |v| options[:quality] = v.to_sym }
|
|
49
|
-
opts.on('-c STR', '--cookies STR') { |v| options[:cookies] = v }
|
|
50
|
-
opts.on('-j N', '--jobs N', Integer) { |v| options[:jobs] = v }
|
|
51
|
-
opts.on('-s', '--skip-existing') { options[:skip_existing] = true }
|
|
52
|
-
opts.on('--proxy URL') { |v| options[:proxy] = v }
|
|
53
|
-
opts.on('--timeout SEC', Integer) { |v| options[:timeout] = v }
|
|
54
|
-
opts.on('--retries N', Integer) { |v| options[:retries] = v }
|
|
55
|
-
opts.on('-v', '--verbose') { options[:verbose] = true }
|
|
56
|
-
opts.on('--version') do
|
|
57
|
-
puts PinterestDL::VERSION
|
|
58
|
-
exit 0
|
|
59
|
-
end
|
|
60
|
-
opts.on('-h', '--help') do
|
|
61
|
-
puts usage
|
|
62
|
-
exit 0
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
begin
|
|
67
|
-
parser.parse!(ARGV)
|
|
68
|
-
rescue OptionParser::ParseError => e
|
|
69
|
-
warn "pinterest-dl: #{e.message}"
|
|
70
|
-
exit 1
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
command = ARGV.shift
|
|
74
|
-
target = ARGV.shift
|
|
75
|
-
|
|
76
|
-
if command.nil? || target.nil?
|
|
77
|
-
puts usage
|
|
78
|
-
exit(command.nil? ? 0 : 1)
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def die(message, code = 1)
|
|
82
|
-
warn "pinterest-dl: #{message}"
|
|
83
|
-
exit code
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def handle_pins(pins, options)
|
|
87
|
-
if pins.empty?
|
|
88
|
-
warn 'No matching pins found'
|
|
89
|
-
return
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
if options[:type] == :pin
|
|
93
|
-
links = pins.map { |p| p[:pin_url] }
|
|
94
|
-
if options[:output]
|
|
95
|
-
FileUtils.mkdir_p(options[:output])
|
|
96
|
-
out_file = File.join(options[:output], 'pins.txt')
|
|
97
|
-
File.write(out_file, "#{links.join("\n")}\n")
|
|
98
|
-
puts "Saved #{links.size} pin links to #{out_file}"
|
|
99
|
-
else
|
|
100
|
-
puts links
|
|
101
|
-
end
|
|
102
|
-
elsif options[:output]
|
|
103
|
-
urls = pins.filter_map do |p|
|
|
104
|
-
options[:type] == :image ? p[:image_url] : (p[:video_url] || p[:image_url])
|
|
105
|
-
end
|
|
106
|
-
bar = PinterestDL::ProgressBar.new(total: urls.size, out: $stderr)
|
|
107
|
-
result = PinterestDL.download_batch(
|
|
108
|
-
urls,
|
|
109
|
-
dir: options[:output],
|
|
110
|
-
concurrency: options[:jobs],
|
|
111
|
-
overwrite: !options[:skip_existing]
|
|
112
|
-
) { |done, _total, _| bar.update(done) }
|
|
113
|
-
skipped_msg = result[:skipped]&.any? ? " (#{result[:skipped].size} skipped)" : ''
|
|
114
|
-
puts "Downloaded #{result[:succeeded].size}/#{urls.size} files to #{options[:output]}#{skipped_msg}"
|
|
115
|
-
exit 1 if result[:succeeded].empty? && result[:failed].any?
|
|
116
|
-
else
|
|
117
|
-
puts JSON.pretty_generate(pins)
|
|
118
|
-
end
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
begin
|
|
122
|
-
PinterestDL.configure do |c|
|
|
123
|
-
c.cookies = options[:cookies] if options[:cookies]
|
|
124
|
-
c.quality = options[:quality] if options[:quality]
|
|
125
|
-
c.concurrency = options[:jobs] if options[:jobs]
|
|
126
|
-
c.overwrite = !options[:skip_existing]
|
|
127
|
-
c.proxy = options[:proxy] if options[:proxy]
|
|
128
|
-
if options[:timeout]
|
|
129
|
-
c.open_timeout = options[:timeout]
|
|
130
|
-
c.read_timeout = options[:timeout]
|
|
131
|
-
end
|
|
132
|
-
c.max_retries = options[:retries] if options[:retries]
|
|
133
|
-
c.logger.level = Logger::DEBUG if options[:verbose]
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
case command
|
|
137
|
-
when 'image'
|
|
138
|
-
url = PinterestDL.get_image_url(target, quality: options[:quality])
|
|
139
|
-
if options[:output]
|
|
140
|
-
PinterestDL.download(url, path: options[:output], overwrite: !options[:skip_existing])
|
|
141
|
-
puts "Saved to #{options[:output]}"
|
|
142
|
-
else
|
|
143
|
-
puts url
|
|
144
|
-
end
|
|
145
|
-
when 'video'
|
|
146
|
-
url = PinterestDL.get_video_url(target)
|
|
147
|
-
if options[:output]
|
|
148
|
-
PinterestDL.download(url, path: options[:output], overwrite: !options[:skip_existing])
|
|
149
|
-
puts "Saved to #{options[:output]}"
|
|
150
|
-
else
|
|
151
|
-
puts url
|
|
152
|
-
end
|
|
153
|
-
when 'media'
|
|
154
|
-
puts JSON.pretty_generate(PinterestDL.get_media(target, quality: options[:quality]))
|
|
155
|
-
when 'search'
|
|
156
|
-
handle_pins(PinterestDL.search(target, limit: options[:limit], type: options[:type]), options)
|
|
157
|
-
when 'board'
|
|
158
|
-
handle_pins(PinterestDL.board(target, limit: options[:limit], type: options[:type]), options)
|
|
159
|
-
else
|
|
160
|
-
die "unknown command '#{command}'\n\n#{usage}"
|
|
161
|
-
end
|
|
162
|
-
rescue Interrupt
|
|
163
|
-
warn "\npinterest-dl: interrupted"
|
|
164
|
-
exit 130
|
|
165
|
-
rescue PinterestDL::Error, ArgumentError => e
|
|
166
|
-
die e.message
|
|
167
|
-
end
|
|
6
|
+
exit(PinterestDL::CLI.run(ARGV))
|