Class: AirVideo::Client
Overview
The AirVideo Client. At this stage it can emulate the iPhone app in all major features.
Minor features, such as requesting a specific streams when using the Live Conversion feature aren’t yet supported, but it’s just a question of figuring out what the server is expecting.
Setting #max_height and #max_width should be working with the Live Conversion, but for some reason it’s not quite happening. Defaults are 640x480
Defined Under Namespace
Classes: FileObject, FolderObject
Instance Attribute Summary collapse
-
#max_height ⇒ Object
Returns the value of attribute max_height.
-
#max_width ⇒ Object
Returns the value of attribute max_width.
Instance Method Summary collapse
-
#cd(dir) ⇒ Object
Changes to the given directory.
-
#get_url(fileobj, liveconvert = false) ⇒ Object
Returns the streaming video URL for the given AirVideo::FileObject.
-
#initialize(server, port = 45631, password = nil) ⇒ Client
constructor
Specify where your AirVideo Server lives.
- #inspect ⇒ Object
-
#ls(dir = ".") ⇒ Object
Lists the folders and videos in the current directory as an Array of AirVideo::FileObject and AirVideo::FolderObject objects.
-
#pwd ⇒ Object
(also: #getcwd)
Returns the path to the current directory.
Constructor Details
#initialize(server, port = 45631, password = nil) ⇒ Client
Specify where your AirVideo Server lives. If your HTTP_PROXY environment variable is set, it will be honoured.
At the moment I’m expecting ENV to have the form ‘sub.domain.com:8080’, I throw an http:// and bung it into URI.parse for convenience.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/airvideo.rb', line 21 def initialize(server,port = 45631,password=nil) begin proxy = URI.parse("http://"+ENV['HTTP_PROXY']) @http = Net::HTTP::Proxy(proxy.host, proxy.port) rescue @http = Net::HTTP end @endpoint = URI.parse "http://#{server}:#{port}/service" @passworddigest = Digest::SHA1.hexdigest("S@17" + password + "@1r").upcase if !password.nil? @req = Net::HTTP::Post.new(@endpoint.path) @req['User-Agent'] = 'AirVideo/2.2.4 CFNetwork/459 Darwin/10.0.0d3' @req['Accept'] = '*/*' @req['Accept-Language'] = 'en-us' @req['Accept-Encoding'] = 'gzip, deflate' @current_dir = "/" @max_width = 640 @max_height = 480 end |
Instance Attribute Details
#max_height ⇒ Object
Returns the value of attribute max_height.
16 17 18 |
# File 'lib/airvideo.rb', line 16 def max_height @max_height end |
#max_width ⇒ Object
Returns the value of attribute max_width.
16 17 18 |
# File 'lib/airvideo.rb', line 16 def max_width @max_width end |
Instance Method Details
#cd(dir) ⇒ Object
70 71 72 73 74 |
# File 'lib/airvideo.rb', line 70 def cd(dir) dir = dir.location if dir.is_a? FolderObject @current_dir = File.(dir,@current_dir) self end |
#get_url(fileobj, liveconvert = false) ⇒ Object
Returns the streaming video URL for the given AirVideo::FileObject.
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/airvideo.rb', line 77 def get_url(fileobj,liveconvert = false) raise NoMethodError, "Please pass a FileObject" if not fileobj.is_a? FileObject begin if liveconvert request("livePlaybackService","initLivePlayback",[conversion_settings(fileobj)])['result']['contentURL'] else request("playbackService","initPlayback",[fileobj.location[1..-1]])['result']['contentURL'] end rescue NoMethodError raise RuntimeError, "This video does not exist" end end |
#inspect ⇒ Object
96 97 98 |
# File 'lib/airvideo.rb', line 96 def inspect "<AirVideo Connection: #{@endpoint.host}:#{@endpoint.port}>" end |
#ls(dir = ".") ⇒ Object
Lists the folders and videos in the current directory as an Array of AirVideo::FileObject and AirVideo::FolderObject objects.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/airvideo.rb', line 44 def ls(dir = ".") dir = dir.location if dir.is_a? FolderObject dir = File.(dir,@current_dir)[1..-1] dir = nil if dir == "" begin request("browseService","getItems",[dir])['result']['items'].collect do |hash| case hash.name when "air.video.DiskRootFolder", "air.video.ITunesRootFolder","air.video.Folder" FolderObject.new(self,hash['name'],hash['itemId']) when "air.video.VideoItem","air.video.ITunesVideoItem" FileObject.new(self,hash['name'],hash['itemId'],hash['detail'] || {}) else raise NotImplementedError, "Unknown: #{hash.name}" end end rescue NoMethodError raise RuntimeError, "This folder does not exist" end end |
#pwd ⇒ Object Also known as: getcwd
Returns the path to the current directory
91 92 93 |
# File 'lib/airvideo.rb', line 91 def pwd @current_dir end |