module TivoHMO::Server::Helpers
Public Instance Methods
container_url(container)
click to toggle source
# File lib/tivohmo/server.rb, line 115 def container_url(container) url = "/TiVoConnect" params = { Command: 'QueryContainer', Container: container.title_path } url << "?" << build_query(params) end
format_date(time)
click to toggle source
to format date/time as needed by tivo in builders
# File lib/tivohmo/server.rb, line 146 def format_date(time) "0x#{time.to_i.to_s(16)}" end
format_iso_date(time)
click to toggle source
# File lib/tivohmo/server.rb, line 150 def format_iso_date(time) return "" unless time time.utc.strftime("%FT%T.%6N") end
format_iso_duration(duration)
click to toggle source
# File lib/tivohmo/server.rb, line 155 def format_iso_duration(duration) return "" unless duration seconds = duration % 60 minutes = (duration / 60) % 60 hours = (duration / (60 * 60)) % 24 days = (duration / (60 * 60 * 24)).to_i 'P%sDT%sH%sM%sS' % [days, hours, minutes, seconds] end
format_uuid(s)
click to toggle source
to format uuids as needed by tivo in builders
# File lib/tivohmo/server.rb, line 141 def format_uuid(s) Zlib.crc32(s) end
item_detail_url(item)
click to toggle source
# File lib/tivohmo/server.rb, line 128 def item_detail_url(item) url = "/TiVoConnect" container = item.app.title file = item.title_path.sub("/#{container}/", '') params = { Command: 'TVBusQuery', Container: container, File: file } url << "?" << build_query(params) end
item_url(item)
click to toggle source
# File lib/tivohmo/server.rb, line 124 def item_url(item) item.title_path end
logger()
click to toggle source
# File lib/tivohmo/server.rb, line 62 def logger Server.logger end
pad(length, align)
click to toggle source
# File lib/tivohmo/server.rb, line 164 def pad(length, align) extra = length % align extra = align - extra if extra > 0 extra end
select_all_items(children)
click to toggle source
# File lib/tivohmo/server.rb, line 79 def select_all_items(children) just_items = [] all = children.dup all.each do |child| if child.is_a?(TivoHMO::API::Container) all.concat(child.children) else just_items << child end end children = just_items.uniq {|node| node.identifier } end
server()
click to toggle source
# File lib/tivohmo/server.rb, line 66 def server @server end
sort(items, sort_order)
click to toggle source
# File lib/tivohmo/server.rb, line 92 def sort(items, sort_order) sort_order = sort_order.split(/\s*,\s*/) sort_order.each do |order| reverse = false if order[0] == '!' reverse = true order = order[1..-1] end case order when 'Title' items = items.sort_by(&:title) when 'CaptureDate' items = items.sort_by(&:created_at) end items = items.reverse if reverse end items end
tivo_header(item, mime)
click to toggle source
# File lib/tivohmo/server.rb, line 170 def tivo_header(item, mime) if mime == 'video/x-tivo-mpeg-ts' flag = 45 else flag = 13 end item_details_xml = builder :item_details, layout: true, locals: {item: item} item_details_xml.force_encoding('ascii-8bit') ld = item_details_xml.bytesize chunk = item_details_xml + '\0' * (pad(ld, 4) + 4) lc = chunk.bytesize blocklen = lc * 2 + 40 padding = pad(blocklen, 1024) data = 'TiVo' data << [4, flag, 0, padding + blocklen, 2].pack('nnnNn') data << [lc + 12, ld, 1, 0].pack('NNnn') data << chunk data << [lc + 12, ld, 2, 0].pack('NNnn') data << chunk data << "\0" * padding data end
transliterate(s)
click to toggle source
# File lib/tivohmo/server.rb, line 197 def transliterate(s) # unidecoder gem s.to_ascii rescue s end
tsn()
click to toggle source
# File lib/tivohmo/server.rb, line 75 def tsn headers['TiVo_TCD_ID'] end
unsupported()
click to toggle source
# File lib/tivohmo/server.rb, line 70 def unsupported status 404 builder :unsupported, layout: true end