ZMediumToMarkdown 2.3.7 → 2.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a97b61290289e8989c8bd6283be69f1e8167636b0489d7af46b66a5ec7307936
4
- data.tar.gz: 9d270ec137cf4cae7438f9038ec79fa7bd09748e891d82aeda47d0ed4fd4f1dd
3
+ metadata.gz: c57f5610ede891d1c9677db7c4c3c0345bb5d309f5825538524d238db5b991c4
4
+ data.tar.gz: d06da63e8bb12bb776959d93d9dddff1f407a9654cec1883916b94c7ddd6b2d9
5
5
  SHA512:
6
- metadata.gz: 16767e5244986c9ece667ce4c6f26a2a676253b1421a202a4a2820225dd248b249d6df424474ae400c851f6c30c7011c0379384d2e3f7bd52060809cfde807e4
7
- data.tar.gz: 9616218726f4dcea5d00cbbb5ad75fe15ae9c6aa2eae1f29232fc9c27eef5bccc7da3ca056caef791098ff044f2262ee4946e613212a22d431011e1f712bbb17
6
+ metadata.gz: 2437e85b4184dfe4e72e8923af91a7ae4f849e973f618c4a66d8ff7edd3fc09122f32cc11152f8a947fc74d0fbec1f751eff57d94e036ef3b19060252c08d088
7
+ data.tar.gz: d374e8169f365f4934b2911a96028680dc2ab0f57edd3a3a07469876ec131d0429679b45f9ba52202544c048792551d2f9bca47478a4c79fbed102f75a11ee00
@@ -8,6 +8,9 @@ require "ZMediumFetcher"
8
8
  require "Helper"
9
9
  require "optparse"
10
10
 
11
+ $cookie_sid = nil
12
+ $cookie_uid = nil
13
+
11
14
  class Main
12
15
  def initialize
13
16
  fetcher = ZMediumFetcher.new
@@ -17,22 +20,31 @@ class Main
17
20
 
18
21
  OptionParser.new do |opts|
19
22
  opts.banner = "Usage: ZMediumFetcher [options]"
20
-
21
- opts.on('-uUSERNAME', '--username=USERNAME', 'Downloading all posts from user') do |username|
23
+
24
+ opts.on('-s', '--cookie_sid COOKIESID', 'Your logged-in Medium cookie sid value') do |cookie_sid|
25
+ $cookie_sid = cookie_sid
26
+ puts $cookie_sid
27
+ end
28
+
29
+ opts.on('-d', '--cookie_uid COOKIEUID', 'Your logged-in Medium cookie uid value') do |cookie_uid|
30
+ $cookie_uid = cookie_uid
31
+ end
32
+
33
+ opts.on('-u', '--username USERNAME', 'Downloading all posts from user') do |username|
22
34
  outputFilePath = PathPolicy.new("#{filePath}/Output", "Output")
23
35
  fetcher.downloadPostsByUsername(username, outputFilePath)
24
36
 
25
37
  Helper.printNewVersionMessageIfExists()
26
38
  end
27
39
 
28
- opts.on('-pPOST_URL', '--postURL=POST_URL', 'Downloading single post') do |postURL|
40
+ opts.on('-p', '--postURL POST_URL', 'Downloading single post') do |postURL|
29
41
  outputFilePath = PathPolicy.new("#{filePath}/Output", "Output")
30
42
  fetcher.downloadPost(postURL, outputFilePath, nil)
31
43
 
32
44
  Helper.printNewVersionMessageIfExists()
33
45
  end
34
46
 
35
- opts.on('-jUSERNAME', '--jekyllUsername=USERNAME', 'Downloading all posts from user with Jekyll friendly') do |username|
47
+ opts.on('-j', '--jekyllUsername USERNAME', 'Downloading all posts from user with Jekyll friendly') do |username|
36
48
  outputFilePath = PathPolicy.new(filePath, "")
37
49
  fetcher.isForJekyll = true
38
50
  fetcher.downloadPostsByUsername(username, outputFilePath)
@@ -40,7 +52,7 @@ class Main
40
52
  Helper.printNewVersionMessageIfExists()
41
53
  end
42
54
 
43
- opts.on('-kPOST_URL', '--jekyllPostURL=POST_URL', 'Downloading single post with Jekyll friendly') do |postURL|
55
+ opts.on('-k', '--jekyllPostURL POST_URL', 'Downloading single post with Jekyll friendly') do |postURL|
44
56
  outputFilePath = PathPolicy.new(filePath, "")
45
57
  fetcher.isForJekyll = true
46
58
  fetcher.downloadPost(postURL, outputFilePath, nil)
@@ -8,6 +8,10 @@ class ImageDownloader
8
8
  dir.pop()
9
9
  Helper.createDirIfNotExist(dir.join("/"))
10
10
 
11
+ if File.exist?(path)
12
+ return true
13
+ end
14
+
11
15
  begin
12
16
  imageResponse = URI.open(url)
13
17
  File.write(path, imageResponse.read)
data/lib/Post.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  $lib = File.expand_path('../lib', File.dirname(__FILE__))
2
2
 
3
3
  require "Request"
4
+ require "net/http"
4
5
  require 'uri'
5
6
  require 'nokogiri'
6
7
  require 'json'
@@ -50,10 +51,22 @@ class Post
50
51
  }
51
52
  ]
52
53
 
53
- body = Request.body(Request.URL("https://medium.com/_/graphql", "POST", query))
54
+ uri = URI("https://medium.com/_/graphql")
55
+ https = Net::HTTP.new(uri.host, uri.port)
56
+ https.use_ssl = true
57
+ request = Net::HTTP::Post.new(uri)
58
+ request['Content-Type'] = 'application/json'
59
+ if !$cookie_sid.nil? && !$cookie_uid.nil?
60
+ request['Cookie'] = "sid=#{$cookie_sid}; uid=#{$cookie_uid}"
61
+ end
62
+ request.body = JSON.dump(query)
63
+ response = https.request(request)
64
+
65
+
66
+ body = Request.body(response)
54
67
  if !body.nil?
55
68
  json = JSON.parse(body)
56
- json&.dig(0, "data", "post", "viewerEdge", "fullContent", "bodyModel", "paragraphs")
69
+ json&.dig(0, "data", "post", "viewerEdge", "fullContent")
57
70
  else
58
71
  nil
59
72
  end
@@ -148,8 +148,21 @@ class ZMediumFetcher
148
148
  end
149
149
 
150
150
  postInfo = Post.parsePostInfoFromPostContent(postContent, postID, imagePathPolicy)
151
+ contentInfo = Post.fetchPostParagraphs(postID)
152
+
153
+ if contentInfo.nil?
154
+ raise "Error: Paragraph Content not found! PostURL: #{postURL}"
155
+ end
156
+
157
+ isLockedPreviewOnly = contentInfo&.dig("isLockedPreviewOnly")
158
+
159
+ if isLockedPreviewOnly
160
+ puts "Skip: This post is listed in Medium's paywall. You need to provide Medium Member vaild logged-in cookies to access it (refer to Readme.md). PostURL: #{postURL}"
161
+ return
162
+ end
163
+
164
+ sourceParagraphs = contentInfo&.dig("bodyModel", "paragraphs")
151
165
 
152
- sourceParagraphs = Post.fetchPostParagraphs(postID)
153
166
  if sourceParagraphs.nil?
154
167
  raise "Error: Paragraph not found! PostURL: #{postURL}"
155
168
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ZMediumToMarkdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.7
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ZhgChgLi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-26 00:00:00.000000000 Z
11
+ date: 2024-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri