tvdb_party_v2 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/.gitignore +9 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +26 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +83 -0
- data/Rakefile +11 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/tvdb_party_v2.rb +10 -0
- data/lib/tvdb_party_v2/actor.rb +19 -0
- data/lib/tvdb_party_v2/banner.rb +34 -0
- data/lib/tvdb_party_v2/episode.rb +51 -0
- data/lib/tvdb_party_v2/search.rb +150 -0
- data/lib/tvdb_party_v2/series.rb +95 -0
- data/lib/tvdb_party_v2/version.rb +3 -0
- data/tvdb_party_v2.gemspec +35 -0
- metadata +91 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: f07d59956d9fe030bbeb2d96e0091da4f8f1486f
|
|
4
|
+
data.tar.gz: c545c672907eaaaf37e288ad0db6cb2cd11c6eb3
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 399d19db077513b2c670bf9fff1da0159853cacef1217058d03e9fea94e86aff14f9276d97a7341e58bb6778176e4e41e4f2b32cea1f753db21e782a6c24f2d4
|
|
7
|
+
data.tar.gz: 53773f41fe47a9c156bcd56aef532486da6782af3f80087adbe95a3f4d50b270a5bd6ff41f548a95d9235acdecfc0ce412703905947b850df639d272c0933319
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
|
2
|
+
|
|
3
|
+
## Our Pledge
|
|
4
|
+
|
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
|
10
|
+
orientation.
|
|
11
|
+
|
|
12
|
+
## Our Standards
|
|
13
|
+
|
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
|
15
|
+
include:
|
|
16
|
+
|
|
17
|
+
* Using welcoming and inclusive language
|
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
|
19
|
+
* Gracefully accepting constructive criticism
|
|
20
|
+
* Focusing on what is best for the community
|
|
21
|
+
* Showing empathy towards other community members
|
|
22
|
+
|
|
23
|
+
Examples of unacceptable behavior by participants include:
|
|
24
|
+
|
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
|
26
|
+
advances
|
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
|
28
|
+
* Public or private harassment
|
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
|
30
|
+
address, without explicit permission
|
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
|
32
|
+
professional setting
|
|
33
|
+
|
|
34
|
+
## Our Responsibilities
|
|
35
|
+
|
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
|
38
|
+
response to any instances of unacceptable behavior.
|
|
39
|
+
|
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
|
44
|
+
threatening, offensive, or harmful.
|
|
45
|
+
|
|
46
|
+
## Scope
|
|
47
|
+
|
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
|
49
|
+
when an individual is representing the project or its community. Examples of
|
|
50
|
+
representing a project or community include using an official project e-mail
|
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
|
53
|
+
further defined and clarified by project maintainers.
|
|
54
|
+
|
|
55
|
+
## Enforcement
|
|
56
|
+
|
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
|
58
|
+
reported by contacting the project team at davidpanchina@gmail.com. All
|
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
|
63
|
+
|
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
|
66
|
+
members of the project's leadership.
|
|
67
|
+
|
|
68
|
+
## Attribution
|
|
69
|
+
|
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
|
72
|
+
|
|
73
|
+
[homepage]: http://contributor-covenant.org
|
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
tvdb_party_v2 (0.1.0)
|
|
5
|
+
|
|
6
|
+
GEM
|
|
7
|
+
remote: https://rubygems.org/
|
|
8
|
+
specs:
|
|
9
|
+
httparty (0.16.2)
|
|
10
|
+
multi_xml (>= 0.5.2)
|
|
11
|
+
minitest (5.11.3)
|
|
12
|
+
multi_xml (0.6.0)
|
|
13
|
+
rake (10.5.0)
|
|
14
|
+
|
|
15
|
+
PLATFORMS
|
|
16
|
+
ruby
|
|
17
|
+
|
|
18
|
+
DEPENDENCIES
|
|
19
|
+
bundler (~> 1.16)
|
|
20
|
+
httparty
|
|
21
|
+
minitest
|
|
22
|
+
rake (~> 10.0)
|
|
23
|
+
tvdb_party_v2!
|
|
24
|
+
|
|
25
|
+
BUNDLED WITH
|
|
26
|
+
1.16.1
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 David Pan
|
|
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 all
|
|
13
|
+
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 THE
|
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 David Pan
|
|
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,83 @@
|
|
|
1
|
+
# TvdbPartyV2
|
|
2
|
+
|
|
3
|
+
Simple Ruby library to talk to thetvdb.com API v2
|
|
4
|
+
|
|
5
|
+
# what is thetvdb.com?
|
|
6
|
+
|
|
7
|
+
This site is an open tvshow database that can be modified by anybody.
|
|
8
|
+
thetvdb.com api v2.1.2 (https://api.thetvdb.com/swagger)
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
Add this line to your application's Gemfile:
|
|
13
|
+
|
|
14
|
+
```ruby
|
|
15
|
+
gem 'tvdb_party_v2'
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
And then execute:
|
|
19
|
+
|
|
20
|
+
$ bundle
|
|
21
|
+
|
|
22
|
+
Or install it yourself as:
|
|
23
|
+
|
|
24
|
+
$ gem install tvdb_party_v2
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
```ruby
|
|
30
|
+
# connect api
|
|
31
|
+
@thetvdb = TvdbPartyV2::Search.new(apikey,username,userkey)
|
|
32
|
+
|
|
33
|
+
# search tv show
|
|
34
|
+
r = @thetvdb.search("Homeland")
|
|
35
|
+
|
|
36
|
+
# get series
|
|
37
|
+
puts homeland = @thetvdb.get_series_by_id(r.first["id"])
|
|
38
|
+
|
|
39
|
+
# get episode
|
|
40
|
+
puts s01e01 = homeland.episode(1,1)
|
|
41
|
+
|
|
42
|
+
#get series fanart – pass in your language
|
|
43
|
+
puts homeland.fanart.first.url
|
|
44
|
+
=> "https://www.thetvdb.com/banners/fanart/original/247897-18.jpg"
|
|
45
|
+
|
|
46
|
+
#get series posters
|
|
47
|
+
puts homeland.posters.first.url
|
|
48
|
+
=> "https://www.thetvdb.com/banners/seasons/247897-1.jpg"
|
|
49
|
+
|
|
50
|
+
#get series banners
|
|
51
|
+
puts homeland.series_banners.first.url
|
|
52
|
+
=> "https://www.thetvdb.com/banners/graphical/247897-g.jpg"
|
|
53
|
+
|
|
54
|
+
#get season posters
|
|
55
|
+
puts homeland.season_posters(2).first.url
|
|
56
|
+
=> "https://www.thetvdb.com/banners/seasons/247897-2.jpg"
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Development
|
|
61
|
+
|
|
62
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
63
|
+
|
|
64
|
+
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
65
|
+
|
|
66
|
+
## Contributing
|
|
67
|
+
|
|
68
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/davidpan/tvdb_party_v2. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
|
|
72
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
73
|
+
|
|
74
|
+
## Code of Conduct
|
|
75
|
+
|
|
76
|
+
Everyone interacting in the TvdbPartyV2 project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/tvdb_party_v2/blob/master/CODE_OF_CONDUCT.md).
|
|
77
|
+
|
|
78
|
+
## Thanks
|
|
79
|
+
|
|
80
|
+
Project Derived from maddox/tvdb_party.
|
|
81
|
+
|
|
82
|
+
Thanks to thetvdb.com for their awesome database allowing us to meta out to our hearts consent.
|
|
83
|
+
Project name graciously stolen from jduff/tmdb_party.
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "tvdb_party_v2"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
require "tvdb_party_v2/version"
|
|
2
|
+
require 'rubygems'
|
|
3
|
+
require 'httparty'
|
|
4
|
+
|
|
5
|
+
directory = File.expand_path(File.dirname(__FILE__))
|
|
6
|
+
require File.join(directory, 'tvdb_party_v2', 'search')
|
|
7
|
+
require File.join(directory, 'tvdb_party_v2', 'series')
|
|
8
|
+
require File.join(directory, 'tvdb_party_v2', 'episode')
|
|
9
|
+
require File.join(directory, 'tvdb_party_v2', 'banner')
|
|
10
|
+
require File.join(directory, 'tvdb_party_v2', 'actor')
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module TvdbPartyV2
|
|
2
|
+
class Actor
|
|
3
|
+
attr_accessor :id, :name, :role, :image, :sortorder
|
|
4
|
+
|
|
5
|
+
def initialize(options = {})
|
|
6
|
+
@id = options["id"]
|
|
7
|
+
@name = options["name"]
|
|
8
|
+
@role = options["role"] if options["role"]
|
|
9
|
+
@image = options["image"] if options["image"]
|
|
10
|
+
@sortorder = options["sortOrder"] if options["sortOrder"]
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def image_url
|
|
14
|
+
return nil unless @image
|
|
15
|
+
"http://www.thetvdb.com/banners/" + @image
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module TvdbPartyV2
|
|
2
|
+
class Banner
|
|
3
|
+
attr_accessor :banner_type, :banner_resolution, :subkey, :path, :thumbnail_path, :ratingaverage, :ratingcount
|
|
4
|
+
|
|
5
|
+
def initialize(options = {})
|
|
6
|
+
@banner_type = options["keyType"]
|
|
7
|
+
@banner_resolution = options["resolution"]
|
|
8
|
+
@subkey = options["subKey"]
|
|
9
|
+
@path = options["fileName"]
|
|
10
|
+
|
|
11
|
+
if options["ratingsInfo"]["average"] && options["ratingsInfo"]["average"] > 0
|
|
12
|
+
@ratingaverage = options["ratingsInfo"]["average"].to_f
|
|
13
|
+
else
|
|
14
|
+
@ratingaverage = 0
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
if options["ratingsInfo"]["count"] && options["ratingsInfo"]["count"] > 0
|
|
18
|
+
@ratingcount = options["ratingsInfo"]["count"]
|
|
19
|
+
else
|
|
20
|
+
@ratingcount = 0
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def url
|
|
26
|
+
"https://www.thetvdb.com/banners/" + @path
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def thumb_url
|
|
30
|
+
"https://www.thetvdb.com/banners/_cache/" + @path
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
module TvdbPartyV2
|
|
2
|
+
|
|
3
|
+
class Episode
|
|
4
|
+
attr_reader :client
|
|
5
|
+
attr_accessor :id, :season_number, :number, :name, :overview, :air_date, :thumb, :guest_stars, :director, :writer, :imdb_id, :rating, :ratingcount, :season_id
|
|
6
|
+
|
|
7
|
+
def initialize(client, options = {})
|
|
8
|
+
@client = client
|
|
9
|
+
@id = options["id"]
|
|
10
|
+
@season_number = options["airedSeason"]
|
|
11
|
+
@number = options["airedEpisodeNumber"]
|
|
12
|
+
@name = options["episodeName"]
|
|
13
|
+
@overview = options["overview"]
|
|
14
|
+
@thumb = "http://www.thetvdb.com/banners/" + options["filename"] unless options["filename"].nil?
|
|
15
|
+
@director = options["directors"]
|
|
16
|
+
@writer = options["writers"]
|
|
17
|
+
@series_id = options["seriesId"]
|
|
18
|
+
@season_id = options["airedSeasonID"]
|
|
19
|
+
@imdb_id = options["imdbId"]
|
|
20
|
+
if options["guestStars"]
|
|
21
|
+
@guest_stars = options["guestStars"]
|
|
22
|
+
else
|
|
23
|
+
@guest_stars = []
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
begin
|
|
27
|
+
@air_date = Date.parse(options["firstAired"])
|
|
28
|
+
rescue
|
|
29
|
+
puts 'invalid date'
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
if options["siteRating"] && options["siteRating"] > 0
|
|
33
|
+
@rating = options["siteRating"].to_f
|
|
34
|
+
else
|
|
35
|
+
@rating = 0
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
if options["siteRatingCount"] && options["siteRatingCount"] > 0
|
|
39
|
+
@ratingcount = options["siteRatingCount"]
|
|
40
|
+
else
|
|
41
|
+
@ratingcount = 0
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def series
|
|
47
|
+
client.get_series_by_id(@series.id)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
end
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
module TvdbPartyV2
|
|
2
|
+
|
|
3
|
+
class Search
|
|
4
|
+
include HTTParty
|
|
5
|
+
base_uri 'https://api.thetvdb.com'
|
|
6
|
+
headers "Content-Type" => "application/json"
|
|
7
|
+
attr_accessor :token, :language
|
|
8
|
+
|
|
9
|
+
def initialize(apikey, username, userkey, language = 'en', cache_options = {})
|
|
10
|
+
@language = language
|
|
11
|
+
thetvdb = self.class.post('/login',
|
|
12
|
+
:body => {"apikey" => apikey,
|
|
13
|
+
"username" => username,
|
|
14
|
+
"userkey" => userkey}.to_json)
|
|
15
|
+
@token = thetvdb['token']
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
#基于电视剧英文名称获取thetvdb的查询结果
|
|
19
|
+
def search(series_name)
|
|
20
|
+
response = self.get("/search/series?name=#{URI::encode(series_name)}")
|
|
21
|
+
return [] unless response["data"]
|
|
22
|
+
case response["data"]
|
|
23
|
+
when Array
|
|
24
|
+
response["data"]
|
|
25
|
+
when Hash
|
|
26
|
+
[response["data"]]
|
|
27
|
+
else
|
|
28
|
+
[]
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
#基于imdbid获取thetvdb的查询结果
|
|
33
|
+
def search_by_imdb(imdb_id)
|
|
34
|
+
response = self.get("/search/series?imdbId=#{imdb_id}")
|
|
35
|
+
return [] unless response["data"]
|
|
36
|
+
|
|
37
|
+
case response["data"]
|
|
38
|
+
when Array
|
|
39
|
+
response["data"]
|
|
40
|
+
when Hash
|
|
41
|
+
[response["data"]]
|
|
42
|
+
else
|
|
43
|
+
[]
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
#基于电视剧id获取电视剧详细信息
|
|
48
|
+
def get_series_by_id(series_id, language = self.language)
|
|
49
|
+
response = self.get("/series/#{series_id.to_s}")
|
|
50
|
+
if response["data"]
|
|
51
|
+
Series.new(self, response["data"])
|
|
52
|
+
else
|
|
53
|
+
nil
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
#基于电视剧集id获取每集的详细信息
|
|
58
|
+
def get_episode_by_id(episode_id, language = self.language)
|
|
59
|
+
response = self.get("/episodes/#{episode_id.to_s}")
|
|
60
|
+
if response["data"]
|
|
61
|
+
Episode.new(self, response["data"])
|
|
62
|
+
else
|
|
63
|
+
nil
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
#基于季数、集数获取集的详细信息
|
|
68
|
+
def get_episode(series, season_number, episode_number = nil, page_id = nil)
|
|
69
|
+
if episode_number
|
|
70
|
+
url = "/series/#{series.id}/episodes/query?airedSeason=#{season_number}&airedEpisode=#{episode_number}"
|
|
71
|
+
else
|
|
72
|
+
url = "/series/#{series.id}/episodes/query?airedSeason=#{season_number}"
|
|
73
|
+
end
|
|
74
|
+
url = url + "&page=#{page_id}" unless page_id.nil?
|
|
75
|
+
|
|
76
|
+
response = self.get(url)
|
|
77
|
+
return [] unless response["data"]
|
|
78
|
+
if response['links']['next'].nil?
|
|
79
|
+
data = response["data"]
|
|
80
|
+
else
|
|
81
|
+
data << response["data"]
|
|
82
|
+
get_episode(series, season_number, episode_number, self.language, response['links']['next'])
|
|
83
|
+
end
|
|
84
|
+
data.map {|e| self.get_episode_by_id(e["id"])}
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def get_all_episodes(series, page_id = 1)
|
|
89
|
+
if page_id == 1
|
|
90
|
+
url = "/series/#{series.id}/episodes"
|
|
91
|
+
else
|
|
92
|
+
pp url = "/series/#{series.id}/episodes?page=#{page_id}"
|
|
93
|
+
end
|
|
94
|
+
response = self.get(url)
|
|
95
|
+
if response['links']['next'].nil?
|
|
96
|
+
data = response["data"]
|
|
97
|
+
else
|
|
98
|
+
data << response["data"]
|
|
99
|
+
get_all_episodes(series, self.language, response['links']['next'].to_s)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
return [] unless data
|
|
103
|
+
data.select! {|d| d["airedSeason"] > 0} #去除特殊季部分。
|
|
104
|
+
data.map {|e| self.get_episode_by_id(e["id"])}
|
|
105
|
+
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def get_actors(series)
|
|
109
|
+
response = self.get("/series/#{series.id}/actors")
|
|
110
|
+
if response["data"]
|
|
111
|
+
response["data"].collect {|a| Actor.new(a)}
|
|
112
|
+
else
|
|
113
|
+
nil
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# 获取季数
|
|
118
|
+
def get_seasons(series)
|
|
119
|
+
response = self.get("/series/#{series.id}/episodes/summary")
|
|
120
|
+
if response["data"] && response["data"]["airedSeasons"]
|
|
121
|
+
return response["data"]["airedSeasons"]
|
|
122
|
+
else
|
|
123
|
+
return []
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def get_banners(series, keyType, subKey = nil)
|
|
128
|
+
if subKey
|
|
129
|
+
url = "/series/#{series.id}/images/query?keyType=#{keyType}&subKey=#{subKey}"
|
|
130
|
+
else
|
|
131
|
+
url = "/series/#{series.id}/images/query?keyType=#{keyType}"
|
|
132
|
+
end
|
|
133
|
+
response = self.get(url)
|
|
134
|
+
return [] unless response["data"]
|
|
135
|
+
case response["data"]
|
|
136
|
+
when Array
|
|
137
|
+
response["data"].map {|result| Banner.new(result)}
|
|
138
|
+
when Hash
|
|
139
|
+
[Banner.new(response["data"])]
|
|
140
|
+
else
|
|
141
|
+
[]
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def get(url)
|
|
146
|
+
return self.class.get(url,
|
|
147
|
+
:headers => {"Authorization" => 'Bearer ' + @token,"Accept-Language" => self.language}).parsed_response
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
module TvdbPartyV2
|
|
2
|
+
|
|
3
|
+
class Series
|
|
4
|
+
attr_reader :client
|
|
5
|
+
attr_accessor :id, :name, :overview, :seasons, :first_aired, :genres, :network, :rating, :runtime,
|
|
6
|
+
:actors, :banners, :air_time, :imdb_id, :ratingcount, :status, :airs_dayofweek
|
|
7
|
+
|
|
8
|
+
def initialize(client, options = {})
|
|
9
|
+
@client = client
|
|
10
|
+
@id = options["id"]
|
|
11
|
+
@name = options["seriesName"]
|
|
12
|
+
@overview = options["overview"]
|
|
13
|
+
@network = options["network"]
|
|
14
|
+
@runtime = options["runtime"]
|
|
15
|
+
@air_time = options['airstime'] if options['airstime']
|
|
16
|
+
@imdb_id = options["imdbId"]
|
|
17
|
+
@status = options["status"] if options["status"]
|
|
18
|
+
@airs_dayofweek = options["airsDayOfWeek"]
|
|
19
|
+
|
|
20
|
+
if options["genre"]
|
|
21
|
+
@genres = options["genre"]
|
|
22
|
+
else
|
|
23
|
+
@genres = []
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
if options["siteRating"] && options["siteRating"] > 0
|
|
27
|
+
@rating = options["siteRating"].to_f
|
|
28
|
+
else
|
|
29
|
+
@rating = 0
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
if options["siteRatingCount"] && options["siteRatingCount"] > 0
|
|
33
|
+
@ratingcount = options["siteRatingCount"].to_f
|
|
34
|
+
else
|
|
35
|
+
@ratingcount = 0
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
begin
|
|
39
|
+
@first_aired = Date.parse(options["firstAired"])
|
|
40
|
+
rescue
|
|
41
|
+
puts 'invalid date'
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def get_episode(season_number, episode_number)
|
|
46
|
+
client.get_episode(self, season_number, episode_number)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def posters
|
|
50
|
+
@banners_posters ||= client.get_banners(self, 'season')
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def fanart
|
|
54
|
+
@banners_fanarts ||= client.get_banners(self, 'fanart')
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def series_banners
|
|
58
|
+
@banners_series ||= client.get_banners(self, 'series')
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def seasonwide
|
|
62
|
+
@banners_seasonwide ||= client.get_banners(self, 'seasonwide')
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def season_posters(season_number)
|
|
66
|
+
posters.select {|b| b.subkey == season_number.to_s}
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def seasonwide_posters(season_number)
|
|
70
|
+
seasonwide.select {|b| b.subkey == season_number.to_s}
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def banners
|
|
74
|
+
@banners ||= client.get_banners(self)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def seasons
|
|
78
|
+
@seasons ||= client.get_seasons(self)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def episodes
|
|
82
|
+
@episodes ||= client.get_all_episodes(self)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def actors
|
|
86
|
+
@actors ||= client.get_actors(self)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def season(season_number)
|
|
90
|
+
@season ||= client.get_episode(self, season_number)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "tvdb_party_v2/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "tvdb_party_v2"
|
|
8
|
+
spec.version = TvdbPartyV2::VERSION
|
|
9
|
+
spec.authors = ["David Pan"]
|
|
10
|
+
spec.email = ["davidpanchina@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{Simple Ruby library to talk to thetvdb.com's v2 API.}
|
|
13
|
+
spec.description = %q{Simple Ruby library to talk to thetvdb.com's v2 API.}
|
|
14
|
+
spec.homepage = "https://github.com/davidpan/tvdb_party_v2"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
|
19
|
+
if spec.respond_to?(:metadata)
|
|
20
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
|
21
|
+
else
|
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
|
23
|
+
"public gem pushes."
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
|
28
|
+
end
|
|
29
|
+
spec.bindir = "exe"
|
|
30
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
31
|
+
spec.require_paths = ["lib"]
|
|
32
|
+
|
|
33
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
35
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: tvdb_party_v2
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- David Pan
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-05-03 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.16'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.16'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
description: Simple Ruby library to talk to thetvdb.com's v2 API.
|
|
42
|
+
email:
|
|
43
|
+
- davidpanchina@gmail.com
|
|
44
|
+
executables: []
|
|
45
|
+
extensions: []
|
|
46
|
+
extra_rdoc_files: []
|
|
47
|
+
files:
|
|
48
|
+
- ".gitignore"
|
|
49
|
+
- CODE_OF_CONDUCT.md
|
|
50
|
+
- Gemfile
|
|
51
|
+
- Gemfile.lock
|
|
52
|
+
- LICENSE
|
|
53
|
+
- LICENSE.txt
|
|
54
|
+
- README.md
|
|
55
|
+
- Rakefile
|
|
56
|
+
- bin/console
|
|
57
|
+
- bin/setup
|
|
58
|
+
- lib/tvdb_party_v2.rb
|
|
59
|
+
- lib/tvdb_party_v2/actor.rb
|
|
60
|
+
- lib/tvdb_party_v2/banner.rb
|
|
61
|
+
- lib/tvdb_party_v2/episode.rb
|
|
62
|
+
- lib/tvdb_party_v2/search.rb
|
|
63
|
+
- lib/tvdb_party_v2/series.rb
|
|
64
|
+
- lib/tvdb_party_v2/version.rb
|
|
65
|
+
- tvdb_party_v2.gemspec
|
|
66
|
+
homepage: https://github.com/davidpan/tvdb_party_v2
|
|
67
|
+
licenses:
|
|
68
|
+
- MIT
|
|
69
|
+
metadata:
|
|
70
|
+
allowed_push_host: https://rubygems.org
|
|
71
|
+
post_install_message:
|
|
72
|
+
rdoc_options: []
|
|
73
|
+
require_paths:
|
|
74
|
+
- lib
|
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
|
+
requirements:
|
|
77
|
+
- - ">="
|
|
78
|
+
- !ruby/object:Gem::Version
|
|
79
|
+
version: '0'
|
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
|
+
requirements:
|
|
82
|
+
- - ">="
|
|
83
|
+
- !ruby/object:Gem::Version
|
|
84
|
+
version: '0'
|
|
85
|
+
requirements: []
|
|
86
|
+
rubyforge_project:
|
|
87
|
+
rubygems_version: 2.6.14
|
|
88
|
+
signing_key:
|
|
89
|
+
specification_version: 4
|
|
90
|
+
summary: Simple Ruby library to talk to thetvdb.com's v2 API.
|
|
91
|
+
test_files: []
|