Exemple #1
0
SongList PLSParser::Load(QIODevice *device, const QString& playlist_path, const QDir &dir) const {
    QMap<int, Song> songs;
    QRegExp n_re("\\d+$");

    while (!device->atEnd()) {
        QString line = QString::fromUtf8(device->readLine()).trimmed();
        int equals = line.indexOf('=');
        QString key = line.left(equals).toLower();
        QString value = line.mid(equals + 1);

        n_re.indexIn(key);
        int n = n_re.cap(0).toInt();

        if (key.startsWith("file")) {
            Song song = LoadSong(value, 0, dir);

            // Use the title and length we've already loaded if any
            if (!songs[n].title().isEmpty())
                song.set_title(songs[n].title());
            if (!songs[n].length_nanosec() != -1)
                song.set_length_nanosec(songs[n].length_nanosec());

            songs[n] = song;
        } else if (key.startsWith("title")) {
            songs[n].set_title(value);
        } else if (key.startsWith("length")) {
            qint64 seconds = value.toLongLong();
            if (seconds > 0) {
                songs[n].set_length_nanosec(seconds * kNsecPerSec);
            }
        }
    }

    return songs.values();
}
Exemple #2
0
void Playlist::p_add_PLS(const QByteArray& playlist)
{

  QTextStream stream(playlist, QIODevice::ReadOnly);

  QString line = stream.readLine().trimmed();

  QMap<int, PlaylistItem> items;
  while (!line.isNull())
  {

    int equals = line.indexOf('=');
    QString key = line.left(equals).toLower();
    QString value = line.mid(equals + 1);

    QRegExp n_re("\\d+$");
    n_re.indexIn(key);
    int n = n_re.cap(0).toInt();

    if (key.startsWith("file"))
    {
      items[n].setFilename(value);
    }
    else if (key.startsWith("title"))
    {
      items[n].setTitle(value);
    }
    else if (key.startsWith("length"))
    {
      bool ok;
      int seconds = value.toInt(&ok);
      if (ok) items[n].setLength(seconds);
    }

    line = stream.readLine().trimmed();
  }

  QMap<int, PlaylistItem>::const_iterator i = items.constBegin();
  while (i != items.constEnd())
  {
    p_playlist.append(i.value());
    ++i;
  }

}