ZMediumToMarkdown 2.3.8 → 2.4.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.
- checksums.yaml +4 -4
- data/bin/ZMediumToMarkdown +17 -5
- data/lib/Post.rb +15 -2
- data/lib/ZMediumFetcher.rb +14 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c57f5610ede891d1c9677db7c4c3c0345bb5d309f5825538524d238db5b991c4
|
4
|
+
data.tar.gz: d06da63e8bb12bb776959d93d9dddff1f407a9654cec1883916b94c7ddd6b2d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2437e85b4184dfe4e72e8923af91a7ae4f849e973f618c4a66d8ff7edd3fc09122f32cc11152f8a947fc74d0fbec1f751eff57d94e036ef3b19060252c08d088
|
7
|
+
data.tar.gz: d374e8169f365f4934b2911a96028680dc2ab0f57edd3a3a07469876ec131d0429679b45f9ba52202544c048792551d2f9bca47478a4c79fbed102f75a11ee00
|
data/bin/ZMediumToMarkdown
CHANGED
@@ -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('-
|
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('-
|
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('-
|
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('-
|
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)
|
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
|
-
|
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"
|
69
|
+
json&.dig(0, "data", "post", "viewerEdge", "fullContent")
|
57
70
|
else
|
58
71
|
nil
|
59
72
|
end
|
data/lib/ZMediumFetcher.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2024-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|