Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed integer bug in load_comments

  • Loading branch information...
commit c1652dac9a7a0ff2d45b61dbb988c20acc57f95b 1 parent 0029f1a
Stepan Boltalin authored
View
10 app/models/plot.rb
@@ -117,10 +117,16 @@ def self.collect_videos(w, page, indexing)
if !video_array.empty?
video_array.each do |hash|
hash.each do |k,v|
- comments = Video.load_comments(k)
+ arr = k.split(/\sDURATION\s/)
+ v_id = arr[0]
+ duration = Integer(arr[1])
+ print "DURATION \n"
+ print duration.class
+ comments = Video.load_comments(v_id, duration)
if comments != "--- []\n"
vid = Video.create
- vid.content = k
+ vid.content = v_id
+ vid.duration = duration
vid.keywords = v
vid.comments = comments
vid.save!
View
34 app/models/video.rb
@@ -19,8 +19,10 @@ def self.pull_videos_from_youtube(query)
def self.process_single_yt_from_query(wow)
video_array = []
video_string = wow.video_id
+ duration = wow.duration
content_string = video_string[/video:(.*)/]
- real_video_id = $1
+ print "BOOOO"
+ real_video_id = $1 +" DURATION #{duration}"
keywords_string = wow.keywords
video_hash = {real_video_id => keywords_string}
print video_hash
@@ -90,16 +92,38 @@ def self.pull_remaining_from_youtube
end
- def self.load_comments(youtube_id)
+ def self.load_comments(youtube_id, duration)
@comments_content = String.new
@comments_array = Array.new
comments_query = Video.yt_session.comments(youtube_id)
-
comments_query.each do |comment|
@comments_content = "PARSEFROMHERE " + comment.content + " ENDPARSEFROMHERE"
- matches = @comments_content.match(/\d+:\d+/)
+ matches = @comments_content.match(/\d{1,2}:\d\d/)
if !matches.nil?
- @comments_array.push @comments_content
+ timecode = @comments_content.scan(/(\d{1,2}:\d\d)/).join(',')
+ timecode = timecode.split(',')
+ puts "#{timecode} << TIMECODE for #{@comments_content}"
+ time = timecode[0].split(':')
+ puts "#{time} for #{youtube_id}"
+ seconds = time[1]
+ puts seconds
+ minutes = time[0]
+ mtch2 = minutes.match(/0\d/)
+ if !mtch2.nil?
+ minutes = Integer(minutes[1])
+ else
+ minutes = Integer(minutes)
+ end
+ mtch = seconds.match(/0\d/)
+ if !mtch.nil?
+ seconds = Integer(seconds[1])
+ else
+ seconds = Integer(seconds)
+ end
+ time2 = minutes*60+seconds
+ if (Integer(duration) - Integer(time2)) > 8
+ @comments_array.push @comments_content
+ end
end
end
return @comments_array
View
5 db/migrate/20120226001427_add_duration_to_videos.rb
@@ -0,0 +1,5 @@
+class AddDurationToVideos < ActiveRecord::Migration
+ def change
+ add_column :videos, :duration, :integer
+ end
+end
View
3  db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120211195447) do
+ActiveRecord::Schema.define(:version => 20120226001427) do
create_table "comments", :force => true do |t|
t.text "content", :limit => 255
@@ -128,6 +128,7 @@
t.string "views"
t.boolean "download"
t.string "rating"
+ t.integer "duration"
end
add_index "videos", ["comments"], :name => "index_videos_on_comments"
Please sign in to comment.
Something went wrong with that request. Please try again.