1 
2 #include "vorbistoolscodecglobal.h"
3 
4 #include "soundkonverter_codec_vorbistools.h"
5 #include "../../core/conversionoptions.h"
6 #include "vorbistoolscodecwidget.h"
7 
8 
soundkonverter_codec_vorbistools(QObject * parent,const QVariantList & args)9 soundkonverter_codec_vorbistools::soundkonverter_codec_vorbistools( QObject *parent, const QVariantList& args  )
10     : CodecPlugin( parent )
11 {
12     Q_UNUSED(args)
13 
14     binaries["oggenc"] = "";
15     binaries["oggdec"] = "";
16 
17     allCodecs += "ogg vorbis";
18     allCodecs += "wav";
19 }
20 
~soundkonverter_codec_vorbistools()21 soundkonverter_codec_vorbistools::~soundkonverter_codec_vorbistools()
22 {}
23 
name() const24 QString soundkonverter_codec_vorbistools::name() const
25 {
26     return global_plugin_name;
27 }
28 
codecTable()29 QList<ConversionPipeTrunk> soundkonverter_codec_vorbistools::codecTable()
30 {
31     QList<ConversionPipeTrunk> table;
32     ConversionPipeTrunk newTrunk;
33 
34     newTrunk.codecFrom = "wav";
35     newTrunk.codecTo = "ogg vorbis";
36     newTrunk.rating = 100;
37     newTrunk.enabled = ( binaries["oggenc"] != "" );
38     newTrunk.problemInfo = standardMessage( "encode_codec,backend", "ogg vorbis", "oggenc" ) + "\n" + i18n( "'%1' is usually in the package '%2' which should be shipped with your distribution.", QString("oggenc"), QString("vorbis-tools") );
39     newTrunk.data.hasInternalReplayGain = false;
40     table.append( newTrunk );
41 
42     newTrunk.codecFrom = "ogg vorbis";
43     newTrunk.codecTo = "wav";
44     newTrunk.rating = 100;
45     newTrunk.enabled = ( binaries["oggdec"] != "" );
46     newTrunk.problemInfo = standardMessage( "decode_codec,backend", "ogg vorbis", "oggdec" ) + "\n" + i18n( "'%1' is usually in the package '%2' which should be shipped with your distribution.", QString("oggdec"), QString("vorbis-tools") );
47     newTrunk.data.hasInternalReplayGain = false;
48     table.append( newTrunk );
49 
50     return table;
51 }
52 
isConfigSupported(ActionType action,const QString & codecName)53 bool soundkonverter_codec_vorbistools::isConfigSupported( ActionType action, const QString& codecName )
54 {
55     Q_UNUSED(action)
56     Q_UNUSED(codecName)
57 
58     return false;
59 }
60 
showConfigDialog(ActionType action,const QString & codecName,QWidget * parent)61 void soundkonverter_codec_vorbistools::showConfigDialog( ActionType action, const QString& codecName, QWidget *parent )
62 {
63     Q_UNUSED(action)
64     Q_UNUSED(codecName)
65     Q_UNUSED(parent)
66 }
67 
hasInfo()68 bool soundkonverter_codec_vorbistools::hasInfo()
69 {
70     return false;
71 }
72 
showInfo(QWidget * parent)73 void soundkonverter_codec_vorbistools::showInfo( QWidget *parent )
74 {
75     Q_UNUSED(parent)
76 }
77 
newCodecWidget()78 CodecWidget *soundkonverter_codec_vorbistools::newCodecWidget()
79 {
80     VorbisToolsCodecWidget *widget = new VorbisToolsCodecWidget();
81     return qobject_cast<CodecWidget*>(widget);
82 }
83 
convert(const KUrl & inputFile,const KUrl & outputFile,const QString & inputCodec,const QString & outputCodec,const ConversionOptions * _conversionOptions,TagData * tags,bool replayGain)84 int soundkonverter_codec_vorbistools::convert( const KUrl& inputFile, const KUrl& outputFile, const QString& inputCodec, const QString& outputCodec, const ConversionOptions *_conversionOptions, TagData *tags, bool replayGain )
85 {
86     QStringList command = convertCommand( inputFile, outputFile, inputCodec, outputCodec, _conversionOptions, tags, replayGain );
87     if( command.isEmpty() )
88         return BackendPlugin::UnknownError;
89 
90     CodecPluginItem *newItem = new CodecPluginItem( this );
91     newItem->id = lastId++;
92     newItem->process = new KProcess( newItem );
93     newItem->process->setOutputChannelMode( KProcess::MergedChannels );
94     connect( newItem->process, SIGNAL(readyRead()), this, SLOT(processOutput()) );
95     connect( newItem->process, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(processExit(int,QProcess::ExitStatus)) );
96 
97     newItem->process->clearProgram();
98     newItem->process->setShellCommand( command.join(" ") );
99     newItem->process->start();
100 
101     logCommand( newItem->id, command.join(" ") );
102 
103     backendItems.append( newItem );
104     return newItem->id;
105 }
106 
convertCommand(const KUrl & inputFile,const KUrl & outputFile,const QString & inputCodec,const QString & outputCodec,const ConversionOptions * _conversionOptions,TagData * tags,bool replayGain)107 QStringList soundkonverter_codec_vorbistools::convertCommand( const KUrl& inputFile, const KUrl& outputFile, const QString& inputCodec, const QString& outputCodec, const ConversionOptions *_conversionOptions, TagData *tags, bool replayGain )
108 {
109     Q_UNUSED(inputCodec)
110     Q_UNUSED(tags)
111     Q_UNUSED(replayGain)
112 
113     if( !_conversionOptions )
114         return QStringList();
115 
116     QStringList command;
117     const ConversionOptions *conversionOptions = _conversionOptions;
118 
119     if( outputCodec == "ogg vorbis" )
120     {
121         command += binaries["oggenc"];
122 //         if( inputFile.isEmpty() )
123 //         {
124 //             command += "--raw";
125 //         }
126         if( conversionOptions->qualityMode == ConversionOptions::Quality )
127         {
128             command += "-q";
129             command += QString::number(conversionOptions->quality);
130         }
131         else if( conversionOptions->qualityMode == ConversionOptions::Bitrate )
132         {
133             if( conversionOptions->bitrateMode == ConversionOptions::Abr )
134             {
135                 command += "-b";
136                 command += QString::number(conversionOptions->bitrate);
137             }
138             else if( conversionOptions->bitrateMode == ConversionOptions::Cbr )
139             {
140                 command += "--managed";
141                 command += "-b";
142                 command += QString::number(conversionOptions->bitrate);
143             }
144         }
145         command += "\"" + escapeUrl(inputFile) + "\"";
146         command += "-o";
147         command += "\"" + escapeUrl(outputFile) + "\"";
148     }
149     else
150     {
151         command += binaries["oggdec"];
152         if( outputFile.isEmpty() )
153         {
154             command += "-Q";
155         }
156         command += "\"" + escapeUrl(inputFile) + "\"";
157         command += "-o";
158         command += "\"" + escapeUrl(outputFile) + "\"";
159     }
160 
161     return command;
162 }
163 
parseOutput(const QString & output)164 float soundkonverter_codec_vorbistools::parseOutput( const QString& output )
165 {
166     //         [ 99.5%]
167 
168     if( output == "" || !output.contains("%") || output.contains("error",Qt::CaseInsensitive) )
169         return -1;
170 
171     QString data = output;
172     data.remove( 0, data.indexOf("[")+1 );
173     data = data.left( data.indexOf("%") );
174     return data.toFloat();
175 }
176 
177 K_PLUGIN_FACTORY(codec_vorbistools, registerPlugin<soundkonverter_codec_vorbistools>();)
178 
179 #include "soundkonverter_codec_vorbistools.moc"
180