webtoon_source 0.4.0 → 0.6.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: 84c3872b98c0871c7ebb7de85a05e6da119187e8cbb44dfec8e6ff9a6166d3ed
4
- data.tar.gz: 1c9f93cf981fb435571ce93a3b3469b5282c0200aca40db058426eba714f82cd
3
+ metadata.gz: 07b90095a4ff0d2080dc569a2ee23258f94b09b39bbe7b3a3f44b7f2df369b66
4
+ data.tar.gz: fed20be0a93c2c2468c65e5795267a896bd43e5989d9b68fe16e055b0288456d
5
5
  SHA512:
6
- metadata.gz: 35b20661e7c04540c4ef3e8f21d35bb8f308f64c1ca15d13c3720c899a5795d01c4e958e370b7bef2cd3594c569dfe7cbf21bd222e8946b4eee5c798cf6f936f
7
- data.tar.gz: 8881783a6941ab286dbffa44fa8b7fe1f2b1fa13e8d574a281c7dd56a268140ba6ff64e24cf6be4cb8371e3974a95a907dcbec96498c70156389d5ab6cfedafd
6
+ metadata.gz: e1c6da5483a82ef197b7c3aa0c1f20dfa950a2757dda2ceae9cf2a65d716684b96e63d899e74bfdba8121e250327223df710e9400d5b72f047d2a5684c9e9268
7
+ data.tar.gz: b79911952acd161ef9a0b4fb3a66fdd4f6efcfd5c4a7f7b17fa848a9555adf9f129851f1a4084922d20cd2abcb88734789906a67dcb34ef05f8ab6c027068efe
data/README.md CHANGED
@@ -1,43 +1,21 @@
1
1
  # WebtoonSource
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
4
-
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/webtoon_source`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ A gem to source your webtoons from webtoon platforms.
6
4
 
7
5
  ## Installation
8
6
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
-
11
7
  Install the gem and add to the application's Gemfile by executing:
12
8
 
13
9
  ```bash
14
- bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
10
+ bundle add webtoon_source
15
11
  ```
16
12
 
17
13
  If bundler is not being used to manage dependencies, install the gem by executing:
18
14
 
19
15
  ```bash
