snumplugin.cpp (krename-4.0.9) | : | snumplugin.cpp (krename-4.90.90) | ||
---|---|---|---|---|
skipping to change at line 23 | skipping to change at line 23 | |||
* the Free Software Foundation; either version 2 of the License, or * | * the Free Software Foundation; either version 2 of the License, or * | |||
* (at your option) any later version. * | * (at your option) any later version. * | |||
* * | * * | |||
***************************************************************************/ | ***************************************************************************/ | |||
#include "snumplugin.h" | #include "snumplugin.h" | |||
#include "batchrenamer.h" | #include "batchrenamer.h" | |||
#include <kiconloader.h> | #include <kiconloader.h> | |||
#include <klistwidget.h> | #include <KLocalizedString> | |||
#include <klocale.h> | ||||
#include <QLabel> | ||||
#include <QHBoxLayout> | ||||
#include <QRegExp> | #include <QRegExp> | |||
SnumPlugin::SnumPlugin( PluginLoader* loader ) | SnumPlugin::SnumPlugin(PluginLoader *loader) | |||
: FilePlugin( loader ) | : FilePlugin(loader) | |||
{ | { | |||
this->addSupportedToken("snum"); | this->addSupportedToken("snum"); | |||
this->addSupportedToken("season"); | this->addSupportedToken("season"); | |||
this->addSupportedToken("episode"); | this->addSupportedToken("episode"); | |||
//this->addSupportedToken("season;.*"); | //this->addSupportedToken("season;.*"); | |||
//this->addSupportedToken("episode;.*"); | //this->addSupportedToken("episode;.*"); | |||
m_help.append( "[snum];;" + i18n("Inserts the series number of original file | m_help.append("[snum];;" + i18n("Inserts the series number of original filen | |||
name") ); | ame")); | |||
m_help.append( "[season];;" + i18n("Inserts the season number in two digits" | m_help.append("[season];;" + i18n("Inserts the season number in two digits") | |||
) ); | ); | |||
m_help.append( "[episode];;" + i18n("Inserts the episode number in two or th | m_help.append("[episode];;" + i18n("Inserts the episode number in two or thr | |||
ree digits") ); | ee digits")); | |||
//m_help.append( "[season;pad];;" + i18n("Inserts the season number in at le ast pad digits") ); | //m_help.append( "[season;pad];;" + i18n("Inserts the season number in at le ast pad digits") ); | |||
//m_help.append( "[episode;pad];;" + i18n("Inserts the episode number in at least pad digits") ); | //m_help.append( "[episode;pad];;" + i18n("Inserts the episode number in at least pad digits") ); | |||
m_name = i18n("SeriesNumber"); | m_name = i18n("SeriesNumber"); | |||
m_icon = "video-television"; | m_icon = "video-television"; | |||
m_comment = i18n("<qt>This plugin can extract information from the filename " | m_comment = i18n("<qt>This plugin can extract information from the filename " | |||
"of a TV series.</qt>"); | "of a TV series.</qt>"); | |||
} | } | |||
SnumPlugin::~SnumPlugin() | SnumPlugin::~SnumPlugin() | |||
{ | { | |||
} | } | |||
QString SnumPlugin::processFile( BatchRenamer* b, int index, const QString & fil enameOrToken, EPluginType eCurrentType ) | QString SnumPlugin::processFile(BatchRenamer *b, int index, const QString &filen ameOrToken, EPluginType eCurrentType) | |||
{ | { | |||
QString src; | QString src; | |||
QString token; | QString token; | |||
// This plugin supports to types | // This plugin supports to types | |||
if( eCurrentType == ePluginType_Token ) | if (eCurrentType == ePluginType_Token) { | |||
{ | ||||
token = filenameOrToken.toLower(); | token = filenameOrToken.toLower(); | |||
if( token == "snum" ) | if (token == "snum") { | |||
{ | src = b->files()->at(index).srcFilename(); | |||
src = b->files()->at( index ).srcFilename(); | ||||
return this->extractnum( src ,0 ); | return this->extractnum(src , 0); | |||
} | } else if (token == "season") { | |||
else if( token == "season" ) | src = b->files()->at(index).srcFilename(); | |||
{ | ||||
src = b->files()->at( index ).srcFilename(); | return this->extractnum(src , 1); | |||
} else if (token == "episode") { | ||||
return this->extractnum( src ,1 ); | src = b->files()->at(index).srcFilename(); | |||
} | ||||
else if( token == "episode" ) | ||||
{ | ||||
src = b->files()->at( index ).srcFilename(); | ||||
return this->extractnum( src ,2 ); | return this->extractnum(src , 2); | |||
} | } | |||
} | } | |||
return QString::null; | return QString(); | |||
} | } | |||
QString SnumPlugin::extractnum(const QString & unicoded, int a) | QString SnumPlugin::extractnum(const QString &unicoded, int a) | |||
{ | { | |||
int pos; | int pos; | |||
QString tmp = ""; | QString tmp = ""; | |||
QString seriesnum = ""; | QString seriesnum = ""; | |||
QString season = ""; | QString season = ""; | |||
QString episode = ""; | QString episode = ""; | |||
QRegExp rx( "(\\d{1,2})[^\\d]{1}(\\d{1,3})" ); | QRegExp rx("(\\d{1,2})[^\\d]{1}(\\d{1,3})"); | |||
pos = 0; | pos = 0; | |||
pos = rx.indexIn( unicoded, pos ); | pos = rx.indexIn(unicoded, pos); | |||
if ( pos > -1 ) { | if (pos > -1) { | |||
season += rx.cap( 1 ); | season += rx.cap(1); | |||
episode += rx.cap( 2 ); | episode += rx.cap(2); | |||
pos += rx.matchedLength(); | pos += rx.matchedLength(); | |||
} | } else { | |||
else | QRegExp px("(\\d{1,2})[^\\d]{2}(\\d{1,3})"); | |||
{ | ||||
QRegExp px( "(\\d{1,2})[^\\d]{2}(\\d{1,3})" ); | ||||
pos = 0; | pos = 0; | |||
pos = px.indexIn( unicoded, pos ); | pos = px.indexIn(unicoded, pos); | |||
if ( pos > -1 ) { | if (pos > -1) { | |||
season += px.cap( 1 ); | season += px.cap(1); | |||
episode += px.cap( 2 ); | episode += px.cap(2); | |||
pos += px.matchedLength(); | pos += px.matchedLength(); | |||
} | } else { | |||
else | QRegExp gx("(\\d{1,2})[^\\d]{0}(\\d{2})"); | |||
{ | ||||
QRegExp gx( "(\\d{1,2})[^\\d]{0}(\\d{2})" ); | ||||
pos = 0; | pos = 0; | |||
pos = gx.indexIn( unicoded, pos ); | pos = gx.indexIn(unicoded, pos); | |||
if ( pos > -1 ) { | if (pos > -1) { | |||
season += gx.cap( 1 ); | season += gx.cap(1); | |||
episode += gx.cap( 2 ); | episode += gx.cap(2); | |||
pos += gx.matchedLength(); | pos += gx.matchedLength(); | |||
} | } | |||
} | } | |||
} | } | |||
if (season.length() == 1) | if (season.length() == 1) { | |||
tmp = '0' + season; | tmp = '0' + season; | |||
else | } else { | |||
tmp = season; | tmp = season; | |||
season=tmp; | } | |||
season = tmp; | ||||
if (episode.length() == 1) | if (episode.length() == 1) { | |||
tmp = '0' + episode; | tmp = '0' + episode; | |||
else | } else { | |||
tmp = episode; | tmp = episode; | |||
episode=tmp; | } | |||
episode = tmp; | ||||
seriesnum += season + 'e' + episode; | seriesnum += season + 'e' + episode; | |||
if (a==0) | if (a == 0) { | |||
return seriesnum; | return seriesnum; | |||
else if (a==1) | } else if (a == 1) { | |||
{ | ||||
return season; | return season; | |||
} | } else { | |||
else | ||||
return episode; | return episode; | |||
} | ||||
} | } | |||
End of changes. 26 change blocks. | ||||
65 lines changed or deleted | 53 lines changed or added |