File indexing completed on 2024-04-28 16:06:19

0001 /* AUDEX CDDA EXTRACTOR
0002  * SPDX-FileCopyrightText: Copyright (C) 2007 Marco Nelles
0003  * <https://userbase.kde.org/Audex>
0004  *
0005  * SPDX-License-Identifier: GPL-3.0-or-later
0006  */
0007 
0008 #ifndef PLAYLIST_HEADER
0009 #define PLAYLIST_HEADER
0010 
0011 #include <QDir>
0012 #include <QDomDocument>
0013 #include <QFileInfo>
0014 #include <QString>
0015 #include <QStringList>
0016 #include <QTextStream>
0017 
0018 #include <KLocalizedString>
0019 
0020 class PlaylistItem
0021 {
0022 public:
0023     PlaylistItem()
0024     {
0025         p_length = 0;
0026     }
0027     PlaylistItem(const PlaylistItem &other)
0028     {
0029         p_filename = other.p_filename;
0030         p_artist = other.p_artist;
0031         p_title = other.p_title;
0032         p_length = other.p_length;
0033     }
0034     PlaylistItem &operator=(const PlaylistItem &other)
0035     {
0036         p_filename = other.p_filename;
0037         p_artist = other.p_artist;
0038         p_title = other.p_title;
0039         p_length = other.p_length;
0040         return *this;
0041     }
0042     ~PlaylistItem()
0043     {
0044     }
0045 
0046     bool operator==(const PlaylistItem &other) const
0047     {
0048         return (p_filename == other.p_filename && p_title == other.p_title && p_artist == other.p_artist && p_length == other.p_length);
0049     }
0050 
0051     void clear()
0052     {
0053         p_filename.clear();
0054         p_artist.clear();
0055         p_title.clear();
0056         p_length = 0;
0057     }
0058 
0059     void setFilename(const QString &filename)
0060     {
0061         p_filename = filename;
0062     }
0063     const QString filename()
0064     {
0065         return p_filename;
0066     }
0067     void setArtist(const QString &artist)
0068     {
0069         p_artist = artist;
0070     }
0071     const QString artist()
0072     {
0073         return p_artist;
0074     }
0075     void setTitle(const QString &title)
0076     {
0077         p_title = title;
0078     }
0079     const QString title()
0080     {
0081         return p_title;
0082     }
0083     void setLength(const int length)
0084     {
0085         p_length = length;
0086     }
0087     int length()
0088     {
0089         return p_length;
0090     }
0091 
0092 private:
0093     QString p_filename;
0094     QString p_artist;
0095     QString p_title;
0096     int p_length; // sec
0097 };
0098 
0099 typedef QList<PlaylistItem> PlaylistItemList;
0100 
0101 class Playlist
0102 {
0103 public:
0104     Playlist();
0105     explicit Playlist(const QByteArray &playlist);
0106     ~Playlist();
0107 
0108     void addPlaylist(const QByteArray &playlist);
0109 
0110     void clear();
0111 
0112     void appendItem(const PlaylistItem &item);
0113 
0114     // if playlistPath is set, then filename paths will be relative to playlistPath
0115     QByteArray toM3U(const QString &playlistPath = "", const bool utf8 = false) const;
0116     QByteArray toPLS(const QString &playlistPath = "", const bool utf8 = false) const;
0117     QByteArray toXSPF() const;
0118 
0119 private:
0120     PlaylistItemList p_playlist;
0121 
0122     // guess the playlist format: m3u, pls, xspf
0123     const QString p_playlist_format(const QByteArray &playlist);
0124 
0125     void p_add_M3U(const QByteArray &playlist);
0126     void p_add_PLS(const QByteArray &playlist);
0127     void p_add_XSPF(const QByteArray &playlist);
0128 
0129     const PlaylistItem p_parse_m3u_metadata_line(const QString &line);
0130 };
0131 
0132 #endif