Class: BlipTV::Video

Inherits:
Object
  • Object
show all
Defined in:
lib/bliptv/video.rb

Overview

This class wraps Blip.tv’s video’s information.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(blip_id) ⇒ Video

:nodoc:



40
41
42
43
44
45
46
47
48
# File 'lib/bliptv/video.rb', line 40

def initialize(blip_id) #:nodoc:
  blip_id = blip_id.to_s if blip_id.class == Fixnum
  
  if blip_id.class == String && blip_id.match(BLIP_TV_ID_EXPR)
    update_attributes_from_id(blip_id)
  elsif blip_id.class == Hash
    update_attributes_from_hash(blip_id)
  end
end

Instance Attribute Details

#authorObject

Returns the value of attribute author.



24
25
26
# File 'lib/bliptv/video.rb', line 24

def author
  @author
end

#deletedObject

Returns the value of attribute deleted.



24
25
26
# File 'lib/bliptv/video.rb', line 24

def deleted
  @deleted
end

#descriptionObject

Returns the value of attribute description.



24
25
26
# File 'lib/bliptv/video.rb', line 24

def description
  @description
end

#embed_codeObject

Returns the value of attribute embed_code.



24
25
26
# File 'lib/bliptv/video.rb', line 24

def embed_code
  @embed_code
end

#embed_urlObject

Returns the value of attribute embed_url.



24
25
26
# File 'lib/bliptv/video.rb', line 24

def embed_url
  @embed_url
end

#explicitObject

Returns the value of attribute explicit.



24
25
26
# File 'lib/bliptv/video.rb', line 24

def explicit
  @explicit
end

#guidObject

Returns the value of attribute guid.



24
25
26
# File 'lib/bliptv/video.rb', line 24

def guid
  @guid
end

#idObject

Returns the value of attribute id.



24
25
26
# File 'lib/bliptv/video.rb', line 24

def id
  @id
end

#licenseObject

Returns the value of attribute license.



24
25
26
# File 'lib/bliptv/video.rb', line 24

def license
  @license
end

Returns the value of attribute links.



24
25
26
# File 'lib/bliptv/video.rb', line 24

def links
  @links
end

#notesObject

Returns the value of attribute notes.



24
25
26
# File 'lib/bliptv/video.rb', line 24

def notes
  @notes
end

#tagsObject

Returns the value of attribute tags.



24
25
26
# File 'lib/bliptv/video.rb', line 24

def tags
  @tags
end

#titleObject

Returns the value of attribute title.



24
25
26
# File 'lib/bliptv/video.rb', line 24

def title
  @title
end

#update_timeObject

Returns the value of attribute update_time.



24
25
26
# File 'lib/bliptv/video.rb', line 24

def update_time
  @update_time
end

#view_countObject

Returns the value of attribute view_count.



24
25
26
# File 'lib/bliptv/video.rb', line 24

def view_count
  @view_count
end

Instance Method Details

#delete!(creds = {}, section = "file", reason = "because") ⇒ Object

delete! will delete the file from Blip.tv



114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/bliptv/video.rb', line 114

def delete!(creds = {}, section = "file", reason = "because")
  BlipTV::ApiSpec.check_attributes('videos.delete', creds)
  
  reason = reason.gsub(" ", "%20") # TODO write a method to handle this and other illegalities of URL
  
  if creds[:username] && !creds[:userlogin]
    creds[:userlogin] = creds[:username]
  end
  
  url, path = "www.blip.tv", "/?userlogin=#{creds[:userlogin]}&password=#{creds[:password]}&cmd=delete&s=file&id=#{@id}&reason=#{reason}&skin=api"
  request = Net::HTTP.get(url, path)
  hash = Hash.from_xml(request)
  make_sure_video_was_deleted(hash)
end

#get_attributesObject

fire off a HTTP GET response to Blip.tv

In the future, this should probably be rolled into the BlipTV::Request class, so that all exception raising and network communication exists in instances of that class.



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/bliptv/video.rb', line 84

def get_attributes                                                         
  url = URI.parse('http://www.blip.tv/')   
  res = Net::HTTP.start(url.host, url.port) {|http|      
   http.get("http://www.blip.tv/file/#{@id.to_s}?skin=api")
  }                                                                                
  
  hash = Hash.from_xml(res.body)
  
  if hash["response"]["status"] != "OK"
    raise VideoResponseError.new(hash["response"]["notice"])
  end
  
  if hash["response"]["payload"]["asset"].is_a?(Array) 
    return hash["response"]["payload"]["asset"][0] # there may be several assets. In that case, read the first one
  else
    return hash["response"]["payload"]["asset"]
  end
end

#refreshObject

Refresh the current video object. Useful to check up on encoding progress, etc.



107
108
109
# File 'lib/bliptv/video.rb', line 107

def refresh
  update_attributes_from_id(@id)
end

#update_attributes_from_hash(a) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/bliptv/video.rb', line 57

def update_attributes_from_hash(a)
  
  @id               = a['item_id'] if @id == nil
  @title            = a['title']
  @description      = a['description']
  @guid             = a['guid']
  @deleted          = a['deleted']
  @view_count       = a['views']
  @tags             = parse_tags a['tags']
  @links            = a['links']['link']
  @thumbnail_url    = a['thumbnail_url']
  @author           = a['created_by']['login'] if a['created_by']
  @update_time      = a['timestamp'] ? Time.at(a['update_time'].to_i) : nil
  @explicit         = a['explicit']
  @license          = a['license']
  @notes            = a['notes']
  @embed_url        = a['embed_url']
  @embed_code       = a['embed_code']
end

#update_attributes_from_id(blip_id) ⇒ Object



50
51
52
53
54
55
# File 'lib/bliptv/video.rb', line 50

def update_attributes_from_id(blip_id)
  @id = blip_id
  
  a = get_attributes
  update_attributes_from_hash(a)
end