Class: AirVideo::Client

Inherits:
Object show all
Defined in:
lib/airvideo.rb

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

Instance Method Summary collapse

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_heightObject

Returns the value of attribute max_height.



16
17
18
# File 'lib/airvideo.rb', line 16

def max_height
  @max_height
end

#max_widthObject

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

Changes to the given directory. Will accept an AirVideo::FolderObject or a string. Returns the AirVideo::Client instance, so you can string commands:

AirVideo::Client.new('127.0.0.1').ls[0].cd.ls

NB. This will not check to see if the folder actually exists!



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.expand_path(dir,@current_dir)
  self
end

#get_url(fileobj, liveconvert = false) ⇒ Object

Returns the streaming video URL for the given AirVideo::FileObject.

Raises:

  • (NoMethodError)


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

#inspectObject



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.expand_path(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

#pwdObject 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