int deletePlaylist(FILE * fp, char * utf8file) { char * file = utf8ToFsCharset(utf8file); char * rfile = malloc(strlen(file)+strlen(".")+ strlen(PLAYLIST_FILE_SUFFIX)+1); char * actualFile; strcpy(rfile,file); strcat(rfile,"."); strcat(rfile,PLAYLIST_FILE_SUFFIX); if((actualFile = rpp2app(rfile)) && isPlaylist(actualFile)) free(rfile); else { free(rfile); commandError(fp, ACK_ERROR_NO_EXIST, "playlist \"%s\" not found", utf8file); return -1; } if(unlink(actualFile)<0) { commandError(fp, ACK_ERROR_SYSTEM, "problems deleting file", NULL); return -1; } return 0; }
bool PlaylistImporter::importPlaylist(QStringList &fileList, const QString &playlistFile) { QFileInfo file(playlistFile); QDir baseDir(file.canonicalPath()); QDir rootDir(baseDir); while(rootDir.cdUp()); //Sanity check if(file.size() < 3 || file.size() > 512000) { return false; } //Detect playlist type playlist_t playlistType = isPlaylist(file.canonicalFilePath()); //Exit if not a playlist if(playlistType == notPlaylist) { return false; } QFile data(playlistFile); //Open file for reading if(!data.open(QIODevice::ReadOnly)) { return false; } //Skip very large files (parsing could take very long) if(data.size() >= 10485760i64) { qWarning("File is very big. Probably not a Playlist. Rejecting..."); return false; } //Parse playlist depending on type switch(playlistType) { case m3uPlaylist: return parsePlaylist_m3u(data, fileList, baseDir, rootDir); break; case plsPlaylist: return parsePlaylist_pls(data, fileList, baseDir, rootDir); break; case wplPlaylist: return parsePlaylist_wpl(data, fileList, baseDir, rootDir); break; default: return false; break; } }
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; }
int Controller::open(Mlt::Producer* producer, bool) { int error = 0; if (producer != m_producer) close(); if (producer && producer->is_valid()) { m_producer = producer; // In some versions of MLT, the resource property is the XML filename, // but the Mlt::Producer(Service&) constructor will fail unless it detects // the type as playlist, and mlt_service_identify() needs the resource // property to say "<playlist>" to identify it as playlist type. if (isPlaylist()) m_producer->set("resource", "<playlist>"); } else { // Cleanup on error error = 1; delete producer; } return error; }
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; }
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; }
int QMplayer::scanDir(QString const& path, int level, int maxLevel, int min, int max, bool followSymLinks) { if(abort) { return 0; } QDir dir(path); QFileInfoList list = dir.entryInfoList(QDir::AllEntries, QDir::Name); int found = 0; int index = lw->count(); for(int i = 0; i < list.count(); i++) { QFileInfo fi = list.at(i); if(!fi.isFile()) { continue; } QString fileName = fi.fileName(); if(fileName.endsWith(".mp3", Qt::CaseInsensitive) || fileName.endsWith(".ogg", Qt::CaseInsensitive) || fileName.endsWith(".ogv", Qt::CaseInsensitive) || fileName.endsWith(".avi", Qt::CaseInsensitive) || fileName.endsWith(".mp4", Qt::CaseInsensitive) || fileName.endsWith(".wav", Qt::CaseInsensitive) || fileName.endsWith(".flv", Qt::CaseInsensitive) || fileName.endsWith(".flac", Qt::CaseInsensitive) || isPlaylist(fileName)) { if(fileName.contains(".qmplayer.")) { if(delTmpFiles < 0) { delTmpFiles = (QMessageBox::question(this, "qmplayer", tr("Delete qmplayer temporary files?"), QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes); } if(delTmpFiles) { QFile::remove(fi.absoluteFilePath()); } continue; } lw->addItem(fileName); found++; } } if(found) { lw->insertItem(index, getDirItem(lw, path)); } if(level >= maxLevel) { return found; } for(int i = 0; i < list.count(); i++) { QFileInfo fi = list.at(i); if(fi.isFile() || fi.fileName() == "." || fi.fileName() == ".." || (!followSymLinks && fi.isSymLink())) { continue; } int unit = (max - min) / list.count(); int value = min + i * unit; if(progress->value() == value) { value++; } progress->setValue(value); label->setText(fi.absolutePath()); QApplication::processEvents(); found += scanDir(fi.filePath(), level + 1, maxLevel, value, value + unit, true); } return found; }
void QMplayer::okClicked() { if(screen == QMplayer::ScreenInit || screen == QMplayer::ScreenEncoding) { QString dir = ""; bool hit = false; QStringList list; QStringList downList; QStringList nameList; QMessageBox::StandardButton answer = QMessageBox::NoButton; QMessageBox::StandardButton moreAnswer = QMessageBox::NoButton; list << mpargs; list << mplist; if (mpgui) { QListWidgetItem *sel = lw->currentItem(); if(sel == NULL) { return; } if(sel == scanItem) { scan(); return; } if(sel == sharingItem) { sharing(); return; } if(sel == encodingItem) { if(screen != ScreenEncoding) { showScreen(ScreenEncoding); if(lw->count() > NUM_MENU_ITEMS) { QListWidgetItem *item = lw->item(NUM_MENU_ITEMS); item->setSelected(true); } } else { showScreen(ScreenInit); } return; } for(int i = NUM_MENU_ITEMS; i < lw->count(); i++) { QListWidgetItem *item = lw->item(i); QString path = item->text(); bool isDir = isDirectory(path); if(isDir) { if(hit) { break; } dir = path; } hit |= (item == sel); if(!hit || isDir) { continue; } if(!dir.startsWith("http://")) { list.append(dir + "/" + path); // add local files to playlist continue; } if(moreAnswer == QMessageBox::NoButton) { answer = QMessageBox::question(this, "qmplayer", path, QMessageBox::Save | QMessageBox::Open | QMessageBox::Cancel); } if(answer == QMessageBox::Cancel) { break; } if(answer == QMessageBox::Open) { list.append(dir + pathToUrl(path)); // append to playlist if we just play (no download) } downList.append(dir + pathToUrl(path)); nameList.append(path); if(moreAnswer != QMessageBox::YesToAll) { moreAnswer = QMessageBox::question(this, "qmplayer", tr("Next file?"), QMessageBox::Yes | QMessageBox::No | QMessageBox::YesToAll); if(moreAnswer == QMessageBox::No) { break; } } } for(int i = 0; i < downList.count(); i++) { QString url = downList[i]; int slashIndex = url.lastIndexOf('/'); if(slashIndex < 0) { continue; } QString filename = nameList[i]; QString destPath = QDir::homePath() + "/" + filename; if(QDir("/media/card").exists()) { destPath = "/media/card/" + filename; } bool justCheck = list.contains(url); if(!download(url, destPath, filename, justCheck)) { return; } if(justCheck) { continue; } // Add downloaded file to list list.append(destPath); } } if(list.count() > mpargs.count()) { if(screen == ScreenEncoding) { encode(list.at(0)); } else { if (isPlaylist(list[mpargs.count()])) list.insert(mpargs.count(),"-playlist"); play(list); } } } else if(screen == QMplayer::ScreenPlay) { if(processRunning(process)) { process->write(" "); } showScreen(QMplayer::ScreenStopped); } else if(screen == QMplayer::ScreenStopped) { if(processRunning(process)) { process->write(" "); #ifdef QTOPIA // Workaround unpause not working for alsa out in mplayer glamo. // We send left key to make mplayer start playing. process->write("\x1b""[D"); #endif } showScreen(QMplayer::ScreenPlay); } else if(screen == QMplayer::ScreenConnect) { runClient(); } else if(screen == QMplayer::ScreenTube) { this->screen = QMplayer::ScreenInit; okClicked(); } }
bool Controller::isClip() const { return !isPlaylist() && !isMultitrack(); }
int loadPlaylist(FILE * fp, char * utf8file) { FILE * fileP; char s[MAXPATHLEN+1]; int slength = 0; char * temp = strdup(utf8ToFsCharset(utf8file)); char * rfile = malloc(strlen(temp)+strlen(".")+ strlen(PLAYLIST_FILE_SUFFIX)+1); char * actualFile; char * parent = parentPath(temp); int parentlen = strlen(parent); char * erroredFile = NULL; int tempInt; int commentCharFound = 0; strcpy(rfile,temp); strcat(rfile,"."); strcat(rfile,PLAYLIST_FILE_SUFFIX); free(temp); if((actualFile = rpp2app(rfile)) && isPlaylist(actualFile)) free(rfile); else { free(rfile); commandError(fp, ACK_ERROR_NO_EXIST, "playlist \"%s\" not found", utf8file); return -1; } while(!(fileP = fopen(actualFile,"r")) && errno==EINTR); if(fileP==NULL) { commandError(fp, ACK_ERROR_SYSTEM, "problems opening file \"%s\"", utf8file); return -1; } while((tempInt = fgetc(fileP))!=EOF) { s[slength] = tempInt; if(s[slength]=='\n' || s[slength]=='\0') { commentCharFound = 0; s[slength] = '\0'; if(s[0]==PLAYLIST_COMMENT) { commentCharFound = 1; } if(strncmp(s,musicDir,strlen(musicDir))==0) { strcpy(s,&(s[strlen(musicDir)])); } else if(parentlen) { temp = strdup(s); memset(s,0,MAXPATHLEN+1); strcpy(s,parent); strncat(s,"/",MAXPATHLEN-parentlen); strncat(s,temp,MAXPATHLEN-parentlen-1); if(strlen(s)>=MAXPATHLEN) { commandError(fp, ACK_ERROR_PLAYLIST_LOAD, "\"%s\" too long", temp); free(temp); while(fclose(fileP) && errno==EINTR); if(erroredFile) free(erroredFile); return -1; } free(temp); } slength = 0; temp = fsCharsetToUtf8(s); if(!temp) continue; temp = strdup(temp); if(commentCharFound && !getSongFromDB(temp) && !isRemoteUrl(temp)) { free(temp); continue; } if((addToPlaylist(stderr,temp))<0) { if(!erroredFile) erroredFile = strdup(temp); } free(temp); } else if(slength==MAXPATHLEN) { s[slength] = '\0'; commandError(fp, ACK_ERROR_PLAYLIST_LOAD, "line in \"%s\" is too long", utf8file); ERROR("line \"%s\" in playlist \"%s\" is too long\n", s, utf8file); while(fclose(fileP) && errno==EINTR); if(erroredFile) free(erroredFile); return -1; } else if(s[slength]!='\r') slength++; } while(fclose(fileP) && errno==EINTR); if(erroredFile) { commandError(fp, ACK_ERROR_PLAYLIST_LOAD, "can't add file \"%s\"", erroredFile); free(erroredFile); return -1; } return 0; }