Class: Itasa
- Inherits:
-
Object
- Object
- Itasa
- Defined in:
- lib/subdl.rb
Instance Method Summary collapse
- #download_zip(id) {|zipped_subtitle.body| ... } ⇒ Object
-
#initialize(agent) ⇒ Itasa
constructor
A new instance of Itasa.
- #login(username, password) ⇒ Object
- #search_subtitles(text) ⇒ Object
- #search_url(text) ⇒ Object
- #subtitle_page_url(id) ⇒ Object
- #subtitle_zip_url(page) ⇒ Object
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
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 login username, password @agent.login 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 |