Ticket #5191: eitfixup1.patch
File eitfixup1.patch, 8.2 KB (added by , 16 years ago) |
---|
-
libs/libmythtv/eitfixup.cpp
21 21 m_ukNew("(New\\.|\\s*(Brand New|New)\\s*(Series|Episode)\\s*[:\\.\\-])",false), 22 22 m_ukCEPQ("[:\\!\\.\\?]"), 23 23 m_ukColonPeriod("[:\\.]"), 24 m_ukDotSpaceStart("^ \\."),24 m_ukDotSpaceStart("^(?:\\. | )"), 25 25 m_ukDotEnd("\\.$"), 26 26 m_ukSpaceColonStart("^[ |:]*"), 27 27 m_ukSpaceStart("^ "), … … 41 41 m_ukYearColon("^[\\d]{4}:"), 42 42 m_ukExclusionFromSubtitle("(starring|stars\\s|drama|series|sitcom)",false), 43 43 m_ukCompleteDots("^\\.\\.+$"), 44 m_uk5xNumberHyphen3xNumber("\\d\\d\\d\\d\\d-\\d\\d\\d [A-Z]"), 44 45 m_comHemCountry("^(\\(.+\\))?\\s?([^ ]+)\\s([^\\.0-9]+)" 45 46 "(?:\\sfrån\\s([0-9]{4}))(?:\\smed\\s([^\\.]+))?\\.?"), 46 47 m_comHemDirector("[Rr]egi"), … … 300 301 */ 301 302 void EITFixUp::SetUKSubtitle(DBEvent &event) const 302 303 { 304 if (!event.subtitle.isEmpty()) 305 return; 306 303 307 QStringList strListColon = QStringList::split(":",event.description,TRUE); 304 308 QStringList strListEnd; 305 309 … … 325 329 QString strTmp = event.description.mid(nPosition1+1, 326 330 nLength-nPosition1); 327 331 328 if (QStringList::split(" ", strTmp ,TRUE).count()< 332 if (QStringList::split(" ", strTmp ,TRUE).count()<=kMaxDotToColon) 329 333 fSingleDot = false; 330 334 } 331 335 … … 336 340 } 337 341 else if (!fSingleDot) 338 342 { 339 QStringList strListTmp;340 uint nTitle=0;341 int n TitleMax=-1;343 int nCount=strListColon.count(); 344 int nMaxLength=0; 345 int nMaxTitle=0; 342 346 int i; 343 for (i =0; (i<(int)strListColon.count()) && (nTitleMax==-1);i++)347 for (i=0;i<(nCount-1);i++) 344 348 { 345 if ((nTitle+= 346 QStringList::split(" ",strListColon[i],TRUE).count()) 347 <kMaxToTitle) 348 strListTmp.push_back(strListColon[i]); 349 else 350 nTitleMax=i; 349 QString strTmp = strListColon[i+1].stripWhiteSpace(); 350 QChar aLetter = strTmp.at(0); 351 QChar bLetter = aLetter.lower(); 352 uint nTmp= 353 QStringList::split(" ",strListColon[i],FALSE).count(); 354 if ((nMaxLength+nTmp > kMaxToTitle) || (aLetter==bLetter)) 355 break; 356 nMaxLength = nMaxLength+nTmp; 357 nMaxTitle = i; 351 358 } 352 QString strPartial; 353 for (i=0;i<(nTitleMax-1);i++) 354 strPartial+=strListTmp[i]+":"; 355 if (nTitleMax>0) 359 if (nMaxLength) 356 360 { 357 strPartial+=strListTmp[nTitleMax-1]; 361 QString strPartial; 362 for (i=0;i<=nMaxTitle;i++) 363 { 364 strPartial+=strListColon[i]; 365 if (i<(nMaxTitle)) 366 strPartial+=":"; 367 } 358 368 strListEnd.push_back(strPartial); 359 }360 for (i=nTitleMax+1;i<(int)strListColon.count();i++)361 strListEnd.push_back(strListColon[i]);362 fColon = true;369 for (i=(nMaxTitle+1);i<nCount;i++) 370 strListEnd.push_back(strListColon[i]); 371 fColon=true; 372 } 363 373 } 364 374 } 365 375 QStringList strListPeriod; … … 367 377 QStringList strListExcl; 368 378 if (!fColon) 369 379 { 380 int nLength=INT_MAX; 370 381 strListPeriod = QStringList::split(".",event.description,TRUE); 382 strListQuestion = QStringList::split("?",event.description,TRUE); 383 strListExcl = QStringList::split("!",event.description,TRUE); 384 371 385 if (strListPeriod.count() >1) 372 386 { 373 387 nPosition1 = event.description.find("."); 374 388 int nPosition2 = event.description.find(".."); 375 389 if ((nPosition1 < nPosition2) || (nPosition2==-1)) 390 { 391 nLength = strListPeriod[0].length(); 376 392 strListEnd = strListPeriod; 393 } 377 394 } 378 395 379 strListQuestion = QStringList::split("?",event.description,TRUE);380 strListExcl = QStringList::split("!",event.description,TRUE);381 396 if ((strListQuestion.count()>1) && 382 (strListQuestion.count()<=kMaxQuestionExclamation)) 397 (strListQuestion.count()<=kMaxQuestionExclamation) && 398 ((int)(strListQuestion[0].length())<nLength)) 383 399 { 384 400 strListEnd = strListQuestion; 385 401 strEnd = "?"; 386 402 } 387 403 else if ((strListExcl.count()>1) && 388 (strListExcl.count()<=kMaxQuestionExclamation)) 404 (strListExcl.count()<=kMaxQuestionExclamation) && 405 ((int)(strListExcl[0].length())<nLength)) 389 406 { 390 407 strListEnd = strListExcl; 391 408 strEnd = "!"; … … 397 414 if (strListEnd.count()) 398 415 { 399 416 QStringList strListSpace = QStringList::split(" ",strListEnd[0]); 400 if ( fColon && (strListSpace.count() > kMaxToTitle))417 if (strListSpace.count() > kMaxToTitle) 401 418 return; 402 if (strListSpace.count() > kDotToTitle) 403 return; 419 404 420 if (strListSpace.grep(m_ukExclusionFromSubtitle).count()==0) 405 421 { 406 422 event.subtitle = strListEnd[0]+strEnd; … … 492 508 } 493 509 494 510 QRegExp tmp24ep = m_uk24ep; 495 if (!event.title.startsWith("CSI:") && !event.title.startsWith("CD:")) 511 if (!event.title.startsWith("CSI:") && 512 !event.title.startsWith("Law & Order:") && 513 !event.title.startsWith("CD:")) 496 514 { 497 515 if (((position1=event.title.find(m_ukDoubleDotEnd)) != -1) && 498 516 ((position2=event.description.find(m_ukDoubleDotStart)) != -1)) … … 580 598 } 581 599 else 582 600 SetUKSubtitle(event); 601 /* 602 if (event.subtitle.isEmpty() && 603 (position1=event.description.find(m_uk5xNumberHyphen3xNumber)) && 604 (position1 >0) && ((uint)position1<SUBTITLE_MAX_LEN)) 605 { 606 event.subtitle = event.description.left(position1+9); 607 event.description = event.description.mid(position1+9); 608 } 609 */ 583 610 } 584 611 585 612 // Work out the year (if any) … … 597 624 } 598 625 599 626 // Trim leading/trailing '.' 627 event.description.remove(m_ukDotSpaceStart); 600 628 event.subtitle.remove(m_ukDotSpaceStart); 601 629 if (event.subtitle.findRev("..") != (((int)event.subtitle.length())-2)) 602 630 event.subtitle.remove(m_ukDotEnd); 603 631 632 // Demote the subtitle if it matches the title 633 if (!event.title.isEmpty() && !event.subtitle.isEmpty() && 634 event.title == event.subtitle) 635 { 636 event.description=event.subtitle+" "+event.description; 637 event.subtitle=QString::null; 638 } 639 604 640 // Reverse the subtitle and empty description 605 641 if (event.description.isEmpty() && !event.subtitle.isEmpty()) 606 642 { -
libs/libmythtv/eitfixup.h
18 18 // max length of subtitle field in db. 19 19 static const uint SUBTITLE_MAX_LEN = 128; 20 20 // max number of words included in a subtitle 21 static const uint kMaxToTitle = 14; 22 // max number of words up to a period, question mark 23 static const uint kDotToTitle = 9; 21 static const uint kMaxToTitle = 10; 24 22 // max number of question/exclamation marks 25 23 static const uint kMaxQuestionExclamation = 2; 26 24 // max number of difference in words between a period and a colon 27 static const uint kMaxDotToColon = 5;25 static const uint kMaxDotToColon = 6; 28 26 29 27 public: 30 28 enum FixUpType … … 108 106 const QRegExp m_ukYearColon; 109 107 const QRegExp m_ukExclusionFromSubtitle; 110 108 const QRegExp m_ukCompleteDots; 109 const QRegExp m_uk5xNumberHyphen3xNumber; 111 110 const QRegExp m_comHemCountry; 112 111 const QRegExp m_comHemDirector; 113 112 const QRegExp m_comHemActor;