comicinfo-comic_vine 0.1.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 +7 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +15 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.md +21 -0
- data/README.md +56 -0
- data/Rakefile +10 -0
- data/lib/comicinfo/comic_vine/client.rb +77 -0
- data/lib/comicinfo/comic_vine/cover_date.rb +26 -0
- data/lib/comicinfo/comic_vine/credits.rb +25 -0
- data/lib/comicinfo/comic_vine/errors.rb +26 -0
- data/lib/comicinfo/comic_vine/found_issue.rb +84 -0
- data/lib/comicinfo/comic_vine/plain_text.rb +27 -0
- data/lib/comicinfo/comic_vine/version.rb +5 -0
- data/lib/comicinfo/comic_vine.rb +105 -0
- data/sig/comicinfo/comic_vine.rbs +6 -0
- metadata +90 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 966f46bf37bf140d3eba6be4f8f2fa5ccf9eeb70a863f1f49a1efc8c10b5fef3
|
|
4
|
+
data.tar.gz: ce0ff386adbf22ddfced79d9faa23470b33833b6627015b1c9358ca32d2377cb
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 20de97b47bcdf1ae78c650c339f740dc9825a41777faedcdfdbf3e160a4cde8721211b9ae0fd6042674876b51124d474c7373141af1903493633e5bdb72c22d0
|
|
7
|
+
data.tar.gz: 69774c9a2046b2437361c357a4050a5936705f6a9148c7ca79ef6de60ae9a59574ccf7e4fcfa31d29bbb3a2a92a58a89f33ad1bc8329f597a48fd11aea768b5e
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
4.0.9
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.1.0] - 2026-11-26
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `ComicInfo::ComicVine`, a metadata source for [Comic Vine](https://comicvine.gamespot.com). `matches(issue)` finds the issue with the comic's number in every series whose name matches, ranked by series name then cover year. `issue(match)` reads the picked issue and its series into a `ComicInfo::Issue`: title, cover year and month, publisher, issue count, summary as plain text, credits by role, characters, teams, locations, story arcs, and its Comic Vine page
|
|
14
|
+
- `ComicInfo::ComicVine::HTTPError` and `ComicInfo::ComicVine::APIError`: an HTTP error status, or an error Comic Vine reports itself, such as an invalid API key
|
|
15
|
+
- A live API spec, run against the real Comic Vine API when `COMIC_VINE_API_KEY` is set and skipped when it isn't
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
|
10
|
+
identity and orientation.
|
|
11
|
+
|
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
|
13
|
+
diverse, inclusive, and healthy community.
|
|
14
|
+
|
|
15
|
+
## Our Standards
|
|
16
|
+
|
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
|
18
|
+
community include:
|
|
19
|
+
|
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
|
24
|
+
and learning from the experience
|
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
|
26
|
+
community
|
|
27
|
+
|
|
28
|
+
Examples of unacceptable behavior include:
|
|
29
|
+
|
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
|
31
|
+
any kind
|
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
|
33
|
+
* Public or private harassment
|
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
|
35
|
+
without their explicit permission
|
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
37
|
+
professional setting
|
|
38
|
+
|
|
39
|
+
## Enforcement Responsibilities
|
|
40
|
+
|
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
|
44
|
+
or harmful.
|
|
45
|
+
|
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
|
49
|
+
decisions when appropriate.
|
|
50
|
+
|
|
51
|
+
## Scope
|
|
52
|
+
|
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
|
54
|
+
an individual is officially representing the community in public spaces.
|
|
55
|
+
Examples of representing our community include using an official email address,
|
|
56
|
+
posting via an official social media account, or acting as an appointed
|
|
57
|
+
representative at an online or offline event.
|
|
58
|
+
|
|
59
|
+
## Enforcement
|
|
60
|
+
|
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
62
|
+
reported to the community leaders responsible for enforcement at
|
|
63
|
+
veganstraightedge@gmail.com.
|
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
|
65
|
+
|
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
|
67
|
+
reporter of any incident.
|
|
68
|
+
|
|
69
|
+
## Enforcement Guidelines
|
|
70
|
+
|
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
|
73
|
+
|
|
74
|
+
### 1. Correction
|
|
75
|
+
|
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
|
77
|
+
unprofessional or unwelcome in the community.
|
|
78
|
+
|
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
|
82
|
+
|
|
83
|
+
### 2. Warning
|
|
84
|
+
|
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
|
86
|
+
actions.
|
|
87
|
+
|
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
|
93
|
+
ban.
|
|
94
|
+
|
|
95
|
+
### 3. Temporary Ban
|
|
96
|
+
|
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
|
98
|
+
sustained inappropriate behavior.
|
|
99
|
+
|
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
|
101
|
+
communication with the community for a specified period of time. No public or
|
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
|
104
|
+
Violating these terms may lead to a permanent ban.
|
|
105
|
+
|
|
106
|
+
### 4. Permanent Ban
|
|
107
|
+
|
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
|
111
|
+
|
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
|
113
|
+
community.
|
|
114
|
+
|
|
115
|
+
## Attribution
|
|
116
|
+
|
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
|
118
|
+
version 2.1, available at
|
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
|
120
|
+
|
|
121
|
+
Community Impact Guidelines were inspired by
|
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
|
123
|
+
|
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
|
127
|
+
|
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Shane Becker
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# comicinfo-comic_vine
|
|
2
|
+
|
|
3
|
+
Looks up comic details in [Comic Vine](https://comicvine.gamespot.com), for the [comicinfo](https://github.com/veganstraightedge/comicinfo) gem.
|
|
4
|
+
|
|
5
|
+
`ComicInfo::ComicVine` is a metadata source: it searches Comic Vine for an issue, and returns what Comic Vine knows about the one picked as a `ComicInfo::Issue`. See [Looking Up Details in Online Databases](https://github.com/veganstraightedge/comicinfo/blob/main/doc/metadata-sources.md).
|
|
6
|
+
|
|
7
|
+
It's the Ruby counterpart of [ComicInfoComicVine.swift](https://github.com/veganstraightedge/ComicInfoComicVine.swift).
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```ruby
|
|
12
|
+
gem 'comicinfo-comic_vine'
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```ruby
|
|
18
|
+
require 'comicinfo/comic_vine'
|
|
19
|
+
|
|
20
|
+
comic_vine = ComicInfo::ComicVine.new api_key: 'your API key', user_agent: 'MyApp/1.0'
|
|
21
|
+
|
|
22
|
+
issue = ComicInfo.load 'path/to/ComicInfo.xml'
|
|
23
|
+
matches = comic_vine.matches issue # best first
|
|
24
|
+
found = comic_vine.issue matches[0] # after a person picks one
|
|
25
|
+
updated = issue.with_blanks_filled_from found
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
- `matches` needs a Series and a Number; `missing_details` says so when either is blank.
|
|
29
|
+
- It searches every series whose name matches, so a recent series with a common name isn't missed, and ranks the matches by series name, then cover year.
|
|
30
|
+
- `issue` reads the issue and its series: title, cover year and month, publisher, issue count, summary (as plain text), credits by role, characters, teams, locations, story arcs, and the issue's Comic Vine page as its web link.
|
|
31
|
+
- A request Comic Vine refuses raises `ComicInfo::ComicVine::HTTPError` (with its `status`), and an error Comic Vine reports, such as an invalid API key, raises `ComicInfo::ComicVine::APIError` (with its `reason`). Both are `ComicInfo::ComicVine::Error`s.
|
|
32
|
+
|
|
33
|
+
## Terms
|
|
34
|
+
|
|
35
|
+
- An API key comes with a free Comic Vine account: <https://comicvine.gamespot.com/api/>.
|
|
36
|
+
- Comic Vine's data is for non-commercial use only, and whatever shows it must credit and link to Comic Vine (`comic_vine.name`, `comic_vine.home_url`).
|
|
37
|
+
- Comic Vine refuses generic HTTP clients, so `user_agent:` must name your app.
|
|
38
|
+
|
|
39
|
+
## Development
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
bin/setup # bundle install
|
|
43
|
+
bundle exec rake # specs and RuboCop
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The specs answer every request from a local server with a recorded Comic Vine response from `spec/fixtures/`, so they need no key or network.
|
|
47
|
+
|
|
48
|
+
`spec/comic_info/comic_vine_live_spec.rb` also calls the real API, when `COMIC_VINE_API_KEY` holds an API key. Without it, it's skipped:
|
|
49
|
+
|
|
50
|
+
```sh
|
|
51
|
+
COMIC_VINE_API_KEY=your-key bundle exec rake
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## License
|
|
55
|
+
|
|
56
|
+
[MIT](LICENSE.md)
|
data/Rakefile
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
require 'net/http'
|
|
3
|
+
require 'uri'
|
|
4
|
+
require_relative 'errors'
|
|
5
|
+
|
|
6
|
+
module ComicInfo
|
|
7
|
+
class ComicVine
|
|
8
|
+
# Calls the Comic Vine API with one API key.
|
|
9
|
+
#
|
|
10
|
+
# Results are Comic Vine's JSON, parsed with symbol keys. See
|
|
11
|
+
# https://comicvine.gamespot.com/api/documentation
|
|
12
|
+
class Client
|
|
13
|
+
# The fields asked for whenever a volume is read
|
|
14
|
+
VOLUME_FIELDS = 'count_of_issues,id,name,publisher,site_detail_url,start_year'.freeze
|
|
15
|
+
|
|
16
|
+
# The most volumes one list request returns
|
|
17
|
+
VOLUME_LIST_LIMIT = 100
|
|
18
|
+
|
|
19
|
+
def initialize api_key:, base_url:, user_agent:
|
|
20
|
+
@api_key = api_key
|
|
21
|
+
@base_url = base_url
|
|
22
|
+
@user_agent = user_agent
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# The series whose names match query, best first; Comic Vine stops at 10
|
|
26
|
+
def search_volumes query
|
|
27
|
+
get 'search/', field_list: VOLUME_FIELDS,
|
|
28
|
+
query:,
|
|
29
|
+
resources: 'volume'
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Up to 100 volumes whose names contain name, newest first.
|
|
33
|
+
#
|
|
34
|
+
# Wider than #search_volumes, which can leave a recent series of a common name ("Archie") out.
|
|
35
|
+
def list_volumes name
|
|
36
|
+
# The filter syntax separates filters with commas, so a name's own commas are left out of it.
|
|
37
|
+
filter_name = name.tr ',', ' '
|
|
38
|
+
|
|
39
|
+
get 'volumes/', field_list: VOLUME_FIELDS,
|
|
40
|
+
filter: "name:#{filter_name}",
|
|
41
|
+
limit: VOLUME_LIST_LIMIT,
|
|
42
|
+
sort: 'start_year:desc'
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# The issues numbered number in any of the volumes
|
|
46
|
+
def find_issues number:, volume_ids:
|
|
47
|
+
volumes = volume_ids.join '|'
|
|
48
|
+
|
|
49
|
+
get 'issues/', field_list: 'cover_date,id,issue_number,name,site_detail_url,volume',
|
|
50
|
+
filter: "volume:#{volumes},issue_number:#{number}"
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# One issue, credits and all
|
|
54
|
+
def issue(id) = get "issue/4000-#{id}/"
|
|
55
|
+
|
|
56
|
+
# One volume: its publisher, start year and issue count
|
|
57
|
+
def volume(id) = get "volume/4050-#{id}/", field_list: VOLUME_FIELDS
|
|
58
|
+
|
|
59
|
+
private
|
|
60
|
+
|
|
61
|
+
# Calls one API resource and returns its results
|
|
62
|
+
def get path, parameters = {}
|
|
63
|
+
uri = URI.join @base_url, path
|
|
64
|
+
uri.query = URI.encode_www_form parameters.merge(api_key: @api_key, format: 'json').sort
|
|
65
|
+
|
|
66
|
+
response = Net::HTTP.get_response uri, 'User-Agent' => @user_agent
|
|
67
|
+
raise HTTPError, response.code.to_i unless response.is_a? Net::HTTPOK
|
|
68
|
+
|
|
69
|
+
body = JSON.parse response.body, symbolize_names: true
|
|
70
|
+
# The status is read first: an error response's results are an empty list, whatever was asked for.
|
|
71
|
+
raise APIError, body[:error] unless body[:status_code] == 1
|
|
72
|
+
|
|
73
|
+
body[:results]
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module ComicInfo
|
|
2
|
+
class ComicVine
|
|
3
|
+
# A cover date such as "2007-10-01", as a year and month.
|
|
4
|
+
#
|
|
5
|
+
# The day is left out: Comic Vine writes the 1st when it only knows the month.
|
|
6
|
+
class CoverDate
|
|
7
|
+
def initialize text
|
|
8
|
+
@parts = text.to_s.split '-'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# The year, or nil when there isn't one
|
|
12
|
+
def year
|
|
13
|
+
year = Integer @parts[0], 10, exception: false if @parts.length >= 2
|
|
14
|
+
|
|
15
|
+
year if year&.between? 1000, 9999
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# The month, 1 to 12, or nil when there isn't one
|
|
19
|
+
def month
|
|
20
|
+
month = Integer @parts[1], 10, exception: false if @parts.length >= 2
|
|
21
|
+
|
|
22
|
+
month if month&.between? 1, 12
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module ComicInfo
|
|
2
|
+
class ComicVine
|
|
3
|
+
# The people credited on an issue, by lowercase role.
|
|
4
|
+
#
|
|
5
|
+
# Comic Vine gives each person a comma-separated list of roles, such as "artist, writer".
|
|
6
|
+
class Credits
|
|
7
|
+
def initialize people
|
|
8
|
+
@names_by_role = Hash.new { |hash, role| hash[role] = [] }
|
|
9
|
+
|
|
10
|
+
people.each do |person|
|
|
11
|
+
person[:role].to_s.split(',').each do |role|
|
|
12
|
+
@names_by_role[role.strip.downcase] << person[:name]
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Everyone credited with any of the roles, each once, in order, joined with commas; nil when no one is
|
|
18
|
+
def names *roles
|
|
19
|
+
people = roles.flat_map { @names_by_role.fetch it, [] }.uniq
|
|
20
|
+
|
|
21
|
+
people.join ', ' unless people.empty?
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module ComicInfo
|
|
2
|
+
class ComicVine
|
|
3
|
+
# Why a Comic Vine request failed
|
|
4
|
+
class Error < ComicInfo::Error; end
|
|
5
|
+
|
|
6
|
+
# Comic Vine answered with an HTTP error status, such as 403 or 503
|
|
7
|
+
class HTTPError < Error
|
|
8
|
+
attr_reader :status
|
|
9
|
+
|
|
10
|
+
def initialize status
|
|
11
|
+
@status = status
|
|
12
|
+
super("Comic Vine answered with HTTP status #{status}.")
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Comic Vine answered with an error of its own, such as "Invalid API Key"
|
|
17
|
+
class APIError < Error
|
|
18
|
+
attr_reader :reason
|
|
19
|
+
|
|
20
|
+
def initialize reason
|
|
21
|
+
@reason = reason
|
|
22
|
+
super("Comic Vine said: #{reason}.")
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
require 'nokogiri'
|
|
2
|
+
require_relative 'cover_date'
|
|
3
|
+
require_relative 'credits'
|
|
4
|
+
require_relative 'plain_text'
|
|
5
|
+
|
|
6
|
+
module ComicInfo
|
|
7
|
+
class ComicVine
|
|
8
|
+
# A Comic Vine issue and its volume, as a ComicInfo::Issue.
|
|
9
|
+
#
|
|
10
|
+
# The issue is built from ComicInfo XML with only the fields Comic Vine knows, so
|
|
11
|
+
# ComicInfo::Issue#with_blanks_filled_from keeps what a comic already has.
|
|
12
|
+
class FoundIssue
|
|
13
|
+
# - issue: Comic Vine's issue detail
|
|
14
|
+
# - volume: Comic Vine's detail for the issue's volume
|
|
15
|
+
def initialize issue:, volume:
|
|
16
|
+
@issue = issue
|
|
17
|
+
@volume = volume
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def to_issue
|
|
21
|
+
ComicInfo.load(xml)
|
|
22
|
+
.with_characters(names(@issue[:character_credits]))
|
|
23
|
+
.with_locations(names(@issue[:location_credits]))
|
|
24
|
+
.with_teams(names(@issue[:team_credits]))
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
# ComicInfo XML with every field Comic Vine knows, by element name
|
|
30
|
+
def xml
|
|
31
|
+
document = Nokogiri::XML::Document.new
|
|
32
|
+
root = document.create_element 'ComicInfo'
|
|
33
|
+
|
|
34
|
+
fields.each { |element, value| root.add_child document.create_element(element, value.to_s) }
|
|
35
|
+
document.root = root
|
|
36
|
+
|
|
37
|
+
document.to_xml
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def fields
|
|
41
|
+
credits = Credits.new @issue[:person_credits].to_a
|
|
42
|
+
cover_date = CoverDate.new @issue[:cover_date]
|
|
43
|
+
summary = PlainText.new(@issue[:description]).text || PlainText.new(@issue[:deck]).text
|
|
44
|
+
|
|
45
|
+
{
|
|
46
|
+
'Colorist' => credits.names('colorist', 'colourist'),
|
|
47
|
+
'Count' => count,
|
|
48
|
+
'CoverArtist' => credits.names('cover'),
|
|
49
|
+
'Editor' => credits.names('editor'),
|
|
50
|
+
'Inker' => credits.names('inker', 'artist'),
|
|
51
|
+
'Letterer' => credits.names('letterer'),
|
|
52
|
+
'Month' => cover_date.month,
|
|
53
|
+
'Number' => present(@issue[:issue_number]),
|
|
54
|
+
'Penciller' => credits.names('penciler', 'penciller', 'artist'),
|
|
55
|
+
'Publisher' => present(@volume.dig(:publisher, :name)),
|
|
56
|
+
'Series' => present(@volume[:name] || @issue.dig(:volume, :name)),
|
|
57
|
+
'StoryArc' => present(names(@issue[:story_arc_credits]).join(', ')),
|
|
58
|
+
'Summary' => summary,
|
|
59
|
+
'Title' => present(@issue[:name]),
|
|
60
|
+
'Web' => present(@issue[:site_detail_url]),
|
|
61
|
+
'Writer' => credits.names('writer'),
|
|
62
|
+
'Year' => cover_date.year
|
|
63
|
+
}.compact
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# The volume's issue count, or nil when Comic Vine doesn't know it
|
|
67
|
+
def count
|
|
68
|
+
count = @volume[:count_of_issues]
|
|
69
|
+
|
|
70
|
+
count if count.to_i.positive?
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# The names of the characters, teams, locations, or story arcs Comic Vine credits
|
|
74
|
+
def names(references) = references.to_a.filter_map { it[:name] }
|
|
75
|
+
|
|
76
|
+
# The text, trimmed, or nil when it's blank
|
|
77
|
+
def present text
|
|
78
|
+
trimmed = text.to_s.strip
|
|
79
|
+
|
|
80
|
+
trimmed unless trimmed.empty?
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'nokogiri'
|
|
2
|
+
|
|
3
|
+
module ComicInfo
|
|
4
|
+
class ComicVine
|
|
5
|
+
# An HTML fragment, such as an issue's description, as plain text with its whitespace collapsed
|
|
6
|
+
class PlainText
|
|
7
|
+
# Elements whose text reads as separate from what's around them
|
|
8
|
+
BLOCK_ELEMENTS = %w[
|
|
9
|
+
address article aside blockquote br dd div dl dt figcaption figure footer
|
|
10
|
+
h1 h2 h3 h4 h5 h6 header hr li main nav ol p pre section table td th tr ul
|
|
11
|
+
].freeze
|
|
12
|
+
|
|
13
|
+
def initialize html
|
|
14
|
+
@html = html.to_s
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# The text, or nil when there is none
|
|
18
|
+
def text
|
|
19
|
+
fragment = Nokogiri::HTML5.fragment @html
|
|
20
|
+
fragment.css(*BLOCK_ELEMENTS).each { it.add_next_sibling Nokogiri::XML::Text.new(' ', fragment.document) }
|
|
21
|
+
text = fragment.text.split.join ' '
|
|
22
|
+
|
|
23
|
+
text unless text.empty?
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
require 'comicinfo'
|
|
2
|
+
require_relative 'comic_vine/client'
|
|
3
|
+
require_relative 'comic_vine/errors'
|
|
4
|
+
require_relative 'comic_vine/found_issue'
|
|
5
|
+
require_relative 'comic_vine/version'
|
|
6
|
+
|
|
7
|
+
module ComicInfo
|
|
8
|
+
# Looks up comic details in Comic Vine, https://comicvine.gamespot.com
|
|
9
|
+
#
|
|
10
|
+
# comic_vine = ComicInfo::ComicVine.new api_key: key, user_agent: 'MyApp/1.0'
|
|
11
|
+
# matches = comic_vine.matches issue
|
|
12
|
+
# found = comic_vine.issue matches.first
|
|
13
|
+
# updated = issue.with_blanks_filled_from found
|
|
14
|
+
#
|
|
15
|
+
# Comic Vine's terms: non-commercial use only, and whatever shows its data links back to it.
|
|
16
|
+
# An API key comes with a free account: https://comicvine.gamespot.com/api/
|
|
17
|
+
class ComicVine
|
|
18
|
+
BASE_URL = 'https://comicvine.gamespot.com/api/'.freeze
|
|
19
|
+
|
|
20
|
+
# - api_key: the account's Comic Vine API key
|
|
21
|
+
# - user_agent: names the app, such as "MyApp/1.0". Comic Vine refuses generic HTTP clients
|
|
22
|
+
# - base_url: where the API is, for testing against a server of your own
|
|
23
|
+
def initialize api_key:, user_agent:, base_url: BASE_URL
|
|
24
|
+
@client = Client.new(api_key:, base_url:, user_agent:)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def name = 'Comic Vine'
|
|
28
|
+
def home_url = 'https://comicvine.gamespot.com/'
|
|
29
|
+
|
|
30
|
+
# What the issue still needs before it can be searched for, or nil
|
|
31
|
+
def missing_details issue
|
|
32
|
+
return if present(issue.series) && present(issue.number)
|
|
33
|
+
|
|
34
|
+
'Comic Vine needs a Series and a Number to search for.'
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# The issues with the issue's number in every series whose name matches its series, best first.
|
|
38
|
+
#
|
|
39
|
+
# Comic Vine's search finds the best few series, and its list finds up to 100 more, newest first,
|
|
40
|
+
# so a recent series of a common name isn't missed.
|
|
41
|
+
def matches issue
|
|
42
|
+
searched = client.search_volumes issue.series
|
|
43
|
+
listed = client.list_volumes issue.series
|
|
44
|
+
|
|
45
|
+
volumes_by_id = (searched + listed).uniq { it[:id] }.to_h { [it[:id], it] }
|
|
46
|
+
searched_ids = searched.map { it[:id] }.uniq
|
|
47
|
+
listed_ids = listed.map { it[:id] }.uniq - searched_ids
|
|
48
|
+
|
|
49
|
+
# The issues list stops at 100 results, so the search's few, best series are asked about apart
|
|
50
|
+
# from the list's many, and first.
|
|
51
|
+
found = [searched_ids, listed_ids].reject(&:empty?).flat_map do |volume_ids|
|
|
52
|
+
client.find_issues number: issue.number, volume_ids:
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
matches = found.uniq { it[:id] }.map do |found_issue|
|
|
56
|
+
volume = volumes_by_id[found_issue.dig(:volume, :id)]
|
|
57
|
+
|
|
58
|
+
match_for found_issue, volume:
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
issue.rank matches
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Everything Comic Vine knows about the match's issue and its series, as a ComicInfo::Issue
|
|
65
|
+
def issue match
|
|
66
|
+
id = Integer match.id, 10, exception: false
|
|
67
|
+
raise APIError, "No issue with the ID #{match.id}" unless id
|
|
68
|
+
|
|
69
|
+
found = client.issue id
|
|
70
|
+
volume = client.volume found.dig(:volume, :id)
|
|
71
|
+
|
|
72
|
+
FoundIssue.new(issue: found, volume:).to_issue
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
private
|
|
76
|
+
|
|
77
|
+
attr_reader :client
|
|
78
|
+
|
|
79
|
+
# One issue from the issues list, in its volume, as a match
|
|
80
|
+
def match_for found, volume:
|
|
81
|
+
series = found.dig(:volume, :name) || volume&.dig(:name) || ''
|
|
82
|
+
start_year = present volume&.dig(:start_year)
|
|
83
|
+
year = start_year ? " (#{start_year})" : ''
|
|
84
|
+
cover_date = "Cover date #{present(found[:cover_date]) || 'unknown'}"
|
|
85
|
+
publisher = present volume&.dig(:publisher, :name)
|
|
86
|
+
details = [publisher, cover_date].compact.join ' · '
|
|
87
|
+
|
|
88
|
+
Match.new cover_date: found[:cover_date],
|
|
89
|
+
details:,
|
|
90
|
+
heading: "#{series}#{year} ##{found[:issue_number]}",
|
|
91
|
+
id: found[:id].to_s,
|
|
92
|
+
number: found[:issue_number],
|
|
93
|
+
series:,
|
|
94
|
+
site_url: found[:site_detail_url],
|
|
95
|
+
title: present(found[:name])
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# The text, trimmed, or nil when it's blank
|
|
99
|
+
def present text
|
|
100
|
+
trimmed = text.to_s.strip
|
|
101
|
+
|
|
102
|
+
trimmed unless trimmed.empty?
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: comicinfo-comic_vine
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Shane Becker
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: comicinfo
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '2.3'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '2.3'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: nokogiri
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 1.19.7
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: 1.19.7
|
|
40
|
+
description: |
|
|
41
|
+
A metadata source for the comicinfo gem: searches Comic Vine for an issue,
|
|
42
|
+
and returns what Comic Vine knows about the one picked as a ComicInfo::Issue
|
|
43
|
+
email:
|
|
44
|
+
- veganstraightedge@gmail.com
|
|
45
|
+
executables: []
|
|
46
|
+
extensions: []
|
|
47
|
+
extra_rdoc_files: []
|
|
48
|
+
files:
|
|
49
|
+
- ".ruby-version"
|
|
50
|
+
- CHANGELOG.md
|
|
51
|
+
- CODE_OF_CONDUCT.md
|
|
52
|
+
- LICENSE.md
|
|
53
|
+
- README.md
|
|
54
|
+
- Rakefile
|
|
55
|
+
- lib/comicinfo/comic_vine.rb
|
|
56
|
+
- lib/comicinfo/comic_vine/client.rb
|
|
57
|
+
- lib/comicinfo/comic_vine/cover_date.rb
|
|
58
|
+
- lib/comicinfo/comic_vine/credits.rb
|
|
59
|
+
- lib/comicinfo/comic_vine/errors.rb
|
|
60
|
+
- lib/comicinfo/comic_vine/found_issue.rb
|
|
61
|
+
- lib/comicinfo/comic_vine/plain_text.rb
|
|
62
|
+
- lib/comicinfo/comic_vine/version.rb
|
|
63
|
+
- sig/comicinfo/comic_vine.rbs
|
|
64
|
+
homepage: https://github.com/veganstraightedge/comicinfo-comic_vine
|
|
65
|
+
licenses:
|
|
66
|
+
- MIT
|
|
67
|
+
metadata:
|
|
68
|
+
allowed_push_host: https://rubygems.org
|
|
69
|
+
homepage_uri: https://github.com/veganstraightedge/comicinfo-comic_vine
|
|
70
|
+
source_code_uri: https://github.com/veganstraightedge/comicinfo-comic_vine
|
|
71
|
+
changelog_uri: https://github.com/veganstraightedge/comicinfo-comic_vine/blob/main/CHANGELOG.md
|
|
72
|
+
rubygems_mfa_required: 'true'
|
|
73
|
+
rdoc_options: []
|
|
74
|
+
require_paths:
|
|
75
|
+
- lib
|
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
|
+
requirements:
|
|
78
|
+
- - ">="
|
|
79
|
+
- !ruby/object:Gem::Version
|
|
80
|
+
version: 4.0.9
|
|
81
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
82
|
+
requirements:
|
|
83
|
+
- - ">="
|
|
84
|
+
- !ruby/object:Gem::Version
|
|
85
|
+
version: '0'
|
|
86
|
+
requirements: []
|
|
87
|
+
rubygems_version: 4.0.20
|
|
88
|
+
specification_version: 4
|
|
89
|
+
summary: Looks up comic details in Comic Vine, for the comicinfo gem
|
|
90
|
+
test_files: []
|