panchira 0.3.0 → 1.0.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: e0715fad65f1b2f6654761d9d1132217ce644c49b621a94aff1f0a6372dd327b
4
- data.tar.gz: 265c9ab995d2c2913465e0dd17e69c008389c1c06e3b8fbeb798e24dcdced89d
3
+ metadata.gz: b5625692d52a2fa265db20d62c9311f877a27b4a8d099446bae7dda346b9fcb5
4
+ data.tar.gz: 0be90bf0354d5f87ca15e213722c7c44b4c522ec9ad048a611c8f0d307e8fb84
5
5
  SHA512:
6
- metadata.gz: 231b3b600e88c20f3479943c93efd3b8d720c7052c45c26301818b88a860ac8387610fdd7006c2c6211ecf482a76b24389e4e409290c8817869a3a19af0b0966
7
- data.tar.gz: a69dfa20c85d5ef15c12d825dd791450835c7ac9edf511a2b3b5592621706ba0c80d94cf258fd513dc8568e5972270fd5e7271a3c7219c0a3ad8724e4a9a0b23
6
+ metadata.gz: 98c86bab322717af51f335a5c252dd465c3ec06fdb4bd54e3d3c166153e9571d3b6a94625ab708c286cf18ef8846114cc74cc6ec27f66e376bddbd4fbfcb8aae
7
+ data.tar.gz: 1efabc99a91e770e47a06ddb527cf72ac361f165a0e5f5a4fcfc4ab17eae99436a55bdb70f721da0826117e6febd10062736b47c02442ae8870a6604070bf2e2
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- panchira (0.3.0)
4
+ panchira (1.0.0)
5
5
  fastimage (~> 2.1.7)
6
6
  nokogiri (~> 1.10.9)
7
7
 
data/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  Due to some legal or ethical issues, most hentai and NSFW platforms don't clarify their content on meta tags. As a result, most hentai platforms are rendered poorly on the card previews on social media.
8
8
 
9
- To solve this issue, Panchira is made to parse correct and uncensored metadata from such web platforms (at this time we cover **DLSite, Komiflo, Melonbooks, Nijie and Pixiv**).
9
+ To solve this issue, Panchira is made to parse correct and uncensored metadata from such web platforms (at this time we cover **DLSite, Komiflo, Melonbooks, Nijie, Pixiv, Shousetsuka ni narou and Twitter**).
10
10
 
11
11
  If you need card previews of hentai on your web application, but can't get them with simply parsing metatags, then it is time for Panchira.
12
12
 
@@ -39,10 +39,12 @@ Or install it yourself as:
39
39
  ```
40
40
  > Panchira.fetch("https://www.pixiv.net/artworks/61711172")
41
41
 
42
- => {:canonical_url=>"https://pixiv.net/member_illust.php?mode=medium&illust_id=61711172", :title=>"#輿水幸子 すずしい顔で締め切りを破る幸子 - むらためのイラスト - pixiv", :description=>"(UTF16の)Pietで実行すると「すずしい」と出力する幸子(5色+白Pietカラーゴルフ)。解説記事は http://chy72.hatenablog.com/entry/2016/12/24/1", :image=>{:url=>"https://pixiv.cat/61711172.jpg", :width=>810, :height=>500}}
42
+ => #<Panchira::PanchiraResult:0x00007fb95d2c53f8 @canonical_url="https://pixiv.net/member_illust.php?mode=medium&illust_id=61711172", @title="#輿水幸子 すずしい顔で締め切りを破る幸子 - むらためのイラスト - pixiv", @description="(UTF16の)Pietで実行すると「すずしい」と出力する幸子(5色+白Pietカラーゴルフ)。解説記事は http://chy72.hatenablog.com/entry/2016/12/24/1", @image=#<Panchira::PanchiraImage:0x00007fb95f126ea0 @url="https://pixiv.cat/61711172.jpg", @width=810, @height=500>, @tags=["輿水幸子", "Piet", "プログラミング"]>
43
43
  ```
44
44
 
45
- Panchira is in beta at this time and doesn't have stable API documentation yet.
45
+ In most situation you would call `Panchira#fetch`. It is a singular method that takes a URI and returns an instance of `PanchiraResult`, which is a simple class that stores the website's information, such as title, description and so on.
46
+
47
+ Panchira has a special treatment for each website. `Resolver` classes are where those treatments take place, and you can use your own `Resolver` classes by registering it to Panchira. See `Panchira::Extensions` documentation in source code for further details.
46
48
 
47
49
  ## Development
48
50
 
@@ -8,6 +8,6 @@ module Panchira
8
8
 
9
9
  # Result class for Panchira.fetch.
10
10
  class PanchiraResult
11
- attr_accessor :canonical_url, :title, :description, :image
11
+ attr_accessor :canonical_url, :title, :description, :image, :tags
12
12
  end
13
13
  end
@@ -9,6 +9,10 @@ module Panchira
9
9
  def parse_image_url
10
10
  @page.css('//meta[property="og:image"]/@content').first.to_s.sub(/sam/, 'main')
11
11
  end
12
+
13
+ def parse_tags
14
+ @page.css('.main_genre').children.children.map(&:text)
15
+ end
12
16
  end
13
17
 
14
18
  ::Panchira::Extensions.register(Panchira::DlsiteResolver)
