cain 0.0.1
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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/Rakefile +9 -0
- data/cain.gemspec +25 -0
- data/lib/cain.rb +6 -0
- data/lib/cain/movies/identifier.rb +61 -0
- data/lib/cain/version.rb +7 -0
- data/spec/movies/identifier_spec.rb +35 -0
- data/spec/samples/movies/sample.nfo +67 -0
- data/spec/spec_helper.rb +3 -0
- metadata +144 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
data/cain.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/cain/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Marc Bowes"]
|
6
|
+
gem.email = ["marcbowes@gmail.com"]
|
7
|
+
gem.description = %q{Hello, my friend. Stay awhile and listen...}
|
8
|
+
gem.summary = %q{You have unidentified items. We can help.}
|
9
|
+
gem.homepage = ""
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "cain"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Cain.version
|
17
|
+
|
18
|
+
gem.add_development_dependency("rake")
|
19
|
+
gem.add_development_dependency("rspec")
|
20
|
+
|
21
|
+
# tmdb relies on Object#blank?, which in turn requires i18n.
|
22
|
+
gem.add_runtime_dependency("tmdb_party")
|
23
|
+
gem.add_runtime_dependency("active_support")
|
24
|
+
gem.add_runtime_dependency("i18n")
|
25
|
+
end
|
data/lib/cain.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
module Cain
|
2
|
+
module Movies
|
3
|
+
class Identifier
|
4
|
+
|
5
|
+
require "tmdb_party"
|
6
|
+
|
7
|
+
IMDB_TT_URI = "http://www.imdb.com/title/tt"
|
8
|
+
IMDB_TT_RE = /#{Regexp.escape(IMDB_TT_URI)}(\d+)/
|
9
|
+
|
10
|
+
attr_accessor :path
|
11
|
+
attr_accessor :tmdb_api_key
|
12
|
+
|
13
|
+
def initialize(path, tmdb_api_key)
|
14
|
+
self.path = path
|
15
|
+
self.tmdb_api_key = tmdb_api_key
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
def tmdb
|
20
|
+
@tmdb ||= mk_tmdb(tmdb_api_key)
|
21
|
+
end
|
22
|
+
|
23
|
+
def mk_tmdb(api_key)
|
24
|
+
TMDBParty::Base.new(api_key)
|
25
|
+
end
|
26
|
+
|
27
|
+
def identify
|
28
|
+
case File.directory?(path)
|
29
|
+
when true
|
30
|
+
identify_folder(path)
|
31
|
+
else
|
32
|
+
identify_file(path)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def identify_folder(folder)
|
37
|
+
if (nfo = nfo_in(folder))
|
38
|
+
if (tt = get_imdb_tt_from_nfo(nfo))
|
39
|
+
return get_metadata_by_imdb_tt(tt)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_metadata_by_imdb_tt(tt)
|
45
|
+
tmdb.imdb_lookup("tt#{tt}")
|
46
|
+
end
|
47
|
+
|
48
|
+
def nfo_in(folder)
|
49
|
+
if (file = Dir[File.join(folder, "*.nfo")].first)
|
50
|
+
File.read(file)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_imdb_tt_from_nfo(nfo)
|
55
|
+
if (m = nfo.match(IMDB_TT_RE))
|
56
|
+
m[1]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/cain/version.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
require "cain/movies/identifier"
|
4
|
+
|
5
|
+
module Cain::Movies
|
6
|
+
|
7
|
+
describe Identifier do
|
8
|
+
|
9
|
+
let(:path) { File.expand_path("samples/movies", SPEC_ROOT) }
|
10
|
+
let(:api_key) { double("api-key") }
|
11
|
+
let(:i) { Identifier.new(path, api_key) }
|
12
|
+
let(:tmdb) { double("tmdb") }
|
13
|
+
|
14
|
+
before do
|
15
|
+
i.stub(:tmdb).and_return(tmdb)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should know if its a file or folder" do
|
19
|
+
i.should_receive(:identify_folder)
|
20
|
+
i.identify
|
21
|
+
end
|
22
|
+
|
23
|
+
context "parsing nfos" do
|
24
|
+
|
25
|
+
it "should find the nfo" do
|
26
|
+
i.nfo_in(path).should_not be_nil
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should parse the nfo" do
|
30
|
+
nfo = i.nfo_in(path)
|
31
|
+
i.get_imdb_tt_from_nfo(nfo).should == "0458339"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
|
2
|
+
�� �
|
3
|
+
� �۰� ��
|
4
|
+
߰� �� �� �
|
5
|
+
� ��� �� � �� ������ ߰� ��
|
6
|
+
߰� � ��� ��� � ��� ������� �۰�
|
7
|
+
�� ���۱��� �� ��� �� ���
|
8
|
+
�����ܲ���� ��������� �� ��� �� ���
|
9
|
+
������������ �� � �� �����۱ ޱ ��
|
10
|
+
������� [720p] � �� �� ��� ۲ ���
|
11
|
+
������ �� �� �� ��� ��� ��� ���
|
12
|
+
����� ���� ����� � ��� ������
|
13
|
+
���� Title: Captain America: The First Avenger (2011)
|
14
|
+
���� Retail Date: 25-10-2011
|
15
|
+
��� Release Date: 14-10-2011
|
16
|
+
��� Source: BLURAY
|
17
|
+
���� iMDB: http://www.imdb.com/title/tt0458339/
|
18
|
+
���� �������������
|
19
|
+
���� Rating: 7.2/10 52,546 (votes) ����������������������
|
20
|
+
��۱ ����������������������������
|
21
|
+
��۲ �������������� ߲������
|
22
|
+
���� ���������������� ������
|
23
|
+
������ ����������������� ������
|
24
|
+
��������� ����������������� �����
|
25
|
+
���������������������������� �����
|
26
|
+
���������۱������� �����
|
27
|
+
Video Bitrate: 720p (1280x544 @ 4787 kbps ����
|
28
|
+
Audio Bitrate: DTS @ 1510 kbps �����
|
29
|
+
Runtime: 124mn �����
|
30
|
+
Subs: N/A �����
|
31
|
+
Archives: 59x100mb �����
|
32
|
+
�����
|
33
|
+
Notes: Sit Back, Relax! �����
|
34
|
+
����������� �۱��
|
35
|
+
������������������ �۲�
|
36
|
+
����������߲������������� �����
|
37
|
+
������� �������������� �����
|
38
|
+
������ ����������� �����
|
39
|
+
����� ����������� �����
|
40
|
+
����� Greetings: ������������ ������
|
41
|
+
���۰ ������������� Ph^Z/SiLK �������
|
42
|
+
���۱ - CLUE - iCON - IGUANA - ��������۲�������������������
|
43
|
+
���۲ ����������������������
|
44
|
+
���۲ - MaxHD - TARGET - ����������۲��
|
45
|
+
�����
|
46
|
+
����� - THUGLiNE - XPRESS -
|
47
|
+
�����
|
48
|
+
�����
|
49
|
+
������ ��������
|
50
|
+
�������� ���������������۲
|
51
|
+
������۲����������������۱����������۲
|
52
|
+
��������������������� ߲��������۱�
|
53
|
+
������������� �����������۱
|
54
|
+
�������������������
|
55
|
+
���������������������������
|
56
|
+
�۱���� ����������� ���۱��
|
57
|
+
۱��������������������۲���
|
58
|
+
ޱ�������������������� ����
|
59
|
+
� �۲���������߲�� ���
|
60
|
+
� �� ������ �� �
|
61
|
+
�� �� �� ��
|
62
|
+
� � � �
|
63
|
+
�� � � ��
|
64
|
+
�� ��
|
65
|
+
�� � � ��
|
66
|
+
��۲����ܲ���
|
67
|
+
�������
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cain
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Marc Bowes
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-11-26 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
22
|
+
none: false
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
hash: 3
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
prerelease: false
|
31
|
+
requirement: *id001
|
32
|
+
type: :development
|
33
|
+
name: rake
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
hash: 3
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
prerelease: false
|
45
|
+
requirement: *id002
|
46
|
+
type: :development
|
47
|
+
name: rspec
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
hash: 3
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
version: "0"
|
58
|
+
prerelease: false
|
59
|
+
requirement: *id003
|
60
|
+
type: :runtime
|
61
|
+
name: tmdb_party
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
hash: 3
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
prerelease: false
|
73
|
+
requirement: *id004
|
74
|
+
type: :runtime
|
75
|
+
name: active_support
|
76
|
+
- !ruby/object:Gem::Dependency
|
77
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
hash: 3
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
version: "0"
|
86
|
+
prerelease: false
|
87
|
+
requirement: *id005
|
88
|
+
type: :runtime
|
89
|
+
name: i18n
|
90
|
+
description: Hello, my friend. Stay awhile and listen...
|
91
|
+
email:
|
92
|
+
- marcbowes@gmail.com
|
93
|
+
executables: []
|
94
|
+
|
95
|
+
extensions: []
|
96
|
+
|
97
|
+
extra_rdoc_files: []
|
98
|
+
|
99
|
+
files:
|
100
|
+
- .gitignore
|
101
|
+
- Gemfile
|
102
|
+
- Rakefile
|
103
|
+
- cain.gemspec
|
104
|
+
- lib/cain.rb
|
105
|
+
- lib/cain/movies/identifier.rb
|
106
|
+
- lib/cain/version.rb
|
107
|
+
- spec/movies/identifier_spec.rb
|
108
|
+
- spec/samples/movies/sample.nfo
|
109
|
+
- spec/spec_helper.rb
|
110
|
+
homepage: ""
|
111
|
+
licenses: []
|
112
|
+
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
hash: 3
|
124
|
+
segments:
|
125
|
+
- 0
|
126
|
+
version: "0"
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
hash: 3
|
133
|
+
segments:
|
134
|
+
- 0
|
135
|
+
version: "0"
|
136
|
+
requirements: []
|
137
|
+
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 1.8.11
|
140
|
+
signing_key:
|
141
|
+
specification_version: 3
|
142
|
+
summary: You have unidentified items. We can help.
|
143
|
+
test_files: []
|
144
|
+
|