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.
@@ -0,0 +1,318 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PinterestDL
4
+ module TUI
5
+ class Theme
6
+ RESET = "\e[0m"
7
+ BOLD = "\e[1m"
8
+ DIM = "\e[2m"
9
+
10
+ PALETTE = {
11
+ bg: [13, 9, 26],
12
+ bg_panel: [18, 13, 34],
13
+ bg_pill: [32, 22, 58],
14
+ pink: [255, 59, 141],
15
+ hot_pink: [255, 105, 180],
16
+ purple: [180, 108, 255],
17
+ border_dim: [108, 72, 162],
18
+ border_muted: [68, 46, 108],
19
+ cyan: [92, 225, 255],
20
+ green: [74, 222, 128],
21
+ yellow: [251, 191, 36],
22
+ red: [248, 81, 110],
23
+ white: [245, 240, 255],
24
+ soft_text: [186, 168, 216],
25
+ dim_text: [128, 110, 162]
26
+ }.freeze
27
+
28
+ ANSI256_MAP = {
29
+ bg: 17,
30
+ bg_panel: 17,
31
+ bg_pill: 53,
32
+ pink: 198,
33
+ hot_pink: 205,
34
+ purple: 141,
35
+ border_dim: 97,
36
+ border_muted: 60,
37
+ cyan: 81,
38
+ green: 78,
39
+ yellow: 220,
40
+ red: 203,
41
+ white: 231,
42
+ soft_text: 183,
43
+ dim_text: 103
44
+ }.freeze
45
+
46
+ ANSI16_MAP = {
47
+ bg: 40,
48
+ bg_panel: 40,
49
+ bg_pill: 45,
50
+ pink: 95,
51
+ hot_pink: 95,
52
+ purple: 35,
53
+ border_dim: 35,
54
+ border_muted: 90,
55
+ cyan: 96,
56
+ green: 92,
57
+ yellow: 93,
58
+ red: 91,
59
+ white: 97,
60
+ soft_text: 37,
61
+ dim_text: 90
62
+ }.freeze
63
+
64
+ BORDER_ROUND = {
65
+ tl: '╭', tr: '╮', bl: '╰', br: '╯', h: '─', v: '│'
66
+ }.freeze
67
+
68
+ BORDER_HEAVY = {
69
+ tl: '┏', tr: '┓', bl: '┗', br: '┛', h: '━', v: '┃'
70
+ }.freeze
71
+
72
+ attr_reader :color_mode
73
+
74
+ def initialize(color_mode: nil, env: ENV)
75
+ @color_mode = color_mode || detect_color_mode(env)
76
+ end
77
+
78
+ def fg(color_name)
79
+ return '' if @color_mode == :mono
80
+
81
+ case @color_mode
82
+ when :truecolor
83
+ rgb = PALETTE[color_name] || PALETTE[:white]
84
+ "\e[38;2;#{rgb[0]};#{rgb[1]};#{rgb[2]}m"
85
+ when :ansi256
86
+ "\e[38;5;#{ANSI256_MAP[color_name] || 231}m"
87
+ else
88
+ "\e[#{ANSI16_MAP[color_name] || 97}m"
89
+ end
90
+ end
91
+
92
+ def bg(color_name)
93
+ return '' if @color_mode == :mono
94
+
95
+ case @color_mode
96
+ when :truecolor
97
+ rgb = PALETTE[color_name] || PALETTE[:bg]
98
+ "\e[48;2;#{rgb[0]};#{rgb[1]};#{rgb[2]}m"
99
+ when :ansi256
100
+ "\e[48;5;#{ANSI256_MAP[color_name] || 17}m"
101
+ else
102
+ "\e[40m"
103
+ end
104
+ end
105
+
106
+ def paint(text, color: nil, background: nil, bold: false, dim: false)
107
+ return text.to_s if @color_mode == :mono
108
+
109
+ seq = +''
110
+ seq << BOLD if bold
111
+ seq << DIM if dim
112
+ seq << fg(color) if color
113
+ seq << bg(background) if background
114
+ return text.to_s if seq.empty?
115
+
116
+ "#{seq}#{text}#{RESET}"
117
+ end
118
+
119
+ def apply_canvas_bg(line)
120
+ return line.to_s if @color_mode == :mono
121
+
122
+ base = bg(:bg)
123
+ "#{base}#{line.to_s.gsub(RESET, "#{RESET}#{base}")}"
124
+ end
125
+
126
+ def sanitize_display(text)
127
+ out = +''
128
+ text.to_s.gsub(/\s+/, ' ').strip.each_char do |ch|
129
+ cp = ch.ord
130
+ next if cp < 0x20 || cp == 0x7F || combining_mark?(cp)
131
+ next if cp >= 0x1F000 && cp <= 0x1FAFF
132
+
133
+ out << (cp >= 0x1D400 && cp <= 0x1D7FF ? normalize_math_alnum(cp) : ch)
134
+ end
135
+ out.gsub(/\s+/, ' ').strip
136
+ end
137
+
138
+ def gradient_bar(ratio, width:)
139
+ clamped = [[ratio.to_f, 0.0].max, 1.0].min
140
+ filled = (width * clamped).round
141
+ empty = [width - filled, 0].max
142
+ return "#{'#' * filled}#{'-' * empty}" if @color_mode == :mono
143
+
144
+ out = +''
145
+ filled.times do |i|
146
+ pos = filled > 1 ? (i.to_f / (filled - 1)) : 1.0
147
+ out << if @color_mode == :truecolor
148
+ r = (148 + (107 * pos)).round
149
+ g = (72 - (10 * pos)).round
150
+ b = (255 - (85 * pos)).round
151
+ "\e[38;2;#{r};#{g};#{b}m█"
152
+ else
153
+ "#{fg(pos > 0.5 ? :pink : :purple)}█"
154
+ end
155
+ end
156
+ out << "#{fg(:border_muted)}#{'░' * empty}" if empty.positive?
157
+ out << RESET
158
+ end
159
+
160
+ def border(selected: false)
161
+ selected ? BORDER_HEAVY : BORDER_ROUND
162
+ end
163
+
164
+ def strip_ansi(text)
165
+ text.to_s.gsub(/\e\[[0-9;?]*[A-Za-z]/, '')
166
+ end
167
+
168
+ def char_width(ch)
169
+ cp = ch.ord
170
+ return 0 if cp < 0x20 || cp == 0x7F
171
+ return 0 if combining_mark?(cp)
172
+ return 2 if wide_codepoint?(cp)
173
+
174
+ 1
175
+ end
176
+
177
+ def visible_length(text)
178
+ strip_ansi(text).each_char.sum { |ch| char_width(ch) }
179
+ end
180
+
181
+ def fit(text, target_width)
182
+ return '' if target_width <= 0
183
+
184
+ clipped = clip_ansi(text.to_s, target_width)
185
+ vis = visible_length(clipped)
186
+ vis < target_width ? "#{clipped}#{' ' * (target_width - vis)}" : clipped
187
+ end
188
+
189
+ def truncate(text, max_width, ellipsis: '...')
190
+ str = sanitize_display(text)
191
+ return '' if max_width <= 0
192
+ return str if visible_length(str) <= max_width
193
+
194
+ ell_w = visible_length(ellipsis)
195
+ return clip_plain(str, max_width) if max_width <= ell_w
196
+
197
+ "#{clip_plain(str, max_width - ell_w)}#{ellipsis}"
198
+ end
199
+
200
+ def truncate_chars(text, max_chars, ellipsis: '...')
201
+ str = sanitize_display(text)
202
+ return '' if max_chars <= 0
203
+ return str if str.length <= max_chars
204
+
205
+ "#{str[0, max_chars]}#{ellipsis}"
206
+ end
207
+
208
+ def wrap_text(text, max_width, max_lines: 3)
209
+ str = sanitize_display(text)
210
+ return [] if str.empty? || max_width <= 0 || max_lines <= 0
211
+
212
+ lines = []
213
+ current = +''
214
+ str.split(' ').each do |word|
215
+ if current.empty?
216
+ current = clip_plain(word, max_width)
217
+ elsif visible_length(current) + 1 + visible_length(word) <= max_width
218
+ current = "#{current} #{word}"
219
+ else
220
+ lines << current
221
+ break if lines.size >= max_lines
222
+
223
+ current = clip_plain(word, max_width)
224
+ end
225
+ end
226
+ lines << current if !current.empty? && lines.size < max_lines
227
+ if lines.size == max_lines && str.length > lines.join(' ').length
228
+ lines[-1] = truncate(lines[-1], max_width)
229
+ end
230
+ lines
231
+ end
232
+
233
+ def clip_ansi(text, max_cols)
234
+ return text if visible_length(text) <= max_cols
235
+
236
+ out = +''
237
+ cols = 0
238
+ has_ansi = false
239
+ idx = 0
240
+ len = text.length
241
+
242
+ while idx < len
243
+ if text[idx] == "\e"
244
+ m = text.match(/\G\e\[[0-9;?]*[A-Za-z]/, idx)
245
+ if m
246
+ out << m[0]
247
+ has_ansi = true
248
+ idx += m[0].length
249
+ next
250
+ end
251
+ end
252
+
253
+ ch = text[idx]
254
+ cw = char_width(ch)
255
+ break if cols + cw > max_cols
256
+
257
+ out << ch
258
+ cols += cw
259
+ idx += 1
260
+ end
261
+
262
+ out << RESET if has_ansi
263
+ out
264
+ end
265
+
266
+ private
267
+
268
+ def normalize_math_alnum(cp)
269
+ offset = (cp - 0x1D400) % 52
270
+ offset < 26 ? (65 + offset).chr : (97 + (offset - 26)).chr
271
+ rescue RangeError
272
+ ''
273
+ end
274
+
275
+ def clip_plain(str, max_cols)
276
+ out = +''
277
+ cols = 0
278
+ str.each_char do |ch|
279
+ cw = char_width(ch)
280
+ break if cols + cw > max_cols
281
+
282
+ out << ch
283
+ cols += cw
284
+ end
285
+ out
286
+ end
287
+
288
+ def combining_mark?(cp)
289
+ (cp >= 0x0300 && cp <= 0x036F) ||
290
+ (cp >= 0xFE00 && cp <= 0xFE0F) ||
291
+ cp == 0x200D ||
292
+ (cp >= 0x064B && cp <= 0x065F)
293
+ end
294
+
295
+ def wide_codepoint?(cp)
296
+ (cp >= 0x1100 && cp <= 0x115F) ||
297
+ (cp >= 0x2E80 && cp <= 0xA4CF) ||
298
+ (cp >= 0xAC00 && cp <= 0xD7A3) ||
299
+ (cp >= 0xF900 && cp <= 0xFAFF) ||
300
+ (cp >= 0xFE10 && cp <= 0xFE6F) ||
301
+ (cp >= 0xFF00 && cp <= 0xFF60) ||
302
+ (cp >= 0xFFE0 && cp <= 0xFFE6) ||
303
+ (cp >= 0x1F300 && cp <= 0x1FAFF)
304
+ end
305
+
306
+ def detect_color_mode(env)
307
+ return :mono if env['NO_COLOR'] && !env['NO_COLOR'].empty?
308
+ return :mono if env['TERM'].to_s == 'dumb'
309
+
310
+ colorterm = env['COLORTERM'].to_s.downcase
311
+ return :truecolor if colorterm.include?('truecolor') || colorterm.include?('24bit')
312
+ return :ansi256 if env['TERM'].to_s.include?('256color')
313
+
314
+ :truecolor
315
+ end
316
+ end
317
+ end
318
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'tui/theme'
4
+ require_relative 'tui/icons'
5
+ require_relative 'tui/terminal'
6
+ require_relative 'tui/preview'
7
+ require_relative 'tui/download_queue'
8
+ require_relative 'tui/state'
9
+ require_relative 'tui/renderer'
10
+ require_relative 'tui/app'
11
+
12
+ module PinterestDL
13
+ module TUI
14
+ DEFAULT_COOKIE_PATHS = [
15
+ './cookies.txt',
16
+ '~/cookies.txt',
17
+ '~/.config/pinterest-dl/cookies.txt'
18
+ ].freeze
19
+
20
+ module_function
21
+
22
+ def start(**options)
23
+ App.new(**options).run
24
+ end
25
+
26
+ def build_auto_session(proxy: nil, cookies: nil, env: ENV)
27
+ detected_proxy = proxy || detect_proxy(env)
28
+ detected_cookies = cookies || detect_cookies_file
29
+ PinterestDL.session do |cfg|
30
+ cfg.proxy = detected_proxy if detected_proxy
31
+ cfg.cookies = detected_cookies if detected_cookies
32
+ end
33
+ end
34
+
35
+ def detect_proxy(env = ENV)
36
+ %w[HTTPS_PROXY https_proxy HTTP_PROXY http_proxy ALL_PROXY all_proxy].each do |var|
37
+ val = env[var].to_s.strip
38
+ return val unless val.empty?
39
+ end
40
+ nil
41
+ end
42
+
43
+ def detect_cookies_file(paths = DEFAULT_COOKIE_PATHS)
44
+ paths.each do |raw|
45
+ expanded = File.expand_path(raw)
46
+ return expanded if File.file?(expanded) && File.readable?(expanded)
47
+ end
48
+ nil
49
+ rescue StandardError
50
+ nil
51
+ end
52
+ end
53
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PinterestDL
4
- VERSION = '2.3.0'
4
+ VERSION = '2.5.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pinterest-dl
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Monji
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-08 00:00:00.000000000 Z
11
+ date: 2026-11-22 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A Ruby toolkit for getting direct image and video URLs from Pinterest
14
14
  pins, searching pins, fetching board contents, and downloading media to disk — as
@@ -19,6 +19,7 @@ executables:
19
19
  extensions: []
20
20
  extra_rdoc_files: []
21
21
  files:
22
+ - ".yardopts"
22
23
  - CHANGELOG.md
23
24
  - LICENSE
24
25
  - README.md
@@ -26,16 +27,33 @@ files:
26
27
  - lib/pinterest-dl.rb
27
28
  - lib/pinterest_dl/api.rb
28
29
  - lib/pinterest_dl/board.rb
30
+ - lib/pinterest_dl/cli.rb
29
31
  - lib/pinterest_dl/client.rb
30
32
  - lib/pinterest_dl/configuration.rb
33
+ - lib/pinterest_dl/cookie_jar.rb
31
34
  - lib/pinterest_dl/downloader.rb
32
35
  - lib/pinterest_dl/errors.rb
33
36
  - lib/pinterest_dl/extractors/image.rb
34
37
  - lib/pinterest_dl/extractors/pin_data.rb
35
38
  - lib/pinterest_dl/extractors/video.rb
36
39
  - lib/pinterest_dl/media_type.rb
40
+ - lib/pinterest_dl/media_validator.rb
41
+ - lib/pinterest_dl/models.rb
42
+ - lib/pinterest_dl/paginator.rb
37
43
  - lib/pinterest_dl/progress_bar.rb
38
44
  - lib/pinterest_dl/search.rb
45
+ - lib/pinterest_dl/security.rb
46
+ - lib/pinterest_dl/session.rb
47
+ - lib/pinterest_dl/transport.rb
48
+ - lib/pinterest_dl/tui.rb
49
+ - lib/pinterest_dl/tui/app.rb
50
+ - lib/pinterest_dl/tui/download_queue.rb
51
+ - lib/pinterest_dl/tui/icons.rb
52
+ - lib/pinterest_dl/tui/preview.rb
53
+ - lib/pinterest_dl/tui/renderer.rb
54
+ - lib/pinterest_dl/tui/state.rb
55
+ - lib/pinterest_dl/tui/terminal.rb
56
+ - lib/pinterest_dl/tui/theme.rb
39
57
  - lib/pinterest_dl/version.rb
40
58
  homepage: https://github.com/monji024/pinterest-dl
41
59
  licenses:
@@ -54,7 +72,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
54
72
  requirements:
55
73
  - - ">="
56
74
  - !ruby/object:Gem::Version
57
- version: 2.7.0
75
+ version: 3.0.0
58
76
  required_rubygems_version: !ruby/object:Gem::Requirement
59
77
  requirements:
60
78
  - - ">="