~ubuntu-branches/ubuntu/karmic/tellico/karmic

« back to all changes in this revision

Viewing changes to src/fetch/imdbfetcher.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Regis Boudin
  • Date: 2008-05-23 21:28:59 UTC
  • mfrom: (0.1.14 upstream) (2.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20080523212859-n0gl4ap37xb0uj1a
Tags: 1.3.2-1
* New upstream release.
* Recommend khelpcenter for acces to the help (Closes: #478975).

Show diffs side-by-side

added added

removed removed

Lines of Context:
346
346
  while(m_started && start > -1) {
347
347
    // split title at parenthesis
348
348
    const QString cap1 = s_anchorTitleRx->cap(1); // the anchor url
349
 
    const QString cap2 = s_anchorTitleRx->cap(2); // the anchor text
 
349
    const QString cap2 = s_anchorTitleRx->cap(2).stripWhiteSpace(); // the anchor text
350
350
    start += s_anchorTitleRx->matchedLength();
351
351
    int pPos = cap2.find('('); // if it has parentheses, use that for description
352
352
    QString desc;
435
435
    bool isEpisode = false;
436
436
    len = s_anchorTitleRx->cap(0).length();
437
437
    // split title at parenthesis
438
 
    const QString cap2 = s_anchorTitleRx->cap(2);
 
438
    const QString cap2 = s_anchorTitleRx->cap(2).stripWhiteSpace();
439
439
    int pPos = cap2.find('(');
440
440
    if(pPos > -1) {
441
441
      desc = cap2.mid(pPos);
507
507
  }
508
508
 
509
509
  // find beginning of partial matches
510
 
  int end = output.find(QString::fromLatin1("Other Results"), KMAX(pos, 0), false);
 
510
  int end = output.find(QString::fromLatin1("Other Results"), QMAX(pos, 0), false);
511
511
  if(end == -1) {
512
 
    end = output.find(QString::fromLatin1("Partial Matches"), KMAX(pos, 0), false);
 
512
    end = output.find(QString::fromLatin1("Partial Matches"), QMAX(pos, 0), false);
513
513
    if(end == -1) {
514
 
      end = output.find(QString::fromLatin1("Approx Matches"), KMAX(pos, 0), false);
 
514
      end = output.find(QString::fromLatin1("Approx Matches"), QMAX(pos, 0), false);
515
515
      if(end == -1) {
516
516
        end = output.length();
517
517
      }
527
527
    pos = s_anchorNameRx->search(output, pos+13);
528
528
    while(pos > -1 && pos < end && m_matches.size() < m_limit) {
529
529
      KURL u(m_url, s_anchorNameRx->cap(1));
530
 
      s = s_anchorNameRx->cap(2) + ' ';
 
530
      s = s_anchorNameRx->cap(2).stripWhiteSpace() + ' ';
531
531
      // if more than one exact, add parentheses
532
532
      if(nameMap.contains(s) && nameMap[s] > 0) {
533
533
        // fix the first one that didn't have a number
551
551
  pos = s_anchorNameRx->search(output, end);
552
552
  while(pos > -1 && m_matches.size() < m_limit) {
553
553
    KURL u(m_url, s_anchorNameRx->cap(1)); // relative URL
554
 
    s = s_anchorNameRx->cap(2);
 
554
    s = s_anchorNameRx->cap(2).stripWhiteSpace();
555
555
    if(nameMap.contains(s) && nameMap[s] > 0) {
556
556
    // fix the first one that didn't have a number
557
557
      if(nameMap[s] == 1) {
671
671
 
672
672
  doTitle(str_, entry);
673
673
  doRunningTime(str_, entry);
 
674
  doAspectRatio(str_, entry);
674
675
  doAlsoKnownAs(str_, entry);
675
676
  doPlot(str_, entry, m_url);
676
677
  doLists(str_, entry);
730
731
  }
731
732
}
732
733
 
 
734
void IMDBFetcher::doAspectRatio(const QString& str_, Data::EntryPtr entry_) {
 
735
  QRegExp rx(QString::fromLatin1("aspect ratio:.*([\\d\\.]+\\s*:\\s*[\\d\\.]+)"), false);
 
736
  rx.setMinimal(true);
 
737
 
 
738
  if(rx.search(str_) > -1) {
 
739
//    myDebug() << "aspect ratio = " << rx.cap(1) << endl;
 
740
    entry_->setField(QString::fromLatin1("aspect-ratio"), rx.cap(1).stripWhiteSpace());
 
741
  }
 
742
}
 
743
 
733
744
void IMDBFetcher::doAlsoKnownAs(const QString& str_, Data::EntryPtr entry_) {
734
745
  if(m_fields.findIndex(QString::fromLatin1("alttitle")) == -1) {
735
746
    return;
831
842
  divRx.setMinimal(true);
832
843
  QString name = QString::fromLatin1("/name/");
833
844
 
834
 
  QStringList people;
 
845
  StringSet people;
835
846
  for(int pos = str_.find(imdbHeader_); pos > 0; pos = str_.find(imdbHeader_, pos)) {
836
847
    // loop until repeated <br> tags or </div> tag
837
848
    const int endPos1 = str_.find(br2Rx, pos);
840
851
    pos = s_anchorRx->search(str_, pos+1);
841
852
    while(pos > -1 && pos < endPos) {
842
853
      if(s_anchorRx->cap(1).find(name) > -1) {
843
 
        people += s_anchorRx->cap(2);
 
854
        people.add(s_anchorRx->cap(2).stripWhiteSpace());
844
855
      }
845
856
      pos = s_anchorRx->search(str_, pos+1);
846
857
    }
847
858
  }
848
859
  if(!people.isEmpty()) {
849
 
    entry_->setField(fieldName_, people.join(sep));
 
860
    entry_->setField(fieldName_, people.toList().join(sep));
850
861
  }
851
862
}
852
863
 
918
929
      // there's a column with ellipses then the character
919
930
      const int pos2 = tdRx.search(castText, pos);
920
931
      if(pos2 > -1 && tdRx.search(castText, pos2+1) > -1) {
921
 
        cast += s_anchorRx->cap(2) + QString::fromLatin1("::") + tdRx.cap(1).simplifyWhiteSpace().remove(*s_tagRx);
 
932
        cast += s_anchorRx->cap(2).stripWhiteSpace()
 
933
              + QString::fromLatin1("::") + tdRx.cap(1).simplifyWhiteSpace().remove(*s_tagRx);
922
934
      } else {
923
 
        cast += s_anchorRx->cap(2);
 
935
        cast += s_anchorRx->cap(2).stripWhiteSpace();
924
936
      }
925
937
    }
926
938
    pos = s_anchorRx->search(castText, pos+1);
1006
1018
  const QString cert = QString::fromLatin1("certificates=");
1007
1019
  const QString soundMix = QString::fromLatin1("sound-mix=");
1008
1020
  const QString year = QString::fromLatin1("/Years/");
 
1021
  const QString company = QString::fromLatin1("/company/");
1009
1022
 
1010
1023
  // IIMdb also has links with the word "sections" in them, remove that
1011
1024
  // for genres and nationalities
1012
1025
 
1013
 
  QStringList genres, countries, langs, certs, tracks;
 
1026
  QStringList genres, countries, langs, certs, tracks, studios;
1014
1027
  for(int pos = s_anchorRx->search(str_); pos > -1; pos = s_anchorRx->search(str_, pos+1)) {
1015
1028
    const QString cap1 = s_anchorRx->cap(1);
1016
1029
    if(cap1.find(genre) > -1) {
1017
1030
      if(s_anchorRx->cap(2).find(QString::fromLatin1(" section"), 0, false) == -1) {
1018
 
        genres += s_anchorRx->cap(2);
 
1031
        genres += s_anchorRx->cap(2).stripWhiteSpace();
1019
1032
      }
1020
1033
    } else if(cap1.find(country) > -1) {
1021
1034
      if(s_anchorRx->cap(2).find(QString::fromLatin1(" section"), 0, false) == -1) {
1022
 
        countries += s_anchorRx->cap(2);
 
1035
        countries += s_anchorRx->cap(2).stripWhiteSpace();
1023
1036
      }
1024
1037
    } else if(cap1.find(lang) > -1) {
1025
 
      langs += s_anchorRx->cap(2);
 
1038
      langs += s_anchorRx->cap(2).stripWhiteSpace();
1026
1039
    } else if(cap1.find(colorInfo) > -1) {
1027
1040
      // change "black and white" to "black & white"
1028
1041
      entry_->setField(QString::fromLatin1("color"),
1029
 
                       s_anchorRx->cap(2).replace(QString::fromLatin1("and"), QChar('&')));
 
1042
                       s_anchorRx->cap(2).replace(QString::fromLatin1("and"), QChar('&')).stripWhiteSpace());
1030
1043
    } else if(cap1.find(cert) > -1) {
1031
 
      certs += s_anchorRx->cap(2);
 
1044
      certs += s_anchorRx->cap(2).stripWhiteSpace();
1032
1045
    } else if(cap1.find(soundMix) > -1) {
1033
 
      tracks += s_anchorRx->cap(2);
 
1046
      tracks += s_anchorRx->cap(2).stripWhiteSpace();
 
1047
    } else if(cap1.find(company) > -1) {
 
1048
      studios += s_anchorRx->cap(2).stripWhiteSpace();
1034
1049
      // if year field wasn't set before, do it now
1035
1050
    } else if(entry_->field(QString::fromLatin1("year")).isEmpty() && cap1.find(year) > -1) {
1036
 
      entry_->setField(QString::fromLatin1("year"), s_anchorRx->cap(2));
 
1051
      entry_->setField(QString::fromLatin1("year"), s_anchorRx->cap(2).stripWhiteSpace());
1037
1052
    }
1038
1053
  }
1039
1054
 
1041
1056
  entry_->setField(QString::fromLatin1("nationality"), countries.join(sep));
1042
1057
  entry_->setField(QString::fromLatin1("language"), langs.join(sep));
1043
1058
  entry_->setField(QString::fromLatin1("audio-track"), tracks.join(sep));
 
1059
  entry_->setField(QString::fromLatin1("studio"), studios.join(sep));
1044
1060
  if(!certs.isEmpty()) {
1045
1061
    // first try to set default certification
1046
1062
    const QStringList& certsAllowed = entry_->collection()->fieldByName(QString::fromLatin1("certification"))->allowed();