@@ -37,6 +37,10 @@ module Panchira
37
37
  id = @url.slice(%r{komiflo\.com(?:/#!)?/comics/(\d+)}, 1)
38
38
  'https://komiflo.com/comics/' + id
39
39
  end
40
+
41
+ def parse_tags
42
+ @json['content']['attributes']['tags']['children'].map{|content| content['data']['name']}
43
+ end
40
44
  end
41
45
 
42
46
  ::Panchira::Extensions.register(Panchira::KomifloResolver)
@@ -25,6 +25,10 @@ module Panchira
25
25
  def parse_image_url
26
26
  @page.css('//meta[property="og:image"]/@content').first.to_s.sub(/&c=1/, '')
27
27
  end
28
+
29
+ def parse_tags
30
+ @page.css('#related_tags .clearfix').children.children.map(&:text)
31
+ end
28
32
  end
29
33
 
30
34
  ::Panchira::Extensions.register(Panchira::MelonbooksResolver)
@@ -3,18 +3,42 @@
3
3
  require 'net/https'
4
4
 
5
5
  module Panchira
6
- class NarouResolver < Resolver
7
- URL_REGEXP = %r{novel18\.syosetu\.com/}.freeze
6
+ module Narou
7
+ class Novel18Resolver < Resolver
8
+ URL_REGEXP = %r{novel18\.syosetu\.com/}.freeze
9
+ ID_REGEXP = %{novel18\.syosetu\.com/(?<id>[^/]+)}.freeze
8
10
 
9
- def fetch_page(uri)
10
- u = URI.parse(uri)
11
- http = Net::HTTP.new(u.host, u.port)
12
- http.use_ssl = u.port == 443
13
- res = http.get u.request_uri, { 'cookie' => 'over18=yes;' }
11
+ def fetch_page(uri)
12
+ u = URI.parse(uri)
13
+ http = Net::HTTP.new(u.host, u.port)
14
+ http.use_ssl = u.port == 443
15
+ res = http.get u.request_uri, { 'cookie' => 'over18=yes;' }
14
16
 
15
- Nokogiri::HTML.parse(res.body, uri)
17
+ Nokogiri::HTML.parse(res.body, uri)
18
+ end
19
+
20
+ def parse_tags
21
+ id = @url.match(ID_REGEXP)[:id]
22
+ return [] unless id
23
+
24
+ desc = fetch_page("https://novel18.syosetu.com/novelview/infotop/ncode/#{id}/")
25
+ desc.xpath('//*[@id="noveltable1"]/tr[3]')&.text&.split("\n\n\n")&.dig(1)&.split(' ') # つらい。
26
+ end
27
+ end
28
+ class NcodeResolver < Resolver
29
+ URL_REGEXP = %r{ncode\.syosetu\.com}.freeze
30
+ ID_REGEXP = %{ncode\.syosetu\.com/(?<id>[^/]+)}.freeze
31
+
32
+ def parse_tags
33
+ id = @url.match(ID_REGEXP)[:id]
34
+ return [] unless id
35
+
36
+ desc = fetch_page("https://ncode.syosetu.com/novelview/infotop/ncode/#{id}/")
37
+ desc.xpath('//*[@id="noveltable1"]/tr[3]')&.text&.split("\n\n\n")&.dig(1)&.delete("\u00A0")&.split(' ')&.grep_v('') # めっちゃつらい。
38
+ end
16
39
  end
17
40
  end
18
41
 
19
- ::Panchira::Extensions.register(Panchira::NarouResolver)
42
+ ::Panchira::Extensions.register(Panchira::Narou::NcodeResolver)
43
+ ::Panchira::Extensions.register(Panchira::Narou::Novel18Resolver)
20
44
  end
@@ -24,6 +24,10 @@ module Panchira
24
24
  @page.css('//meta[property="og:image"]/@content').first.to_s
25
25
  end
26
26
  end
27
+
28
+ def parse_tags
29
+ @page.css('#view-tag span.tag_name').map(&:text)
30
+ end
27
31
  end
28
32
 
29
33
  ::Panchira::Extensions.register(Panchira::NijieResolver)
@@ -7,6 +7,9 @@ module Panchira
7
7
  def initialize(url)
8
8
  super(url)
9
9
  @illust_id = url.slice(URL_REGEXP, 2)
10
+
11
+ raw_json = URI.parse("https://www.pixiv.net/ajax/illust/#{@illust_id}").read('User-Agent' => USER_AGENT)
12
+ @json = JSON.parse(raw_json)
10
13
  end
11
14
 
12
15
  private
@@ -27,6 +30,10 @@ module Panchira
27
30
  rescue StandardError
28
31
  @page.css('//meta[property="og:image"]/@content').first.to_s
29
32
  end
33
+
34
+ def parse_tags
35
+ @json['body']['tags']['tags'].map{|content| content['tag']}
36
+ end
30
37
  end
31
38
 
32
39
  ::Panchira::Extensions.register(Panchira::PixivResolver)
@@ -30,6 +30,7 @@ module Panchira
30
30
  result.title = parse_title
31
31
  result.description = parse_description
32
32
  result.image = parse_image
33
+ result.tags = parse_tags
33
34
 
34
35
  result
35
36
  end
@@ -97,5 +98,9 @@ module Panchira
97
98
  def parse_image_url
98
99
  @page.css('//meta[property="og:image"]/@content').first.to_s
99
100
  end
101
+
102
+ def parse_tags
103
+ []
104
+ end
100
105
  end
101
106
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Panchira
4
- VERSION = '0.3.0'
4
+ VERSION = '1.0.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: panchira
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kyp
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-04 00:00:00.000000000 Z
11
+ date: 2020-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler