subtitulos_downloader 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.rspec +2 -0
- data/Gemfile +12 -0
- data/LICENSE +20 -0
- data/README.md +76 -0
- data/Rakefile +16 -0
- data/lib/subtitulos_downloader.rb +67 -0
- data/lib/subtitulos_downloader/exception.rb +25 -0
- data/lib/subtitulos_downloader/provider/provider.rb +22 -0
- data/lib/subtitulos_downloader/provider/subtitulos_es.rb +143 -0
- data/lib/subtitulos_downloader/show_episode.rb +111 -0
- data/lib/subtitulos_downloader/subtitle.rb +29 -0
- data/lib/subtitulos_downloader/version.rb +3 -0
- data/spec/show_episode_spec.rb +68 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/subtitle_spec.rb +31 -0
- data/spec/subtitulos_downloader_spec.rb +58 -0
- data/spec/subtitulos_es_spec.rb +94 -0
- data/subtitulos_downloader.gemspec +29 -0
- metadata +150 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Hector Sanchez-Pajares
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
Subtitulos Downloader
|
2
|
+
=====================
|
3
|
+
Subtitulos Downloader is a gem to download subtitles focused in spanish language.
|
4
|
+
|
5
|
+
Description
|
6
|
+
-----------
|
7
|
+
Subtitles Downloader can use different subtitles providers to fetch the files from different webs.
|
8
|
+
It allows to download subtitles for multiple languages supported by the provider used.
|
9
|
+
|
10
|
+
It also supports TVdb to fetch the episode name and the real name for the show given a season and an episode number.
|
11
|
+
|
12
|
+
It saves the file(s) to a given path.Right now, only supported format name is:
|
13
|
+
<code>Show Name/Season #/Show Name - SxEE - Episode Name-Language.srt</code>
|
14
|
+
|
15
|
+
|
16
|
+
### Providers
|
17
|
+
The providers currently developed are:
|
18
|
+
* [subtitulos.es](http://www.subtitulos.es)
|
19
|
+
|
20
|
+
|
21
|
+
Installation
|
22
|
+
------------
|
23
|
+
To install the gem
|
24
|
+
<pre>
|
25
|
+
gem install subtitulos_downloader
|
26
|
+
</pre>
|
27
|
+
|
28
|
+
Usage
|
29
|
+
-----
|
30
|
+
For using this gem all you have to do is
|
31
|
+
<pre>
|
32
|
+
require 'subtitulos_downloader'
|
33
|
+
sub_downloader = SubtitulosDownloader::SubtitulosDownloader({
|
34
|
+
:provider = SubtitulosDownloader::SubtitlosEs,
|
35
|
+
:tvdb_api_key = 'XXXXXXXXXXXXX'
|
36
|
+
})
|
37
|
+
|
38
|
+
# Fetching spanish subtitles given a show name, season and episode
|
39
|
+
episode = sub_downloader.fetch('Fringe', 4, 7, %w[ es ])
|
40
|
+
|
41
|
+
# Fetching english subtitles given a file name
|
42
|
+
episode = sub_downloader.fetch_by_file_name('Fringe.S04E07.HDTV.XviD-LOL.avi.avi', %w[ en ])
|
43
|
+
|
44
|
+
# Fetching english and spanish subtitles given an episode object
|
45
|
+
episode = SubtitulosDownloader::ShowEpisode.new_from_file_name('Fringe.S04E07.HDTV.XviD-LOL.avi.avi', {:tvdb_api_key = 'XXXXXXX'})
|
46
|
+
sub_downloader.fetch_by_show_episode(episode, %w[ es en ])
|
47
|
+
|
48
|
+
# To save the subtitles
|
49
|
+
# Ex: /path_to_save/Fringe/Season 4/Fringe - 4x07 - Wallflower-English.srt
|
50
|
+
sub_downloader.save_subs_to_path(episode, '/path_to_save')
|
51
|
+
|
52
|
+
# Episode Object
|
53
|
+
episode =
|
54
|
+
subs = episode.subtitles # Array containing all subtitles for the episode
|
55
|
+
name = episode.full_name # Ex: Fringe - 4x07 - Wallflower
|
56
|
+
ep_name = episode.episode_name # Ex: Wallflower
|
57
|
+
season = episode.season # Ex: 4
|
58
|
+
episode = episode.episode # Ex: 7
|
59
|
+
show = episode.show_name # Ex: Fringe
|
60
|
+
|
61
|
+
# Subtitle Object
|
62
|
+
subtitles = episode.subtitles.first
|
63
|
+
subtitles.language # Language of subtitles
|
64
|
+
subtitles.subtitles # String containing the subtitles
|
65
|
+
</pre>
|
66
|
+
|
67
|
+
Contact
|
68
|
+
------
|
69
|
+
Héctor Sánchez-Pajares
|
70
|
+
[hector@aerstudio.com](mailto:hector@aerstudio.com)
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
|
5
|
+
Bundler.setup(:default, :development)
|
6
|
+
|
7
|
+
|
8
|
+
desc "Run all RSpec tests"
|
9
|
+
RSpec::Core::RakeTask.new(:spec)
|
10
|
+
|
11
|
+
desc "Build the gem"
|
12
|
+
task :gem do
|
13
|
+
sh 'gem build *.gemspec'
|
14
|
+
end
|
15
|
+
|
16
|
+
task :default => :spec
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require "subtitulos_downloader/version"
|
2
|
+
require "subtitulos_downloader/subtitle"
|
3
|
+
require "subtitulos_downloader/show_episode"
|
4
|
+
require "subtitulos_downloader/exception"
|
5
|
+
require "subtitulos_downloader/provider/provider"
|
6
|
+
Dir["#{File.dirname(__FILE__)}/subtitulos_downloader/provider/*.rb"].each {|f| require f}
|
7
|
+
|
8
|
+
|
9
|
+
module SubtitulosDownloader
|
10
|
+
|
11
|
+
class SubtitulosDownloader
|
12
|
+
def initialize(opts = {})
|
13
|
+
options = {
|
14
|
+
:provider => SubtitulosEs
|
15
|
+
}.merge!(opts)
|
16
|
+
|
17
|
+
@provider = options[:provider].new(options)
|
18
|
+
@options = options
|
19
|
+
end
|
20
|
+
|
21
|
+
def fetch(show_name, season, episode, languages = %w[ es en ])
|
22
|
+
languages = [languages] if not languages.respond_to?('each')
|
23
|
+
show_episode = ShowEpisode.new(show_name, season, episode, @options)
|
24
|
+
languages.each do |language|
|
25
|
+
@provider.fetch(show_episode, language)
|
26
|
+
end
|
27
|
+
show_episode
|
28
|
+
end
|
29
|
+
|
30
|
+
def fetch_by_file_name(file_name, languages = %w[ es en ])
|
31
|
+
languages = [languages] if not languages.respond_to?('each')
|
32
|
+
show_episode = ShowEpisode.new_from_file_name(file_name, @options)
|
33
|
+
languages.each do |language|
|
34
|
+
@provider.fetch(show_episode, language)
|
35
|
+
end
|
36
|
+
show_episode
|
37
|
+
end
|
38
|
+
|
39
|
+
def fetch_by_show_episode(show_episode, languages = %w[ es en ])
|
40
|
+
languages = [languages] if not languages.respond_to?('each')
|
41
|
+
languages.each do |language|
|
42
|
+
@provider.fetch(show_episode, language)
|
43
|
+
end
|
44
|
+
show_episode
|
45
|
+
end
|
46
|
+
|
47
|
+
def save_subs_to_path(show_episode, path)
|
48
|
+
show_episode.subtitles.each do |subtitle|
|
49
|
+
check_if_path_exists("#{path}/#{show_episode.show_path}")
|
50
|
+
check_if_path_exists("#{path}/#{show_episode.season_path}")
|
51
|
+
file = File.new("#{path}/#{subtitle.save_path}", "w")
|
52
|
+
file.write(subtitle.subtitles)
|
53
|
+
file.close
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
protected
|
59
|
+
|
60
|
+
def check_if_path_exists(path)
|
61
|
+
if not FileTest::directory?(path)
|
62
|
+
Dir::mkdir(path)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module SubtitulosDownloader
|
2
|
+
class SDException < Exception
|
3
|
+
end
|
4
|
+
|
5
|
+
class Timeout < SDException
|
6
|
+
end
|
7
|
+
|
8
|
+
class ShowNotFound < SDException
|
9
|
+
end
|
10
|
+
|
11
|
+
class MoreThanOneShow < SDException
|
12
|
+
end
|
13
|
+
|
14
|
+
class EpisodeNotFound < SDException
|
15
|
+
end
|
16
|
+
|
17
|
+
class SeasonNotFound < SDException
|
18
|
+
end
|
19
|
+
|
20
|
+
class TranslationNotFinished < SDException
|
21
|
+
end
|
22
|
+
|
23
|
+
class LanguageNotFound < SDException
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'version'
|
2
|
+
module SubtitulosDownloader
|
3
|
+
class Provider
|
4
|
+
|
5
|
+
def initialize(options={})
|
6
|
+
@options = options
|
7
|
+
@user_agent = "SubtitulosDownloader/#{VERSION}"
|
8
|
+
init
|
9
|
+
end
|
10
|
+
|
11
|
+
def init(options)
|
12
|
+
# to be override
|
13
|
+
@base_uri = ""
|
14
|
+
@provider_name =''
|
15
|
+
end
|
16
|
+
|
17
|
+
def fetch(show, language)
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,143 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'hpricot'
|
3
|
+
require "version"
|
4
|
+
|
5
|
+
module SubtitulosDownloader
|
6
|
+
|
7
|
+
class SubtitulosEs < Provider
|
8
|
+
|
9
|
+
def init
|
10
|
+
@base_uri = "http://www.subtitulos.es"
|
11
|
+
@provider_name = "subtitulos.es"
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def fetch(show_episode, language)
|
16
|
+
|
17
|
+
get_shows_page unless @shows_doc
|
18
|
+
|
19
|
+
shows = search_show show_episode
|
20
|
+
|
21
|
+
show_sub = shows.first
|
22
|
+
|
23
|
+
episode_subs_table = get_episode_table show_episode, show_sub
|
24
|
+
|
25
|
+
case language
|
26
|
+
when 'en'
|
27
|
+
lang = 'English'
|
28
|
+
when 'es'
|
29
|
+
lang = 'España'
|
30
|
+
else
|
31
|
+
lang = language
|
32
|
+
end
|
33
|
+
|
34
|
+
begin
|
35
|
+
subs = get_subtitles(lang, episode_subs_table, show_sub)
|
36
|
+
subtitle = Subtitle.new subs, language, show_episode
|
37
|
+
rescue SDException => e
|
38
|
+
if language == 'es'
|
39
|
+
if lang == 'España'
|
40
|
+
lang = 'Latinoamérica'
|
41
|
+
retry
|
42
|
+
elsif lang == 'Latinoamérica'
|
43
|
+
lang = 'Español'
|
44
|
+
retry
|
45
|
+
else
|
46
|
+
raise e
|
47
|
+
end
|
48
|
+
else
|
49
|
+
raise e
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
subtitle
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
protected
|
58
|
+
|
59
|
+
def get_subtitles(language, episode_table, show_sub)
|
60
|
+
(episode_table/"tr/td.language").each do |lang|
|
61
|
+
language_sub = lang.inner_html.strip.force_encoding('utf-8')
|
62
|
+
if language_sub =~ /#{language}/i
|
63
|
+
# puts "Language #{language} found"
|
64
|
+
if not lang.next_sibling.inner_html =~ /[0-9]+\.?[0-9]*% Completado/i
|
65
|
+
# puts "Translation for language #{language} completed"
|
66
|
+
subtitle_a = lang.parent.search("a").at(0)
|
67
|
+
subtitle_url = subtitle_a.attributes['href']
|
68
|
+
# puts "Fetching #{language} subtitle file"
|
69
|
+
open(subtitle_url,
|
70
|
+
"User-Agent" => @user_agent,
|
71
|
+
"Referer" => "#{@base_uri}/show/#{show_sub[:id_show]}") { |f|
|
72
|
+
# Save the response body
|
73
|
+
subs= f.read
|
74
|
+
return subs
|
75
|
+
}
|
76
|
+
else
|
77
|
+
raise TranslationNotFinished, "[#{@provider_name}] #{language} translation not finished for #{show_sub[:show_episode].full_name}"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
raise LanguageNotFound, "[#{@provider_name}] #{language} not found for #{show_sub[:show_episode].full_name}"
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
def search_show show_episode
|
86
|
+
shows = []
|
87
|
+
@shows_doc.search("a").each do |show_subs|
|
88
|
+
show_name = show_subs.inner_html.force_encoding('utf-8')
|
89
|
+
show_url = show_subs.attributes['href']
|
90
|
+
if show_name =~ /#{show_episode.show_name}/i
|
91
|
+
shows << { :show_episode => show_episode, :url => show_url, :id_show => show_url.split('/show/')[1].to_i }
|
92
|
+
end
|
93
|
+
end
|
94
|
+
raise ShowNotFound, "[#{@provider_name}] #{show_episode.show_name} not found" if shows.count == 0
|
95
|
+
raise MoreThanOneShow, "[#{@provider_name}] Found #{shows.count} for #{show_episode.show_name}" if shows.count > 1
|
96
|
+
shows
|
97
|
+
end
|
98
|
+
|
99
|
+
def get_episode_table(show_episode, show_sub)
|
100
|
+
|
101
|
+
season_url = "#{@base_uri}/ajax_loadShow.php?show=#{show_sub[:id_show]}&season=#{show_episode.season}"
|
102
|
+
ep_t = nil
|
103
|
+
open(season_url,
|
104
|
+
"User-Agent" => @user_agent,
|
105
|
+
"Referer" =>"#{@base_uri}" ) { |f|
|
106
|
+
|
107
|
+
cont = f.read
|
108
|
+
raise SeasonNotFound, "[#{@provider_name}] Season for #{show_episode.full_name} not found" if cont == ''
|
109
|
+
|
110
|
+
season_doc = Hpricot(cont)
|
111
|
+
|
112
|
+
season_doc.search('table').each do |episode_table|
|
113
|
+
title = (episode_table/"tr/td[@colspan='5']/a").inner_html.force_encoding('utf-8')
|
114
|
+
episode_str = "%02d" % show_episode.episode
|
115
|
+
episode_number = "#{show_episode.season}x#{episode_str}"
|
116
|
+
if title =~ /#{episode_number}/i
|
117
|
+
ep_t = episode_table
|
118
|
+
break
|
119
|
+
end
|
120
|
+
end
|
121
|
+
}
|
122
|
+
|
123
|
+
if ep_t
|
124
|
+
return ep_t
|
125
|
+
else
|
126
|
+
raise EpisodeNotFound, "[#{@provider_name}] Episode #{show_episode.full_name} not found"
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
|
132
|
+
def get_shows_page
|
133
|
+
open(
|
134
|
+
"#{@base_uri}/series",
|
135
|
+
"User-Agent" => @user_agent,
|
136
|
+
"Referer" =>"#{@base_uri}" ) { |f|
|
137
|
+
@shows_doc = Hpricot(f.read)
|
138
|
+
}
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'tvdb'
|
2
|
+
|
3
|
+
module SubtitulosDownloader
|
4
|
+
|
5
|
+
class ShowEpisode
|
6
|
+
|
7
|
+
attr_accessor :show_name, :season, :episode, :episode_name
|
8
|
+
attr_accessor :tvdb_episode, :tvdb_show, :subtitles
|
9
|
+
|
10
|
+
def initialize(show_name, season, episode, options = {})
|
11
|
+
|
12
|
+
@show_name = show_name
|
13
|
+
@season = season.to_i
|
14
|
+
@episode = episode.to_i
|
15
|
+
@options = options
|
16
|
+
@subtitles = []
|
17
|
+
|
18
|
+
if @options[:tvdb_api_key]
|
19
|
+
fetch_data_from_tvdb(@options[:tvdb_api_key])
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def fetch_data_from_tvdb(key)
|
24
|
+
@tvdb = TVdb::Client.new(key)
|
25
|
+
tvdb_show = @tvdb.search(@show_name)
|
26
|
+
if tvdb_show.count > 0
|
27
|
+
tvdb_show = tvdb_show[0]
|
28
|
+
@show_name = tvdb_show.seriesname
|
29
|
+
tvdb_show.episodes.each do |ep|
|
30
|
+
ep_number = ep.episodenumber
|
31
|
+
ep_season = ep.combined_season
|
32
|
+
if ep_number.to_i == @episode && ep_season.to_i == @season
|
33
|
+
@episode_name = ep.episodename
|
34
|
+
break
|
35
|
+
end
|
36
|
+
end
|
37
|
+
else
|
38
|
+
raise ShowNotFound, "[TVdb] show #{@show_name} not found"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def subtitle_language(lang)
|
43
|
+
subs = nil
|
44
|
+
@subtitles.each do |sub|
|
45
|
+
if sub.language == lang
|
46
|
+
return sub
|
47
|
+
break
|
48
|
+
end
|
49
|
+
end
|
50
|
+
return nil
|
51
|
+
end
|
52
|
+
|
53
|
+
def full_name
|
54
|
+
episode_str = "%02d" % @episode
|
55
|
+
if @episode_name
|
56
|
+
"#{@show_name} - #{@season}x#{episode_str} - #{@episode_name}"
|
57
|
+
else
|
58
|
+
"#{@show_name} - #{@season}x#{episode_str}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def show_path
|
63
|
+
"#{@show_name}"
|
64
|
+
end
|
65
|
+
|
66
|
+
def season_path
|
67
|
+
"#{@show_name}/Season #{@season}"
|
68
|
+
end
|
69
|
+
|
70
|
+
def episode_path
|
71
|
+
"#{@show_name}/Season #{@season}/#{self.full_name}"
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.new_from_file_name(file_name, options={})
|
75
|
+
# House.S04E13.HDTV.XviD-XOR.avi
|
76
|
+
# my.name.is.earl.s03e07-e08.hdtv.xvid-xor.[VTV].avi
|
77
|
+
# My_Name_Is_Earl.3x17.No_Heads_And_A_Duffel_Bag.HDTV_XviD-FoV.[VTV].avi
|
78
|
+
# My Name Is Earl - 3x04.avi
|
79
|
+
# MythBusters - S04E01 - Newspaper Crossbow.avi
|
80
|
+
# my.name.is.earl.305.hdtv-lol.[VTV].avi
|
81
|
+
|
82
|
+
# TODO look up the regex used in XBMC to get data from TV episodes
|
83
|
+
re =
|
84
|
+
/^(.*?)(?:\s?[-\.]\s?)?\s*\[?s?(?:
|
85
|
+
(?:
|
86
|
+
(\d{1,2})
|
87
|
+
\s?\.?\s?[ex-]\s?
|
88
|
+
(?:(\d{2})(?:\s?[,-]\s?[ex]?(\d{2}))?)
|
89
|
+
)
|
90
|
+
|
|
91
|
+
(?:
|
92
|
+
\.(\d{1})(\d{2})(?!\d)
|
93
|
+
)
|
94
|
+
)\]?\s?.*$/ix
|
95
|
+
|
96
|
+
if match = file_name.to_s.match(re)
|
97
|
+
series = match[1].gsub(/[\._]/, ' ').strip.gsub(/\b\w/){$&.upcase}
|
98
|
+
season = (match[2] || match[5]).to_i
|
99
|
+
episode = (match[3] || match[6]).to_i
|
100
|
+
episode = (episode)..(match[4].to_i) unless match[4].nil?
|
101
|
+
|
102
|
+
show_episode = ShowEpisode.new(series, season, episode, options)
|
103
|
+
else
|
104
|
+
nil
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module SubtitulosDownloader
|
2
|
+
|
3
|
+
class Subtitle
|
4
|
+
|
5
|
+
attr_accessor :subtitles, :language, :show_episode
|
6
|
+
|
7
|
+
def initialize(subs, language, show_episode)
|
8
|
+
@subtitles = subs
|
9
|
+
@language = language
|
10
|
+
@show_episode = show_episode
|
11
|
+
@show_episode.subtitles << self
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def save_path
|
16
|
+
case @language
|
17
|
+
when 'es'
|
18
|
+
lang = 'Spanish'
|
19
|
+
when 'en'
|
20
|
+
lang = 'English'
|
21
|
+
else
|
22
|
+
lang = @language
|
23
|
+
end
|
24
|
+
"#{@show_episode.episode_path}-#{lang}.srt"
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe SubtitulosDownloader::ShowEpisode do
|
5
|
+
|
6
|
+
context "Initializing" do
|
7
|
+
|
8
|
+
it 'should create a new show episode from show, season and episode' do
|
9
|
+
episode = SubtitulosDownloader::ShowEpisode.new('Raising Hope', 2, 4)
|
10
|
+
episode.show_name.should == 'Raising Hope'
|
11
|
+
episode.season.should == 2
|
12
|
+
episode.episode.should == 4
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should create a new show episode from a file name' do
|
16
|
+
ep = SubtitulosDownloader::ShowEpisode.new_from_file_name("Fringe.S04E07.HDTV.XviD-LOL.avi.avi")
|
17
|
+
ep.show_name.should == 'Fringe'
|
18
|
+
ep.season.should == 4
|
19
|
+
ep.episode.should == 7
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should fetch data from TVdb' do
|
23
|
+
ep = SubtitulosDownloader::ShowEpisode.new_from_file_name("Fringe.S04E07.HDTV.XviD-LOL.avi.avi", {:tvdb_api_key => 'EF41E54C744526F7'})
|
24
|
+
ep.episode_name.should == 'Wallflower'
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should show the episode full name' do
|
28
|
+
ep = SubtitulosDownloader::ShowEpisode.new_from_file_name("Fringe.S04E07.HDTV.XviD-LOL.avi.avi", {:tvdb_api_key => 'EF41E54C744526F7'})
|
29
|
+
ep.full_name.should == 'Fringe - 4x07 - Wallflower'
|
30
|
+
episode = SubtitulosDownloader::ShowEpisode.new('Raising Hope', 2, 4)
|
31
|
+
episode.full_name.should == 'Raising Hope - 2x04'
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should show the subtitle given a language' do
|
35
|
+
episode = SubtitulosDownloader::ShowEpisode.new('fake show', 3, 3)
|
36
|
+
subtitle = SubtitulosDownloader::Subtitle.new('subs', 'es', episode)
|
37
|
+
sub = episode.subtitle_language 'es'
|
38
|
+
sub.should == subtitle
|
39
|
+
sub.subtitles.should =='subs'
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
context "Paths" do
|
46
|
+
before(:all) do
|
47
|
+
@ep = SubtitulosDownloader::ShowEpisode.new_from_file_name("Fringe.S04E07.HDTV.XviD-LOL.avi.avi", {:tvdb_api_key => 'EF41E54C744526F7'})
|
48
|
+
end
|
49
|
+
it 'should show the show path' do
|
50
|
+
@ep.show_path.should == 'Fringe'
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should show the season path' do
|
54
|
+
@ep.season_path.should == 'Fringe/Season 4'
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should show the episode path' do
|
58
|
+
@ep.episode_path.should == 'Fringe/Season 4/Fringe - 4x07 - Wallflower'
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "Exceptions" do
|
63
|
+
|
64
|
+
it 'should raise a show not found exception' do
|
65
|
+
lambda{ SubtitulosDownloader::ShowEpisode.new('fake show', 4, 5, {:tvdb_api_key => 'EF41E54C744526F7'}) }.should raise_error(SubtitulosDownloader::ShowNotFound)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
|
4
|
+
describe SubtitulosDownloader::Subtitle do
|
5
|
+
|
6
|
+
context "Initializing" do
|
7
|
+
before(:all) do
|
8
|
+
@ep = SubtitulosDownloader::ShowEpisode.new_from_file_name("Fringe.S04E07.HDTV.XviD-LOL.avi.avi", {:tvdb_api_key => 'EF41E54C744526F7'})
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should initialize' do
|
12
|
+
sub = SubtitulosDownloader::Subtitle.new('subs', 'en', @ep)
|
13
|
+
sub.subtitles.should == 'subs'
|
14
|
+
sub.language.should == 'en'
|
15
|
+
sub.show_episode.should == @ep
|
16
|
+
@ep.subtitles.count.should == 1
|
17
|
+
@ep.subtitles.first.should == sub
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should show the path to save' do
|
21
|
+
sub = SubtitulosDownloader::Subtitle.new('subs', 'en', @ep)
|
22
|
+
sub.save_path.should == 'Fringe/Season 4/Fringe - 4x07 - Wallflower-English.srt'
|
23
|
+
sub = SubtitulosDownloader::Subtitle.new('subs', 'es', @ep)
|
24
|
+
sub.save_path.should == 'Fringe/Season 4/Fringe - 4x07 - Wallflower-Spanish.srt'
|
25
|
+
sub = SubtitulosDownloader::Subtitle.new('subs', 'ca', @ep)
|
26
|
+
sub.save_path.should == 'Fringe/Season 4/Fringe - 4x07 - Wallflower-ca.srt'
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
|
5
|
+
describe SubtitulosDownloader::SubtitulosDownloader do
|
6
|
+
|
7
|
+
context "Fetching" do
|
8
|
+
before(:all) do
|
9
|
+
@sub_downloader = SubtitulosDownloader::SubtitulosDownloader.new
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should fetch subtitles given name, season and episode' do
|
13
|
+
episode = @sub_downloader.fetch('Fringe', 4, 7, %w[ es ])
|
14
|
+
episode.subtitles.count.should == 1
|
15
|
+
subs = (episode.subtitles.first.subtitles =~ /Ahora solo tengo que averiguar/) > 1
|
16
|
+
subs.should == true
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should fetch subtitles in english and spanish by default' do
|
20
|
+
episode = @sub_downloader.fetch('Fringe', 4, 7)
|
21
|
+
episode.subtitles.count.should == 2
|
22
|
+
subtitle = episode.subtitle_language 'es'
|
23
|
+
subs = (subtitle.subtitles =~ /Ahora solo tengo que averiguar/) > 1
|
24
|
+
subs.should == true
|
25
|
+
subtitle = episode.subtitle_language 'en'
|
26
|
+
subs = (subtitle.subtitles =~ /10-4. Copy location./) > 1
|
27
|
+
subs.should == true
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should fetch subtitles given a file name' do
|
31
|
+
episode = @sub_downloader.fetch_by_file_name('Fringe.S04E07.HDTV.XviD-LOL.avi.avi', %w[ es ])
|
32
|
+
episode.subtitles.count.should == 1
|
33
|
+
subs = (episode.subtitles.first.subtitles =~ /Ahora solo tengo que averiguar/) > 1
|
34
|
+
subs.should == true
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should fetch subtitles given a show episode' do
|
38
|
+
episode = SubtitulosDownloader::ShowEpisode.new_from_file_name('Fringe.S04E07.HDTV.XviD-LOL.avi.avi')
|
39
|
+
@sub_downloader.fetch_by_show_episode(episode, %w[ es ])
|
40
|
+
episode.subtitles.count.should == 1
|
41
|
+
subs = (episode.subtitles.first.subtitles =~ /Ahora solo tengo que averiguar/) > 1
|
42
|
+
subs.should == true
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
context "Saving" do
|
48
|
+
it 'should save the subtitles to disk' do
|
49
|
+
sub_downloader = SubtitulosDownloader::SubtitulosDownloader.new
|
50
|
+
episode = sub_downloader.fetch('Fringe', 4, 7)
|
51
|
+
sub_downloader.save_subs_to_path(episode, '/tmp')
|
52
|
+
episode.subtitles.each do |sub|
|
53
|
+
exists = File.exists?('/tmp/' + sub.save_path)
|
54
|
+
exists.should == true
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
|
5
|
+
describe SubtitulosDownloader::SubtitulosEs do
|
6
|
+
|
7
|
+
context "Fetching subtitles" do
|
8
|
+
before(:all) do
|
9
|
+
@ep = SubtitulosDownloader::ShowEpisode.new_from_file_name("Fringe.S04E07.HDTV.XviD-LOL.avi.avi")
|
10
|
+
@simpsons = SubtitulosDownloader::ShowEpisode.new_from_file_name("The Simpsons - 20x05 - Dangerous Curves")
|
11
|
+
@simpsons2 = SubtitulosDownloader::ShowEpisode.new_from_file_name("The Simpsons - 20x07 - Mypods and Boomsticks")
|
12
|
+
@provider = SubtitulosDownloader::SubtitulosEs.new()
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should fetch spanish subtitle' do
|
16
|
+
subtitle = @provider.fetch(@ep, 'es')
|
17
|
+
subtitle.language.should == 'es'
|
18
|
+
subtitle.show_episode.should == @ep
|
19
|
+
subs = (subtitle.subtitles =~ /Ahora solo tengo que averiguar/) > 1
|
20
|
+
subs.should == true
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should fetch english subtitle' do
|
24
|
+
subtitle = @provider.fetch(@ep, 'en')
|
25
|
+
subtitle.language.should == 'en'
|
26
|
+
subtitle.show_episode.should == @ep
|
27
|
+
subs = (subtitle.subtitles =~ /10-4. Copy location./) > 1
|
28
|
+
subs.should == true
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should fetch latinoamerican instead of spanish subtitles' do
|
32
|
+
subtitle = @provider.fetch(@simpsons, 'es')
|
33
|
+
subtitle.language.should == 'es'
|
34
|
+
subtitle.show_episode.should == @simpsons
|
35
|
+
subs = (subtitle.subtitles =~ /Tenemos cubos amarillos, cubos anaranjados/) > 1
|
36
|
+
subs.should == true
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should fetch español instead of spanish subtitles' do
|
40
|
+
subtitle = @provider.fetch(@simpsons2, 'es')
|
41
|
+
subtitle.language.should == 'es'
|
42
|
+
subtitle.show_episode.should == @simpsons2
|
43
|
+
subs = (subtitle.subtitles =~ /me gusta la forma de pensar de ustedes los italianos/) > 1
|
44
|
+
subs.should == true
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should fetch italian language' do
|
48
|
+
episode = SubtitulosDownloader::ShowEpisode.new('fringe', 3, 7)
|
49
|
+
subtitle = @provider.fetch(episode, 'italian')
|
50
|
+
subtitle.language.should == 'italian'
|
51
|
+
subtitle.show_episode.should == episode
|
52
|
+
subs = (subtitle.subtitles =~ /Quello che conta e' che sono nei guai./) > 1
|
53
|
+
subs.should == true
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "Rasing Exceptions" do
|
58
|
+
before(:all) do
|
59
|
+
@provider = SubtitulosDownloader::SubtitulosEs.new()
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should raise a not show found exception' do
|
63
|
+
episode = SubtitulosDownloader::ShowEpisode.new('fake show', 2, 4)
|
64
|
+
lambda{@provider.fetch(episode, 'es')}.should raise_error(SubtitulosDownloader::ShowNotFound)
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should raise more than one show exception' do
|
68
|
+
episode = SubtitulosDownloader::ShowEpisode.new('the', 3, 4)
|
69
|
+
lambda{@provider.fetch(episode, 'es')}.should raise_error(SubtitulosDownloader::MoreThanOneShow)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should raise season not found exception' do
|
73
|
+
episode = SubtitulosDownloader::ShowEpisode.new('the simpsons', 3, 4)
|
74
|
+
lambda{@provider.fetch(episode, 'es')}.should raise_error(SubtitulosDownloader::SeasonNotFound)
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should raise episode not found exception' do
|
78
|
+
episode = SubtitulosDownloader::ShowEpisode.new('the simpsons', 22, 34)
|
79
|
+
lambda{@provider.fetch(episode, 'es')}.should raise_error(SubtitulosDownloader::EpisodeNotFound)
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should raise episode not translated exception' do
|
83
|
+
episode = SubtitulosDownloader::ShowEpisode.new('the simpsons', 20, 1)
|
84
|
+
lambda{@provider.fetch(episode, 'galego')}.should raise_error(SubtitulosDownloader::TranslationNotFinished)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should raise language not found exception' do
|
88
|
+
episode = SubtitulosDownloader::ShowEpisode.new('the simpsons', 20, 1)
|
89
|
+
lambda{@provider.fetch(episode, 'esperanto')}.should raise_error(SubtitulosDownloader::LanguageNotFound)
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "subtitulos_downloader/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "subtitulos_downloader"
|
7
|
+
s.version = SubtitulosDownloader::VERSION
|
8
|
+
s.authors = ["hector spc"]
|
9
|
+
s.email = ["hector@aerstudio.com"]
|
10
|
+
s.homepage = "https://github.com/hecspc/Subtitulos-Downloader"
|
11
|
+
s.summary = "Fetch subtitles focused on spanish language"
|
12
|
+
s.description = "Fetch subtitles from different providers and save them to a given path"
|
13
|
+
|
14
|
+
s.rubyforge_project = "subtitulos_downloader"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
s.add_development_dependency "rake"
|
23
|
+
s.add_development_dependency "rspec", "~>2.0"
|
24
|
+
# s.add_runtime_dependency "rest-client"
|
25
|
+
s.add_dependency("tvdb", ">= 0.1.0")
|
26
|
+
s.add_dependency("hpricot", ">= 0.8.4")
|
27
|
+
s.add_dependency("httparty", ">= 0.8.1")
|
28
|
+
s.add_dependency("prowler", ">= 1.3.1")
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: subtitulos_downloader
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.5.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- hector spc
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-11-20 00:00:00 +01:00
|
14
|
+
default_executable:
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rake
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :development
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ~>
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "2.0"
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: tvdb
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 0.1.0
|
46
|
+
type: :runtime
|
47
|
+
prerelease: false
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: hpricot
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: 0.8.4
|
57
|
+
type: :runtime
|
58
|
+
prerelease: false
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: httparty
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 0.8.1
|
68
|
+
type: :runtime
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: *id005
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: prowler
|
73
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 1.3.1
|
79
|
+
type: :runtime
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: *id006
|
82
|
+
description: Fetch subtitles from different providers and save them to a given path
|
83
|
+
email:
|
84
|
+
- hector@aerstudio.com
|
85
|
+
executables: []
|
86
|
+
|
87
|
+
extensions: []
|
88
|
+
|
89
|
+
extra_rdoc_files: []
|
90
|
+
|
91
|
+
files:
|
92
|
+
- .gitignore
|
93
|
+
- .rspec
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- lib/subtitulos_downloader.rb
|
99
|
+
- lib/subtitulos_downloader/exception.rb
|
100
|
+
- lib/subtitulos_downloader/provider/provider.rb
|
101
|
+
- lib/subtitulos_downloader/provider/subtitulos_es.rb
|
102
|
+
- lib/subtitulos_downloader/show_episode.rb
|
103
|
+
- lib/subtitulos_downloader/subtitle.rb
|
104
|
+
- lib/subtitulos_downloader/version.rb
|
105
|
+
- spec/show_episode_spec.rb
|
106
|
+
- spec/spec_helper.rb
|
107
|
+
- spec/subtitle_spec.rb
|
108
|
+
- spec/subtitulos_downloader_spec.rb
|
109
|
+
- spec/subtitulos_es_spec.rb
|
110
|
+
- subtitulos_downloader.gemspec
|
111
|
+
has_rdoc: true
|
112
|
+
homepage: https://github.com/hecspc/Subtitulos-Downloader
|
113
|
+
licenses: []
|
114
|
+
|
115
|
+
post_install_message:
|
116
|
+
rdoc_options: []
|
117
|
+
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
hash: -1979499645020437577
|
126
|
+
segments:
|
127
|
+
- 0
|
128
|
+
version: "0"
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
hash: -1979499645020437577
|
135
|
+
segments:
|
136
|
+
- 0
|
137
|
+
version: "0"
|
138
|
+
requirements: []
|
139
|
+
|
140
|
+
rubyforge_project: subtitulos_downloader
|
141
|
+
rubygems_version: 1.6.2
|
142
|
+
signing_key:
|
143
|
+
specification_version: 3
|
144
|
+
summary: Fetch subtitles focused on spanish language
|
145
|
+
test_files:
|
146
|
+
- spec/show_episode_spec.rb
|
147
|
+
- spec/spec_helper.rb
|
148
|
+
- spec/subtitle_spec.rb
|
149
|
+
- spec/subtitulos_downloader_spec.rb
|
150
|
+
- spec/subtitulos_es_spec.rb
|