pinterest-dl 2.4.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 +7 -0
- data/README.md +173 -107
- data/lib/pinterest-dl.rb +1 -0
- data/lib/pinterest_dl/board.rb +8 -4
- data/lib/pinterest_dl/cli.rb +41 -14
- data/lib/pinterest_dl/configuration.rb +1 -1
- data/lib/pinterest_dl/cookie_jar.rb +89 -116
- data/lib/pinterest_dl/downloader.rb +158 -27
- data/lib/pinterest_dl/extractors/pin_data.rb +13 -12
- data/lib/pinterest_dl/paginator.rb +2 -1
- data/lib/pinterest_dl/progress_bar.rb +3 -1
- data/lib/pinterest_dl/search.rb +4 -2
- data/lib/pinterest_dl/security.rb +1 -1
- data/lib/pinterest_dl/transport.rb +7 -3
- 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 +13 -45
- data/lib/pinterest_dl/downloader/part_file.rb +0 -25
- data/lib/pinterest_dl/downloader/response_plan.rb +0 -194
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,13 @@
|
|
|
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
|
+
|
|
6
13
|
## [2.4.0]
|
|
7
14
|
|
|
8
15
|
### Security
|
data/README.md
CHANGED
|
@@ -1,28 +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
8
|
[](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
|
-
> **
|
|
12
|
+
> **Network note:** Users in regions where Pinterest is restricted may need an HTTP/HTTPS proxy (`--proxy` or `config.proxy`).
|
|
14
13
|
|
|
15
|
-
|
|
14
|
+
## Features
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
-
|
|
20
|
-
- **
|
|
21
|
-
-
|
|
22
|
-
- **Downloads** single files or parallel batches with live progress bars (percentage, bytes, speed, ETA), HTTP `Range` resume, bandwidth throttling, content-type/magic-byte verification, max file size limits, and automatic deduplication.
|
|
23
|
-
- Provides **isolated sessions** (`PinterestDL.session`) alongside global configuration, with domain-scoped `CookieJar` protection, cross-domain redirect guards, SSRF prevention, and automatic log redaction.
|
|
24
|
-
- Raises **specific, catchable exceptions** (`NotFoundError`, `ForbiddenError`, `RateLimitError`, `AuthenticationError`, `TimeoutError`, `SSRFError`, `FileTooLargeError`, `IncompleteDownloadError`, `InvalidMediaError`, ...) instead of returning `nil`.
|
|
25
|
-
- Ships a full-featured **CLI** (`pinterest-dl`) with `text`, `json`, `csv`, and `quiet` output modes.
|
|
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`).
|
|
26
21
|
|
|
27
22
|
## Installation
|
|
28
23
|
|
|
@@ -30,37 +25,83 @@ Pinterest doesn't give you a clean, official API for getting a direct media URL
|
|
|
30
25
|
gem install pinterest-dl
|
|
31
26
|
```
|
|
32
27
|
|
|
33
|
-
Or add
|
|
28
|
+
Or add to your `Gemfile`:
|
|
34
29
|
|
|
35
30
|
```ruby
|
|
36
31
|
gem 'pinterest-dl'
|
|
37
32
|
```
|
|
38
33
|
|
|
39
|
-
|
|
34
|
+
Requires Ruby **3.0 or newer** (no external runtime dependencies).
|
|
35
|
+
|
|
36
|
+
## Quick Start
|
|
37
|
+
|
|
38
|
+
### Interactive TUI
|
|
39
|
+
|
|
40
|
+
Launch the interactive terminal interface with gallery browsing, live previews, quality selection, mouse controls, and batch downloading:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pinterest-dl tui
|
|
44
|
+
# or simply run `pinterest-dl` in an interactive terminal
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Proxy environment variables (`HTTPS_PROXY`, `HTTP_PROXY`, `ALL_PROXY`) and local `cookies.txt` files are detected automatically.
|
|
48
|
+
|
|
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`).
|
|
52
|
+
|
|
53
|
+
#### Optional: Install `ueberzugpp` on Ubuntu / Pop!_OS
|
|
54
|
+
|
|
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
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
*(Replace `xUbuntu_26.04` with `xUbuntu_24.04` or `xUbuntu_22.04` for earlier Ubuntu or Pop!_OS releases.)*
|
|
63
|
+
|
|
64
|
+
### CLI
|
|
65
|
+
|
|
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
|
|
70
|
+
|
|
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
|
|
74
|
+
|
|
75
|
+
# Inspect both image and video URLs as JSON
|
|
76
|
+
pinterest-dl media https://www.pinterest.com/pin/1234567890123456789/
|
|
77
|
+
|
|
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
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### Ruby Library
|
|
40
86
|
|
|
41
87
|
```ruby
|
|
42
88
|
require 'pinterest-dl'
|
|
43
89
|
|
|
44
|
-
#
|
|
45
|
-
PinterestDL.get_image_url('https://www.pinterest.com/pin/1234567890123456789/')
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
#
|
|
49
|
-
PinterestDL.get_video_url('https://www.pinterest.com/pin/1234567890123456789/')
|
|
50
|
-
# => "https://v.pinimg.com/videos/mc/720p/aa/bb/cc/aabbcc....mp4"
|
|
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 }
|
|
51
95
|
|
|
52
|
-
# Download
|
|
53
|
-
PinterestDL.download(
|
|
54
|
-
PinterestDL.get_image_url('https://www.pinterest.com/pin/1234567890123456789/'),
|
|
55
|
-
path: 'downloads/pin.jpg'
|
|
56
|
-
)
|
|
96
|
+
# Download a single file
|
|
97
|
+
PinterestDL.download(image_url, path: 'downloads/pin.jpg', resume: true)
|
|
57
98
|
```
|
|
58
99
|
|
|
59
|
-
## Usage
|
|
100
|
+
## Library Usage
|
|
60
101
|
|
|
61
102
|
### Isolated Sessions
|
|
62
103
|
|
|
63
|
-
|
|
104
|
+
Use `PinterestDL.session` when running multiple configurations or accounts concurrently without mutating `PinterestDL.config`:
|
|
64
105
|
|
|
65
106
|
```ruby
|
|
66
107
|
session = PinterestDL.session(
|
|
@@ -71,115 +112,140 @@ session = PinterestDL.session(
|
|
|
71
112
|
)
|
|
72
113
|
|
|
73
114
|
pins = session.board('https://www.pinterest.com/username/board-name/', limit: 50)
|
|
74
|
-
report = session.download_batch(pins, dir: './downloads')
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
### Get image / video URLs
|
|
78
|
-
|
|
79
|
-
```ruby
|
|
80
|
-
url = PinterestDL.get_image_url('https://www.pinterest.com/pin/example/')
|
|
81
|
-
|
|
82
|
-
# Pick a specific size bucket (:originals, :"1200x", :"736x", :"564x", :"474x", :"236x")
|
|
83
|
-
url = PinterestDL.get_image_url('https://www.pinterest.com/pin/example/', quality: :"736x")
|
|
84
|
-
|
|
85
|
-
url = PinterestDL.get_video_url('https://www.pinterest.com/pin/example/')
|
|
86
|
-
|
|
87
|
-
# Both at once
|
|
88
|
-
media = PinterestDL.get_media('https://www.pinterest.com/pin/example/')
|
|
89
|
-
# => { image_url: "https://i.pinimg.com/...", video_url: nil }
|
|
115
|
+
report = session.download_batch(pins, dir: './downloads', collision_strategy: :rename)
|
|
90
116
|
```
|
|
91
117
|
|
|
92
|
-
### Search
|
|
118
|
+
### Search and Boards
|
|
93
119
|
|
|
94
120
|
```ruby
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
videos = PinterestDL.search_videos('tutorial', limit: 3)
|
|
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)
|
|
100
125
|
|
|
101
|
-
#
|
|
102
|
-
|
|
126
|
+
# Fetch pins from a board or board section
|
|
127
|
+
board_pins = PinterestDL.board('https://www.pinterest.com/username/board-name/', limit: 100)
|
|
103
128
|
section_pins = PinterestDL.board('https://www.pinterest.com/username/board-name/section-slug/', limit: 50)
|
|
104
129
|
```
|
|
105
130
|
|
|
106
|
-
### Downloading
|
|
131
|
+
### Batch Downloading & Collision Strategies
|
|
107
132
|
|
|
108
|
-
|
|
109
|
-
# Single file with resume, max size, and speed limit
|
|
110
|
-
PinterestDL.download(
|
|
111
|
-
'https://i.pinimg.com/originals/aa/bb/cc/img.jpg',
|
|
112
|
-
path: 'out/img.jpg',
|
|
113
|
-
resume: true,
|
|
114
|
-
max_size: 100 * 1024 * 1024,
|
|
115
|
-
max_speed: '1.5M'
|
|
116
|
-
)
|
|
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]`):
|
|
117
134
|
|
|
118
|
-
|
|
135
|
+
```ruby
|
|
119
136
|
urls = PinterestDL.search_images('mountains', limit: 40)
|
|
137
|
+
|
|
120
138
|
report = PinterestDL.download_batch(
|
|
121
139
|
urls,
|
|
122
140
|
dir: './downloads',
|
|
123
|
-
concurrency:
|
|
124
|
-
overwrite: false,
|
|
141
|
+
concurrency: 4,
|
|
125
142
|
resume: true,
|
|
126
143
|
deduplicate: true,
|
|
127
|
-
collision_strategy: :rename
|
|
128
|
-
)
|
|
144
|
+
collision_strategy: :rename # :rename, :skip, or :overwrite
|
|
145
|
+
) do |done, total, url|
|
|
146
|
+
warn "Progress: #{done}/#{total} (#{url})"
|
|
147
|
+
end
|
|
129
148
|
|
|
130
|
-
puts "
|
|
149
|
+
puts "Succeeded: #{report.succeeded.size}"
|
|
150
|
+
puts "Skipped: #{report.skipped.size}"
|
|
151
|
+
puts "Failed: #{report.failed.size}"
|
|
152
|
+
puts "Bytes: #{report.bytes_downloaded}"
|
|
131
153
|
```
|
|
132
154
|
|
|
133
155
|
### Configuration
|
|
134
156
|
|
|
135
157
|
```ruby
|
|
136
158
|
PinterestDL.configure do |c|
|
|
137
|
-
c.cookies = File.expand_path('~/cookies.txt')
|
|
138
|
-
c.
|
|
139
|
-
c.
|
|
140
|
-
c.
|
|
141
|
-
c.
|
|
142
|
-
c.
|
|
143
|
-
c.
|
|
144
|
-
c.
|
|
145
|
-
c.
|
|
146
|
-
c.
|
|
147
|
-
c.
|
|
148
|
-
c.
|
|
149
|
-
c.
|
|
150
|
-
c.
|
|
151
|
-
c.
|
|
152
|
-
c.
|
|
153
|
-
c.
|
|
154
|
-
c.
|
|
155
|
-
c.
|
|
156
|
-
c.max_cache_entries = 256
|
|
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
|
|
157
179
|
end
|
|
158
180
|
```
|
|
159
181
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
pinterest-dl
|
|
165
|
-
pinterest-dl
|
|
166
|
-
pinterest-dl
|
|
167
|
-
pinterest-dl
|
|
168
|
-
pinterest-dl board
|
|
169
|
-
|
|
170
|
-
|
|
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
|
|
171
216
|
```
|
|
172
217
|
|
|
173
|
-
##
|
|
218
|
+
## Error Handling
|
|
219
|
+
|
|
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`). |
|
|
238
|
+
|
|
239
|
+
## Development & Testing
|
|
240
|
+
|
|
241
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for development instructions.
|
|
174
242
|
|
|
175
243
|
```bash
|
|
176
244
|
bundle install
|
|
177
|
-
bundle exec rake test
|
|
178
|
-
bundle exec rake
|
|
179
|
-
bundle exec rake rubocop # lint
|
|
180
|
-
bundle exec rake # test + rubocop
|
|
245
|
+
bundle exec rake test
|
|
246
|
+
bundle exec rake rubocop
|
|
181
247
|
```
|
|
182
248
|
|
|
183
249
|
## License
|
|
184
250
|
|
|
185
|
-
WTFPL — [monji024](https://github.com/monji024)
|
|
251
|
+
[WTFPL](LICENSE) — [monji024](https://github.com/monji024)
|
data/lib/pinterest-dl.rb
CHANGED
|
@@ -21,6 +21,7 @@ require_relative 'pinterest_dl/downloader'
|
|
|
21
21
|
require_relative 'pinterest_dl/progress_bar'
|
|
22
22
|
require_relative 'pinterest_dl/session'
|
|
23
23
|
require_relative 'pinterest_dl/api'
|
|
24
|
+
require_relative 'pinterest_dl/tui'
|
|
24
25
|
require_relative 'pinterest_dl/cli'
|
|
25
26
|
|
|
26
27
|
module PinterestDL
|
data/lib/pinterest_dl/board.rb
CHANGED
|
@@ -4,6 +4,7 @@ require 'json'
|
|
|
4
4
|
require 'uri'
|
|
5
5
|
require_relative 'paginator'
|
|
6
6
|
require_relative 'media_type'
|
|
7
|
+
require_relative 'security'
|
|
7
8
|
require_relative 'extractors/pin_data'
|
|
8
9
|
|
|
9
10
|
module PinterestDL
|
|
@@ -41,14 +42,17 @@ module PinterestDL
|
|
|
41
42
|
url = board_url.to_s.strip
|
|
42
43
|
raise PinterestDL::InvalidURLError.new("Not a Pinterest board URL: #{board_url}", url: board_url) if url.empty?
|
|
43
44
|
|
|
44
|
-
|
|
45
|
+
uri = URI.parse(url)
|
|
46
|
+
if Security.shortener_host?(uri.host)
|
|
45
47
|
@client.raw_get(url)
|
|
46
|
-
url = @client.last_url
|
|
48
|
+
url = @client.last_url.to_s
|
|
49
|
+
uri = URI.parse(url)
|
|
47
50
|
end
|
|
48
51
|
|
|
49
|
-
uri = URI(url)
|
|
50
52
|
parts = uri.path.to_s.split('/').reject(&:empty?)
|
|
51
|
-
valid = uri.
|
|
53
|
+
valid = %w[http https].include?(uri.scheme.to_s.downcase) &&
|
|
54
|
+
uri.user.nil? && uri.password.nil? &&
|
|
55
|
+
Security.pinterest_host?(uri.host) &&
|
|
52
56
|
[2, 3].include?(parts.size) &&
|
|
53
57
|
!RESERVED_PATHS.include?(parts.first.to_s.downcase)
|
|
54
58
|
raise PinterestDL::InvalidURLError.new("Not a Pinterest board URL: #{board_url}", url: board_url) unless valid
|
data/lib/pinterest_dl/cli.rb
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'csv'
|
|
4
3
|
require 'fileutils'
|
|
5
4
|
require 'json'
|
|
6
5
|
require 'optparse'
|
|
@@ -10,6 +9,7 @@ require_relative 'errors'
|
|
|
10
9
|
require_relative 'progress_bar'
|
|
11
10
|
require_relative 'session'
|
|
12
11
|
require_relative 'api'
|
|
12
|
+
require_relative 'tui'
|
|
13
13
|
|
|
14
14
|
module PinterestDL
|
|
15
15
|
class CLI
|
|
@@ -33,6 +33,10 @@ module PinterestDL
|
|
|
33
33
|
command = @argv.shift
|
|
34
34
|
target = @argv.shift
|
|
35
35
|
|
|
36
|
+
if command == 'tui' || (command.nil? && launch_tui_directly?)
|
|
37
|
+
return run_tui
|
|
38
|
+
end
|
|
39
|
+
|
|
36
40
|
if command.nil? || target.nil?
|
|
37
41
|
@out.puts usage
|
|
38
42
|
return command.nil? ? 0 : 1
|
|
@@ -56,6 +60,8 @@ module PinterestDL
|
|
|
56
60
|
pinterest-dl v#{PinterestDL::VERSION}
|
|
57
61
|
|
|
58
62
|
Usage:
|
|
63
|
+
pinterest-dl
|
|
64
|
+
pinterest-dl tui [-o DIR] [-c COOKIES] [--proxy URL]
|
|
59
65
|
pinterest-dl image URL [-q QUALITY] [-o PATH] [options]
|
|
60
66
|
pinterest-dl video URL [-o PATH] [options]
|
|
61
67
|
pinterest-dl media URL [-q QUALITY] [options]
|
|
@@ -91,6 +97,18 @@ module PinterestDL
|
|
|
91
97
|
|
|
92
98
|
private
|
|
93
99
|
|
|
100
|
+
def launch_tui_directly?
|
|
101
|
+
!@options[:non_interactive] && @out.respond_to?(:tty?) && @out.tty? && $stdin.respond_to?(:tty?) && $stdin.tty?
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def run_tui
|
|
105
|
+
@options[:proxy] ||= PinterestDL::TUI.detect_proxy
|
|
106
|
+
@options[:cookies] ||= PinterestDL::TUI.detect_cookies_file
|
|
107
|
+
out_dir = @options[:output] || './downloads'
|
|
108
|
+
PinterestDL::TUI.start(session: build_session, output_dir: out_dir)
|
|
109
|
+
0
|
|
110
|
+
end
|
|
111
|
+
|
|
94
112
|
def default_options
|
|
95
113
|
{
|
|
96
114
|
limit: 25,
|
|
@@ -316,7 +334,7 @@ module PinterestDL
|
|
|
316
334
|
elapsed_seconds: elapsed.round(2)
|
|
317
335
|
})
|
|
318
336
|
when :csv
|
|
319
|
-
@out.puts
|
|
337
|
+
@out.puts csv_line([media_kind, url, path, size])
|
|
320
338
|
when :text
|
|
321
339
|
badge = "[#{media_kind.to_s.upcase}]"
|
|
322
340
|
@out.puts "#{badge} Saved to #{path} (#{ProgressBar.format_bytes(size)} in #{elapsed.round(2)}s)"
|
|
@@ -326,8 +344,8 @@ module PinterestDL
|
|
|
326
344
|
def emit_media_info(media)
|
|
327
345
|
case @options[:format]
|
|
328
346
|
when :csv
|
|
329
|
-
@out.puts
|
|
330
|
-
@out.puts
|
|
347
|
+
@out.puts csv_line(%w[image_url video_url])
|
|
348
|
+
@out.puts csv_line([media[:image_url], media[:video_url]])
|
|
331
349
|
when :quiet
|
|
332
350
|
nil
|
|
333
351
|
else
|
|
@@ -338,9 +356,9 @@ module PinterestDL
|
|
|
338
356
|
def emit_pins_output(pins)
|
|
339
357
|
case @options[:format]
|
|
340
358
|
when :csv
|
|
341
|
-
@out.puts
|
|
359
|
+
@out.puts csv_line(%w[id pin_url title creator image_url video_url])
|
|
342
360
|
pins.each do |p|
|
|
343
|
-
@out.puts
|
|
361
|
+
@out.puts csv_line([p[:id], p[:pin_url], p[:title], p[:creator], p[:image_url], p[:video_url]])
|
|
344
362
|
end
|
|
345
363
|
when :quiet
|
|
346
364
|
nil
|
|
@@ -355,14 +373,15 @@ module PinterestDL
|
|
|
355
373
|
when :json
|
|
356
374
|
@out.puts report.to_json
|
|
357
375
|
when :csv
|
|
358
|
-
@out.puts
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
376
|
+
@out.puts csv_line(%w[succeeded skipped failed bytes_downloaded elapsed_seconds])
|
|
377
|
+
row = [
|
|
378
|
+
report[:succeeded].size,
|
|
379
|
+
report[:skipped].size,
|
|
380
|
+
report[:failed].size,
|
|
381
|
+
report.bytes_downloaded,
|
|
382
|
+
report.elapsed_seconds.round(2)
|
|
383
|
+
]
|
|
384
|
+
@out.puts csv_line(row)
|
|
366
385
|
when :text
|
|
367
386
|
skipped_msg = report[:skipped]&.any? ? " (#{report[:skipped].size} skipped)" : ''
|
|
368
387
|
failed_msg = report[:failed]&.any? ? ", #{report[:failed].size} failed" : ''
|
|
@@ -389,6 +408,14 @@ module PinterestDL
|
|
|
389
408
|
@options[:progress] && !@options[:non_interactive] && @options[:format] != :json && @options[:format] != :quiet
|
|
390
409
|
end
|
|
391
410
|
|
|
411
|
+
def csv_line(fields)
|
|
412
|
+
row = fields.map do |field|
|
|
413
|
+
str = field.to_s
|
|
414
|
+
str.match?(/[,"\r\n]/) ? "\"#{str.gsub('"', '""')}\"" : str
|
|
415
|
+
end.join(',')
|
|
416
|
+
"#{row}\n"
|
|
417
|
+
end
|
|
418
|
+
|
|
392
419
|
def extract_url_basename(url)
|
|
393
420
|
File.basename(URI(url.to_s).path.to_s)
|
|
394
421
|
rescue URI::InvalidURIError
|
|
@@ -48,7 +48,7 @@ module PinterestDL
|
|
|
48
48
|
@retry_jitter = 0.25
|
|
49
49
|
@quality = :originals
|
|
50
50
|
@rate_limit_interval = 0.0
|
|
51
|
-
@proxy = ENV['HTTPS_PROXY'] || ENV['https_proxy'] || ENV['HTTP_PROXY'] || ENV
|
|
51
|
+
@proxy = ENV['HTTPS_PROXY'] || ENV['https_proxy'] || ENV['HTTP_PROXY'] || ENV['http_proxy']
|
|
52
52
|
@max_cache_entries = 256
|
|
53
53
|
@concurrency = 4
|
|
54
54
|
@overwrite = true
|