static void ReadM3U(std::vector<std::string> &file_list, std::string path, unsigned depth = 0) { std::vector<std::string> ret; FileWrapper m3u_file(path.c_str(), FileWrapper::MODE_READ, _("M3U CD Set")); std::string dir_path; char linebuf[2048]; MDFN_GetFilePathComponents(path, &dir_path); while(m3u_file.get_line(linebuf, sizeof(linebuf))) { std::string efp; if(linebuf[0] == '#') continue; MDFN_rtrim(linebuf); if(linebuf[0] == 0) continue; efp = MDFN_EvalFIP(dir_path, std::string(linebuf)); if(efp.size() >= 4 && efp.substr(efp.size() - 4) == ".m3u") { if(efp == path) throw(MDFN_Error(0, _("M3U at \"%s\" references self."), efp.c_str())); if(depth == 99) throw(MDFN_Error(0, _("M3U load recursion too deep!"))); ReadM3U(file_list, efp, depth++); } else file_list.push_back(efp); } }
QList<QUrl> PlayListModel::m3uToUrls(QUrl url) { QList<QUrl> urls; QFile m3u_file(url.path()); if (m3u_file.open(QFile::ReadOnly)) { while (true) { QByteArray line = m3u_file.readLine(); line.chop(1); if (line.length() == 0) break; if (line.at(0) == '#') continue; urls.append(QUrl::fromUserInput(line)); } } return urls; }
void Playlist_persistence_Test::initTestCase() { // Init playlist and persistence process. this->playlist = new Playlist("base_path", "playlist"); this->playlist_persist = new Playlist_persistence(); // Create a test playlist file. QString m3u(PLAYLIST_M3U); m3u.replace("<DATA_DIR>", QDir(DATA_DIR).absolutePath()); m3u.replace("<URI_PREFIX>", URI_PREFIX); QFile m3u_file(QDir(DATA_DIR).filePath(PLAYLIST_M3U_FILE)); if (m3u_file.open(QIODevice::WriteOnly | QIODevice::Text) == true) { QTextStream m3u_stream(&m3u_file); m3u_stream << m3u.toUtf8(); m3u_file.close(); } }