Python Forum

Full Version: Extracting clips from Aja Ki Pro FileRecorder
You're currently viewing a stripped down version of our content. View the full version with proper formatting.


I am trying to get this script to work to download video clips off of a filerecorder device networked. I'm getting errors and I don't understand why.

import urllib, sys, string, os, posix, time

def is_download_allowed(address):
    f = urllib.urlopen("http://"+address+"/config?action=get&paramid=eParamID_MediaState")
    response = f.read()
    if (response.find('"value":"1"') > -1):
        return True
    f = urllib.urlopen("http://"+address+"/config?action=set&paramid=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&paramid=eParamID_MediaState&value=0")
            print "No new clips found"
Error:
At line:9 char:23 + response = f.read() + ~ An expression was expected after '('. At line:10 char:42 + if (response.find('"value":"1"') > -1): + ~ Missing statement block after if ( condition ). At line:17 char:36 + posix.system("curl --output " + clip + " " + url); + ~ You must provide a value expression following the '+' operator. At line:17 char:37 + posix.system("curl --output " + clip + " " + url); + ~~~~ Unexpected token 'clip' in expression or statement. At line:17 char:36 + posix.system("curl --output " + clip + " " + url); + ~ Missing closing ')' in expression. At line:17 char:53 + posix.system("curl --output " + clip + " " + url); + ~ Unexpected token ')' in expression or statement. At line:22 char:8 + for word in values: + ~ Missing opening '(' after keyword 'for'. At line:24 char:38 + if(word.find('clipname') > -1): + ~ Missing statement block after if ( condition ). At line:25 char:54 + clip = values[i].split(',')[0].translate(string.maketrans ... + ~ Missing ')' in method call. At line:25 char:93 + ... s[i].split(',')[0].translate(string.maketrans("",""), '[]{} \,\"\" ') + ~ Unexpected token ')' in expression or statement. Not all parse errors were reported. Correct the reported errors and try again. + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException + FullyQualifiedErrorId : ExpectedExpression
Those aren't really parentheses, but a unicode character that kinda looks like parentheses. Delete them, and replace them with real parentheses (they're on your keyboard), and the errors should go away.
I figured out that it runs but I don't understand why it doesn't do anything. Any help is appreciated!
You define a few functions, but never call them.
It makes sense now. So what doesn't make sense is when I call the download_clip and the download_clips functions I can't seem to figure out what argument types it wants.
Quote:
def download_clip(clip):
    url = "http://" + address + "/media/" + clip

download_clip takes one argument, which it them immediately concats onto a string.  Which means it's almost guaranteed to be expecting a string.

Same with download_clips, although it's expecting that string to be in some sort of special format.  Probably whatever you get from some external resource (which is probably why it's called response).