Includes, comments and bugfixes

- Fix includes
- Use common regex (Song::kCoverRemoveDisc) for removing Disc/CD from album
- Remove Disc/CD from album when creating hash
- Make imobiledevice support compile
- Fix setting device on windows
This commit is contained in:
Jonas Kvinge
2018-05-01 00:41:33 +02:00
parent fccbd6790c
commit e337b7933b
518 changed files with 7003 additions and 4693 deletions

View File

@@ -18,13 +18,17 @@
*
*/
#include "config.h"
#include <QObject>
#include <QIODevice>
#include <QByteArray>
#include <QDir>
#include <QString>
#include <QTextStream>
#include "asxiniparser.h"
#include "core/logging.h"
#include "playlistparsers/parserbase.h"
#include <QTextStream>
#include <QtDebug>
class CollectionBackendInterface;
AsxIniParser::AsxIniParser(CollectionBackendInterface *collection, QObject *parent)
: ParserBase(collection, parent) {}

View File

@@ -21,9 +21,20 @@
#ifndef ASXINIPARSER_H
#define ASXINIPARSER_H
#include "config.h"
#include <stdbool.h>
#include <QObject>
#include <QIODevice>
#include <QByteArray>
#include <QDir>
#include <QString>
#include <QStringList>
#include "config.h"
#include "core/song.h"
#include "parserbase.h"
#include "playlist/playlist.h"
class CollectionBackendInterface;
class AsxIniParser : public ParserBase {
Q_OBJECT

View File

@@ -18,19 +18,23 @@
*
*/
#include "config.h"
#include "asxparser.h"
#include "core/utilities.h"
#include <QBuffer>
#include <QDomDocument>
#include <QFile>
#include <QObject>
#include <QIODevice>
#include <QBuffer>
#include <QDir>
#include <QByteArray>
#include <QString>
#include <QStringBuilder>
#include <QRegExp>
#include <QUrl>
#include <QXmlStreamReader>
#include <QtDebug>
#include <QXmlStreamWriter>
#include "asxparser.h"
#include "core/utilities.h"
#include "playlistparsers/xmlparser.h"
class CollectionBackendInterface;
ASXParser::ASXParser(CollectionBackendInterface *collection, QObject *parent)
: XMLParser(collection, parent) {}

View File

@@ -21,10 +21,23 @@
#ifndef ASXPARSER_H
#define ASXPARSER_H
#include "config.h"
#include <stdbool.h>
#include <QObject>
#include <QIODevice>
#include <QByteArray>
#include <QDir>
#include <QString>
#include <QStringList>
#include <QXmlStreamReader>
#include "config.h"
#include "core/song.h"
#include "playlist/playlist.h"
#include "xmlparser.h"
class CollectionBackendInterface;
class ASXParser : public XMLParser {
Q_OBJECT

View File

@@ -18,21 +18,27 @@
*
*/
#include "config.h"
#include "cueparser.h"
#include "core/logging.h"
#include "core/timeconstants.h"
#include <QBuffer>
#include <QDateTime>
#include <QtGlobal>
#include <QObject>
#include <QIODevice>
#include <QDir>
#include <QFileInfo>
#include <QStringBuilder>
#include <QDateTime>
#include <QList>
#include <QString>
#include <QStringList>
#include <QRegExp>
#include <QTextCodec>
#include <QTextStream>
#include <QtDebug>
#include "core/logging.h"
#include "core/timeconstants.h"
#include "cueparser.h"
#include "playlistparsers/parserbase.h"
class CollectionBackendInterface;
const char *CueParser::kFileLineRegExp = "(\\S+)\\s+(?:\"([^\"]+)\"|(\\S+))\\s*(?:\"([^\"]+)\"|(\\S+))?";
const char *CueParser::kIndexRegExp = "(\\d{2,3}):(\\d{2}):(\\d{2})";
@@ -174,8 +180,7 @@ SongList CueParser::Load(QIODevice *device, const QString &playlist_path, const
if (line_name == kTrack) {
// the beginning of another track's definition - we're saving the current one
// for later (if it's valid of course)
// the beginning of another track's definition - we're saving the current one for later (if it's valid of course)
// please note that the same code is repeated just after this 'do-while' loop
if(valid_file && !index.isEmpty() && (track_type.isEmpty() || track_type == kAudioTrackType)) {
entries.append(CueEntry(file, index, title, artist, album_artist, album, composer, album_composer, genre, date, disc));
@@ -191,11 +196,10 @@ SongList CueParser::Load(QIODevice *device, const QString &playlist_path, const
}
else if (line_name == kIndex) {
// we need the index's position field
// We need the index's position field
if (!line_additional.isEmpty()) {
// if there's none "01" index, we'll just take the first one
// also, we'll take the "01" index even if it's the last one
// If there's none "01" index, we'll just take the first one also, we'll take the "01" index even if it's the last one
if (line_value == "01" || index.isEmpty()) {
index = line_additional;
@@ -210,17 +214,18 @@ SongList CueParser::Load(QIODevice *device, const QString &playlist_path, const
}
else if (line_name == kSongWriter) {
composer = line_value;
// end of track's for the current file -> parse next one
// End of track's for the current file -> parse next one
}
else if (line_name == kFile) {
break;
}
// just ignore the rest of possible field types for now...
} while (!(line = text_stream.readLine()).isNull());
// Just ignore the rest of possible field types for now...
}
while (!(line = text_stream.readLine()).isNull());
// we didn't add the last song yet...
// We didn't add the last song yet...
if(valid_file && !index.isEmpty() && (track_type.isEmpty() || track_type == kAudioTrackType)) {
entries.append(CueEntry(file, index, title, artist, album_artist, album, composer, album_composer, genre, date, disc));
}
@@ -228,28 +233,26 @@ SongList CueParser::Load(QIODevice *device, const QString &playlist_path, const
QDateTime cue_mtime = QFileInfo(playlist_path).lastModified();
// finalize parsing songs
// Finalize parsing songs
for (int i = 0; i < entries.length(); i++) {
CueEntry entry = entries.at(i);
Song song = LoadSong(entry.file, IndexToMarker(entry.index), dir);
// cue song has mtime equal to qMax(media_file_mtime, cue_sheet_mtime)
// Cue song has mtime equal to qMax(media_file_mtime, cue_sheet_mtime)
if (cue_mtime.isValid()) {
song.set_mtime(qMax(cue_mtime.toTime_t(), song.mtime()));
}
song.set_cue_path(playlist_path);
// overwrite the stuff, we may have read from the file or collection, using
// the current .cue metadata
// Overwrite the stuff, we may have read from the file or collection, using the current .cue metadata
// set track number only in single-file mode
// Set track number only in single-file mode
if (files == 1) {
song.set_track(i + 1);
}
// the last TRACK for every FILE gets it's 'end' marker from the media file's
// length
// The last TRACK for every FILE gets it's 'end' marker from the media file's length
if(i + 1 < entries.size() && entries.at(i).file == entries.at(i + 1).file) {
// incorrect indices?
if (!UpdateSong(entry, entries.at(i + 1).index, &song)) {
@@ -277,24 +280,23 @@ QStringList CueParser::SplitCueLine(const QString &line) const {
return QStringList();
}
// let's remove the empty entries while we're at it
// Let's remove the empty entries while we're at it
return line_regexp.capturedTexts().filter(QRegExp(".+")).mid(1, -1);
}
// Updates the song with data from the .cue entry. This one mustn't be used for the
// last song in the .cue file.
// Updates the song with data from the .cue entry. This one mustn't be used for the last song in the .cue file.
bool CueParser::UpdateSong(const CueEntry &entry, const QString &next_index, Song *song) const {
qint64 beginning = IndexToMarker(entry.index);
qint64 end = IndexToMarker(next_index);
// incorrect indices (we won't be able to calculate beginning or end)
// Incorrect indices (we won't be able to calculate beginning or end)
if (beginning == -1 || end == -1) {
return false;
}
// believe the CUE: Init() forces validity
// Believe the CUE: Init() forces validity
song->Init(entry.title, entry.PrettyArtist(), entry.album, beginning, end);
song->set_albumartist(entry.album_artist);
song->set_composer(entry.PrettyComposer());
@@ -306,18 +308,17 @@ bool CueParser::UpdateSong(const CueEntry &entry, const QString &next_index, Son
}
// Updates the song with data from the .cue entry. This one must be used only for the
// last song in the .cue file.
// Updates the song with data from the .cue entry. This one must be used only for the last song in the .cue file.
bool CueParser::UpdateLastSong(const CueEntry &entry, Song *song) const {
qint64 beginning = IndexToMarker(entry.index);
// incorrect index (we won't be able to calculate beginning)
// Incorrect index (we won't be able to calculate beginning)
if (beginning == -1) {
return false;
}
// believe the CUE and force validity (like UpdateSong() does)
// Believe the CUE and force validity (like UpdateSong() does)
song->set_valid(true);
song->set_title(entry.title);
@@ -329,8 +330,7 @@ bool CueParser::UpdateLastSong(const CueEntry &entry, Song *song) const {
song->set_composer(entry.PrettyComposer());
song->set_disc(entry.disc.toInt());
// we don't do anything with the end here because it's already set to
// the end of the media file (if it exists)
// We don't do anything with the end here because it's already set to the end of the media file (if it exists)
song->set_beginning_nanosec(beginning);
return true;

View File

@@ -23,13 +23,24 @@
#include "config.h"
#include <stdbool.h>
#include <QtGlobal>
#include <QObject>
#include <QIODevice>
#include <QByteArray>
#include <QDir>
#include <QString>
#include <QStringList>
#include "core/song.h"
#include "parserbase.h"
#include "playlist/playlist.h"
#include <QRegExp>
class CollectionBackendInterface;
// This parser will try to detect the real encoding of a .cue file but there's
// a great chance it will fail so it's probably best to assume that the parser
// is UTF compatible only.
// This parser will try to detect the real encoding of a .cue file
// but there's a great chance it will fail so it's probably best to assume that the parser is UTF compatible only.
class CueParser : public ParserBase {
Q_OBJECT

View File

@@ -18,16 +18,26 @@
*
*/
#include "config.h"
#include <QObject>
#include <QIODevice>
#include <QDir>
#include <QBuffer>
#include <QByteArray>
#include <QList>
#include <QVariant>
#include <QString>
#include <QStringList>
#include <QUrl>
#include <QSettings>
#include <QtDebug>
#include "m3uparser.h"
#include "core/logging.h"
#include "core/timeconstants.h"
#include "m3uparser.h"
#include "playlist/playlist.h"
#include "playlistparsers/parserbase.h"
#include <QBuffer>
#include <QtDebug>
class CollectionBackendInterface;
M3UParser::M3UParser(CollectionBackendInterface *collection, QObject *parent)
: ParserBase(collection, parent) {}

View File

@@ -23,9 +23,21 @@
#include "config.h"
#include <QUrl>
#include <stdbool.h>
#include <QtGlobal>
#include <QObject>
#include <QIODevice>
#include <QByteArray>
#include <QDir>
#include <QString>
#include <QStringList>
#include "core/song.h"
#include "parserbase.h"
#include "playlist/playlist.h"
class CollectionBackendInterface;
class M3UParser : public ParserBase {
Q_OBJECT

View File

@@ -18,17 +18,19 @@
*
*/
#include "config.h"
#include "parserbase.h"
#include "core/tagreaderclient.h"
#include "collection/collectionbackend.h"
#include "collection/collectionquery.h"
#include "collection/sqlrow.h"
#include "playlist/playlist.h"
#include <QtGlobal>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QString>
#include <QRegExp>
#include <QUrl>
#include "collection/collectionbackend.h"
#include "core/tagreaderclient.h"
#include "parserbase.h"
#include "playlist/playlist.h"
ParserBase::ParserBase(CollectionBackendInterface *collection, QObject *parent)
: QObject(parent), collection_(collection) {}
@@ -76,8 +78,7 @@ void ParserBase::LoadSong(const QString &filename_or_url, qint64 beginning, cons
collection_song = collection_->GetSongByUrl(url, beginning);
}
// If it was found in the collection then use it, otherwise load metadata from
// disk.
// If it was found in the collection then use it, otherwise load metadata from disk.
if (collection_song.is_valid()) {
*song = collection_song;
}

View File

@@ -21,11 +21,18 @@
#ifndef PARSERBASE_H
#define PARSERBASE_H
#include "config.h"
#include <stdbool.h>
#include <QtGlobal>
#include <QObject>
#include <QIODevice>
#include <QDir>
#include <QByteArray>
#include <QString>
#include <QStringList>
#include <QUrl>
#include "config.h"
#include "core/song.h"
#include "playlist/playlist.h"
@@ -44,29 +51,23 @@ class ParserBase : public QObject {
virtual bool TryMagic(const QByteArray &data) const = 0;
// Loads all songs from playlist found at path 'playlist_path' in directory 'dir'.
// The 'device' argument is an opened and ready to read from represantation of
// this playlist.
// This method might not return all of the songs found in the playlist. Any playlist
// parser may decide to leave out some entries if it finds them incomplete or invalid.
// This means that the final resulting SongList should be considered valid (at least
// from the parser's point of view).
// The 'device' argument is an opened and ready to read from represantation of this playlist.
// This method might not return all of the songs found in the playlist.
// Any playlist parser may decide to leave out some entries if it finds them incomplete or invalid.
// This means that the final resulting SongList should be considered valid (at least from the parser's point of view).
virtual SongList Load(QIODevice *device, const QString &playlist_path = "", const QDir &dir = QDir()) const = 0;
virtual void Save(const SongList &songs, QIODevice *device, const QDir &dir = QDir(), Playlist::Path path_type = Playlist::Path_Automatic) const = 0;
protected:
// Loads a song. If filename_or_url is a URL (with a scheme other than
// "file") then it is set on the song and the song marked as a stream.
// If it is a filename or a file:// URL then it is made absolute and canonical
// and set as a file:// url on the song. Also sets the song's metadata by
// searching in the Collection, or loading from the file as a fallback.
// Loads a song. If filename_or_url is a URL (with a scheme other than "file") then it is set on the song and the song marked as a stream.
// If it is a filename or a file:// URL then it is made absolute and canonical and set as a file:// url on the song.
// Also sets the song's metadata by searching in the Collection, or loading from the file as a fallback.
// This function should always be used when loading a playlist.
Song LoadSong(const QString &filename_or_url, qint64 beginning, const QDir &dir) const;
void LoadSong(const QString &filename_or_url, qint64 beginning, const QDir &dir, Song *song) const;
// If the URL is a file:// URL then returns its path, absolute or relative to
// the directory depending on the path_type option.
// Otherwise returns the URL as is.
// This function should always be used when saving a playlist.
// If the URL is a file:// URL then returns its path, absolute or relative to the directory depending on the path_type option.
// Otherwise returns the URL as is. This function should always be used when saving a playlist.
QString URLOrFilename(const QUrl &url, const QDir &dir, Playlist::Path path_type) const;
private:

View File

@@ -18,19 +18,28 @@
*
*/
#include "config.h"
#include <QObject>
#include <QIODevice>
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QByteArray>
#include <QString>
#include <QStringBuilder>
#include <QStringList>
#include <QtAlgorithms>
#include <QtDebug>
#include "asxparser.h"
#include "asxiniparser.h"
#include "asxparser.h"
#include "core/logging.h"
#include "cueparser.h"
#include "m3uparser.h"
#include "playlistparser.h"
#include "playlistparsers/parserbase.h"
#include "plsparser.h"
#include "wplparser.h"
#include "xspfparser.h"
#include "core/logging.h"
#include <QtDebug>
const int PlaylistParser::kMagicSize = 512;

View File

@@ -21,16 +21,20 @@
#ifndef PLAYLISTPARSER_H
#define PLAYLISTPARSER_H
#include "config.h"
#include <QDir>
#include <QObject>
#include <QIODevice>
#include <QDir>
#include <QByteArray>
#include <QList>
#include <QString>
#include <QStringList>
#include "config.h"
#include "core/song.h"
#include "playlist/playlist.h"
class ParserBase;
class CollectionBackendInterface;
class ParserBase;
class PlaylistParser : public QObject {
Q_OBJECT

View File

@@ -18,14 +18,21 @@
*
*/
#include "config.h"
#include "plsparser.h"
#include "core/logging.h"
#include "core/timeconstants.h"
#include <QtGlobal>
#include <QObject>
#include <QIODevice>
#include <QDir>
#include <QMap>
#include <QByteArray>
#include <QString>
#include <QRegExp>
#include <QTextStream>
#include <QtDebug>
#include "core/timeconstants.h"
#include "playlistparsers/parserbase.h"
#include "plsparser.h"
class CollectionBackendInterface;
PLSParser::PLSParser(CollectionBackendInterface *collection, QObject *parent)
: ParserBase(collection, parent) {}

View File

@@ -21,9 +21,21 @@
#ifndef PLSPARSER_H
#define PLSPARSER_H
#include "config.h"
#include <stdbool.h>
#include <QObject>
#include <QIODevice>
#include <QDir>
#include <QByteArray>
#include <QString>
#include <QStringList>
#include "config.h"
#include "core/song.h"
#include "parserbase.h"
#include "playlist/playlist.h"
class CollectionBackendInterface;
class PLSParser : public ParserBase {
Q_OBJECT

View File

@@ -18,13 +18,20 @@
*
*/
#include "config.h"
#include "wplparser.h"
#include "core/utilities.h"
#include "version.h"
#include <QObject>
#include <QIODevice>
#include <QDir>
#include <QByteArray>
#include <QString>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include "core/utilities.h"
#include "playlistparsers/xmlparser.h"
#include "version.h"
#include "wplparser.h"
class CollectionBackendInterface;
WplParser::WplParser(CollectionBackendInterface *collection, QObject *parent)
: XMLParser(collection, parent) {}

View File

@@ -21,10 +21,24 @@
#ifndef WPLPARSER_H
#define WPLPARSER_H
#include "config.h"
#include <stdbool.h>
#include <QObject>
#include <QIODevice>
#include <QDir>
#include <QByteArray>
#include <QString>
#include <QStringList>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include "config.h"
#include "core/song.h"
#include "playlist/playlist.h"
#include "xmlparser.h"
class CollectionBackendInterface;
class WplParser : public XMLParser {
public:
WplParser(CollectionBackendInterface *collection, QObject *parent = nullptr);

View File

@@ -18,16 +18,13 @@
*
*/
#include "config.h"
#include "playlistparsers/parserbase.h"
#include "xmlparser.h"
#include <QDomDocument>
#include <QFile>
#include <QIODevice>
#include <QRegExp>
#include <QUrl>
#include <QXmlStreamReader>
#include <QObject>
class CollectionBackendInterface;
XMLParser::XMLParser(CollectionBackendInterface *collection, QObject *parent)
: ParserBase(collection, parent) {}

View File

@@ -23,13 +23,14 @@
#include "config.h"
#include "parserbase.h"
#include <QXmlStreamReader>
#include <QtGlobal>
#include <QObject>
#include <QString>
#include <QXmlStreamWriter>
class QDomDocument;
class QDomNode;
#include "parserbase.h"
class CollectionBackendInterface;
class XMLParser : public ParserBase {
protected:

View File

@@ -18,20 +18,26 @@
*
*/
#include "config.h"
#include <QtGlobal>
#include <QObject>
#include <QIODevice>
#include <QDir>
#include <QFileInfo>
#include <QByteArray>
#include <QVariant>
#include <QString>
#include <QUrl>
#include <QSettings>
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
#include "xspfparser.h"
#include "core/timeconstants.h"
#include "core/utilities.h"
#include "playlist/playlist.h"
#include "playlistparsers/xmlparser.h"
#include "xspfparser.h"
#include <QDomDocument>
#include <QFile>
#include <QIODevice>
#include <QRegExp>
#include <QUrl>
#include <QXmlStreamReader>
class CollectionBackendInterface;
XSPFParser::XSPFParser(CollectionBackendInterface *collection, QObject *parent)
: XMLParser(collection, parent) {}
@@ -175,12 +181,12 @@ void XSPFParser::Save(const SongList &songs, QIODevice *device, const QDir &dir,
}
if (!art_filename.isEmpty() && !(art_filename == "(embedded)")) {
// Make this filename relative to the directory we're saving the
// playlist.
// Make this filename relative to the directory we're saving the playlist.
QUrl url = QUrl(art_filename);
url.setScheme("file"); // Need to explicitly set this.
art_filename = URLOrFilename(url, dir, path_type).toUtf8();
} else {
}
else {
// Just use whatever URL was in the Song.
art_filename = art;
}

View File

@@ -23,12 +23,21 @@
#include "config.h"
#include "xmlparser.h"
#include <stdbool.h>
#include <QObject>
#include <QIODevice>
#include <QByteArray>
#include <QDir>
#include <QString>
#include <QStringList>
#include <QXmlStreamReader>
class QDomDocument;
class QDomNode;
#include "core/song.h"
#include "playlist/playlist.h"
#include "xmlparser.h"
class CollectionBackendInterface;
class XSPFParser : public XMLParser {
Q_OBJECT