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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +5 -3
- data/lib/panchira/panchira_result.rb +1 -1
- data/lib/panchira/resolvers/dlsite_resolver.rb +4 -0
- data/lib/panchira/resolvers/komiflo_resolver.rb +4 -0
- data/lib/panchira/resolvers/melonbooks_resolver.rb +4 -0
- data/lib/panchira/resolvers/narou_resolver.rb +33 -9
- data/lib/panchira/resolvers/nijie_resolver.rb +4 -0
- data/lib/panchira/resolvers/pixiv_resolver.rb +7 -0
- data/lib/panchira/resolvers/resolver.rb +5 -0
- data/lib/panchira/version.rb +1 -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: b5625692d52a2fa265db20d62c9311f877a27b4a8d099446bae7dda346b9fcb5
|
4
|
+
data.tar.gz: 0be90bf0354d5f87ca15e213722c7c44b4c522ec9ad048a611c8f0d307e8fb84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98c86bab322717af51f335a5c252dd465c3ec06fdb4bd54e3d3c166153e9571d3b6a94625ab708c286cf18ef8846114cc74cc6ec27f66e376bddbd4fbfcb8aae
|
7
|
+
data.tar.gz: 1efabc99a91e770e47a06ddb527cf72ac361f165a0e5f5a4fcfc4ab17eae99436a55bdb70f721da0826117e6febd10062736b47c02442ae8870a6604070bf2e2
|
data/Gemfile.lock
CHANGED
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
|
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
|
-
=>
|
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
|
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
|
|
@@ -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
|
-
|
7
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
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::
|
42
|
+
::Panchira::Extensions.register(Panchira::Narou::NcodeResolver)
|
43
|
+
::Panchira::Extensions.register(Panchira::Narou::Novel18Resolver)
|
20
44
|
end
|
@@ -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
|
data/lib/panchira/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2020-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|