webtoon_source 0.6.0 → 0.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 07b90095a4ff0d2080dc569a2ee23258f94b09b39bbe7b3a3f44b7f2df369b66
4
- data.tar.gz: fed20be0a93c2c2468c65e5795267a896bd43e5989d9b68fe16e055b0288456d
3
+ metadata.gz: 6e361313d7c25a7daac18a01e865e73ce896089b5bda16868625e47e3d4ae050
4
+ data.tar.gz: 801159263b0dfc575e5bc9ed18a0140543e850589a96a22d82345f1bd5065492
5
5
  SHA512:
6
- metadata.gz: e1c6da5483a82ef197b7c3aa0c1f20dfa950a2757dda2ceae9cf2a65d716684b96e63d899e74bfdba8121e250327223df710e9400d5b72f047d2a5684c9e9268
7
- data.tar.gz: b79911952acd161ef9a0b4fb3a66fdd4f6efcfd5c4a7f7b17fa848a9555adf9f129851f1a4084922d20cd2abcb88734789906a67dcb34ef05f8ab6c027068efe
6
+ metadata.gz: d53c17ae128bb2b87e1b6820342d46036aed2b9a050d8a2332a8e5beeccdef2fc71ade71d502f260d6fc9cb168822d3390b6cc66ee1019ec609cb335b1bdb398
7
+ data.tar.gz: 72828378d742228d9241067bb0331eeb7c695f5e8fc08c15f44ff61e665838cc07da3a072875143979c5aadc9dc3856ad9d218452fb785212b3d2dd1aa8dbfe9
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.4.9
@@ -6,17 +6,19 @@ class WebtoonSource::AsuraScans
6
6
  SERIES_NAME_PATTERN = /(.+)-/
7
7
  PANEL_PATTERN = %r{{\\"order\\":(\d+),\\"url\\":\\"(https://gg.asuracomic.net/storage/media/\d+/conversions/[^"]+)\\"}}
8
8
 
9
- PANEL_ORDER = 0
10
- PANEL_LINK = 1
9
+ PANEL_ORDER = 1
10
+ PANEL_LINK = 0
11
11
 
12
12
  def initialize(domain)
13
- @conn = Faraday.new(domain)
13
+ @conn = Faraday.new(domain) do |config|
14
+ config.headers["User-Agent"] = "WebtoonSource/#{WebtoonSource::VERSION}"
15
+ end
14
16
 
15
17
  yield(self) if block_given?
16
18
  end
17
19
 
18
20
  def latest_updates(params = { page: 1 })
19
- response = @conn.get("/series", params)
21
+ response = @conn.get("/comics", params)
20
22
  # Capture group 1 - series slug
21
23
  # Capture group 2 - anchor tag inner content.
22
24
  series_pattern = %r{<a\s+href="series/([^"]+)"[^>]*>(.*?)</a>}
@@ -32,9 +34,9 @@ class WebtoonSource::AsuraScans
32
34
  end
33
35
 
34
36
  def download(params) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
35
- panels, chapter, name = params.values_at(:panels, :chapter, :name)
37
+ panels, chapter, directory = params.values_at(:panels, :chapter, :directory)
36
38
 
37
- chapter_storage_path = File.join(@storage_path, name, chapter.to_s)
39
+ chapter_storage_path = File.join(@storage_path, directory, chapter.to_s)
38
40
 
39
41
  FileUtils.mkdir_p(chapter_storage_path) unless Dir.exist?(chapter_storage_path)
40
42
 
@@ -43,7 +45,7 @@ class WebtoonSource::AsuraScans
43
45
 
44
46
  media_conn = Faraday.new(panel_domain)
45
47
 
46
- panels.each do |order, link|
48
+ panels.each do |link, order|
47
49
  panel_path = URI(link).path
48
50
  panel_name = "#{order.rjust(2, "0")}.webp"
49
51
 
@@ -61,13 +63,28 @@ class WebtoonSource::AsuraScans
61
63
  slug.match(SERIES_NAME_PATTERN).to_a.last
62
64
  end
63
65
 
64
- def panels(params)
65
- slug, chapter = params.values_at(:slug, :chapter)
66
- chapter_slug = File.join("series", slug, "chapter", chapter.to_s)
67
-
66
+ def panels(chapter_slug)
68
67
  response = @conn.get(chapter_slug)
68
+ chapter_number = chapter_slug.match(%r{chapter/(.+)}).to_a.last
69
+
70
+ panel_pattern = %r{(https://cdn.asurascans.com/asura-images/chapters/.+?/#{chapter_number}/(\d+)\.webp)}
69
71
 
70
- panels = response.body.scan(PANEL_PATTERN).uniq
72
+ panels = response.body.scan(panel_pattern).uniq
71
73
  panels.sort { |a, b| a[PANEL_ORDER].to_i <=> b[PANEL_ORDER].to_i }
72
74
  end
75
+
76
+ def chapters(slug)
77
+ response = @conn.get("comics/#{slug}")
78
+ chapter_pattern = %r{<a\shref="/comics/#{slug}/chapter/([^"]+)}
79
+
80
+ chapters = response.body.scan(chapter_pattern).flatten.uniq
81
+
82
+ sorted = chapters.sort { |a, b| a.to_i <=> b.to_i }
83
+
84
+ sorted.map do |chapter|
85
+ chapter_slug = "comics/#{slug}/chapter/#{chapter}"
86
+
87
+ { chapter_slug:, chapter_number: chapter }
88
+ end
89
+ end
73
90
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class WebtoonSource
4
- VERSION = "0.6.0"
4
+ VERSION = "0.8.0"
5
5
  end
@@ -14,7 +14,7 @@ class WebtoonSource
14
14
  DEFAULT_STORAGE_PATH = File.join(Dir.home, "webtoon_source")
15
15
 
16
16
  DOMAINS = {
17
- asura_scans: "https://asuracomic.net",
17
+ asura_scans: "https://asurascans.com",
18
18
  manhuaus: "https://manhuaus.com/"
19
19
  }.freeze
20
20
 
@@ -55,8 +55,12 @@ class WebtoonSource
55
55
  @source.download(params)
56
56
  end
57
57
 
58
- def panels(params)
59
- @source.panels(params)
58
+ def panels(chapter_slug)
59
+ @source.panels(chapter_slug)
60
+ end
61
+
62
+ def chapters(slug)
63
+ @source.chapters(slug)
60
64
  end
61
65
 
62
66
  def metadata(mal_id)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webtoon_source
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Kenneth Sinay
@@ -35,6 +35,7 @@ executables: []
35
35
  extensions: []
36
36
  extra_rdoc_files: []
37
37
  files:
38
+ - ".ruby-version"
38
39
  - CHANGELOG.md
39
40
  - CODE_OF_CONDUCT.md
40
41
  - LICENSE.txt
@@ -62,7 +63,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
63
  - !ruby/object:Gem::Version
63
64
  version: '0'
64
65
  requirements: []
65
- rubygems_version: 4.0.3
66
+ rubygems_version: 3.6.9
66
67
  specification_version: 4
67
68
  summary: A gem to source your manhwas from webtoon platforms.
68
69
  test_files: []