2021-12-07 Fred Gleason <fredg@paravelsystems.com>

* Added an 'Export()' method to the 'rivwebpyapi' API.

Signed-off-by: Fred Gleason <fredg@paravelsystems.com>
This commit is contained in:
Fred Gleason 2021-12-07 11:35:54 -05:00
parent 0dd11053fb
commit fa28a37c47
4 changed files with 191 additions and 0 deletions

View File

@ -22682,3 +22682,5 @@
* Added an 'AudioStore()' method to the 'rivwebpyapi' API.
2021-12-06 Fred Gleason <fredg@paravelsystems.com>
* Added an 'DeleteAudio()' method to the 'rivwebpyapi' API.
2021-12-07 Fred Gleason <fredg@paravelsystems.com>
* Added an 'Export()' method to the 'rivwebpyapi' API.

View File

@ -27,6 +27,17 @@ from urllib.parse import urlparse
from xml.sax.handler import ContentHandler
import xml.sax
#
# Audio Formats
#
AUDIO_FORMAT_PCM16_WAV=0
AUDIO_FORMAT_PCM24_WAV=7
AUDIO_FORMAT_MPEG_L2_WAV=6
AUDIO_FORMAT_MPEG_L2_NATIVE=2
AUDIO_FORMAT_MPEG_L3_NATIVE=3
AUDIO_FORMAT_FLAC=4
AUDIO_FORMAT_OGG_VORBIS=5
class RivWebPyApi_ListHandler(ContentHandler):
def __init__(self,base_tag,fields):
self.__output=[]
@ -618,6 +629,84 @@ class rivwebpyapi(object):
if(r.status_code!=requests.codes.ok):
r.raise_for_status()
def Export(self,filename,cart_number,cut_number,audio_format,channels,
sample_rate,bit_rate,quality,start_point,end_point,
normalization_level,enable_metadata):
"""
Export audio data from the audio store (file).
Takes the following arguments:
filename - Location to save the exported audio file (string).
cart_number - The number of the desired cart, in the range
1 - 999999 (integer)
cut_number - The number of the desired cut, in the range
1 - 999 (integer)
audio_format - Format of the exported audio (AUDIO_FORMAT)
channels - Channel count of the exported audio (integer)
sample_rate - Sample rate of the exported audio (integer,
samples/sec)
bit_rate - Bit rate of the export audio [MPEG formats only]
(integer, bits/sec)
quality - Quality [OggVorbis only] (integer, -1 - 10)
start_point - Start point of audio export (integer, mS from
absolute start of stored audio)
end_point - End point of audio export (integer, mS from
absolute start of stored audio)
normalization_level - Normalization level, 0 = no normalization
(integer, dBFS)
enable_metadata - Encode metadata into exported file (boolean)
"""
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': '1',
'LOGIN_NAME': self.__connection_username,
'PASSWORD': self.__connection_password,
'CART_NUMBER': str(cart_number),
'CUT_NUMBER': str(cut_number),
'FORMAT': str(audio_format),
'CHANNELS': str(channels),
'SAMPLE_RATE': str(sample_rate),
'BIT_RATE': str(bit_rate),
'QUALITY': str(quality),
'START_POINT': str(start_point),
'END_POINT': str(end_point),
'NORMALIZATION_LEVEL': str(normalization_level)
}
if(enable_metadata):
postdata['ENABLE_METADATA']='1'
else:
postdata['ENABLE_METADATA']='0'
#
# Fetch the audio data
#
r=requests.post(self.__connection_url,data=postdata,stream=True)
if(r.status_code!=requests.codes.ok):
r.raise_for_status()
with open(filename,'wb') as handle:
for block in r.iter_content(1024):
handle.write(block)
def ListCart(self,cart_number,include_cuts=False):
"""
Returns the metadata associated with a Rivendell cart

View File

@ -28,6 +28,7 @@ EXTRA_DIST = add_cart.py\
audio_store.py\
delete_audio.py\
delete_log.py\
export.py\
list_cart.py\
list_cart_sched_codes.py\
list_carts.py\

View File

@ -0,0 +1,99 @@
#!%PYTHON_BANGPATH%
# export.py
#
# RivWebPyApi test script for Rivendell
#
# Test the Export Web API call
#
# (C) Copyright 2021 Fred Gleason <fredg@paravelsystems.com>
#
# 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
audio_format=0
channels=2
sample_rate=48000
bit_rate=0
quality=0
start_point=-1
end_point=-1
normalization_level=0
enable_metadata=False
#
# Get login parameters
#
usage='export --url=<rd-url> --username=<rd-username> --filename=<str> --audio-format=<num> --channels=1|2 --sample-rate=<sps> --bit-rate=<bps> --quality=<qual> --start-point=<msec> --end-point=<msec> --normalization-level=<dbfs> [--enable-metadata] --cart-number=<num> --cut-number=<num> [--password=<passwd>]'
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]=='--cart-number'):
cart_number=int(f0[1])
if(f0[0]=='--cut-number'):
cut_number=int(f0[1])
if(f0[0]=='--audio-format'):
audio_format=int(f0[1])
if(f0[0]=='--channels'):
channels=int(f0[1])
if(f0[0]=='--sample-rate'):
sample_rate=int(f0[1])
if(f0[0]=='--bit-rate'):
bit_rate=int(f0[1])
if(f0[0]=='--quality'):
quality=int(f0[1])
if(f0[0]=='--start-point'):
start_point=int(f0[1])
if(f0[0]=='--end-point'):
end_point=int(f0[1])
if(f0[0]=='--normalization-level'):
normalization_level=int(f0[1])
if(len(f0)==1):
if(f0[0]=='--enable-metadata'):
enable_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.Export(filename=filename,cart_number=cart_number,cut_number=cut_number,
audio_format=audio_format,channels=channels,
sample_rate=sample_rate,bit_rate=bit_rate,quality=quality,
start_point=start_point,end_point=end_point,
normalization_level=normalization_level,
enable_metadata=enable_metadata)