bool PlaylistImporter::parsePlaylist_wpl(QFile &data, QStringList &fileList, const QDir &baseDir, const QDir &rootDir) { bool foundAtLeastOneFile = false; QRegExp skipData("<!--(.+)-->", Qt::CaseInsensitive); QRegExp wplEntry("<(media|ref)[^<>]*(src|href)=\"([^\"]+)\"[^<>]*>", Qt::CaseInsensitive); skipData.setMinimal(true); QByteArray buffer = data.readAll(); QString line = QString::fromUtf8(buffer.constData(), buffer.size()).simplified(); buffer.clear(); int index = 0; while((index = skipData.indexIn(line)) >= 0) { line.remove(index, skipData.matchedLength()); } int offset = 0; while((offset = wplEntry.indexIn(line, offset) + 1) > 0) { QFileInfo filename(QDir::fromNativeSeparators(unescapeXml(wplEntry.cap(3)).trimmed())); filename.setCaching(false); fixFilePath(filename, baseDir, rootDir); if(filename.exists() && filename.isFile()) { if(isPlaylist(filename.canonicalFilePath()) == notPlaylist) { fileList << filename.canonicalFilePath(); foundAtLeastOneFile = true; } } } return foundAtLeastOneFile; }
void ChangeDirThread::fixMcfUploads(UTIL::FS::Path dest, FileList &list) { dest += UTIL::FS::File("mcf_uploads.sqlite"); sqlite3x::sqlite3_connection db(dest.getFullPath().c_str()); sqlite3x::sqlite3_transaction trans(db); try { sqlite3x::sqlite3_command cmd(db, "SELECT key, file FROM mcfupload;"); sqlite3x::sqlite3_reader reader = cmd.executereader(); while (reader.read()) { std::string id = reader.getstring(0); UTIL::FS::Path file = UTIL::FS::PathWithFile(reader.getstring(1)); UTIL::FS::Path dest = file; fixFilePath(dest); list.push_back(FilePair(file, dest)); try { sqlite3x::sqlite3_command cmd(db, "UPDATE mcfupload SET file=? WHERE key=?;"); cmd.bind(1, dest.getFullPath()); cmd.bind(2, id); cmd.executenonquery(); } catch (std::exception) { } } } catch (std::exception) { } trans.commit(); }
bool PlaylistImporter::parsePlaylist_pls(QFile &data, QStringList &fileList, const QDir &baseDir, const QDir &rootDir) { QRegExp plsEntry("File(\\d+)=(.+)", Qt::CaseInsensitive); const QTextCodec *codec = QTextCodec::codecForName("System"); bool foundAtLeastOneFile = false; data.reset(); while(!data.atEnd()) { QString filePath[3]; QByteArray line = data.readLine(); filePath[0] = QString(QDir::fromNativeSeparators(codec->toUnicode(line.constData(), line.size()).trimmed())); filePath[1] = QString(QDir::fromNativeSeparators(QString::fromLatin1(line.constData(), line.size()).trimmed())); filePath[2] = QString(QDir::fromNativeSeparators(QString::fromUtf8(line.constData(), line.size()).trimmed())); for(size_t i = 0; i < 3; i++) { if(!filePath[i].contains(QChar(QChar::ReplacementCharacter))) { if(plsEntry.indexIn(filePath[i]) >= 0) { QFileInfo filename(QDir::fromNativeSeparators(plsEntry.cap(2)).trimmed()); filename.setCaching(false); fixFilePath(filename, baseDir, rootDir); if(filename.exists() && filename.isFile()) { if(isPlaylist(filename.canonicalFilePath()) == notPlaylist) { fileList << filename.canonicalFilePath(); } foundAtLeastOneFile = true; break; } } } } } //If we did not find any files yet, try UTF-16 now if(!foundAtLeastOneFile) { const char* codecs[2] = {"UTF-16LE", "UTF-16BE"}; for(size_t i = 0; i < 2; i++) { QTextStream stream(&data); stream.setAutoDetectUnicode(false); stream.setCodec(codecs[i]); stream.seek(0i64); while(!stream.atEnd()) { QString filePath = stream.readLine().trimmed(); if(!filePath.contains(QChar(QChar::ReplacementCharacter))) { if(plsEntry.indexIn(filePath) >= 0) { QFileInfo filename(QDir::fromNativeSeparators(plsEntry.cap(2)).trimmed()); filename.setCaching(false); fixFilePath(filename, baseDir, rootDir); if(filename.exists() && filename.isFile()) { if(isPlaylist(filename.canonicalFilePath()) == notPlaylist) { fileList << filename.canonicalFilePath(); } foundAtLeastOneFile = true; } } } } if(foundAtLeastOneFile) break; } } return foundAtLeastOneFile; }
void ChangeDirThread::fixMcfStore(UTIL::FS::Path dest, FileList &list) { dest += UTIL::FS::File("mcfstoreb.sqlite"); sqlite3x::sqlite3_connection db(dest.getFullPath().c_str()); sqlite3x::sqlite3_transaction trans(db); try { sqlite3x::sqlite3_command cmd(db, "SELECT internalid, path FROM mcfitem;"); sqlite3x::sqlite3_reader reader = cmd.executereader(); while (reader.read()) { std::string id = reader.getstring(0); UTIL::FS::Path file = UTIL::FS::PathWithFile(reader.getstring(1)); UTIL::FS::Path dest = file; fixFilePath(dest); list.push_back(FilePair(file, dest)); try { sqlite3x::sqlite3_command cmd(db, "UPDATE mcfitem SET path=? WHERE internalid=?;"); cmd.bind(1, dest.getFullPath()); cmd.bind(2, id); cmd.executenonquery(); } catch (std::exception) { } } } catch (std::exception) { } try { sqlite3x::sqlite3_command cmd(db, "SELECT gid, mid, path FROM mcfbackup;"); sqlite3x::sqlite3_reader reader = cmd.executereader(); while (reader.read()) { std::string gid = reader.getstring(0); std::string mid = reader.getstring(1); UTIL::FS::Path file = UTIL::FS::PathWithFile(reader.getstring(2)); UTIL::FS::Path dest = file; fixFilePath(dest); list.push_back(FilePair(file, dest)); try { sqlite3x::sqlite3_command cmd(db, "UPDATE mcfitem SET path=? WHERE gid=? AND mid=?;"); cmd.bind(1, dest.getFullPath()); cmd.bind(2, gid); cmd.bind(3, mid); cmd.executenonquery(); } catch (std::exception) { } } } catch (std::exception) { } trans.commit(); }
bool PlaylistImporter::parsePlaylist_m3u(QFile &data, QStringList &fileList, const QDir &baseDir, const QDir &rootDir) { const QTextCodec *codec = QTextCodec::codecForName("System"); const bool preferUTF8 = data.fileName().endsWith(".m3u8", Qt::CaseInsensitive); bool foundAtLeastOneFile = false; data.reset(); while(!data.atEnd()) { QString filePath[3]; QByteArray line = data.readLine(); if(preferUTF8) { filePath[0] = QString(QDir::fromNativeSeparators(QString::fromUtf8(line.constData(), line.size()).trimmed())); filePath[1] = QString(QDir::fromNativeSeparators(codec->toUnicode(line.constData(), line.size()).trimmed())); filePath[2] = QString(QDir::fromNativeSeparators(QString::fromLatin1(line.constData(), line.size()).trimmed())); } else { filePath[0] = QString(QDir::fromNativeSeparators(codec->toUnicode(line.constData(), line.size()).trimmed())); filePath[1] = QString(QDir::fromNativeSeparators(QString::fromLatin1(line.constData(), line.size()).trimmed())); filePath[2] = QString(QDir::fromNativeSeparators(QString::fromUtf8(line.constData(), line.size()).trimmed())); } for(size_t i = 0; i < 3; i++) { if(!(filePath[i].isEmpty() || filePath[i].startsWith("#") || filePath[i].contains(QChar(QChar::ReplacementCharacter)))) { QFileInfo filename(filePath[i]); filename.setCaching(false); fixFilePath(filename, baseDir, rootDir); if(filename.exists() && filename.isFile()) { qDebug("Found: \"%s\"", filePath[i].toUtf8().constData()); if(isPlaylist(filename.canonicalFilePath()) == notPlaylist) { fileList << filename.canonicalFilePath(); } foundAtLeastOneFile = true; break; } } } } //If we did not find any files yet, try UTF-16 now if(!foundAtLeastOneFile) { const char* codecs[2] = {"UTF-16LE", "UTF-16BE"}; for(size_t i = 0; i < 2; i++) { QTextStream stream(&data); stream.setAutoDetectUnicode(false); stream.setCodec(codecs[i]); stream.seek(0i64); while(!stream.atEnd()) { QString filePath = stream.readLine().trimmed(); if(!(filePath.isEmpty() || filePath.startsWith("#") || filePath.contains(QChar(QChar::ReplacementCharacter)))) { QFileInfo filename(filePath); filename.setCaching(false); fixFilePath(filename, baseDir, rootDir); if(filename.exists() && filename.isFile()) { if(isPlaylist(filename.canonicalFilePath()) == notPlaylist) { fileList << filename.canonicalFilePath(); } foundAtLeastOneFile = true; } } } if(foundAtLeastOneFile) break; } } return true; }