/** * @brief moves all movies in given path to seperate directories * @param path place to organize */ void MovieFilesOrganizer::moveToDirs(QString path) { path = QDir::toNativeSeparators(path); QFileInfo fi(path); if (!fi.isDir()) { canceled(tr("Source %1 is no directory").arg(path)); } QList<QStringList> contents; MovieFileSearcher *fileSearcher = new MovieFileSearcher(this); fileSearcher->scanDir(path, contents, false, true); fileSearcher->deleteLater(); int pos = path.lastIndexOf(QDir::separator()); QString dirName = path.right(path.length() - pos -1); QString fileName; NameFormatter *nameFormat = NameFormatter::instance(this); foreach (QStringList movie, contents) { int pos = movie.at(0).lastIndexOf(QDir::separator()); if (!(movie.at(0).left(pos).endsWith(dirName))) { qDebug() << "skipping " << movie.at(0); continue; } fi.setFile(movie.at(0)); fileName = fi.completeBaseName(); QDir *dir = new QDir(); QString newFolder; if (movie.length() == 1) newFolder = path + QDir::separator() + nameFormat->formatName(fileName); else if (movie.length() > 1) newFolder = path + QDir::separator() + nameFormat->formatName( nameFormat->formatParts(fileName)); else continue; if (!(dir->mkdir(newFolder))) continue; foreach (QString file, movie) { if (!dir->rename(file, newFolder + QDir::separator() + file.right(file.length() - file.lastIndexOf (QDir::separator()) - 1))) qDebug() << "Moving " << file << "to " << newFolder << " failed."; } }
/** * @brief Loads the movies infos with the given MediaCenterInterface * @param mediaCenterInterface MediaCenterInterface to use for loading * @param force Force the loading. If set to false and infos were already loeaded this function just returns * @return Loading was successful or not */ bool MovieController::loadData(MediaCenterInterface *mediaCenterInterface, bool force, bool reloadFromNfo) { if ((m_infoLoaded || m_movie->hasChanged()) && !force && (m_infoFromNfoLoaded || (m_movie->hasChanged() && !m_infoFromNfoLoaded) )) return m_infoLoaded; NameFormatter *nameFormat = NameFormatter::instance(); bool infoLoaded; if (reloadFromNfo) infoLoaded = mediaCenterInterface->loadMovie(m_movie); else infoLoaded = mediaCenterInterface->loadMovie(m_movie, m_movie->nfoContent()); if (!infoLoaded) { if (m_movie->files().size() > 0) { QFileInfo fi(m_movie->files().at(0)); if (QString::compare(fi.fileName(), "VIDEO_TS.IFO", Qt::CaseInsensitive) == 0) { QStringList pathElements = QDir::toNativeSeparators(fi.path()).split(QDir::separator()); if (pathElements.size() > 0 && QString::compare(pathElements.last(), "VIDEO_TS", Qt::CaseInsensitive) == 0) pathElements.removeLast(); if (pathElements.size() > 0) m_movie->setName(nameFormat->formatName(pathElements.last())); } else if (QString::compare(fi.fileName(), "index.bdmv", Qt::CaseInsensitive) == 0) { QStringList pathElements = QDir::toNativeSeparators(fi.path()).split(QDir::separator()); if (pathElements.size() > 0 && QString::compare(pathElements.last(), "BDMV", Qt::CaseInsensitive) == 0) pathElements.removeLast(); if (pathElements.size() > 0) m_movie->setName(nameFormat->formatName(pathElements.last())); } else if (m_movie->inSeparateFolder()) { QStringList splitted = QDir::toNativeSeparators(fi.path()).split(QDir::separator()); if (!splitted.isEmpty()) { m_movie->setName(nameFormat->formatName(splitted.last())); } else { if (m_movie->files().size() > 1) m_movie->setName(nameFormat->formatName( nameFormat->formatParts(fi.completeBaseName()))); else m_movie->setName(nameFormat->formatName(fi.completeBaseName())); } } else { if (m_movie->files().size() > 1) m_movie->setName(nameFormat->formatName( nameFormat->formatParts(fi.completeBaseName()))); else m_movie->setName(nameFormat->formatName(fi.completeBaseName())); } } } m_infoLoaded = infoLoaded; m_infoFromNfoLoaded = infoLoaded && reloadFromNfo; m_movie->setChanged(false); return infoLoaded; }