nx-douban-movie 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/README.md +25 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/nx-douban-movie.rb +5 -0
- data/lib/nx/douban-movie.rb +127 -0
- data/lib/nx/version.rb +5 -0
- data/nx-douban-movie.gemspec +36 -0
- data/package.json +24 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 70f8a97358a21d14ebfa0cbcce2d4dd08e4c12223d394ead8174f6874bbeeb8c
|
4
|
+
data.tar.gz: 9d0df9b68285aacc51c39aed01f0fd7487f785f12ec15bdef29da8112a4fecfa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3b8319b43b3145760425f0dd9d8332ee4d3c07a56bea50a0c6c0c3886023e2dd29792f3c168bd41a1d245d5a335fae3fca071d26cd92bdabf1676c0ce098abdd
|
7
|
+
data.tar.gz: aa6b08c01618600273470c1d2c689b68cd87dd61cc2be8806e2b35a6fe30709f547b907994d746bb4446415da911db6df65a71fea2b50bbed06525bc6ecb7df9
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# nx-douban-movie
|
2
|
+
> Douban movie gem.
|
3
|
+
|
4
|
+
## installation
|
5
|
+
```rb
|
6
|
+
# from gem
|
7
|
+
gem 'nx-douban-movie'
|
8
|
+
# from git
|
9
|
+
gem 'nx-douban-movie', git: 'git@github.com:afeiship/nx-douban-movie.git'
|
10
|
+
```
|
11
|
+
|
12
|
+
## usage
|
13
|
+
```rb
|
14
|
+
dbm = Nx::DoubanMovie.new "https://movie.douban.com/subject/30176393"
|
15
|
+
dbm.to_h
|
16
|
+
```
|
17
|
+
|
18
|
+
## build/publish
|
19
|
+
```shell
|
20
|
+
# build
|
21
|
+
gem build nx-douban-movie.gemspec
|
22
|
+
|
23
|
+
# publish
|
24
|
+
gem push nx-douban-movie-0.1.0.gem
|
25
|
+
```
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "nx-douban-movie"
|
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,127 @@
|
|
1
|
+
module Nx
|
2
|
+
class DoubanMovie
|
3
|
+
def initialize(url)
|
4
|
+
@doc = Nokogiri::HTML(URI.open(url))
|
5
|
+
@url = url
|
6
|
+
@info_list = @doc.css("#info .pl")
|
7
|
+
end
|
8
|
+
|
9
|
+
def url
|
10
|
+
@url
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_h
|
14
|
+
methods = (public_methods(false) - [__method__])
|
15
|
+
methods.map do |method|
|
16
|
+
[method, send(method)]
|
17
|
+
end.to_h
|
18
|
+
end
|
19
|
+
|
20
|
+
# 电影标题
|
21
|
+
def title
|
22
|
+
el = @doc.css('#content > h1 span[property="v:itemreviewed"]')
|
23
|
+
el.text
|
24
|
+
end
|
25
|
+
|
26
|
+
# 上映年份
|
27
|
+
def year
|
28
|
+
el = @doc.css('#content > h1 span[class="year"]')
|
29
|
+
el.text.tr("()", "")
|
30
|
+
end
|
31
|
+
|
32
|
+
# 封面
|
33
|
+
def cover
|
34
|
+
el = @doc.css("#mainpic .nbgnbg img")
|
35
|
+
el.attribute("src").value
|
36
|
+
end
|
37
|
+
|
38
|
+
# 导演
|
39
|
+
def director
|
40
|
+
el = @info_list.find do |item|
|
41
|
+
item.text.include? "导演"
|
42
|
+
end
|
43
|
+
clean_string el.nil? ? "" : el.next_element.text
|
44
|
+
end
|
45
|
+
|
46
|
+
# 编剧
|
47
|
+
def screenwriter
|
48
|
+
el = @info_list.find do |item|
|
49
|
+
item.text.include? "编剧"
|
50
|
+
end
|
51
|
+
clean_string el.nil? ? "" : el.next_element.text
|
52
|
+
end
|
53
|
+
|
54
|
+
# 主演
|
55
|
+
def leading_roles
|
56
|
+
els = @doc.css('#info .actor .attrs a[rel="v:starring"]')
|
57
|
+
els.map do |el|
|
58
|
+
url = el.attribute("href").value
|
59
|
+
{
|
60
|
+
url: "https://movie.douban.com#{url}",
|
61
|
+
name: el.text,
|
62
|
+
}
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# 类型
|
67
|
+
def types
|
68
|
+
els = @doc.css('#info span[property="v:genre"]')
|
69
|
+
els.map do |el|
|
70
|
+
el.text
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# 制片国家/地区
|
75
|
+
def district
|
76
|
+
el = @info_list.find do |item|
|
77
|
+
item.text.include? "制片国家/地区"
|
78
|
+
end
|
79
|
+
clean_string el.nil? ? "" : el.next.text
|
80
|
+
end
|
81
|
+
|
82
|
+
# 语言:
|
83
|
+
def language
|
84
|
+
el = @info_list.find do |item|
|
85
|
+
item.text.include? "语言"
|
86
|
+
end
|
87
|
+
clean_string el.nil? ? "" : el.next.text
|
88
|
+
end
|
89
|
+
|
90
|
+
# 上映日期:
|
91
|
+
def release_dates
|
92
|
+
els = @doc.css('#info [property="v:initialReleaseDate"]')
|
93
|
+
els.map do |el|
|
94
|
+
clean_string el.text
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
# 片长:
|
99
|
+
def runtime
|
100
|
+
el = @doc.css('#info [property="v:runtime"]')
|
101
|
+
clean_string(el.text)
|
102
|
+
end
|
103
|
+
|
104
|
+
# 又名:
|
105
|
+
def aliases
|
106
|
+
el = @info_list.find do |item|
|
107
|
+
item.text.include? "又名"
|
108
|
+
end
|
109
|
+
clean_string el.nil? ? "" : el.next.text
|
110
|
+
end
|
111
|
+
|
112
|
+
# IMDb链接:
|
113
|
+
def imdb_url
|
114
|
+
el = @info_list.find do |item|
|
115
|
+
item.text.include? "IMDb链接"
|
116
|
+
end
|
117
|
+
|
118
|
+
el.next_element.attribute("href").value
|
119
|
+
end
|
120
|
+
|
121
|
+
protected
|
122
|
+
|
123
|
+
def clean_string(str)
|
124
|
+
str.strip
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
data/lib/nx/version.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "nx/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "nx-douban-movie"
|
8
|
+
spec.version = Nx::DoubanMovie::VERSION
|
9
|
+
spec.licenses = ["MIT"]
|
10
|
+
spec.authors = ["afeiship"]
|
11
|
+
spec.email = ["1290657123@qq.com"]
|
12
|
+
|
13
|
+
spec.summary = %q{Douban movie gem.}
|
14
|
+
spec.description = %q{Douban movie gem.}
|
15
|
+
spec.homepage = "https://github.com/aric-spider/nx-douban-movie"
|
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'] = "TODO: Set to 'http://mygemserver.com'"
|
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 "nokogiri"
|
34
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
35
|
+
spec.add_development_dependency "rake", "~> 12.3", ">= 12.3.3"
|
36
|
+
end
|
data/package.json
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
{
|
2
|
+
"name": "nx-douban-movie",
|
3
|
+
"version": "1.0.0",
|
4
|
+
"description": "Douban movie gem.",
|
5
|
+
"directories": {
|
6
|
+
"lib": "lib"
|
7
|
+
},
|
8
|
+
"scripts": {
|
9
|
+
"clean": "rm -rf *.gem",
|
10
|
+
"build": "gem build *.gemspec",
|
11
|
+
"pubpush": "gem push *.gem",
|
12
|
+
"unpublish":"gem yank nx-douban-movie -v '0.1.1'"
|
13
|
+
},
|
14
|
+
"repository": {
|
15
|
+
"type": "git",
|
16
|
+
"url": "git+https://github.com/aric-spider/nx-douban-movie.git"
|
17
|
+
},
|
18
|
+
"author": "afei",
|
19
|
+
"license": "MIT",
|
20
|
+
"bugs": {
|
21
|
+
"url": "https://github.com/aric-spider/nx-douban-movie/issues"
|
22
|
+
},
|
23
|
+
"homepage": "https://github.com/aric-spider/nx-douban-movie#readme"
|
24
|
+
}
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nx-douban-movie
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- afeiship
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-11-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.14'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.14'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '12.3'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 12.3.3
|
51
|
+
type: :development
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '12.3'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 12.3.3
|
61
|
+
description: Douban movie gem.
|
62
|
+
email:
|
63
|
+
- 1290657123@qq.com
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- ".gitignore"
|
69
|
+
- Gemfile
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- bin/console
|
73
|
+
- bin/setup
|
74
|
+
- lib/nx-douban-movie.rb
|
75
|
+
- lib/nx/douban-movie.rb
|
76
|
+
- lib/nx/version.rb
|
77
|
+
- nx-douban-movie.gemspec
|
78
|
+
- package.json
|
79
|
+
homepage: https://github.com/aric-spider/nx-douban-movie
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubygems_version: 3.0.3
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: Douban movie gem.
|
102
|
+
test_files: []
|