pinterest-dl 2.0.0 → 2.0.1
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/lib/pinterest_dl/board.rb +11 -16
- data/lib/pinterest_dl/search.rb +5 -3
- data/lib/pinterest_dl/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b4d94f0a5bbac63a983308d541b5e50a6a13c1d5bee422c356e56395c686ebcd
|
|
4
|
+
data.tar.gz: 148473c309ec313a3e0d7ddb0864f0388d22a2bf9edee39e819e54ccaab10745
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4e26a226009b81da00d41f46f9ccfcdca2f058aa7ff93210b488e1f2082c27f927103f5a0329dcea921ea34a62c49c3ad70c77d411d4a1b569b4b97fbba8c4cf
|
|
7
|
+
data.tar.gz: 66b3ddf6d10555f9e018198a3de376578b22fc504dfe386d8a49f06bdcc213519e0b273c5f123d34bcb33eb3217da51af7609712a2f1a0a3b67004be6858eb9b
|
data/lib/pinterest_dl/board.rb
CHANGED
|
@@ -5,20 +5,15 @@ require 'net/http'
|
|
|
5
5
|
require 'uri'
|
|
6
6
|
|
|
7
7
|
module PinterestDL
|
|
8
|
-
# Handles Pinterest's internal search resource, including pagination
|
|
9
|
-
# via the `bookmarks` cursor Pinterest returns with each page.
|
|
10
8
|
class Search
|
|
11
|
-
|
|
9
|
+
B_URL = 'https://www.pinterest.com/resource/BaseSearchResource/get/'
|
|
12
10
|
|
|
13
11
|
def initialize(client: PinterestDL::Client.new, config: PinterestDL.config)
|
|
14
12
|
@client = client
|
|
15
13
|
@config = config
|
|
16
14
|
end
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
# @param limit [Integer] max number of pins to return in total
|
|
20
|
-
# @param pages [Integer] max number of pages to fetch (pagination safety valve)
|
|
21
|
-
# @return [Array<Hash>] pin metadata hashes
|
|
16
|
+
|
|
22
17
|
def call(query, limit: 25, pages: 5)
|
|
23
18
|
results = []
|
|
24
19
|
bookmarks = nil
|
|
@@ -55,17 +50,17 @@ module PinterestDL
|
|
|
55
50
|
options[:bookmarks] = bookmarks if bookmarks && !bookmarks.empty?
|
|
56
51
|
data = { options: options, context: {} }.to_json
|
|
57
52
|
|
|
58
|
-
res_uri = URI(
|
|
53
|
+
res_uri = URI(B_URL)
|
|
59
54
|
res_uri.query = URI.encode_www_form('source_url' => source_path, 'data' => data)
|
|
60
55
|
|
|
61
56
|
body = @client.get(res_uri.to_s, use_cache: false, headers: {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
57
|
+
'Accept' => 'application/json, text/javascript, */*, q=0.01',
|
|
58
|
+
'X-Requested-With' => 'XMLHttpRequest',
|
|
59
|
+
'X-Pinterest-PWS-Handler' => 'www/search/[scope].js',
|
|
60
|
+
'X-CSRFToken' => csrf,
|
|
61
|
+
'Referer' => home_uri.to_s,
|
|
62
|
+
'Cookie' => cookie_header
|
|
63
|
+
})
|
|
69
64
|
|
|
70
65
|
json = safe_parse(body)
|
|
71
66
|
raise PinterestDL::NotFoundError, "No search results for \"#{query}\"" unless json
|
|
@@ -73,7 +68,7 @@ module PinterestDL
|
|
|
73
68
|
data_node = json.dig('resource_response', 'data') || {}
|
|
74
69
|
raw_results = data_node['results'] || []
|
|
75
70
|
next_bookmarks = json.dig('resource_response', 'bookmark') ||
|
|
76
|
-
|
|
71
|
+
json.dig('resource', 'options', 'bookmarks')
|
|
77
72
|
|
|
78
73
|
{ pins: raw_results.filter_map { |r| build_pin(r) }, bookmarks: Array(next_bookmarks) }
|
|
79
74
|
end
|
data/lib/pinterest_dl/search.rb
CHANGED
|
@@ -6,7 +6,7 @@ require 'uri'
|
|
|
6
6
|
|
|
7
7
|
module PinterestDL
|
|
8
8
|
class Search
|
|
9
|
-
|
|
9
|
+
S_URL = 'https://www.pinterest.com/resource/BaseSearchResource/get/'
|
|
10
10
|
|
|
11
11
|
def initialize(client: PinterestDL::Client.new, config: PinterestDL.config)
|
|
12
12
|
@client = client
|
|
@@ -50,6 +50,8 @@ module PinterestDL
|
|
|
50
50
|
parse_search_response(json)
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
+
# Pinterest's search resource requires a session cookie + CSRF token
|
|
54
|
+
# obtained by first loading the human-facing search page.
|
|
53
55
|
def establish_session(query)
|
|
54
56
|
source_path = "/search/pins/?q=#{URI.encode_www_form_component(query)}"
|
|
55
57
|
home_uri = URI("https://www.pinterest.com#{source_path}")
|
|
@@ -69,7 +71,7 @@ module PinterestDL
|
|
|
69
71
|
options[:bookmarks] = bookmarks if bookmarks && !bookmarks.empty?
|
|
70
72
|
data = { options: options, context: {} }.to_json
|
|
71
73
|
|
|
72
|
-
res_uri = URI(
|
|
74
|
+
res_uri = URI(S_URL)
|
|
73
75
|
res_uri.query = URI.encode_www_form('source_url' => source_path, 'data' => data)
|
|
74
76
|
res_uri.to_s
|
|
75
77
|
end
|
|
@@ -91,7 +93,7 @@ module PinterestDL
|
|
|
91
93
|
data_node = json.dig('resource_response', 'data') || {}
|
|
92
94
|
raw_results = data_node['results'] || []
|
|
93
95
|
next_bookmarks = json.dig('resource_response', 'bookmark') ||
|
|
94
|
-
|
|
96
|
+
json.dig('resource', 'options', 'bookmarks')
|
|
95
97
|
|
|
96
98
|
{ pins: raw_results.filter_map { |r| build_pin(r) }, bookmarks: Array(next_bookmarks) }
|
|
97
99
|
end
|
data/lib/pinterest_dl/version.rb
CHANGED