0

我想做的是使用 Siriproxy 来控制我的 Sky+ 盒子(我已经在一定程度上工作了)

Sky 使用频道编号,但将它们转换为它可以理解的十六进制数字。我有包含所有频道号、频道名称和十六进制代码的文件。我想制作一个 ruby​​ 脚本来查找我说的通道号的十六进制,然后通过 bash 脚本将其作为命令的一部分发送到天空盒(除非有更简单的方法)。

我目前有一种非常粗略和冗长的方法,涉及多个 bash 脚本创建 .txt 文件等,但我确信一定有更好的方法。

编辑更多信息:

#demonstrate capturing data from the user (e.x. "Siri proxy number 15")
listen_for /change the channel number ([0-9,]*[0-9])/i do |number|
#say "Changing the Channel to #{number}"
f = File.new("/root/SiriProxy/sky/channel.txt", "w")
f.puts "SKY#{number}"
f.close
#system("echo [Info - Plugin Manager] Channel number #{number} stored to sky/channel.txt")
system("sh /root/SiriProxy/sky/change_channel.sh")
File.open('/root/SiriProxy/sky/channel_name.txt').each_line{ |s|
#puts s
say "I've changed the channel to #{s}"
}
request_completed
end

然后是 bash 脚本:

#!/bin/bash

for line in `cat /root/SiriProxy/sky/channel.txt`
do
cat /root/SiriProxy/sky/channel_numbers.txt | grep $line | cut -d"  " -f3 > /root/SiriProxy/sky/hex.txt
done

for line in `cat /root/SiriProxy/sky/channel.txt`
do
cat /root/SiriProxy/sky/channel_numbers.txt | grep $line | cut -d"  " -f2 > /root/SiriProxy/sky/channel_name.txt
done

for line in `cat /root/SiriProxy/sky/hex.txt`
do
(echo 'POST /SkyPlay HTTP/1.1
SOAPACTION: "urn:schemas-nds-com:service:SkyPlay:2#SetAVTransportURI"
Content-Type: text/xml; charset=utf-8
Content-Length: 399 

<?xml version="1.0" encoding="utf-8"?><s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><u:SetAVTransportURI xmlns:u="urn:schemas-nds-com:service:SkyPlay:2"><InstanceID>0</InstanceID><CurrentURI>xsi://'$line'</CurrentURI><CurrentURIMetaData>NOT_IMPLEMENTED</CurrentURIMetaData></u:SetAVTransportURI></s:Body></s:Envelope>') | nc -n 192.168.1.82 49153
done

感谢您的帮助,这比我的新手状态略高!

4

1 回答 1

1

我重构了从 bash 脚本中读取的所有文件。请参阅net/http文档以发送发布请求。

这是一个片段。我不确定这是否有效,因为我没有这些文件。但这应该给你一个公平的想法。

#!/usr/bin/env ruby
require 'net/http'

channel_numbers_file = '/root/SiriProxy/sky/channel.txt'
listen_for /change the channel number ([0-9,]*[0-9])/i do |number|
  sky_number = "SKY#{number}"
  #Check whether there are multiple occurrences. No idea whether there are multiple occurrences.Gets only 1st one.
  #Remove commma to get all in an array.
  line, = File.open(channel_numbers_file).readlines.select{ |line| line.chomp.include? sky_number } #grep $line part
  hex, channel_name = line.split[1..2] #check indices. ruby indices start from 0.

  #Refer net/http documentation on POST request.
  #send request  
end  

不确定这是否有帮助。

于 2013-08-17T15:48:12.110 回答