Permalink
Browse files

Merge pull request #5 from lazureykis/master

prostopleer.com support
  • Loading branch information...
mamuso committed Sep 9, 2011
2 parents d57f87f + 8bb5b29 commit e6b2614c34c6424371ea7991b1c35ff6939f69c3
Showing with 67 additions and 0 deletions.
  1. +46 −0 lib/acts_as_unvlogable/vg_prostopleer.rb
  2. +21 −0 test/acts_as_unvlogable_test.rb
@@ -0,0 +1,46 @@
+# ----------------------------------------------
+# Class for prostopleer.com
+# http://prostopleer.com/tracks/401758bI6n
+# ----------------------------------------------
+
+require 'hpricot'
+
+class VgProstopleer
+
+ attr_accessor :track_id
+
+ def initialize(url, options={})
+ @uri = URI.parse(url)
+ @track_id = @uri.path.match(/tracks\/([\w\d]+)/)[1]
+ @url = url
+ raise ArgumentError unless @track_id
+ end
+
+ def title
+ @title ||= [pp_data[:singer], pp_data[:song]].join(' - ')
+ end
+
+ def embed_html(width=411, height=28, options = {})
+ return "<object width=\"#{width}\" height=\"#{height}\"><param name=\"movie\" value=\"http://embed.prostopleer.com/track?id=#{track_id}\"></param><embed src=\"http://embed.prostopleer.com/track?id=#{track_id}\" type=\"application/x-shockwave-flash\" width=\"#{width}\" height=\"#{height}\"></embed></object>"
+ end
+
+ def service
+ "ProstoPleer"
+ end
+
+ private
+ def pp_data
+ return @pp_data if defined? @pp_data
+ hp = Hpricot.parse(Net::HTTP.get(@uri))
+ info = (hp/'li[@singer]').first
+ @pp_data = {
+ :singer => info['singer'], # artist name
+ :song => info['song'], # song title
+ :file_id => info['file_id'], # wtf
+ :link => info['link'], # same as @track_id
+ :duration => info['duration'], # duration of the song in seconds
+ :size => info['size'], # file size
+ :rate => info['rate'] # bit rate
+ }
+ end
+end
@@ -370,6 +370,27 @@ class ActsAsUnvlogableTest < Test::Unit::TestCase
assert_raise(ArgumentError, "Unsuported url or service") { UnvlogIt.new("http://rutube.ru/tracks/abdcd.html?v=523423") }
end
end
+
+# ----------------------------------------------------------
+# Testing Prostopleer
+# ----------------------------------------------------------
+ context "with a prostopleer url" do
+ setup do
+ @videotron = UnvlogIt.new("http://prostopleer.com/tracks/401758bI6n")
+ end
+ should "initialize a VgProstopleer instance" do
+ assert_equal VgProstopleer, @videotron.instance_values['object'].class
+ assert_equal "http://prostopleer.com/tracks/401758bI6n", @videotron.instance_values['object'].instance_values['url']
+ assert_equal "401758bI6n", @videotron.instance_values['object'].instance_values['track_id']
+ assert_equal "Combichrist - sent to destroy", @videotron.title
+ end
+ end
+
+ context "with an invalid prostopleer url" do
+ should "raise an ArgumentError exception" do
+ assert_raise(ArgumentError) { UnvlogIt.new("http://prostopleer.com/trackszz/401758bI6n") }
+ end
+ end
protected

0 comments on commit e6b2614

Please sign in to comment.