Class: Itasa

Inherits:
Object
  • Object
show all
Defined in:
lib/subdl.rb

Instance Method Summary collapse

Constructor Details

#initialize(agent) ⇒ Itasa

Returns a new instance of Itasa.



123
124
125
# File 'lib/subdl.rb', line 123

def initialize agent
  @agent = agent
end

Instance Method Details

#download_zip(id) {|zipped_subtitle.body| ... } ⇒ Object

Yields:

  • (zipped_subtitle.body)


136
137
138
139
140
# File 'lib/subdl.rb', line 136

def download_zip id
  page = @agent.get subtitle_page_url(id)
  zipped_subtitle = @agent.get subtitle_zip_url(page.body)
  yield zipped_subtitle.body
end

#login(username, password) ⇒ Object



127
128
129
# File 'lib/subdl.rb', line 127

def  username, password
  @agent. username, password
end

#search_subtitles(text) ⇒ Object



131
132
133
134
# File 'lib/subdl.rb', line 131

def search_subtitles text
  json = autocomplete_data_for text
  return extract_ids_from_autocomplete_data json
end

#search_url(text) ⇒ Object



147
148
149
150
151
# File 'lib/subdl.rb', line 147

def search_url text
  url = URI.parse "http://#{host}/modules/mod_itasalivesearch/search.php"
  url.query = "term=#{CGI.escape text}"
  return url.to_s
end

#subtitle_page_url(id) ⇒ Object



153
154
155
156
# File 'lib/subdl.rb', line 153

def subtitle_page_url id
  ("http://#{host}/index.php?option=com_remository&Itemid=6&func=fileinfo" +
   "&id=#{id}")
end

#subtitle_zip_url(page) ⇒ Object



142
143
144
145
# File 'lib/subdl.rb', line 142

def subtitle_zip_url page
  doc = Nokogiri::HTML(page)
  return doc.at_xpath("//a[img[contains(@src,'download2.gif')]]")[:href]
end