使用Python与AJA Ki Pro同步文件
我们在另一个地方有一个AJA Ki Pro录音机,我需要建立一个自动化系统,把录制好的文件传到我的编辑工作室。到目前为止,我已经成功地通过一个Python脚本,结合AppleScript和Automator来提取录音。我可以通过iCal来触发这个应用程序。简单来说,我的脚本主要是先把录音机上的“MediaState”参数设置为“Data”(值为1),这样我就可以提取文件,然后把录音机上的文件和我本地的文件进行比较(它只会下载我本地没有的文件),最后再把“MediaState”属性设置回“Rec”(值为0),这样录音机就可以继续使用了。
不过,我现在遇到了两个问题还没解决。请耐心听我说,我对Python的经验大约只有两天 :) 似乎我不小心创建了一个循环,导致它一直显示“正在寻找新片段”和“没有找到新片段”。理想情况下,我希望如果没有找到新片段,脚本能够自动结束。我还希望在通过cURL完成下载后,能自动把“MediaState”设置回值为0,并结束脚本。以下是我目前的代码:
# This script polls the unit downloads any new clips it hasn't already downloaded to the current directory
# Arguments: hostname or IP address of Ki Pro unit
import urllib, sys, string, os, posix, time
def is_download_allowed(address):
f = urllib.urlopen("http://"+address+"/config?action=get¶mid=eParamID_MediaState")
response = f.read()
if (response.find('"value":"1"') > -1):
return True
f = urllib.urlopen("http://"+address+"/config?action=set¶mid=eParamID_MediaState&value=1")
def download_clip(clip):
url = "http://" + address + "/media/" + clip
print url
posix.system("curl --output " + clip + " " + url);
def download_clips(response):
values = response.split(":")
i = 0
for word in values:
i += 1
if(word.find('clipname') > -1):
clip = values[i].split(',')[0].translate(string.maketrans("",""), '[]{} \,\"\" ')
if not os.path.exists(clip):
print "Downloading clip: " + clip
download_clip(clip)
else:
f = urllib.urlopen("http://"+address+"/config?action=set¶mid=eParamID_MediaState&value=0")
print "No new clips found"
address = sys.argv[1]
while 1:
if (is_download_allowed(address)):
print "Looking for new clips"
f = urllib.urlopen("http://"+address+"/clips")
response = f.read()
download_clips(response)
1 个回答
0
如果download_clips
这个函数正在循环处理剪辑名称,那为什么还需要那个无限循环的while 1
呢?我觉得这个是多余的。只要把它去掉,然后把代码块缩进调整一下就可以了。