Ticket #2925: mythmusic-filenames-20070115.patch
File mythmusic-filenames-20070115.patch, 7.3 KB (added by , 17 years ago) |
---|
-
configure
7 7 # default parameters for all plugins 8 8 # 9 9 10 prefix="/usr/ local"10 prefix="/usr/" 11 11 libdir_name="lib" 12 12 13 13 music="yes" -
mythmusic/mythmusic/cdrip.h
40 40 private: 41 41 int ripTrack(QString &cddevice, Encoder *encoder, int tracknum); 42 42 static QString fixFileToken(QString token); 43 static QString fixFileToken_sl(QString token); 43 44 void handleFileTokens(QString &filename, Metadata *track); 44 45 void ejectCD(QString &cddev); 45 46 bool isNewTune(QString &artist, QString &album, QString &title); -
mythmusic/mythmusic/globalsettings.cpp
198 198 gc->setValue("ARTIST/ALBUM/TRACK-TITLE"); // Don't translate 199 199 gc->setHelpText(QObject::tr("Defines the location/name for new songs. " 200 200 "Valid tokens are: GENRE, ARTIST, ALBUM, " 201 "TRACK, TITLE, YEAR, / and -. '-' will be replaced " 202 "by the Token separator")); 201 "TRACK, TITLE, YEAR")); 203 202 return gc; 204 203 }; 205 204 205 /* 206 206 static HostLineEdit *TagSeparator() 207 207 { 208 208 HostLineEdit *gc = new HostLineEdit("TagSeparator"); … … 212 212 "this string.")); 213 213 return gc; 214 214 }; 215 */ 215 216 216 217 static HostCheckBox *NoWhitespace() 217 218 { … … 578 579 rippersettings->setLabel(QObject::tr("CD Ripper Settings")); 579 580 rippersettings->addChild(ParanoiaLevel()); 580 581 rippersettings->addChild(FilenameTemplate()); 581 rippersettings->addChild(TagSeparator());582 //rippersettings->addChild(TagSeparator()); 582 583 rippersettings->addChild(NoWhitespace()); 583 584 rippersettings->addChild(PostCDRipScript()); 584 585 rippersettings->addChild(EjectCD()); -
mythmusic/mythmusic/cdrip.cpp
531 531 532 532 void Ripper::handleFileTokens(QString &filename, Metadata *track) 533 533 { 534 QString original = filename; 535 534 QString musicdir = filename; 535 QDir directoryQD(musicdir); 536 filename = ""; 536 537 QString fntempl = gContext->GetSetting("FilenameTemplate"); 537 538 bool no_ws = gContext->GetNumSetting("NoWhitespace", 0); 538 539 539 540 QRegExp rx_ws("\\s{1,}"); 540 QRegExp rx("(?:\\s?)(GENRE|ARTIST|ALBUM|TRACK|TITLE|YEAR)(?:\\s?)/"); 541 541 QRegExp rx("(GENRE|ARTIST|ALBUM|TRACK|TITLE|YEAR)"); 542 542 int i = 0; 543 int old_i = 0; 543 544 while (i >= 0) 544 545 { 545 546 i = rx.search(fntempl, i); 546 547 if (i >= 0) 547 548 { 549 if (i>0) filename += fixFileToken_sl(fntempl.mid(old_i,i-old_i)); 548 550 i += rx.matchedLength(); 551 old_i = i; 549 552 if ((rx.capturedTexts()[1] == "GENRE") && (track->Genre() != "")) 550 filename += fixFileToken(track->Genre()) + "/";553 filename += fixFileToken(track->Genre()); 551 554 if ((rx.capturedTexts()[1] == "ARTIST") && (track->FormatArtist() != "")) 552 filename += fixFileToken(track->FormatArtist()) + "/";555 filename += fixFileToken(track->FormatArtist()); 553 556 if ((rx.capturedTexts()[1] == "ALBUM") && (track->Album() != "")) 554 filename += fixFileToken(track->Album()) + "/";557 filename += fixFileToken(track->Album()); 555 558 if ((rx.capturedTexts()[1] == "TRACK") && (track->Track() >= 0)) 556 filename += fixFileToken(QString::number(track->Track(), 10)) + "/"; 559 { 560 QString tempstr = QString::number(track->Track(), 10); 561 if (track->Track() < 10) 562 tempstr.prepend('0'); 563 filename += fixFileToken(tempstr); 564 } 557 565 if ((rx.capturedTexts()[1] == "TITLE") && (track->FormatTitle() != "")) 558 filename += fixFileToken(track->FormatTitle()) + "/"; 559 if ((rx.capturedTexts()[1] == "YEAR") && (track->Year() >= 0)) 560 filename += fixFileToken(QString::number(track->Year(), 10)) + "/"; 561 562 if (no_ws) 563 filename.replace(rx_ws, "_"); 564 565 mkdir(filename.local8Bit(), 0775); 566 } 566 filename += fixFileToken(track->FormatTitle()); 567 if ((rx.capturedTexts()[1] == "YEAR") && (track->Year() > 0)) 568 filename += fixFileToken(QString::number(track->Year(), 10)); 569 } 567 570 } 568 569 // remove the dir part and other cruft 570 fntempl.replace(QRegExp("(.*/)|\\s*"), ""); 571 QString tagsep = gContext->GetSetting("TagSeparator"); 572 QStringList tokens = QStringList::split("-", fntempl); 573 QStringList fileparts; 574 QString filepart; 575 576 for (unsigned i = 0; i < tokens.size(); i++) 571 if (no_ws) 572 filename.replace(rx_ws, "_"); 573 if (filename == musicdir || filename.length() > FILENAME_MAX) 577 574 { 578 if ((tokens[i] == "GENRE") && (track->Genre() != ""))579 fileparts += track->Genre();580 else if ((tokens[i] == "ARTIST") && (track->FormatArtist() != ""))581 fileparts += track->FormatArtist();582 else if ((tokens[i] == "ALBUM") && (track->Album() != ""))583 fileparts += track->Album();584 else if ((tokens[i] == "TRACK") && (track->Track() >= 0))585 {586 QString tempstr = QString::number(track->Track(), 10);587 if (track->Track() < 10)588 tempstr.prepend('0');589 fileparts += tempstr;590 }591 else if ((tokens[i] == "TITLE") && (track->FormatTitle() != ""))592 fileparts += track->FormatTitle();593 else if ((tokens[i] == "YEAR") && (track->Year() >= 0))594 fileparts += QString::number(track->Year(), 10);595 }596 597 filepart = fileparts.join( tagsep );598 filename += fixFileToken(filepart);599 600 if (filename == original || filename.length() > FILENAME_MAX)601 {602 575 QString tempstr = QString::number(track->Track(), 10); 603 576 tempstr += " - " + track->FormatTitle(); 604 filename +=fixFileToken(tempstr);577 filename = musicdir + fixFileToken(tempstr); 605 578 VERBOSE(VB_GENERAL, QString("Invalid file storage definition.")); 606 579 } 607 608 if (no_ws) 609 filename.replace(rx_ws, "_"); 580 filename=filename.local8Bit(); 581 582 QStringList directoryList = QStringList::split("/", filename); 583 for (unsigned i = 0; i < (directoryList.size()-1); i++) 584 { 585 musicdir += "/" + directoryList[i]; 586 umask(022); 587 directoryQD.mkdir(musicdir,TRUE); 588 directoryQD.cd(musicdir,TRUE); 589 } 590 filename=directoryQD.absPath()+"/"+directoryList.last(); 610 591 } 611 592 612 593 inline QString Ripper::fixFileToken(QString token) … … 615 596 return token; 616 597 } 617 598 599 inline QString Ripper::fixFileToken_sl(QString token) 600 { 601 // this version doesn't remove fwd-slashes so we can pick them up later and create directories as required 602 token.replace(QRegExp("(\\\\|:|\'|\"|\\?|\\|)"), QString("_")); 603 return token; 604 } 605 618 606 void Ripper::reject() 619 607 { 620 608 QString cddevice = gContext->GetSetting("CDDevice");