diff --git a/ChangeLog b/ChangeLog index de473dcc..b47eabb2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -22660,3 +22660,5 @@ * Modified the 'List*' methods in th 'rivwebpyapi' API to return None in fields that do not exist in the schema of the queried system. +2021-12-06 Fred Gleason + * Added an 'AddCut()' method to the 'rivwebpyapi' API. diff --git a/apis/rivwebpyapi/api/rivwebpyapi.py b/apis/rivwebpyapi/api/rivwebpyapi.py index 035027b1..91d0435a 100755 --- a/apis/rivwebpyapi/api/rivwebpyapi.py +++ b/apis/rivwebpyapi/api/rivwebpyapi.py @@ -211,6 +211,99 @@ class rivwebpyapi(object): self.__connection_username=username self.__connection_password=password +########################## + def AddCut(self,cart_number): + """ + Add a new cut to an existing audio cart. Returns the metadata of + the newly created cut (list of dictionaries). + + Takes the following argument: + + cart_number - The number of the desired cart, in the range + 1 - 999999 (integer) + + """ + + if((cart_number<1)or(cart_number>999999)): + raise ValueError('invalid cart number') + + # + # Build the WebAPI arguments + # + postdata={ + 'COMMAND': '10', + 'LOGIN_NAME': self.__connection_username, + 'PASSWORD': self.__connection_password, + 'CART_NUMBER': str(cart_number) + } + + # + # Fetch the XML + # + r=requests.post(self.__connection_url,data=postdata) + if(r.status_code!=requests.codes.ok): + r.raise_for_status() + + # + # Generate the output dictionary + # + fields={ + 'cutName': 'string', + 'cartNumber': 'integer', + 'cutNumber': 'integer', + 'evergreen': 'boolean', + 'description': 'string', + 'outcue': 'string', + 'isrc': 'string', + 'isci': 'string', + 'recordingMbId': 'string', + 'releaseMbId': 'string', + 'length': 'integer', + 'originDatetime': 'datetime', + 'startDatetime': 'datetime', + 'endDatetime': 'datetime', + 'sun': 'boolean', + 'mon': 'boolean', + 'tue': 'boolean', + 'wed': 'boolean', + 'thu': 'boolean', + 'fri': 'boolean', + 'sat': 'boolean', + 'startDaypart': 'time', + 'endDaypart': 'time', + 'originName': 'string', + 'originLoginName': 'string', + 'sourceHostname': 'string', + 'weight': 'integer', + 'lastPlayDatetime': 'datetime', + 'playCounter': 'integer', + 'codingFormat': 'integer', + 'sampleRate': 'integer', + 'bitRate': 'integer', + 'channels': 'integer', + 'playGain': 'integer', + 'startPoint': 'integer', + 'endPoint': 'integer', + 'fadeupPoint': 'integer', + 'fadedownPoint': 'integer', + 'segueStartPoint': 'integer', + 'segueEndPoint': 'integer', + 'segueGain': 'integer', + 'hookStartPoint': 'integer', + 'hookEndPoint': 'integer', + 'talkStartPoint': 'integer', + 'talkEndPoint': 'integer' + } + handler=RivWebPyApi_ListHandler(base_tag='cut',fields=fields) + xml.sax.parseString(r.text,handler) + + return handler.output() + +########################## + + + + def ListCart(self,cart_number,include_cuts=False): """ Returns the metadata associated with a Rivendell cart diff --git a/apis/rivwebpyapi/tests/Makefile.am b/apis/rivwebpyapi/tests/Makefile.am index 17c3486c..a82689f4 100644 --- a/apis/rivwebpyapi/tests/Makefile.am +++ b/apis/rivwebpyapi/tests/Makefile.am @@ -20,7 +20,8 @@ ## ## Use automake to process this into a Makefile.in -EXTRA_DIST = list_cart.py\ +EXTRA_DIST = add_cut.py\ + list_cart.py\ list_cart_sched_codes.py\ list_carts.py\ list_cut.py\ diff --git a/apis/rivwebpyapi/tests/add_cut.py b/apis/rivwebpyapi/tests/add_cut.py new file mode 100755 index 00000000..41a0112b --- /dev/null +++ b/apis/rivwebpyapi/tests/add_cut.py @@ -0,0 +1,113 @@ +#!%PYTHON_BANGPATH% + +# add_cut.py +# +# RivWebPyApi test script for Rivendell +# +# Test the AddCut Web API call +# +# (C) Copyright 2021 Fred Gleason +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# + +import getpass +import rivwebpyapi +import sys + +url=''; +username='' +password='' +cart_number=0 +cut_number=0 +include_cuts=False + +# +# Get login parameters +# +usage='add_cut --url= --username= --cart-number= [--password=]' +for arg in sys.argv: + f0=arg.split('=') + if(len(f0)==2): + if(f0[0]=='--url'): + url=f0[1] + if(f0[0]=='--username'): + username=f0[1] + if(f0[0]=='--password'): + password=f0[1] + if(f0[0]=='--cart-number'): + cart_number=int(f0[1]) + +if(not password): + password=getpass.getpass() +if((not url)or(not username)): + print(usage) + sys.exit(1) + +# +# Get the cut list +# +webapi=rivwebpyapi.rivwebpyapi(url=url,username=username,password=password) +cuts=webapi.AddCut(cart_number=cart_number) + +# +# Display the cut list +# +for cut in cuts: + print('ADDED:') + print('cutName: '+str(cut['cutName'])) + print('cartNumber: '+str(cut['cartNumber'])) + print('cutNumber: '+str(cut['cutNumber'])) + print('evergreen: '+str(cut['evergreen'])) + print('description: '+str(cut['description'])) + print('outcue: '+str(cut['outcue'])) + print('isrc: '+str(cut['isrc'])) + print('isci: '+str(cut['isci'])) + print('recordingMbId: '+str(cut['recordingMbId'])) + print('releaseMbId: '+str(cut['releaseMbId'])) + print('length: '+str(cut['length'])) + print('originDatetime: '+str(cut['originDatetime'])) + print('startDatetime: '+str(cut['startDatetime'])) + print('endDatetime: '+str(cut['endDatetime'])) + print('sun: '+str(cut['sun'])) + print('mon: '+str(cut['mon'])) + print('tue: '+str(cut['tue'])) + print('wed: '+str(cut['wed'])) + print('thu: '+str(cut['thu'])) + print('fri: '+str(cut['fri'])) + print('sat: '+str(cut['sat'])) + print('startDaypart: '+str(cut['startDaypart'])) + print('endDaypart: '+str(cut['endDaypart'])) + print('originName: '+str(cut['originName'])) + print('originLoginName: '+str(cut['originLoginName'])) + print('sourceHostname: '+str(cut['sourceHostname'])) + print('weight: '+str(cut['weight'])) + print('lastPlayDatetime: '+str(cut['lastPlayDatetime'])) + print('playCounter: '+str(cut['playCounter'])) + print('codingFormat: '+str(cut['codingFormat'])) + print('sampleRate: '+str(cut['sampleRate'])) + print('bitRate: '+str(cut['bitRate'])) + print('channels: '+str(cut['channels'])) + print('playGain: '+str(cut['playGain'])) + print('startPoint: '+str(cut['startPoint'])) + print('endPoint: '+str(cut['endPoint'])) + print('fadeupPoint: '+str(cut['fadeupPoint'])) + print('fadedownPoint: '+str(cut['fadedownPoint'])) + print('segueStartPoint: '+str(cut['segueStartPoint'])) + print('segueEndPoint: '+str(cut['segueEndPoint'])) + print('segueGain: '+str(cut['segueGain'])) + print('hookStartPoint: '+str(cut['hookStartPoint'])) + print('hookEndPoint: '+str(cut['hookEndPoint'])) + print('talkStartPoint: '+str(cut['talkStartPoint'])) + print('talkEndPoint: '+str(cut['talkEndPoint']))