From 61d3b9a19b4bfa791314660b9054e4ff18f734ea Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Tue, 7 Dec 2021 13:53:35 -0500 Subject: [PATCH] 2021-12-07 Fred Gleason * Added an 'Import()' method to the 'rivwebpyapi' API. Signed-off-by: Fred Gleason --- ChangeLog | 2 + apis/rivwebpyapi/api/rivwebpyapi.py | 78 +++++++++++++++++++++++++ apis/rivwebpyapi/tests/Makefile.am | 1 + apis/rivwebpyapi/tests/import.py | 88 +++++++++++++++++++++++++++++ 4 files changed, 169 insertions(+) create mode 100755 apis/rivwebpyapi/tests/import.py diff --git a/ChangeLog b/ChangeLog index a0726ca5..ab24f9b2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -22686,3 +22686,5 @@ * Added an 'Export()' method to the 'rivwebpyapi' API. 2021-12-07 Fred Gleason * Added an 'ExportPeaks()' method to the 'rivwebpyapi' API. +2021-12-07 Fred Gleason + * Added an 'Import()' method to the 'rivwebpyapi' API. diff --git a/apis/rivwebpyapi/api/rivwebpyapi.py b/apis/rivwebpyapi/api/rivwebpyapi.py index 24b9f4d0..516b9821 100755 --- a/apis/rivwebpyapi/api/rivwebpyapi.py +++ b/apis/rivwebpyapi/api/rivwebpyapi.py @@ -747,6 +747,84 @@ class rivwebpyapi(object): ret=ret+block return ret + def Import(self,filename,use_metadata,cart_number=0,cut_number=0, + channels=2,normalization_level=0,autotrim_level=0, + group_name='',title=''): + """ + Import audio into the audio store + + Takes the following arguments: + + filename - Name of the file containing audio to be imported + (string). + + cart_number - The number of the desired cart, in the range + 0 - 999999 (integer) + + cut_number - The number of the desired cut, in the range + 0 - 999 (integer) + + use_metadata - Apply file embedded metadata to the destination + cart/cut (boolean). + + channels - Use specified number of channels in the destination + cut. Valid values are 1 or 2 (integer). + + normalization_level - Normalization level, 0 = no normalization + (integer, dBFS) + + autotrim_level - Autotrim level, 0 = no autotrim (integer, dBFS) + + group_name - If both the 'cart-number' and 'cut-number' parameters + are set to 0 and a valid 'group_name' parameter passed, + the system will attempt to create a new cart/cut in + the specified group. + + title - The value to set as the title of the target cart. This + will override any value found in in-file metadata + (string). + """ + + if(not filename): + raise ValueError('missing filename') + if(group_name): + if((cart_number!=0) or (cut_number!=0)): + raise RuntimeError('cart/cut numbers cannot be specified when using the "group_name" parameter') + else: + if((cart_number<1)or(cart_number>999999)): + raise ValueError('invalid cart number') + if((cut_number<1)or(cut_number>999)): + raise ValueError('invalid cut number') + + # + # Build the WebAPI arguments + # + postdata={ + 'COMMAND': '2', + 'LOGIN_NAME': self.__connection_username, + 'PASSWORD': self.__connection_password, + 'CART_NUMBER': str(cart_number), + 'CUT_NUMBER': str(cut_number), + 'CHANNELS': str(channels), + 'NORMALIZATION_LEVEL': str(normalization_level), + 'AUTOTRIM_LEVEL': str(autotrim_level), + 'TITLE': str(title), + 'USE_METADATA': '0' + } + if(use_metadata): + postdata['USE_METADATA']='1' + if(group_name): + postdata['CREATE']='1' + postdata['GROUP_NAME']=group_name + files={'FILENAME': open(filename,'rb')} + + # + # Execute + # + r=requests.post(self.__connection_url,data=postdata,files=files) + if(r.status_code!=requests.codes.ok): + r.raise_for_status() + 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 4784e9a8..60c53e3b 100644 --- a/apis/rivwebpyapi/tests/Makefile.am +++ b/apis/rivwebpyapi/tests/Makefile.am @@ -30,6 +30,7 @@ EXTRA_DIST = add_cart.py\ delete_log.py\ export.py\ export_peaks.py\ + import.py\ list_cart.py\ list_cart_sched_codes.py\ list_carts.py\ diff --git a/apis/rivwebpyapi/tests/import.py b/apis/rivwebpyapi/tests/import.py new file mode 100755 index 00000000..fdfbee11 --- /dev/null +++ b/apis/rivwebpyapi/tests/import.py @@ -0,0 +1,88 @@ +#!%PYTHON_BANGPATH% + +# import.py +# +# RivWebPyApi test script for Rivendell +# +# Test the Import 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='' +filename='' +cart_number=0 +cut_number=0 +channels=2 +normalization_level=0 +autotrim_level=0 +use_metadata=False +group_name='' +title='' + +# +# Get login parameters +# +usage='import --url= --username= --filename= --channels=1|2 --normalization-level= --autotrim-level= --use-metadata [--cart-number=] [--cut-number=] [--group-name=] [--title=] [--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]=='--filename'): + filename=f0[1] + if(f0[0]=='--group-name'): + group_name=f0[1] + if(f0[0]=='--title'): + title=f0[1] + if(f0[0]=='--cart-number'): + cart_number=int(f0[1]) + if(f0[0]=='--cut-number'): + cut_number=int(f0[1]) + if(f0[0]=='--channels'): + channels=int(f0[1]) + if(f0[0]=='--normalization-level'): + normalization_level=int(f0[1]) + if(f0[0]=='--autotrim-level'): + autotrim_level=int(f0[1]) + if(len(f0)==1): + if(f0[0]=='--use-metadata'): + use_metadata=True + +if(not password): + password=getpass.getpass() +if((not url)or(not username)): + print(usage) + sys.exit(1) + +# +# Get the code list +# +webapi=rivwebpyapi.rivwebpyapi(url=url,username=username,password=password) +webapi.Import(filename=filename,cart_number=cart_number,cut_number=cut_number, + channels=channels,normalization_level=normalization_level, + autotrim_level=autotrim_level,use_metadata=use_metadata, + group_name=group_name,title=title)