Exemple #1
0
QByteArray Playlist::toPLS(const QString& playlistPath, const bool utf8) const
{

  QStringList playlist;
  playlist.append("[Playlist]");

  int j = 0;
  for (int i = 0; i < p_playlist.count(); ++i)
  {
    PlaylistItem pi = p_playlist[i];

    if (pi.filename().isEmpty()) continue;
    ++j;

    if (!playlistPath.isEmpty())
    {
      QDir dir(playlistPath);
      playlist.append(QString("File%1=%2").arg(i+1).arg(dir.relativeFilePath(pi.filename())));
    }
    else
    {
      playlist.append(QString("File%1=%2").arg(i+1).arg(pi.filename()));
    }

    if (!pi.artist().isEmpty())
    {
      playlist.append(QString("Title%1=%2 - %3").arg(i+1).arg(pi.artist()).arg(pi.title()));
    }
    else
    {
      playlist.append(QString("Title%1=%2").arg(i+1).arg(pi.title()));
    }

    playlist.append(QString("Length%1=%2").arg(i+1).arg(pi.length()));

  }

  playlist.append(QString("NumberOfEntries=%1").arg(j));
  playlist.append(QString("Version=2"));

  if (utf8)
    return playlist.join("\n").append("\n").toUtf8();
  else
    return playlist.join("\n").append("\n").toLatin1();

}
Exemple #2
0
QByteArray Playlist::toM3U(const QString& playlistPath, const bool utf8) const {

  QStringList playlist;
  playlist.append("#EXTM3U");

  for (int i = 0; i < p_playlist.count(); ++i)
  {

    PlaylistItem pi = p_playlist[i];
    if (pi.filename().isEmpty()) continue;

    if (!pi.artist().isEmpty())
    {
      playlist.append(QString("#EXTINF:%1,%2 - %3").arg(pi.length()).arg(pi.artist()).arg(pi.title()));
    }
    else
    {
      playlist.append(QString("#EXTINF:%1,%2").arg(pi.length()).arg(pi.title()));
    }
    if (!playlistPath.isEmpty())
    {
      QDir dir(playlistPath);
      playlist.append(dir.relativeFilePath(pi.filename()));
    }
    else
    {
      playlist.append(pi.filename());
    }

  }

  if (utf8)
    return playlist.join("\n").append("\n").toUtf8();
  else
    return playlist.join("\n").append("\n").toLatin1();

}
Exemple #3
0
void Playlist::p_add_M3U(const QByteArray& playlist)
{

  QTextStream stream(playlist, QIODevice::ReadOnly);

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

  bool extended = false;
  if (line.startsWith("#EXTM3U"))
  {
    extended = true;
    line = stream.readLine().trimmed();
  }

  PlaylistItem pi;
  while (!line.isNull())
  {

    if (line.startsWith('#'))
    {
      if (extended && line.startsWith("#EXT"))
      {
        pi = p_parse_m3u_metadata_line(line);
      }
    }
    else if (!line.isEmpty())
    {
      pi.setFilename(line);
      if (!pi.filename().isEmpty())
      {
        p_playlist.append(pi);
        pi.clear();
      }
    }

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

  }

}
Exemple #4
0
QByteArray Playlist::toXSPF() const
{

  QDomDocument doc;
  QDomElement root = doc.createElement("playlist");
  root.setAttribute("version", "1");
  root.setAttribute("xmlns", "http://xspf.org/ns/0");

  QDomElement creator = doc.createElement("creator");
  QDomText text = doc.createTextNode("audex");
  creator.appendChild(text);
  root.appendChild(creator);

  QDomElement tracklist = doc.createElement("trackList");

  int j = 0;
  for (int i = 0; i < p_playlist.count(); ++i)
  {

    PlaylistItem pi = p_playlist[i];

    if (pi.filename().isEmpty()) continue;
    ++j;

    QDomElement track = doc.createElement("track");

    QDomElement ch = doc.createElement("location");
    QDomText text = doc.createTextNode(pi.filename());

    ch.appendChild(text);
    track.appendChild(ch);

    if (!pi.artist().isEmpty())
    {
      ch = doc.createElement("creator");
      text = doc.createTextNode(pi.artist());
      ch.appendChild(text);
      track.appendChild(ch);
    }

    ch = doc.createElement("title");
    text = doc.createTextNode(pi.title());
    ch.appendChild(text);
    track.appendChild(ch);

    ch = doc.createElement("trackNum");
    text = doc.createTextNode(QString::number(j));
    ch.appendChild(text);
    track.appendChild(ch);

    if (pi.length() > 0)
    {
      ch = doc.createElement("duration");
      text = doc.createTextNode(QString::number(pi.length()*1000));
      ch.appendChild(text);
      track.appendChild(ch);
    }

    tracklist.appendChild(track);

  }

  root.appendChild(tracklist);
  doc.appendChild(root);
  QByteArray xml_header("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
  return doc.toByteArray().prepend(xml_header);

}