subdl 0.0.8 → 0.0.9
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.
- checksums.yaml +4 -4
- data/bin/subdl +3 -4
- data/lib/subdl.rb +39 -62
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2db16138366c1df81aeaa2223014160c3d3d34c
|
4
|
+
data.tar.gz: c4766a193aab8bd65530651d666cb0aeb0ae3f5c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ecfbaf73ca2b4cd282b40d5f0599393cd6beeb8d35414439ffa83d2592b1849eb69f5c2636df0eb5068f521873805962c67c5e12b95ef3b81f6be7edac5f075f
|
7
|
+
data.tar.gz: fed07781bea4e3620b5cb5433cbdbfa2b6dbd20e2046ec073a36cdc13f07064f23ae39341dd358d3870d085a4a0df099f1beaf418326c3e7e3e76988de8e4305
|
data/bin/subdl
CHANGED
data/lib/subdl.rb
CHANGED
@@ -4,25 +4,20 @@ require 'json'
|
|
4
4
|
require 'zipruby'
|
5
5
|
require 'nokogiri'
|
6
6
|
|
7
|
+
require 'subdl/subtitles_net'
|
8
|
+
require 'subdl/italiansubs'
|
9
|
+
|
7
10
|
class Subdl
|
8
|
-
def initialize agent, itasa_login, stdout, file_system,
|
9
|
-
file_reader
|
10
|
-
itasa = Itasa.new(agent, itasa_login)
|
11
|
-
credentials = Credentials.new file_reader
|
12
|
-
@crawler = Crawler.new itasa, credentials, file_system, stdout
|
13
|
-
end
|
14
11
|
def main argv
|
15
12
|
until argv.empty? do
|
16
|
-
|
13
|
+
download_sub_for argv.shift
|
17
14
|
end
|
18
15
|
end
|
19
|
-
end
|
20
16
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
@
|
25
|
-
@credentials = credentials
|
17
|
+
def initialize itasa, subtitles_net, stdout, file_system
|
18
|
+
@itasa = Itasa.new itasa
|
19
|
+
@subtitles_net = subtitles_net
|
20
|
+
@credentials = Credentials.new file_system
|
26
21
|
@file_system = file_system
|
27
22
|
@stdout = stdout
|
28
23
|
end
|
@@ -31,22 +26,35 @@ class Crawler
|
|
31
26
|
movie_file = MovieFile.new path, @stdout
|
32
27
|
ids = @itasa.search_subtitles(movie_file.search_term)
|
33
28
|
|
34
|
-
if
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
@itasa.download_zip id do |zip_contents|
|
41
|
-
unpack_subtitle_to zip_contents, movie_file
|
29
|
+
if ids.any?
|
30
|
+
ids.each do |id|
|
31
|
+
@itasa.login *@credentials.read
|
32
|
+
@itasa.download_zip id do |zip_contents|
|
33
|
+
unpack_subtitle_to zip_contents, movie_file, 'itasa'
|
34
|
+
end
|
42
35
|
end
|
36
|
+
else
|
37
|
+
@stdout.puts "No subtitles found on ITASA for: #{path}"
|
38
|
+
show = movie_file.show
|
39
|
+
season = movie_file.season
|
40
|
+
episode = movie_file.episode
|
41
|
+
|
42
|
+
search_results = SearchResults.new(
|
43
|
+
@subtitles_net.search show, season, episode)
|
44
|
+
|
45
|
+
details_page_link = search_results.subtitles.first.href
|
46
|
+
page = @subtitles_net.get details_page_link
|
47
|
+
details_page = DetailsPage.new page
|
48
|
+
|
49
|
+
zip_contents = @subtitles_net.get details_page.zip_location
|
50
|
+
unpack_subtitle_to zip_contents, movie_file, 'subtitles-net'
|
43
51
|
end
|
44
52
|
end
|
45
53
|
|
46
|
-
def unpack_subtitle_to zip_contents, movie_file
|
54
|
+
def unpack_subtitle_to zip_contents, movie_file, source_id
|
47
55
|
Zip::Archive.open_buffer(zip_contents) do |archive|
|
48
56
|
archive.each do |entry|
|
49
|
-
movie_file.save_subtitle entry.read, @file_system
|
57
|
+
movie_file.save_subtitle entry.read, @file_system, source_id
|
50
58
|
end
|
51
59
|
end
|
52
60
|
end
|
@@ -81,9 +89,10 @@ class MovieFile
|
|
81
89
|
"%s %dx%02d" % [show, season, episode]
|
82
90
|
end
|
83
91
|
|
84
|
-
|
92
|
+
# TODO: accept filename instead of source_id
|
93
|
+
def save_subtitle contents, fs, source_id
|
85
94
|
srt_filename = @filename.gsub /.mp4$/, ''
|
86
|
-
srt_filename += "
|
95
|
+
srt_filename += ".#{source_id}#{next_distinguisher}.srt"
|
87
96
|
@stdout.puts "Downloaded as #{srt_filename}"
|
88
97
|
fs.save_file srt_filename, contents
|
89
98
|
end
|
@@ -105,45 +114,18 @@ class FileSystem
|
|
105
114
|
f.write contents
|
106
115
|
end
|
107
116
|
end
|
108
|
-
|
109
|
-
|
110
|
-
def mechanize_agent
|
111
|
-
Mechanize.new do |a|
|
112
|
-
a.user_agent_alias = 'Mac FireFox'
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
class ItasaLoginForm
|
117
|
-
|
118
|
-
def login username, password, page_where_to_login, agent
|
119
|
-
return if logged_in?
|
120
|
-
home_page = agent.get page_where_to_login
|
121
|
-
login_form = home_page.form 'login'
|
122
|
-
login_form.username = username
|
123
|
-
login_form.passwd = password
|
124
|
-
@page = agent.submit(login_form)
|
125
|
-
end
|
126
|
-
|
127
|
-
private
|
128
|
-
|
129
|
-
def logged_in?
|
130
|
-
return false unless @page
|
131
|
-
link_that_exists_only_once_logged = @page.search(
|
132
|
-
"//a[@href='forum/index.php?action=unreadreplies']")
|
133
|
-
return link_that_exists_only_once_logged.first != nil
|
117
|
+
def read_expand expandable_path
|
118
|
+
File.read(File.expand_path(expandable_path))
|
134
119
|
end
|
135
|
-
|
136
|
-
|
137
120
|
end
|
138
121
|
|
139
122
|
class Itasa
|
140
|
-
def initialize agent
|
123
|
+
def initialize agent
|
141
124
|
@agent = agent
|
142
|
-
@login_form = login_form || ItasaLoginForm.new
|
143
125
|
end
|
144
126
|
|
145
127
|
def login username, password
|
146
|
-
@
|
128
|
+
@agent.login username, password
|
147
129
|
end
|
148
130
|
|
149
131
|
def search_subtitles text
|
@@ -201,12 +183,7 @@ class Credentials
|
|
201
183
|
[username, password]
|
202
184
|
end
|
203
185
|
def read
|
204
|
-
parse @file_reader.read_expand('~/.itasa-credentials')
|
186
|
+
@parsed ||= parse @file_reader.read_expand('~/.itasa-credentials')
|
205
187
|
end
|
206
188
|
end
|
207
189
|
|
208
|
-
class FileReader
|
209
|
-
def read_expand expandable_path
|
210
|
-
File.read(File.expand_path(expandable_path))
|
211
|
-
end
|
212
|
-
end
|