undertexter 0.0.3

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.
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/.rspec ADDED
@@ -0,0 +1,5 @@
1
+ --color
2
+ -fs
3
+ -Ilib
4
+ -Ispec
5
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in undertexter.gemspec
4
+ gemspec
@@ -0,0 +1,32 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ undertexterse (0.0.1)
5
+ nokogiri
6
+ rest-client
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ diff-lcs (1.1.2)
12
+ mime-types (1.16)
13
+ nokogiri (1.4.4)
14
+ rest-client (1.6.1)
15
+ mime-types (>= 1.16)
16
+ rspec (2.4.0)
17
+ rspec-core (~> 2.4.0)
18
+ rspec-expectations (~> 2.4.0)
19
+ rspec-mocks (~> 2.4.0)
20
+ rspec-core (2.4.0)
21
+ rspec-expectations (2.4.0)
22
+ diff-lcs (~> 1.1.2)
23
+ rspec-mocks (2.4.0)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ nokogiri
30
+ rest-client
31
+ rspec
32
+ undertexterse!
data/README ADDED
File without changes
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,6 @@
1
+ class Subtitle
2
+ attr_accessor :url, :downloads, :cds, :title, :movie_title
3
+ def initialize(args)
4
+ args.keys.each { |name| instance_variable_set "@" + name.to_s, args[name] }
5
+ end
6
+ end
@@ -0,0 +1,78 @@
1
+ require 'rest-client'
2
+ require 'subtitle'
3
+ require 'nokogiri'
4
+
5
+ class Undertexter
6
+ attr_accessor :raw_data, :base_url, :subtitles
7
+
8
+ def initialize
9
+ @base_url = "http://www.undertexter.se/?p=soek&add=arkiv&str="
10
+ @subtitles = []
11
+ end
12
+
13
+ def self.find(search_string)
14
+ this = self.new
15
+
16
+ # Downloading the page
17
+ this.get(search_string)
18
+
19
+ # If something went wrong, like a timeout, {raw_data} could be nil
20
+ return [] if this.raw_data.nil?
21
+
22
+ this.parse!
23
+
24
+ this.build!
25
+
26
+ return this.subtitles
27
+ end
28
+
29
+ def parse!
30
+ noko = Nokogiri::HTML(@raw_data)
31
+
32
+ # Example output
33
+ # [["(1 cd)", "Nedladdningar: 11891", "Avatar (2009) PROPER DVDSCR XviD-MAXSPEED", "http://www.undertexter.se/?p=undertext&id=19751"]]
34
+
35
+ [15,12].each do |id|
36
+ @block = noko.css("table:nth-child(#{id}) td").to_a.reject do |inner|
37
+ inner.content.empty? or ! inner.content.match(/Nedladdningar/i)
38
+ end.map do |inner|
39
+ inner.content.split("\n").map do |i|
40
+ i.gsub(/"/, "").strip
41
+ end
42
+ end
43
+
44
+ next if @block.nil?
45
+
46
+ noko.css("table:nth-child(#{id}) a").to_a.reject do |inner|
47
+ url = inner.attr('href')
48
+ inner.content.empty? or url.nil? or ! url.match(/p=undertext&id=\d+/i)
49
+ end.map do |y|
50
+ [y.attr('href'), y.content.strip]
51
+ end.each_with_index do |value, index|
52
+ @block[index] << value.first
53
+ @block[index] << value.last
54
+ end
55
+
56
+ @block.map!{|value| value.reject(&:empty?)}
57
+
58
+ break if @block.any?
59
+ end
60
+ end
61
+
62
+ def build!
63
+ @block.each do |movie|
64
+ next unless movie.count == 5
65
+ @subtitles << Subtitle.new({
66
+ :cds => movie[0].match(/\d+/)[0].to_i,
67
+ :downloads => movie[1].match(/\d+$/)[0].to_i,
68
+ :title => movie[2],
69
+ :url => movie[3],
70
+ :movie_title => movie[4]
71
+ })
72
+ end
73
+ end
74
+
75
+ def get(search_string)
76
+ @raw_data = RestClient.get(@base_url + CGI.escape(search_string), :timeout => 10) rescue nil
77
+ end
78
+ end
@@ -0,0 +1,3 @@
1
+ module Undertexter
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,6 @@
1
+ require 'rspec'
2
+ require "#{File.dirname(__FILE__)}/../lib/undertexter"
3
+
4
+ RSpec.configure do |config|
5
+ config.mock_with :rspec
6
+ end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ describe Undertexter do
4
+ before(:all) do
5
+ @use = Undertexter.find("tt0499549")
6
+ end
7
+
8
+ it "should return return at least 31 subtitles" do
9
+ Undertexter.should have_at_least(31).find("tt0499549")
10
+ end
11
+
12
+ it "should contain cds that is of the type Fixnum" do
13
+ @use.each {|subtitle| subtitle.cds.class.should eq(Fixnum)}
14
+ end
15
+
16
+ it "should not contain cds with the value zero" do
17
+ @use.each {|subtitle| subtitle.cds.should_not be(0)}
18
+ end
19
+
20
+ it "should not contain some amount of downloads" do
21
+ @use.each {|subtitle| subtitle.downloads.class.should be(Fixnum)}
22
+ end
23
+
24
+ it "should contain some downloads" do
25
+ @use.reject {|subtitle| subtitle.downloads <= 0}.count.should_not be(0)
26
+ end
27
+
28
+ it "should contain titles that does not have whitespace in the end of beginning" do
29
+ @use.each {|subtitle| subtitle.title.should_not match(/^\s+.+\s+$/)}
30
+ end
31
+
32
+ it "should contain titles that isn't blank" do
33
+ @use.each {|subtitle| subtitle.title.should_not be_empty}
34
+ end
35
+
36
+ it "should contain the right urls" do
37
+ @use.each {|subtitle| subtitle.url.should match(/^http:\/\/www\.undertexter\.se\/\?p=undertext&id=\d+$/)}
38
+ end
39
+ end
40
+
41
+
42
+ describe Undertexter, "trying to find a non existing movie" do
43
+ it "should not return any subtitles" do
44
+ Undertexter.find("some random name").count.should be(0)
45
+ end
46
+ end
47
+
48
+ describe Undertexter, "trying to search for a movie using a title" do
49
+ before(:all) do
50
+ @use = Undertexter.find("die hard")
51
+ end
52
+
53
+ it "should return some subtitles" do
54
+ Undertexter.should have_at_least(36).find("avatar")
55
+ end
56
+
57
+ it "should return some subtitles when searching for a movie with whitespace" do
58
+ Undertexter.should have_at_least(41).find("die hard")
59
+ end
60
+
61
+ it "should return the right title, again" do
62
+ @use.each{|subtitle| subtitle.title.should match(/die.*hard/i)}
63
+ end
64
+
65
+ it "should contain the right urls, again" do
66
+ @use.each {|subtitle| subtitle.url.should match(/^http:\/\/www\.undertexter\.se\/\?p=undertext&id=\d+$/i)}
67
+ end
68
+
69
+ it "should have a movie title" do
70
+ @use.each {|subtitle| subtitle.movie_title.should match(/die hard/i)}
71
+ end
72
+
73
+ it "should have a movie title that is not equal to the subtitle" do
74
+ @use.each {|subtitle| subtitle.movie_title.should_not eq(subtitle.title)}
75
+ end
76
+
77
+ it "should not contain movie title that starts or ends with whitespace" do
78
+ @use.each {|subtitle| subtitle.movie_title.should_not match(/^\s+.+\s+$/)}
79
+ end
80
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "undertexter/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "undertexter"
7
+ s.version = Undertexter::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Linus Oleander"]
10
+ s.email = ["linus@oleander.nu"]
11
+ s.homepage = "https://github.com/oleander/Undertexter"
12
+ s.summary = %q{A subtitle search client for undertexter.se}
13
+ s.description = %q{A subtitle search client to search for swedish subtitles on undertexter.se}
14
+
15
+ s.rubyforge_project = "undertexter"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_dependency('rest-client')
23
+ s.add_dependency('nokogiri')
24
+ s.add_development_dependency('rspec')
25
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: undertexter
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 3
10
+ version: 0.0.3
11
+ platform: ruby
12
+ authors:
13
+ - Linus Oleander
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-23 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rest-client
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: nokogiri
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: rspec
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ hash: 3
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ type: :development
62
+ version_requirements: *id003
63
+ description: A subtitle search client to search for swedish subtitles on undertexter.se
64
+ email:
65
+ - linus@oleander.nu
66
+ executables: []
67
+
68
+ extensions: []
69
+
70
+ extra_rdoc_files: []
71
+
72
+ files:
73
+ - .gitignore
74
+ - .rspec
75
+ - Gemfile
76
+ - Gemfile.lock
77
+ - README
78
+ - Rakefile
79
+ - lib/subtitle.rb
80
+ - lib/undertexter.rb
81
+ - lib/undertexter/version.rb
82
+ - spec/spec_helper.rb
83
+ - spec/undertexter_spec.rb
84
+ - undertexter.gemspec
85
+ has_rdoc: true
86
+ homepage: https://github.com/oleander/Undertexter
87
+ licenses: []
88
+
89
+ post_install_message:
90
+ rdoc_options: []
91
+
92
+ require_paths:
93
+ - lib
94
+ required_ruby_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ hash: 3
100
+ segments:
101
+ - 0
102
+ version: "0"
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ hash: 3
109
+ segments:
110
+ - 0
111
+ version: "0"
112
+ requirements: []
113
+
114
+ rubyforge_project: undertexter
115
+ rubygems_version: 1.3.7
116
+ signing_key:
117
+ specification_version: 3
118
+ summary: A subtitle search client for undertexter.se
119
+ test_files:
120
+ - spec/spec_helper.rb
121
+ - spec/undertexter_spec.rb