I have a python script that manages my imports to MC. I've noticed that MCWS seems "slow" when I look at the log files and wondered if there was a better way than what I was doing to keep a connection open to my server. I have this in my python script:
class mcwsCall:
def __init__(self, call, params, respType="XML"):
self.call = call
self.params = params
self.respType = respType
logging.info("in mcwsCall: {0}".format(self.call))
logging.debug("-params: {0}".format(self.params))
header = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
mcws = "{0}://{1}:{2}/MCWS/v1/".format(cfg['https'],cfg['host'],cfg['port'])
urlparam = ""
if(len(self.params) > 0):
for k in self.params.keys():
urlparam = urlparam + urllib.parse.quote(k,safe='[]();/?:@=+$,') + '=' + urllib.parse.quote(str(self.params[k]),safe='[]();/?:@=+$,') + '&'
urlparam = urlparam[:-1]
mcws = mcws + self.call + "?{0}".format(urlparam)
logging.info("-fullCall: {0}".format(mcws))
response = requests.get(mcws,headers=header,auth = HTTPBasicAuth(cfg["username"],cfg["password"]))
if self.respType == "JSON":
response = response.json()
elif self.respType == "XML":
root = ElementTree.fromstring(response.content)
response = {root.tag:root.attrib}
response["items"] = []
for child in root:
childDict = {child.attrib["Name"]:child.text}
response["items"].append(childDict)
self.response = response
logging.debug("-response: {0}".format(response))
And throughout my code, when I need to call into MCWS I do something like this:
params={"Block":"1","path":file}
call = mcwsCall("Library/Import",params,"XML")
if call.response["Response"]["Status"] != "OK":
dieGraceful("Failed to import file! {0}.".format(file))
if (((settings["analyzeAudioForAudio"] == 1 and mimeType == 'audio')
or (settings["analyzeAudioForVideo"] == 1 and mimeType == 'video'))
and newFileInd == 1):
analyzeAudio = 1
if newFileInd == 1:
params = {"Action":"JSON","Fields":"Key","Query":"[Filename]={0}".format(cleanedFileName)}
call = mcwsCall("Files/Search",params,"JSON")
What I'm noticing is that my log files look like this (I cut a lot of lines out to make it cleaner):
2022-02-25 14:17:27,047 INFO: in mcwsCall: Files/Search
2022-02-25 14:17:27,047 DEBUG: -params: {'Action': 'JSON', 'Fields': 'Key', 'Query': '[Filename]=Y:\\verified\\2022\\d+t2022-02-20.akgc414xlii.flac24\\d+t2022-02-20.akgc414xlii.t08.flac'}
2022-02-25 14:17:27,047 INFO: -fullCall: http://localhost:52199/MCWS/v1/Files/Search?Action=JSON&Fields=Key&Query=[Filename]=Y:%5Cverified%5C2022%5Cd+t2022-02-20.akgc414xlii.flac24%5Cd+t2022-02-20.akgc414xlii.t08.flac
2022-02-25 14:17:27,049 DEBUG: Starting new HTTP connection (1): localhost:52199
2022-02-25 14:17:29,121 DEBUG: http://localhost:52199 "GET /MCWS/v1/Files/Search?Action=JSON&Fields=Key&Query=%5BFilename%5D=Y:%5Cverified%5C2022%5Cd+t2022-02-20.akgc414xlii.flac24%5Cd+t2022-02-20.akgc414xlii.t08.flac HTTP/1.1" 200 2
2022-02-25 14:17:29,122 DEBUG: -response: []
2022-02-25 14:17:29,122 INFO: in mcwsCall: Library/Import
2022-02-25 14:17:29,122 DEBUG: -params: {'Block': '1', 'path': 'Y:\\verified\\2022\\d+t2022-02-20.akgc414xlii.flac24\\d+t2022-02-20.akgc414xlii.t08.flac'}
2022-02-25 14:17:29,122 INFO: -fullCall: http://localhost:52199/MCWS/v1/Library/Import?Block=1&path=Y:%5Cverified%5C2022%5Cd+t2022-02-20.akgc414xlii.flac24%5Cd+t2022-02-20.akgc414xlii.t08.flac
2022-02-25 14:17:29,123 DEBUG: Starting new HTTP connection (1): localhost:52199
2022-02-25 14:17:33,928 DEBUG: http://localhost:52199 "GET /MCWS/v1/Library/Import?Block=1&path=Y:%5Cverified%5C2022%5Cd+t2022-02-20.akgc414xlii.flac24%5Cd+t2022-02-20.akgc414xlii.t08.flac HTTP/1.1" 200 83
2022-02-25 14:17:33,929 DEBUG: -response: {'Response': {'Status': 'OK'}, 'items': []}
2022-02-25 14:17:33,929 INFO: in mcwsCall: Files/Search
2022-02-25 14:17:33,929 DEBUG: -params: {'Action': 'JSON', 'Fields': 'Key', 'Query': '[Filename]=Y:\\verified\\2022\\d+t2022-02-20.akgc414xlii.flac24\\d+t2022-02-20.akgc414xlii.t08.flac'}
2022-02-25 14:17:33,929 INFO: -fullCall: http://localhost:52199/MCWS/v1/Files/Search?Action=JSON&Fields=Key&Query=[Filename]=Y:%5Cverified%5C2022%5Cd+t2022-02-20.akgc414xlii.flac24%5Cd+t2022-02-20.akgc414xlii.t08.flac
2022-02-25 14:17:33,931 DEBUG: Starting new HTTP connection (1): localhost:52199
2022-02-25 14:17:36,012 DEBUG: http://localhost:52199 "GET /MCWS/v1/Files/Search?Action=JSON&Fields=Key&Query=%5BFilename%5D=Y:%5Cverified%5C2022%5Cd+t2022-02-20.akgc414xlii.flac24%5Cd+t2022-02-20.akgc414xlii.t08.flac HTTP/1.1" 200 17
2022-02-25 14:17:36,012 DEBUG: -response: [{'Key': 7929017}]
2022-02-25 14:17:36,012 INFO: in mcwsCall: File/SetInfo
2022-02-25 14:17:36,012 DEBUG: -params: {'File': 7929017, 'List': 'CSV', 'Field': 'Season,Type - Grouping,Series,Source', 'Value': '2022-02-20,flac24,2022,akgc414xlii'}
2022-02-25 14:17:36,012 INFO: -fullCall: http://localhost:52199/MCWS/v1/File/SetInfo?File=7929017&List=CSV&Field=Season,Type%20-%20Grouping,Series,Source&Value=2022-02-20,flac24,2022,akgc414xlii
2022-02-25 14:17:36,014 DEBUG: Starting new HTTP connection (1): localhost:52199
2022-02-25 14:17:38,068 DEBUG: http://localhost:52199 "GET /MCWS/v1/File/SetInfo?File=7929017&List=CSV&Field=Season,Type%20-%20Grouping,Series,Source&Value=2022-02-20,flac24,2022,akgc414xlii HTTP/1.1" 200 83
2022-02-25 14:17:38,069 DEBUG: -response: {'Response': {'Status': 'OK'}, 'items': []}
2022-02-25 14:17:38,071 DEBUG: URL being requested: PATCH https://www.googleapis.com/drive/v3/files/redactedFileId?supportsAllDrives=true&alt=json
2022-02-25 14:17:38,619 INFO: fullPath: Y:\verified\2022\d+t2022-02-20.akgc414xlii.flac24\d+t2022-02-20.akgc414xlii.t08.flac
Each time I call into MCWS, you can see a new "Starting new HTTP connection" item and it takes a few seconds. Whereas if I do that same Files/Search in a local browser, it's milliseconds. When I look in MC, the response time is always milliseconds, whether or not it's within my script or a browser. Is there a better way that I should be approaching this? Thanks!