Skip to content

Commit

Permalink
Merge branch 'master' of github.com:rumblelabs/learningportal
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjrice committed Jul 23, 2012
2 parents c4ca950 + 4a175a5 commit f735fcf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
5 changes: 5 additions & 0 deletions app/assets/stylesheets/master.scss
Expand Up @@ -737,4 +737,9 @@ img.image {
margin:0 auto;
max-height:400px;
max-width:640px;
}

video {
display:block;
margin:0 auto;
}
25 changes: 22 additions & 3 deletions app/models/content.rb
Expand Up @@ -57,7 +57,27 @@ def self.image_url
end

def self.video_url
""
# hit the video endpoint one time to know how many videos are availalbe
video_search_endpoint = "http://archive.org/advancedsearch.php?q=mediatype:movies+AND+licenseurl:[http://creativecommons.org/a+TO+http://creativecommons.org/z]&rows=1&output=json"
video_details_endpoint = "http://archive.org/details/"
response = Typhoeus::Request.get(video_search_endpoint)
response = JSON.parse(response.body)["response"]

# hit the video endpoint again this time choosing a random video
num_found = response["numFound"]
response = Typhoeus::Request.get(video_search_endpoint + "&page=#{rand(num_found)}")
video_identifier = JSON.parse(response.body)["response"]["docs"].first["identifier"]

# yet a further request this time to get the video meta-data itself
response = Typhoeus::Request.get("#{video_details_endpoint}/#{video_identifier}", :params => { :output => "json" })
response = JSON.parse(response.body)

# now pull out the relevant bits to generate the full url to a video
server = response["server"]
path = response["dir"]
filename = response["files"].select { |key, file| file["format"] == "Ogg Video" }.first.first

"http://#{server}#{path}#{filename}"
end

def self.seed!
Expand Down Expand Up @@ -97,8 +117,7 @@ def self.parse(json, popularity=nil)
when 0
revision["*"]
when 1
# self.video_url
revision["*"]
self.video_url
when 2
self.image_url
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/articles/_video.html.haml
@@ -1,4 +1,4 @@
%div
%iframe{:allowfullscreen => "", :frameborder => "0", :height => "355", :src => "http://www.youtube.com/embed/sN8UIaMgvbQ", :width => "640"}
%video{:src => @article['content'], :controls => true}
= render "tags"
= render "contributors"

0 comments on commit f735fcf

Please sign in to comment.