undertexter 0.0.3 → 0.0.4
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/Gemfile.lock +2 -2
- data/README.markdown +71 -0
- data/lib/subtitle.rb +11 -1
- data/lib/undertexter/version.rb +1 -1
- data/lib/undertexter.rb +22 -10
- data/spec/undertexter_spec.rb +29 -4
- metadata +6 -6
- data/README +0 -0
data/Gemfile.lock
CHANGED
data/README.markdown
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
What is Undertexter?
|
2
|
+
===============
|
3
|
+
|
4
|
+
Undertexter provides a basic search client that makes it possible to search for swedish and english subtitles on [Undertexter.se](http://undertexter.se)
|
5
|
+
|
6
|
+
How to use
|
7
|
+
===============
|
8
|
+
|
9
|
+
The find methods takes any string, including an IMDB id.
|
10
|
+
This is how to use it in irb.
|
11
|
+
|
12
|
+
$ require 'undertexter'
|
13
|
+
# => true
|
14
|
+
$ subtite = Undertexter.find("tt0840361").first
|
15
|
+
=> #<Subtitle:0x1020fff98 @downloads=8328, @movie_title="The Town", @title="The.Town.2010....BRRip", @url="http://www.undertexter.se/?p=undertext&id=23711", @cds=1>
|
16
|
+
$ subtitle.downloads
|
17
|
+
=> 8328
|
18
|
+
$ subtitle.movie_title
|
19
|
+
=> "The Town"
|
20
|
+
$ subtitle.title
|
21
|
+
=> "The.Town.2010.EXTENDED.480p.BRRip.XviD-NYDIC"
|
22
|
+
$ subtitle.url
|
23
|
+
= "http://www.undertexter.se/utext.php?id=23711"
|
24
|
+
$ subtitle.details
|
25
|
+
=> "http://www.undertexter.se/?p=undertext&id=23711"
|
26
|
+
$ Undertexter.find("die hard").count
|
27
|
+
=> 41
|
28
|
+
|
29
|
+
You can also provide an language option.
|
30
|
+
|
31
|
+
$ Undertexter.find("tt0840361", :language => :english).count
|
32
|
+
=> 48
|
33
|
+
$ Undertexter.find("tt0840361", :language => :swedish).count
|
34
|
+
=> 8
|
35
|
+
|
36
|
+
If no language option is being passed to find, it will fall back to swedish
|
37
|
+
|
38
|
+
What is being returned from the find method?
|
39
|
+
===============
|
40
|
+
|
41
|
+
The find method returns an `Array` with zero or more subtitles. Every subtitle provides some basic accessors.
|
42
|
+
|
43
|
+
- `movie_title` (String) The official name of the movie.
|
44
|
+
- `cds` (Integer) The amount of cds that the release should contain.
|
45
|
+
- `title` (String) The release name of the subtitle, should have the same name as the downloaded movie.
|
46
|
+
- `downloads` (Integer) The amount of downloads for this particular subtitle.
|
47
|
+
- `url` (String) A direct link to the subtitle file, a rar file for example
|
48
|
+
- `details` (String) A link to the details page for the subtitle
|
49
|
+
|
50
|
+
How to install
|
51
|
+
===============
|
52
|
+
|
53
|
+
sudo gem install undertexter
|
54
|
+
|
55
|
+
How to use it in a rails 3 project
|
56
|
+
===============
|
57
|
+
|
58
|
+
Add `gem 'undertexter'` to your Gemfile and run `bundle`.
|
59
|
+
|
60
|
+
How to help
|
61
|
+
===============
|
62
|
+
|
63
|
+
- Start by copying the project or make your own branch.
|
64
|
+
- Navigate to the root path of the project and run `bundle`.
|
65
|
+
- Start by running all tests using rspec, `rspec spec/undertexter_spec.rb`.
|
66
|
+
- Implement your own code, write some tests, commit and do a pull request.
|
67
|
+
|
68
|
+
Requirements
|
69
|
+
===============
|
70
|
+
|
71
|
+
Undertexter is tested in OS X 10.6.6 using Ruby 1.8.7.
|
data/lib/subtitle.rb
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
class Subtitle
|
2
|
-
attr_accessor :
|
2
|
+
attr_accessor :details, :downloads, :cds, :title, :movie_title, :url
|
3
|
+
|
3
4
|
def initialize(args)
|
4
5
|
args.keys.each { |name| instance_variable_set "@" + name.to_s, args[name] }
|
5
6
|
end
|
7
|
+
|
8
|
+
def url
|
9
|
+
"http://www.undertexter.se/utext.php?id=#{id}"
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
def id
|
14
|
+
@details.match(/id=(\d+)/)[1]
|
15
|
+
end
|
6
16
|
end
|
data/lib/undertexter/version.rb
CHANGED
data/lib/undertexter.rb
CHANGED
@@ -3,15 +3,25 @@ require 'subtitle'
|
|
3
3
|
require 'nokogiri'
|
4
4
|
|
5
5
|
class Undertexter
|
6
|
-
attr_accessor :raw_data, :
|
6
|
+
attr_accessor :raw_data, :base_details, :subtitles
|
7
7
|
|
8
|
-
def initialize
|
9
|
-
@
|
8
|
+
def initialize(options)
|
9
|
+
@options = {
|
10
|
+
:language => {
|
11
|
+
:swedish => 'soek',
|
12
|
+
:english => 'eng_search'
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
16
|
+
# If a non existing language is being used, swedish will be the default
|
17
|
+
lang = @options[:language][options[:language]] || @options[:language][:swedish]
|
18
|
+
|
19
|
+
@base_details = "http://www.undertexter.se/?p=#{lang}&add=arkiv&str="
|
10
20
|
@subtitles = []
|
11
21
|
end
|
12
22
|
|
13
|
-
def self.find(search_string)
|
14
|
-
this = self.new
|
23
|
+
def self.find(search_string, options = {:language => :swedish})
|
24
|
+
this = self.new(options)
|
15
25
|
|
16
26
|
# Downloading the page
|
17
27
|
this.get(search_string)
|
@@ -32,7 +42,7 @@ class Undertexter
|
|
32
42
|
# Example output
|
33
43
|
# [["(1 cd)", "Nedladdningar: 11891", "Avatar (2009) PROPER DVDSCR XviD-MAXSPEED", "http://www.undertexter.se/?p=undertext&id=19751"]]
|
34
44
|
|
35
|
-
[15
|
45
|
+
[12,15].each do |id|
|
36
46
|
@block = noko.css("table:nth-child(#{id}) td").to_a.reject do |inner|
|
37
47
|
inner.content.empty? or ! inner.content.match(/Nedladdningar/i)
|
38
48
|
end.map do |inner|
|
@@ -44,10 +54,12 @@ class Undertexter
|
|
44
54
|
next if @block.nil?
|
45
55
|
|
46
56
|
noko.css("table:nth-child(#{id}) a").to_a.reject do |inner|
|
47
|
-
|
48
|
-
inner.content.empty? or
|
57
|
+
details = inner.attr('href')
|
58
|
+
inner.content.empty? or details.nil? or ! details.match(/(p=undertext&id=\d+)|(p=subtitle&id=\d+)/i)
|
49
59
|
end.map do |y|
|
50
60
|
[y.attr('href'), y.content.strip]
|
61
|
+
end.reject do |list|
|
62
|
+
list.last.empty?
|
51
63
|
end.each_with_index do |value, index|
|
52
64
|
@block[index] << value.first
|
53
65
|
@block[index] << value.last
|
@@ -66,13 +78,13 @@ class Undertexter
|
|
66
78
|
:cds => movie[0].match(/\d+/)[0].to_i,
|
67
79
|
:downloads => movie[1].match(/\d+$/)[0].to_i,
|
68
80
|
:title => movie[2],
|
69
|
-
:
|
81
|
+
:details => movie[3],
|
70
82
|
:movie_title => movie[4]
|
71
83
|
})
|
72
84
|
end
|
73
85
|
end
|
74
86
|
|
75
87
|
def get(search_string)
|
76
|
-
@raw_data = RestClient.get(@
|
88
|
+
@raw_data = RestClient.get(@base_details + CGI.escape(search_string), :timeout => 10) rescue nil
|
77
89
|
end
|
78
90
|
end
|
data/spec/undertexter_spec.rb
CHANGED
@@ -33,8 +33,8 @@ describe Undertexter do
|
|
33
33
|
@use.each {|subtitle| subtitle.title.should_not be_empty}
|
34
34
|
end
|
35
35
|
|
36
|
-
it "should contain the right
|
37
|
-
@use.each {|subtitle| subtitle.
|
36
|
+
it "should contain the right detailss" do
|
37
|
+
@use.each {|subtitle| subtitle.details.should match(/^http:\/\/www\.undertexter\.se\/\?p=undertext&id=\d+$/)}
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -62,8 +62,8 @@ describe Undertexter, "trying to search for a movie using a title" do
|
|
62
62
|
@use.each{|subtitle| subtitle.title.should match(/die.*hard/i)}
|
63
63
|
end
|
64
64
|
|
65
|
-
it "should contain the right
|
66
|
-
@use.each {|subtitle| subtitle.
|
65
|
+
it "should contain the right detailss, again" do
|
66
|
+
@use.each {|subtitle| subtitle.details.should match(/^http:\/\/www\.undertexter\.se\/\?p=undertext&id=\d+$/i)}
|
67
67
|
end
|
68
68
|
|
69
69
|
it "should have a movie title" do
|
@@ -77,4 +77,29 @@ describe Undertexter, "trying to search for a movie using a title" do
|
|
77
77
|
it "should not contain movie title that starts or ends with whitespace" do
|
78
78
|
@use.each {|subtitle| subtitle.movie_title.should_not match(/^\s+.+\s+$/)}
|
79
79
|
end
|
80
|
+
|
81
|
+
it "should return a direct link to the subtitle" do
|
82
|
+
@use.each{|subtitle| subtitle.url.should match(/http:\/\/www\.undertexter\.se\/utext\.php\?id=\d+/i)}
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should return the same id for every link" do
|
86
|
+
@use.each_with_index do |subtitle, index|
|
87
|
+
subtitle.url.match(/id=(\d+)/)[1].should eq(@use[index].details.match(/id=(\d+)/)[1])
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe Undertexter, "should work when trying to fetch some english subtitles" do
|
93
|
+
it "should return at least 48 subtitles" do
|
94
|
+
Undertexter.should have_at_least(48).find("tt0840361", {:language => :english})
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should return at least 8 subtitles" do
|
98
|
+
Undertexter.should have_at_least(8).find("tt0840361", {:language => :swedish})
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should return at least 8 subtitles" do
|
102
|
+
Undertexter.should have_at_least(8).find("tt0840361", {:language => :strange})
|
103
|
+
end
|
104
|
+
# http://www.undertexter.se/www.php?www=http://engsub.net/?p=subtitle&id=92097
|
80
105
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: undertexter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Linus Oleander
|
@@ -74,7 +74,7 @@ files:
|
|
74
74
|
- .rspec
|
75
75
|
- Gemfile
|
76
76
|
- Gemfile.lock
|
77
|
-
- README
|
77
|
+
- README.markdown
|
78
78
|
- Rakefile
|
79
79
|
- lib/subtitle.rb
|
80
80
|
- lib/undertexter.rb
|
@@ -112,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
112
|
requirements: []
|
113
113
|
|
114
114
|
rubyforge_project: undertexter
|
115
|
-
rubygems_version: 1.
|
115
|
+
rubygems_version: 1.4.2
|
116
116
|
signing_key:
|
117
117
|
specification_version: 3
|
118
118
|
summary: A subtitle search client for undertexter.se
|
data/README
DELETED
File without changes
|