pinterest-dl 1.0.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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +25 -0
  3. data/lib/pinterest-dl.rb +136 -0
  4. metadata +43 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 71ad1b053f92b611430a8e44a0a678037daa37577afaa1a0ff5dd04a3f53329b
4
+ data.tar.gz: 2754556eacec0edfcb5f52700773bc9d725597c01c6f512f692fd1eff3c706ac
5
+ SHA512:
6
+ metadata.gz: 55f78b7fe0ffb4d69f17f65b5bdf580d985a8418780145a8717c2a166c61ba123c3de7e64ed6cea1394bc6588db3c0279fe07e621403f0155f71c52eaef3b34b
7
+ data.tar.gz: b662d4914cd490516c54f5c0e6b8b42476c6781e65b7a97846381a1be596295725b3525187338d8a62cee79b46b6d9bdf322ab3c26d66bf752d49027290aae43
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # pinterest-dl
2
+
3
+ Get direct image and video URLs from Pinterest:)
4
+
5
+
6
+
7
+ ```ruby
8
+ gem install pinterest-dl
9
+
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ ```ruby
15
+ require 'pinterest-dl'
16
+ ```
17
+
18
+
19
+ # Get image url
20
+ url = PinterestDL.get_image_url('link')
21
+ # => "https://i.pinimg.com/originals/8e/2a/..."
22
+
23
+ # Get video url
24
+ url = PinterestDL.get_video_url('link')
25
+ # => "https://v.pinimg.com/videos/..."
@@ -0,0 +1,136 @@
1
+ #!/usr/bin/env ruby
2
+ # pinterest-dl.rb
3
+ # Pinterest downloader
4
+ # creator: Monji
5
+ # ver: 1.0.0
6
+ # github: https://github.com/monji024/pinterest-dl
7
+
8
+ require 'net/http'
9
+ require 'uri'
10
+ require 'json'
11
+ require 'openssl'
12
+
13
+
14
+ module PinterestDL
15
+ ver = '1.0.0'.freeze
16
+ craetor = 'Monji'.freeze
17
+ github = 'https://github.com/monji024/pinterest-dl'.freeze
18
+
19
+ puts "pinterest-dl v#{ver} by #{craetor} (#{github})\n\n"
20
+
21
+ USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'.freeze
22
+
23
+ class << self
24
+ def get_image_url(pin_url)
25
+ html = fetch_html(pin_url)
26
+ return nil unless html
27
+
28
+ # 1 -> json-ld
29
+ url = extract_json_ld(html, 'ImageObject')
30
+ return url if url
31
+
32
+ # 2 -> open graph
33
+ match = html.match(%r{<meta[^>]*property="og:image"[^>]*content="([^"]+)"})
34
+ if match
35
+ url = match[1]
36
+ puts "image url: #{url}"
37
+ return url
38
+ end
39
+
40
+ # 3 -> direct i.pinimg.com patterns
41
+ match = html.match(%r{https://i\.pinimg\.com/(?:originals|474x|236x|736x)/[^"\s]+})
42
+ if match
43
+ url = match[0]
44
+ reset = "\e[0m"
45
+ green = "\e[32m"
46
+ puts "#{green}image url :#{reset} #{url}"
47
+ return url
48
+ end
49
+
50
+ puts 'No found'
51
+ nil
52
+ end
53
+
54
+
55
+ def get_video_url(pin_url)
56
+ html = fetch_html(pin_url)
57
+ return nil unless html
58
+
59
+ # 1 -> json-ld
60
+ url = extract_json_ld(html, 'VideoObject')
61
+ if url
62
+ url = url.gsub('\\u002F', '/').gsub('\\', '')
63
+ puts "ok : #{url}"
64
+ return url
65
+ end
66
+
67
+ # 2 -> Open Graph video
68
+ match = html.match(%r{<meta[^>]*property="og:video"[^>]*content="([^"]+)"})
69
+ if match
70
+ url = match[1].gsub('\\u002F', '/').gsub('\\', '')
71
+ puts "video url: #{url}"
72
+ return url
73
+ end
74
+
75
+ # 3 -> contentUrl in page source
76
+ match = html.match(/"contentUrl"\s*:\s*"([^"]+\.mp4[^"]*)"/)
77
+ if match
78
+ url = match[1].gsub('\\u002F', '/').gsub('\\', '')
79
+ green = "\e[32m"
80
+ reset = "\e[0m"
81
+ puts "#{green}video url :#{reset} #{url}"
82
+ return url
83
+ end
84
+
85
+ puts 'No found'
86
+ nil
87
+ end
88
+
89
+ private
90
+
91
+ def fetch_html(url)
92
+ uri = URI(url)
93
+ http = Net::HTTP.new(uri.host, uri.port)
94
+ http.use_ssl = (uri.scheme == 'https')
95
+ http.max_retries = 2
96
+ http.open_timeout = 10
97
+ http.read_timeout = 20
98
+
99
+ resp = http.request(Net::HTTP::Head.new(uri, 'User-Agent' => USER_AGENT))
100
+
101
+ 5.times do
102
+ break unless resp.is_a?(Net::HTTPRedirection)
103
+ location = resp['location']
104
+ location = URI.join(uri.to_s, location) if location.start_with?('/')
105
+ uri = URI(location)
106
+ http = Net::HTTP.new(uri.host, uri.port)
107
+ http.use_ssl = (uri.scheme == 'https')
108
+ resp = http.request(Net::HTTP::Head.new(uri, 'User-Agent' => USER_AGENT))
109
+ end
110
+
111
+ # get final page
112
+ req = Net::HTTP::Get.new(uri, 'User-Agent' => USER_AGENT)
113
+ resp = http.request(req)
114
+
115
+ return resp.body if resp.is_a?(Net::HTTPSuccess)
116
+ nil
117
+ rescue StandardError => e
118
+ red = "\e[31m"
119
+ reset = "\e[0m"
120
+ puts "#{red}http err!:#{reset} #{e.message}"
121
+ nil
122
+ end
123
+ def extract_json_ld(html, type)
124
+ match = html.match(%r{<script[^>]*type="application/ld\+json"[^>]*>(.*?)</script>}m)
125
+ return nil unless match
126
+
127
+ begin
128
+ data = JSON.parse(match[1])
129
+ data = data[0] if data.is_a?(Array) && !data.empty?
130
+ return data['contentUrl'] if data['@type'] == type && data['contentUrl']
131
+ rescue JSON::ParserError
132
+ end
133
+ nil
134
+ end
135
+ end
136
+ end
metadata ADDED
@@ -0,0 +1,43 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pinterest-dl
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Monji
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 2026-02-12 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: Simple Pinterest Downloader Tool:)
13
+ email: hoseinmonjiofficial@gmail.com
14
+ executables: []
15
+ extensions: []
16
+ extra_rdoc_files: []
17
+ files:
18
+ - README.md
19
+ - lib/pinterest-dl.rb
20
+ homepage: https://github.com/monji024/pinterest-dl
21
+ licenses:
22
+ - MIT
23
+ metadata:
24
+ source_code_uri: https://github.com/monji024/pinterest-dl
25
+ bug_tracker_uri: https://github.com/monji024/pinterest-dl/issues
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 2.5.0
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubygems_version: 3.6.3
41
+ specification_version: 4
42
+ summary: Extract direct image/video URLs from Pinterest!!!
43
+ test_files: []