Ejemplo n.º 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();

}
Ejemplo n.º 2
0
void
QueueManager::insertItems()
{
    QPtrList<PlaylistItem> list = Playlist::instance()->m_nextTracks;
    QListViewItem *last = 0;

    for( PlaylistItem *item = list.first(); item; item = list.next() )
    {
        QString title = i18n("%1 - %2").arg( item->artist(), item->title() );

        last = new QueueItem( m_listview, last, title );
        m_map[ last ] = item;
    }

    updateButtons();
}
Ejemplo n.º 3
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();

}
Ejemplo n.º 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);

}