mirror of
https://github.com/ElvishArtisan/rivendell.git
synced 2025-04-07 01:13:50 +02:00
2018-02-04 Fred Gleason <fredg@paravelsystems.com>
* Refactored the RDAudioExport class to use RDApplication.
This commit is contained in:
parent
f932a66cee
commit
69817c1941
@ -16666,3 +16666,5 @@
|
||||
2018-02-04 Fred Gleason <fredg@paravelsystems.com>
|
||||
* Refactored the RDAudioConvert class to use RDApplication.
|
||||
* Converted rdcatchd(8) to use RDApplication.
|
||||
2018-02-04 Fred Gleason <fredg@paravelsystems.com>
|
||||
* Refactored the RDAudioExport class to use RDApplication.
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// Export an Audio File using the RdXport Web Service
|
||||
//
|
||||
// (C) Copyright 2010,2016-2017 Fred Gleason <fredg@paravelsystems.com>
|
||||
// (C) Copyright 2010,2016-2018 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
|
||||
@ -31,6 +31,7 @@
|
||||
#include <qapplication.h>
|
||||
|
||||
#include <rd.h>
|
||||
#include <rdapplication.h>
|
||||
#include <rdxport_interface.h>
|
||||
#include <rdformpost.h>
|
||||
#include <rdaudioexport.h>
|
||||
@ -51,12 +52,9 @@ int ExportProgressCallback(void *clientp,double dltotal,double dlnow,
|
||||
}
|
||||
|
||||
|
||||
RDAudioExport::RDAudioExport(RDStation *station,RDConfig *config,
|
||||
QObject *parent)
|
||||
RDAudioExport::RDAudioExport(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
conv_station=station;
|
||||
conv_config=config;
|
||||
conv_cart_number=0;
|
||||
conv_cut_number=0;
|
||||
conv_start_point=-1;
|
||||
@ -170,13 +168,13 @@ RDAudioExport::ErrorCode RDAudioExport::runExport(const QString &username,
|
||||
// otherwise some versions of LibCurl will throw a 'bad/illegal format'
|
||||
// error.
|
||||
//
|
||||
strncpy(url,conv_station->webServiceUrl(conv_config),1024);
|
||||
strncpy(url,rda->station()->webServiceUrl(rda->config()),1024);
|
||||
curl_easy_setopt(curl,CURLOPT_URL,url);
|
||||
curl_easy_setopt(curl,CURLOPT_WRITEDATA,f);
|
||||
curl_easy_setopt(curl,CURLOPT_POST,1);
|
||||
curl_easy_setopt(curl,CURLOPT_POSTFIELDS,(const char *)post);
|
||||
curl_easy_setopt(curl,CURLOPT_USERAGENT,
|
||||
(const char *)conv_config->userAgent());
|
||||
(const char *)rda->config()->userAgent());
|
||||
curl_easy_setopt(curl,CURLOPT_TIMEOUT,RD_CURL_TIMEOUT);
|
||||
curl_easy_setopt(curl,CURLOPT_PROGRESSFUNCTION,ExportProgressCallback);
|
||||
curl_easy_setopt(curl,CURLOPT_PROGRESSDATA,this);
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// Export an Audio File using the RdXport Web Service
|
||||
//
|
||||
// (C) Copyright 2010,2016 Fred Gleason <fredg@paravelsystems.com>
|
||||
// (C) Copyright 2010,2016-2018 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
|
||||
@ -23,8 +23,6 @@
|
||||
|
||||
#include <qobject.h>
|
||||
|
||||
#include <rdconfig.h>
|
||||
#include <rdstation.h>
|
||||
#include <rdsettings.h>
|
||||
#include <rdaudioconvert.h>
|
||||
|
||||
@ -36,7 +34,7 @@ class RDAudioExport : public QObject
|
||||
ErrorNoDestination=3,ErrorInternal=5,ErrorUrlInvalid=7,
|
||||
ErrorService=8,ErrorInvalidUser=9,ErrorAborted=10,
|
||||
ErrorConverter=11};
|
||||
RDAudioExport(RDStation *station,RDConfig *config,QObject *parent=0);
|
||||
RDAudioExport(QObject *parent=0);
|
||||
unsigned cartNumber() const;
|
||||
void setCartNumber(unsigned cartnum);
|
||||
unsigned cutNumber() const;
|
||||
@ -61,8 +59,6 @@ class RDAudioExport : public QObject
|
||||
void strobe();
|
||||
|
||||
private:
|
||||
RDStation *conv_station;
|
||||
RDConfig *conv_config;
|
||||
unsigned conv_cart_number;
|
||||
unsigned conv_cut_number;
|
||||
QString conv_dst_filename;
|
||||
|
@ -556,7 +556,7 @@ unsigned RDFeed::postCut(RDUser *user,RDStation *station,
|
||||
*err=RDFeed::ErrorCannotOpenFile;
|
||||
return 0;
|
||||
}
|
||||
RDAudioExport *conv=new RDAudioExport(station,config,this);
|
||||
RDAudioExport *conv=new RDAudioExport(this);
|
||||
conv->setCartNumber(cut->cartNumber());
|
||||
conv->setCutNumber(cut->cutNumber());
|
||||
conv->setDestinationFile(tmpfile);
|
||||
|
@ -618,7 +618,7 @@ void RDImportAudio::Export()
|
||||
StartBar();
|
||||
RDCut *cut=new RDCut(import_cutname);
|
||||
import_settings->setNormalizationLevel(import_normalize_spin->value());
|
||||
import_export_conv=new RDAudioExport(import_station,import_config,this);
|
||||
import_export_conv=new RDAudioExport(this);
|
||||
import_export_conv->setCartNumber(cut->cartNumber());
|
||||
import_export_conv->setCutNumber(cut->cutNumber());
|
||||
import_export_conv->setDestinationFile(import_dest_filename);
|
||||
|
@ -184,7 +184,7 @@ bool __RDRenderLogLine::GetCutFile(const QString &cutname,int start_pt,
|
||||
|
||||
strncpy(tempdir,RDTempDirectory::basePath()+"/rdrenderXXXXXX",PATH_MAX);
|
||||
*dest_filename=QString(mkdtemp(tempdir))+"/"+cutname+".wav";
|
||||
RDAudioExport *conv=new RDAudioExport(rda->station(),rda->config());
|
||||
RDAudioExport *conv=new RDAudioExport();
|
||||
conv->setDestinationFile(*dest_filename);
|
||||
conv->setCartNumber(RDCut::cartNumber(cutname));
|
||||
conv->setCutNumber(RDCut::cutNumber(cutname));
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// Test the Rivendell file format exporter.
|
||||
//
|
||||
// (C) Copyright 2010,2016 Fred Gleason <fredg@paravelsystems.com>
|
||||
// (C) Copyright 2010,2016-2018 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
|
||||
@ -18,14 +18,15 @@
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <qapplication.h>
|
||||
|
||||
#include <rdapplication.h>
|
||||
#include <rddb.h>
|
||||
#include <rdcmd_switch.h>
|
||||
#include <rdaudioexport.h>
|
||||
#include <rdstation.h>
|
||||
|
||||
#include <audio_export_test.h>
|
||||
#include "audio_export_test.h"
|
||||
|
||||
MainObject::MainObject(QObject *parent)
|
||||
:QObject(parent)
|
||||
@ -40,61 +41,67 @@ MainObject::MainObject(QObject *parent)
|
||||
bool ok=false;
|
||||
RDAudioConvert::ErrorCode audio_conv_err;
|
||||
RDAudioExport::ErrorCode conv_err;
|
||||
unsigned schema=0;
|
||||
QString err_msg;
|
||||
|
||||
//
|
||||
// Open the Database
|
||||
//
|
||||
rda=new RDApplication("audio_export_test","audio_export_test",AUDIO_EXPORT_TEST_USAGE,this);
|
||||
if(!rda->open(&err_msg)) {
|
||||
fprintf(stderr,"audio_export_test: %s\n",(const char *)err_msg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
//
|
||||
// Read Command Options
|
||||
//
|
||||
RDCmdSwitch *cmd=
|
||||
new RDCmdSwitch(qApp->argc(),qApp->argv(),"audio_export_test",
|
||||
AUDIO_EXPORT_TEST_USAGE);
|
||||
for(unsigned i=0;i<cmd->keys();i++) {
|
||||
if(cmd->key(i)=="--username") {
|
||||
username=cmd->value(i);
|
||||
cmd->setProcessed(i,true);
|
||||
for(unsigned i=0;i<rda->cmdSwitch()->keys();i++) {
|
||||
if(rda->cmdSwitch()->key(i)=="--username") {
|
||||
username=rda->cmdSwitch()->value(i);
|
||||
rda->cmdSwitch()->setProcessed(i,true);
|
||||
}
|
||||
if(cmd->key(i)=="--password") {
|
||||
password=cmd->value(i);
|
||||
cmd->setProcessed(i,true);
|
||||
if(rda->cmdSwitch()->key(i)=="--password") {
|
||||
password=rda->cmdSwitch()->value(i);
|
||||
rda->cmdSwitch()->setProcessed(i,true);
|
||||
}
|
||||
if(cmd->key(i)=="--cart-number") {
|
||||
cart_number=cmd->value(i).toUInt(&ok);
|
||||
if(rda->cmdSwitch()->key(i)=="--cart-number") {
|
||||
cart_number=rda->cmdSwitch()->value(i).toUInt(&ok);
|
||||
if((!ok)||(cart_number>999999)) {
|
||||
fprintf(stderr,"audio_export_test: invalid cart number\n");
|
||||
exit(256);
|
||||
}
|
||||
cmd->setProcessed(i,true);
|
||||
rda->cmdSwitch()->setProcessed(i,true);
|
||||
}
|
||||
if(cmd->key(i)=="--cut-number") {
|
||||
cut_number=cmd->value(i).toUInt(&ok);
|
||||
if(rda->cmdSwitch()->key(i)=="--cut-number") {
|
||||
cut_number=rda->cmdSwitch()->value(i).toUInt(&ok);
|
||||
if((!ok)||(cut_number>999)) {
|
||||
fprintf(stderr,"audio_export_test: invalid cut number\n");
|
||||
exit(256);
|
||||
}
|
||||
cmd->setProcessed(i,true);
|
||||
rda->cmdSwitch()->setProcessed(i,true);
|
||||
}
|
||||
if(cmd->key(i)=="--destination-file") {
|
||||
destination_filename=cmd->value(i);
|
||||
cmd->setProcessed(i,true);
|
||||
if(rda->cmdSwitch()->key(i)=="--destination-file") {
|
||||
destination_filename=rda->cmdSwitch()->value(i);
|
||||
rda->cmdSwitch()->setProcessed(i,true);
|
||||
}
|
||||
if(cmd->key(i)=="--start-point") {
|
||||
start_point=cmd->value(i).toInt(&ok);
|
||||
if(rda->cmdSwitch()->key(i)=="--start-point") {
|
||||
start_point=rda->cmdSwitch()->value(i).toInt(&ok);
|
||||
if(!ok) {
|
||||
fprintf(stderr,"audio_export_test: invalid start point\n");
|
||||
exit(256);
|
||||
}
|
||||
cmd->setProcessed(i,true);
|
||||
rda->cmdSwitch()->setProcessed(i,true);
|
||||
}
|
||||
if(cmd->key(i)=="--end-point") {
|
||||
end_point=cmd->value(i).toInt(&ok);
|
||||
if(rda->cmdSwitch()->key(i)=="--end-point") {
|
||||
end_point=rda->cmdSwitch()->value(i).toInt(&ok);
|
||||
if(!ok) {
|
||||
fprintf(stderr,"audio_export_test: invalid end point\n");
|
||||
exit(256);
|
||||
}
|
||||
cmd->setProcessed(i,true);
|
||||
rda->cmdSwitch()->setProcessed(i,true);
|
||||
}
|
||||
if(cmd->key(i)=="--destination-format") {
|
||||
RDSettings::Format format=(RDSettings::Format)cmd->value(i).toInt(&ok);
|
||||
if(rda->cmdSwitch()->key(i)=="--destination-format") {
|
||||
RDSettings::Format format=(RDSettings::Format)rda->cmdSwitch()->value(i).toInt(&ok);
|
||||
if(!ok) {
|
||||
fprintf(stderr,"audio_export_test: invalid destination format\n");
|
||||
exit(256);
|
||||
@ -107,7 +114,7 @@ MainObject::MainObject(QObject *parent)
|
||||
case RDSettings::Flac:
|
||||
case RDSettings::OggVorbis:
|
||||
destination_settings->setFormat(format);
|
||||
cmd->setProcessed(i,true);
|
||||
rda->cmdSwitch()->setProcessed(i,true);
|
||||
break;
|
||||
|
||||
default:
|
||||
@ -116,52 +123,61 @@ MainObject::MainObject(QObject *parent)
|
||||
}
|
||||
destination_settings->setFormat(format);
|
||||
}
|
||||
if(cmd->key(i)=="--destination-channels") {
|
||||
unsigned channels=cmd->value(i).toInt(&ok);
|
||||
if(rda->cmdSwitch()->key(i)=="--destination-channels") {
|
||||
unsigned channels=rda->cmdSwitch()->value(i).toInt(&ok);
|
||||
if(!ok) {
|
||||
fprintf(stderr,"audio_export_test: invalid destination channels\n");
|
||||
exit(256);
|
||||
}
|
||||
destination_settings->setChannels(channels);
|
||||
cmd->setProcessed(i,true);
|
||||
rda->cmdSwitch()->setProcessed(i,true);
|
||||
}
|
||||
if(cmd->key(i)=="--destination-sample-rate") {
|
||||
unsigned sample_rate=cmd->value(i).toInt(&ok);
|
||||
if(rda->cmdSwitch()->key(i)=="--destination-sample-rate") {
|
||||
unsigned sample_rate=rda->cmdSwitch()->value(i).toInt(&ok);
|
||||
if(!ok) {
|
||||
fprintf(stderr,"audio_export_test: invalid destination sample rate\n");
|
||||
exit(256);
|
||||
}
|
||||
destination_settings->setSampleRate(sample_rate);
|
||||
cmd->setProcessed(i,true);
|
||||
rda->cmdSwitch()->setProcessed(i,true);
|
||||
}
|
||||
if(cmd->key(i)=="--destination-bit-rate") {
|
||||
unsigned bit_rate=cmd->value(i).toInt(&ok);
|
||||
if(rda->cmdSwitch()->key(i)=="--destination-bit-rate") {
|
||||
unsigned bit_rate=rda->cmdSwitch()->value(i).toInt(&ok);
|
||||
if(!ok) {
|
||||
fprintf(stderr,"audio_export_test: invalid destination bit rate\n");
|
||||
exit(256);
|
||||
}
|
||||
destination_settings->setBitRate(bit_rate);
|
||||
cmd->setProcessed(i,true);
|
||||
rda->cmdSwitch()->setProcessed(i,true);
|
||||
}
|
||||
if(cmd->key(i)=="--quality") {
|
||||
unsigned quality=cmd->value(i).toInt(&ok);
|
||||
if(rda->cmdSwitch()->key(i)=="--quality") {
|
||||
unsigned quality=rda->cmdSwitch()->value(i).toInt(&ok);
|
||||
if(!ok) {
|
||||
fprintf(stderr,"audio_export_test: invalid destination quality\n");
|
||||
exit(256);
|
||||
}
|
||||
destination_settings->setQuality(quality);
|
||||
cmd->setProcessed(i,true);
|
||||
rda->cmdSwitch()->setProcessed(i,true);
|
||||
}
|
||||
if(cmd->key(i)=="--normalization-level") {
|
||||
int normalization_level=cmd->value(i).toInt(&ok);
|
||||
if(rda->cmdSwitch()->key(i)=="--normalization-level") {
|
||||
int normalization_level=rda->cmdSwitch()->value(i).toInt(&ok);
|
||||
if((!ok)||(normalization_level>0)) {
|
||||
fprintf(stderr,"audio_export_test: invalid normalization level\n");
|
||||
exit(256);
|
||||
}
|
||||
destination_settings->setNormalizationLevel(normalization_level);
|
||||
cmd->setProcessed(i,true);
|
||||
rda->cmdSwitch()->setProcessed(i,true);
|
||||
}
|
||||
if(!rda->cmdSwitch()->processed(i)) {
|
||||
fprintf(stderr,"audio_export_test: unknown command option \"%s\"\n",
|
||||
(const char *)rda->cmdSwitch()->key(i));
|
||||
exit(2);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Sanity Checks
|
||||
//
|
||||
if(cart_number==0) {
|
||||
fprintf(stderr,"audio_export_test: missing cart-number\n");
|
||||
exit(256);
|
||||
@ -180,26 +196,7 @@ MainObject::MainObject(QObject *parent)
|
||||
exit(256);
|
||||
}
|
||||
|
||||
//
|
||||
// Read Configuration
|
||||
//
|
||||
rdconfig=new RDConfig();
|
||||
rdconfig->load();
|
||||
rdconfig->setModuleName("audio_export_test");
|
||||
|
||||
//
|
||||
// Open Database
|
||||
//
|
||||
QString err (tr("audio_export_test: "));
|
||||
QSqlDatabase *db=RDInitDb(&schema,&err);
|
||||
if(!db) {
|
||||
fprintf(stderr,err.ascii());
|
||||
delete cmd;
|
||||
exit(256);
|
||||
}
|
||||
|
||||
RDStation *station=new RDStation(rdconfig->stationName());
|
||||
RDAudioExport *conv=new RDAudioExport(station,rdconfig,this);
|
||||
RDAudioExport *conv=new RDAudioExport(this);
|
||||
conv->setCartNumber(cart_number);
|
||||
conv->setCutNumber(cut_number);
|
||||
conv->setDestinationFile(destination_filename);
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// Test the Rivendell file format converter.
|
||||
//
|
||||
// (C) Copyright 2010,2016 Fred Gleason <fredg@paravelsystems.com>
|
||||
// (C) Copyright 2010,2016-2018 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
|
||||
@ -24,20 +24,11 @@
|
||||
#include <list>
|
||||
|
||||
#include <qobject.h>
|
||||
#include <qsqldatabase.h>
|
||||
|
||||
#include <rdconfig.h>
|
||||
#include <rdsettings.h>
|
||||
#include <rdcmd_switch.cpp>
|
||||
|
||||
#define AUDIO_EXPORT_TEST_USAGE "[options]\n\nTest the Rivendell audio exporter routines\n\nOptions are:\n--username=<username>\n\n--password=<password>\n\n--cart-number=<cartnum>\n\n--cut-number=<cutnum>\n\n--destination-file=<filename>\n\n--start-point=<msecs>\n\n--end-point=<msecs>\n\n--destination-format=<fmt>\n Supported formats are:\n 0 - PCM16 WAV\n 2 - MPEG Layer 2\n 3 - MPEG Layer 3\n 4 - FLAC\n 5 - OggVorbis\n 6 - MPEG Layer 2 WAV\n\n--destination-channels=<chans>\n\n--destination-sample-rate=<rate>\n\n--destination-bit-rate=<rate>\n\n--destination-quality=<qual>\n\n--normalization-level=<dbfs>\n\n"
|
||||
|
||||
//
|
||||
// Global Variables
|
||||
//
|
||||
RDConfig *rdconfig;
|
||||
|
||||
|
||||
class MainObject : public QObject
|
||||
{
|
||||
public:
|
||||
|
@ -344,7 +344,7 @@ void MainObject::ExportCart(unsigned cartnum)
|
||||
|
||||
void MainObject::ExportCut(RDCart *cart,RDCut *cut)
|
||||
{
|
||||
RDAudioExport *conv=new RDAudioExport(rda->station(),rda->config(),this);
|
||||
RDAudioExport *conv=new RDAudioExport(this);
|
||||
RDAudioExport::ErrorCode export_err;
|
||||
RDAudioConvert::ErrorCode conv_err;
|
||||
RDAudioInfo::ErrorCode info_err;
|
||||
|
Loading…
x
Reference in New Issue
Block a user