ZMediumToMarkdown 2.5.0 → 2.5.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/ZMediumToMarkdown +3 -4
  3. data/lib/Request.rb +21 -15
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3e2329fa42690e35efea3b0231c03949d460484e821f27b9a3da53fe43908906
4
- data.tar.gz: 9636ba2e044114cda97780db906014f4bbe7859af23c3236cc79d8928040fffa
3
+ metadata.gz: 71e19d6c888e760923f2bf919d3fc34b29bd30835cc5c563da057369108b18a2
4
+ data.tar.gz: '03862c8cf6f9dc3b894470f918b0247bb8457f0bebe7299da4cceea0816bc17c'
5
5
  SHA512:
6
- metadata.gz: 1aad74dfa4a903110456dd1fab95ba2b4c2b88e4e355a39312b7dd1924bdf8fb2c9e38581c92ad3651f91ba5ffd0c385ed172fa4834d0aed3d605e89f3b7bc70
7
- data.tar.gz: 31ba0e2502cc5d10ed64ab69ae15864526dd90b698962ba05054f22f1c20d0d518416e0fce86f61980cdc5f3466db9d7dfa1e4f313cec876ea664a1ca4d1306d
6
+ metadata.gz: 4290ca60752a6033ee16dd75c8c537b0cd4030c89d3765d92ca596dfae87c69da6a780f3608eea8cfa62a3897374f77141b3f83243b44860acbe5736247d46d2
7
+ data.tar.gz: 39e4d1d11db6cd81a309e476f7bc63024cc2d32401fb4ef1649fb68989c6f45759dd1214d2a6040fd0694e53fed905edc554bc5e16d8b6769b5ef8a3dc30347c
@@ -8,8 +8,7 @@ require "ZMediumFetcher"
8
8
  require "Helper"
9
9
  require "optparse"
10
10
 
11
- $cookie_sid = nil
12
- $cookie_uid = nil
11
+ $cookies = {}
13
12
 
14
13
  class Main
15
14
  def initialize
@@ -23,11 +22,11 @@ class Main
23
22
  opts.banner = "Usage: ZMediumFetcher [options]"
24
23
 
25
24
  opts.on('-s', '--cookie_sid COOKIESID', 'Your logged-in Medium cookie sid value') do |cookie_sid|
26
- $cookie_sid = cookie_sid
25
+ $cookies['sid'] = cookie_sid
27
26
  end
28
27
 
29
28
  opts.on('-d', '--cookie_uid COOKIEUID', 'Your logged-in Medium cookie uid value') do |cookie_uid|
30
- $cookie_uid = cookie_uid
29
+ $cookies['uid'] = cookie_uid
31
30
  end
32
31
 
33
32
  opts.on('-u', '--username USERNAME', 'Downloading all posts from user') do |username|
data/lib/Request.rb CHANGED
@@ -22,32 +22,38 @@ class Request
22
22
  end
23
23
  end
24
24
 
25
- if !$cookie_sid.nil? && !$cookie_uid.nil?
26
- request['Cookie'] = "sid=#{$cookie_sid}; uid=#{$cookie_uid}";
25
+ cookiesString = $cookies.reject { |_, value| value.nil? }
26
+ .map { |key, value| "#{key}=#{value}" }
27
+ .join("; ");
28
+
29
+ if !cookiesString.nil? && cookiesString != ""
30
+ request['Cookie'] = cookiesString;
27
31
  end
28
32
 
29
33
  response = https.request(request);
30
34
 
31
- cookies = response.get_fields('set-cookie').map { |cookie| cookie.split('; ').first }.each_with_object({}) do |cookie, hash|
32
- key, value = cookie.split('=', 2) # Split by '=' into key and value
33
- hash[key] = value
34
- end;
35
-
36
- if !cookies['uid'].nil?
37
- $cookie_uid = cookies['uid'];
38
- end
35
+ setCookieString = response.get_fields('set-cookie');
36
+ if !setCookieString.nil? && setCookieString != ""
37
+ setCookies = setCookieString.map { |cookie| cookie.split('; ').first }.each_with_object({}) do |cookie, hash|
38
+ key, value = cookie.split('=', 2) # Split by '=' into key and value
39
+ hash[key] = value
40
+ end;
39
41
 
40
- if !cookies['sid'].nil?
41
- $cookie_sid = cookies['sid'];
42
+ setCookies.each do |key, value|
43
+ $cookies[key] = value
44
+ end
42
45
  end
43
46
 
44
- puts response
45
47
  # 3XX Redirect
46
48
  if response.code.to_i == 429
47
- raise "Error: Too Manay Reqeust, blocked by Medium.\n####################\n### Please try again later.\n### Ref: https://zhgchg.li/posts/en-medium-to-jekyll/#paywall-posts-require-a-medium-account-with-access-permissions-and-cookies-author-or-medium-member \n####################\n### ERROR URL: #{url}"
49
+ if retryCount >= 10
50
+ raise "Error: Too Manay Reqeust, blocked by Medium. URL: #{url}";
51
+ else
52
+ response = self.URL(url, method, data, retryCount);
53
+ end
48
54
  elsif response.code.to_i >= 300 && response.code.to_i <= 399 && !response['location'].nil? && response['location'] != ''
49
55
  if retryCount >= 10
50
- raise "Error: Retry limit reached. path: #{url}"
56
+ raise "Error: Retry limit reached. URL: #{url}"
51
57
  else
52
58
  location = response['location']
53
59
  if !location.match? /^(http)/
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ZMediumToMarkdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ZhgChgLi