96
97
return type == Data::Collection::Video;
99
void IMDBFetcher::readConfigHook(KConfig* config_, const QString& group_) {
100
KConfigGroupSaver groupSaver(config_, group_);
101
QString h = config_->readEntry("Host");
100
void IMDBFetcher::readConfigHook(const KConfigGroup& config_) {
101
QString h = config_.readEntry("Host");
102
102
if(!h.isEmpty()) {
105
m_numCast = config_->readNumEntry("Max Cast", 10);
106
m_fetchImages = config_->readBoolEntry("Fetch Images", true);
107
m_fields = config_->readListEntry("Custom Fields");
105
m_numCast = config_.readNumEntry("Max Cast", 10);
106
m_fetchImages = config_.readBoolEntry("Fetch Images", true);
107
m_fields = config_.readListEntry("Custom Fields");
110
110
// multiple values not supported
674
674
doAlsoKnownAs(str_, entry);
675
675
doPlot(str_, entry, m_url);
676
676
doLists(str_, entry);
677
doPerson(str_, entry, QString::fromLatin1("Direct"), QString::fromLatin1("director"));
678
doPerson(str_, entry, QString::fromLatin1("Writ"), QString::fromLatin1("writer"));
677
doPerson(str_, entry, QString::fromLatin1("Director"), QString::fromLatin1("director"));
678
doPerson(str_, entry, QString::fromLatin1("Writer"), QString::fromLatin1("writer"));
679
679
doRating(str_, entry);
680
680
doCast(str_, entry, m_url);
681
681
if(m_fetchImages) {
701
701
const QString cap1 = s_titleRx->cap(1);
702
702
// titles always have parentheses
703
703
int pPos = cap1.find('(');
704
entry_->setField(QString::fromLatin1("title"), cap1.left(pPos).stripWhiteSpace());
704
QString title = cap1.left(pPos).stripWhiteSpace();
705
// remove first and last quotes is there
706
if(title.startsWith(QChar('"')) && title.endsWith(QChar('"'))) {
707
title = title.mid(1, title.length()-2);
709
entry_->setField(QString::fromLatin1("title"), title);
705
710
// remove parenthesis
706
711
uint pPos2 = pPos+1;
707
712
while(pPos2 < cap1.length() && cap1[pPos2].isDigit()) {
821
826
void IMDBFetcher::doPerson(const QString& str_, Data::EntryPtr entry_,
822
827
const QString& imdbHeader_, const QString& fieldName_) {
823
int pos = str_.find(imdbHeader_);
828
QRegExp br2Rx(QString::fromLatin1("<br[\\s/]*>\\s*<br[\\s/]*>"), false);
829
br2Rx.setMinimal(true);
830
QRegExp divRx(QString::fromLatin1("<[/]*div"), false);
831
divRx.setMinimal(true);
832
QString name = QString::fromLatin1("/name/");
835
for(int pos = str_.find(imdbHeader_); pos > 0; pos = str_.find(imdbHeader_, pos)) {
826
836
// loop until repeated <br> tags or </div> tag
827
QRegExp br2Rx(QString::fromLatin1("<br[\\s/]*>\\s*<br[\\s/]*>"), false);
828
br2Rx.setMinimal(true);
829
QRegExp divRx(QString::fromLatin1("<[/]*div"), false);
830
divRx.setMinimal(true);
832
const QString name = QString::fromLatin1("/name/");
833
837
const int endPos1 = str_.find(br2Rx, pos);
834
838
const int endPos2 = str_.find(divRx, pos);
835
839
const int endPos = QMIN(endPos1, endPos2); // ok to be -1
862
866
// be quiet about failure and be sure to translate entities
863
867
QString castPage = Tellico::decodeHTML(FileHandler::readTextFile(castURL, true));
866
870
// the text to search, depends on which page is being read
867
871
QString castText = castPage;
868
if(!castText.isEmpty()) {
869
// fragile, the word "cast" appears in the title, but need to find
870
// the one right above the actual cast table
871
// for TV shows, there's a link on the sidebar for "episodes case"
872
// so need to not match that one
873
pos = castText.find(QString::fromLatin1("cast</"), 0, false);
876
if(castText.mid(pos-9, 9).startsWith(QString::fromLatin1("episodes"))) {
877
// find next cast list
878
pos = castText.find(QString::fromLatin1("cast</"), pos+6, false);
881
} else { // fall back to short list
882
pos = str_.find(QString::fromLatin1("cast overview"), 0, false);
872
if(castText.isEmpty()) {
873
// fall back to short list
875
pos = castText.find(QString::fromLatin1("cast overview"), 0, false);
884
pos = str_.find(QString::fromLatin1("credited cast"), 0, false);
877
pos = castText.find(QString::fromLatin1("credited cast"), 0, false);
880
// first look for anchor
881
QRegExp castAnchorRx(QString::fromLatin1("<a\\s+name\\s*=\\s*\"cast\""), false);
882
pos = castText.find(castAnchorRx);
884
QRegExp tableClassRx(QString::fromLatin1("<table\\s+class\\s*=\\s*\"cast\""), false);
885
pos = castText.find(tableClassRx);
887
// fragile, the word "cast" appears in the title, but need to find
888
// the one right above the actual cast table
889
// for TV shows, there's a link on the sidebar for "episodes case"
890
// so need to not match that one
891
pos = castText.find(QString::fromLatin1("cast</"), 0, false);
894
if(castText.mid(pos-9, 9).startsWith(QString::fromLatin1("episodes"))) {
895
// find next cast list
896
pos = castText.find(QString::fromLatin1("cast</"), pos+6, false);
888
902
if(pos == -1) { // no cast list found
903
myDebug() << "IMDBFetcher::doCast() - no cast list found" << endl;
1151
void IMDBFetcher::ConfigWidget::saveConfig(KConfig* config_) {
1166
void IMDBFetcher::ConfigWidget::saveConfig(KConfigGroup& config_) {
1152
1167
QString host = m_hostEdit->text().stripWhiteSpace();
1153
1168
if(!host.isEmpty()) {
1154
config_->writeEntry("Host", host);
1169
config_.writeEntry("Host", host);
1156
config_->writeEntry("Max Cast", m_numCast->value());
1157
config_->writeEntry("Fetch Images", m_fetchImageCheck->isChecked());
1171
config_.writeEntry("Max Cast", m_numCast->value());
1172
config_.writeEntry("Fetch Images", m_fetchImageCheck->isChecked());
1159
1174
saveFieldsConfig(config_);
1160
1175
slotSetModified(false);