20
- gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
16
+ gem install webtoon_source
21
17
  ```
22
18
 
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/webtoon_source. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/webtoon_source/blob/master/CODE_OF_CONDUCT.md).
36
-
37
19
  ## License
38
20
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
-
41
- ## Code of Conduct
42
-
43
- Everyone interacting in the WebtoonSource project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/webtoon_source/blob/master/CODE_OF_CONDUCT.md).
21
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -1,10 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class WebtoonSource::AsuraScans
4
- HOST_NAME = "https://asuracomic.net"
4
+ attr_accessor :storage_path
5
5
 
6
- def initialize(host_name = HOST_NAME)
7
- @conn = Faraday.new(host_name)
6
+ SERIES_NAME_PATTERN = /(.+)-/
7
+ PANEL_PATTERN = %r{{\\"order\\":(\d+),\\"url\\":\\"(https://gg.asuracomic.net/storage/media/\d+/conversions/[^"]+)\\"}}
8
+
9
+ PANEL_ORDER = 0
10
+ PANEL_LINK = 1
11
+
12
+ def initialize(domain)
13
+ @conn = Faraday.new(domain)
14
+
15
+ yield(self) if block_given?
8
16
  end
9
17
 
10
18
  def latest_updates(params = { page: 1 })
@@ -22,4 +30,44 @@ class WebtoonSource::AsuraScans
22
30
  [slug, thumbnail_link]
23
31
  end
24
32
  end
33
+
34
+ def download(params) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
35
+ panels, chapter, name = params.values_at(:panels, :chapter, :name)
36
+
37
+ chapter_storage_path = File.join(@storage_path, name, chapter.to_s)
38
+
39
+ FileUtils.mkdir_p(chapter_storage_path) unless Dir.exist?(chapter_storage_path)
40
+
41
+ panel_link = URI(panels.first[PANEL_LINK])
42
+ panel_domain = "#{panel_link.scheme}://#{panel_link.hostname}"
43
+
44
+ media_conn = Faraday.new(panel_domain)
45
+
46
+ panels.each do |order, link|
47
+ panel_path = URI(link).path
48
+ panel_name = "#{order.rjust(2, "0")}.webp"
49
+
50
+ panel_storage_path = File.join(chapter_storage_path, panel_name)
51
+
52
+ File.open(panel_storage_path, "wb") do |f|
53
+ media_conn.get(panel_path) do |response|
54
+ response.options.on_data = proc { |chunk, _size| f.write chunk }
55
+ end
56
+ end
57
+ end
58
+ end
59
+
60
+ def extract_series_name(slug)
61
+ slug.match(SERIES_NAME_PATTERN).to_a.last
62
+ end
63
+
64
+ def panels(params)
65
+ slug, chapter = params.values_at(:slug, :chapter)
66
+ chapter_slug = File.join("series", slug, "chapter", chapter.to_s)
67
+
68
+ response = @conn.get(chapter_slug)
69
+
70
+ panels = response.body.scan(PANEL_PATTERN).uniq
71
+ panels.sort { |a, b| a[PANEL_ORDER].to_i <=> b[PANEL_ORDER].to_i }
72
+ end
25
73
  end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Source of metadata.
4
+ class WebtoonSource::Jikan
5
+ VERSION = "v4"
6
+
7
+ def initialize
8
+ @conn = Faraday.new("https://api.jikan.moe") do |config|
9
+ config.request :json
10
+ config.response :json
11
+ config.response :raise_error
12
+ end
13
+ end
14
+
15
+ def manga_full_by_id(mal_id)
16
+ response = @conn.get("#{VERSION}/manga/#{mal_id}/full")
17
+ response.body["data"]
18
+ end
19
+
20
+ def search(params)
21
+ response = @conn.get("#{VERSION}/manga", params)
22
+ response.body
23
+ end
24
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module WebtoonSource
4
- VERSION = "0.4.0"
3
+ class WebtoonSource
4
+ VERSION = "0.6.0"
5
5
  end
@@ -1,17 +1,86 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "webtoon_source/version"
4
- require_relative "webtoon_source/configuration"
5
4
  require_relative "webtoon_source/asura_scans"
5
+ require_relative "webtoon_source/jikan"
6
6
  require "faraday"
7
+ require "fileutils"
7
8
 
9
+ # This is the main namespace for WebtoonSource.
8
10
  class WebtoonSource
9
11
  class Error < StandardError; end
10
- attr_accessor :storage_path
12
+ attr_reader :storage_path, :domain
11
13
 
12
- def initialize(platform = "asura_scans")
13
- @platform = platform
14
+ DEFAULT_STORAGE_PATH = File.join(Dir.home, "webtoon_source")
15
+
16
+ DOMAINS = {
17
+ asura_scans: "https://asuracomic.net",
18
+ manhuaus: "https://manhuaus.com/"
19
+ }.freeze
20
+
21
+ SOURCES = {
22
+ asura_scans: WebtoonSource::AsuraScans
23
+ }.freeze
24
+
25
+ def initialize(platform = :asura_scans)
26
+ @storage_path = DEFAULT_STORAGE_PATH
27
+
28
+ @domain = DOMAINS[platform]
29
+ @source_class = SOURCES[platform] || raise(WebtoonSource::Error, "Unknown platform: #{platform}")
30
+
31
+ @source = @source_class.new(@domain) do |config|
32
+ config.storage_path = @storage_path
33
+ end
14
34
 
15
35
  yield(self) if block_given?
16
36
  end
37
+
38
+ def domain=(value)
39
+ domain_callback(value)
40
+ @domain = value
41
+ end
42
+
43
+ def storage_path=(value)
44
+ storage_path_callback(value)
45
+ @storage_path = value
46
+ end
47
+
48
+ # Checks if a specific chapter for a webtoon has been downloaded.
49
+ def downloaded?(chapter_path)
50
+ path = File.join(@storage_path, chapter_path)
51
+ Dir.exist?(path) && !Dir.empty?(path)
52
+ end
53
+
54
+ def download(params)
55
+ @source.download(params)
56
+ end
57
+
58
+ def panels(params)
59
+ @source.panels(params)
60
+ end
61
+
62
+ def metadata(mal_id)
63
+ jikan_service.manga_full_by_id(mal_id)
64
+ end
65
+
66
+ def search(params)
67
+ jikan_service.search(params)
68
+ end
69
+
70
+ private
71
+
72
+ def domain_callback(new_domain)
73
+ @source = @source_class.new(new_domain)
74
+ end
75
+
76
+ def storage_path_callback(new_storage_path)
77
+ @source = @source_class.new(@domain) do |config|
78
+ config.storage_path = new_storage_path
79
+ end
80
+ end
81
+
82
+ def jikan_service
83
+ service ||= Jikan.new
84
+ service
85
+ end
17
86
  end
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.4.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Kenneth Sinay
@@ -42,7 +42,7 @@ files:
42
42
  - Rakefile
43
43
  - lib/webtoon_source.rb
44
44
  - lib/webtoon_source/asura_scans.rb
45
- - lib/webtoon_source/configuration.rb
45
+ - lib/webtoon_source/jikan.rb
46
46
  - lib/webtoon_source/version.rb
47
47
  - sig/webtoon_source.rbs
48
48
  licenses:
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module WebtoonSource
4
- BASE_STORAGE_PATH = "webtoon_source"
5
-
6
- class Configuration
7
- attr_accessor :storage_path
8
-
9
- def initialize
10
- @storage_path = File.join(Dir.home, BASE_STORAGE_PATH)
11
- end
12
- end
13
- end