subdl 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/subdl.rb +23 -10
  2. metadata +1 -1
@@ -67,7 +67,7 @@ class MovieFile
67
67
  distinguisher = ".#{@subs_added}"
68
68
  else
69
69
  distinguisher = ''
70
- end
70
+ end
71
71
  @subs_added = @subs_added.to_i + 1
72
72
  return distinguisher
73
73
  end
@@ -86,26 +86,25 @@ class Itasa
86
86
  @agent = Mechanize.new do |a|
87
87
  a.user_agent_alias = 'Mac FireFox'
88
88
  end
89
- @page = @agent.get "http://#{host}"
90
89
  end
91
90
 
92
91
  def login username, password
93
- login_form = @page.form 'login'
92
+ home_page = @agent.get "http://#{host}"
93
+ login_form = home_page.form 'login'
94
94
  login_form.username = username
95
95
  login_form.passwd = password
96
96
  @page = @agent.submit(login_form)
97
97
  end
98
98
 
99
99
  def logged_in?
100
+ return false unless @page
100
101
  link_that_exists_only_once_logged = @page.search(
101
102
  "//a[@href='forum/index.php?action=unreadreplies']")
102
103
  link_that_exists_only_once_logged.first
103
104
  end
104
105
 
105
106
  def each_id text
106
- url = URI.parse "http://#{host}/modules/mod_itasalivesearch/search.php"
107
- url.query = "term=#{CGI.escape text}"
108
- response = @agent.get url
107
+ response = @agent.get search_url(text)
109
108
  JSON.parse(response.body).each do |episode|
110
109
  yield episode['id'], episode['value']
111
110
  end
@@ -113,13 +112,27 @@ class Itasa
113
112
  end
114
113
 
115
114
  def download_zip id
116
- url = "http://#{host}/index.php?option=com_remository&Itemid=6&func=fileinfo&id=#{id}"
117
- page = @agent.get url
118
- download_link = page.search("//a[img[contains(@src,'download2.gif')]]").first
119
- zipped_subtitle = @agent.get download_link[:href]
115
+ page = @agent.get subtitle_page_url(id)
116
+ zipped_subtitle = @agent.get subtitle_zip_url(page)
120
117
  yield zipped_subtitle.body
121
118
  end
122
119
 
120
+ def subtitle_zip_url page
121
+ link = page.search("//a[img[contains(@src,'download2.gif')]]").first
122
+ return link[:href]
123
+ end
124
+
125
+ def search_url text
126
+ url = URI.parse "http://#{host}/modules/mod_itasalivesearch/search.php"
127
+ url.query = "term=#{CGI.escape text}"
128
+ return url
129
+ end
130
+
131
+ def subtitle_page_url id
132
+ ("http://#{host}/index.php?option=com_remository&Itemid=6&func=fileinfo" +
133
+ "&id=#{id}")
134
+ end
135
+
123
136
  def host
124
137
  'www.italiansubs.net'
125
138
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: subdl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: