youtubesearchresultscraper 0.0.5 → 0.0.6

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.
data/CHANGELOG CHANGED
@@ -15,3 +15,6 @@
15
15
 
16
16
  0.0.5 2007-02-16
17
17
  Fix scraping rule for video_count, video_from, video_to
18
+
19
+ 0.0.6 2007-02-16
20
+ Fix error handling for video_count, video_from, video_to
@@ -83,9 +83,9 @@ module Youtube #:nodoc:
83
83
 
84
84
  # Get search result from youtube by specified keyword.
85
85
  def open
86
- url = @@youtube_search_base_url + CGI.escape(@keyword)
87
- url += "&page=#{@page}" if not @page == nil
88
- @html = Kernel.open(url).read
86
+ @url = @@youtube_search_base_url + CGI.escape(@keyword)
87
+ @url += "&page=#{@page}" if not @page == nil
88
+ @html = Kernel.open(@url).read
89
89
  replace_document_write_javascript
90
90
  @search_result = Hpricot.parse(@html)
91
91
  end
@@ -204,25 +204,34 @@ module Youtube #:nodoc:
204
204
 
205
205
  def scrape_video_count
206
206
  video_count = scrape_result_header
207
- raise "no video count" unless video_count.sub!(/.+Results \d+-\d+ of( | about )([0-9,]+)/m , '\2')
207
+ unless video_count.sub!(/.+Results \d+-\d+ of( | about )([0-9,]+)/m , '\2')
208
+ raise "no video count: " + @url unless is_no_result
209
+ end
208
210
  video_count.gsub!(/,/, '')
209
211
  video_count.to_i
210
212
  end
211
213
 
212
214
  def scrape_video_from
213
215
  video_from = scrape_result_header
214
- raise "no video from" unless video_from.sub!(/.+Results (\d+)/m, '\1')
216
+ unless video_from.sub!(/.+Results (\d+)/m, '\1')
217
+ raise "no video from: " + @url unless is_no_result
218
+ end
215
219
  video_from.to_i
216
220
  end
217
221
 
218
222
  def scrape_video_to
219
223
  video_to = scrape_result_header
220
- raise "no video to" unless video_to.sub!(/.+Results \d+-(\d+)/m, '\1')
224
+ unless video_to.sub!(/.+Results \d+-(\d+)/m, '\1')
225
+ raise "no video to: " + @url unless is_no_result
226
+ end
221
227
  video_to.to_i
222
228
  end
223
229
 
224
230
  def is_no_result
225
- @html.include?('No Videos found')
231
+ if @is_no_result == nil
232
+ @is_no_result = @html.include?('No Videos found')
233
+ end
234
+ @is_no_result
226
235
  end
227
236
 
228
237
  def check_video video
@@ -199,24 +199,25 @@ module Youtube #:nodoc:
199
199
  end
200
200
 
201
201
  def scrape_result_header
202
- @search_result.search("div[@id='sectionHeader']/div").inner_html
202
+ @search_result.search("div[@id='sectionHeader']").inner_html
203
203
  end
204
204
 
205
205
  def scrape_video_count
206
- video_count = scrape_result_header.sub(/.+of *(\d+)/m , '\1')
207
- raise "no video count" if video_count.empty?
206
+ video_count = scrape_result_header
207
+ raise "no video count" unless video_count.sub!(/.+Results \d+-\d+ of( | about )([0-9,]+)/m , '\2')
208
+ video_count.gsub!(/,/, '')
208
209
  video_count.to_i
209
210
  end
210
211
 
211
212
  def scrape_video_from
212
- video_from = scrape_result_header.sub(/Results *(\d+)-.+/m, '\1')
213
- raise "no video from" if video_from.empty?
213
+ video_from = scrape_result_header
214
+ raise "no video from" unless video_from.sub!(/.+Results (\d+)/m, '\1')
214
215
  video_from.to_i
215
216
  end
216
217
 
217
218
  def scrape_video_to
218
- video_to = scrape_result_header.sub(/Results.+-(\d+) *of.+/m, '\1')
219
- raise "no video to" if video_to.empty?
219
+ video_to = scrape_result_header
220
+ raise "no video to" unless video_to.sub!(/.+Results \d+-(\d+)/m, '\1')
220
221
  video_to.to_i
221
222
  end
222
223
 
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: youtubesearchresultscraper
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.5
6
+ version: 0.0.6
7
7
  date: 2007-02-16 00:00:00 +09:00
8
8
  summary: This gem provide function to scrape html of search result on youtube
9
9
  require_paths: