Skip to content

Commit

Permalink
Merge pull request #3916 from daschuer/m3u8
Browse files Browse the repository at this point in the history
Get rid of the not working binary file check
  • Loading branch information
uklotzde authored May 26, 2021
2 parents 2725a5e + b84eb6c commit 7411d0d
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 33 deletions.
27 changes: 0 additions & 27 deletions src/library/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,33 +33,6 @@ long Parser::countParsed() {
return (long)m_sLocations.count();
}

bool Parser::isBinary(const QString& filename) {
char firstByte;
QFile file(filename);
if (file.open(QIODevice::ReadOnly) && file.getChar(&firstByte)) {
// If starting byte is not an ASCII character then the file
// probably contains binary data.
if (firstByte >= 32 && firstByte <= 126) {
// Valid ASCII character
return false;
}
// Check for UTF-8 BOM
if (firstByte == '\xEF') {
char nextChar;
if (file.getChar(&nextChar) &&
nextChar == '\xBB' &&
file.getChar(&nextChar) &&
nextChar == '\xBF') {
// UTF-8 text file
return false;
}
return true;
}
}
qDebug() << "Parser: Error reading from" << filename;
return true; //should this raise an exception?
}

// The following public domain code is taken from
// http://stackoverflow.com/questions/1031645/how-to-detect-utf-8-in-plain-c
// Thank you Christoph!
Expand Down
2 changes: 0 additions & 2 deletions src/library/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ class Parser : public QObject {
long countParsed();
// Clears m_psLocations
void clearLocations();
// Checks if the file does contain binary content
bool isBinary(const QString&);
// check for Utf8 encoding
static bool isUtf8(const char* string);
// Resolve an absolute or relative file path
Expand Down
2 changes: 1 addition & 1 deletion src/library/parsercsv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ QList<QString> ParserCsv::parse(const QString& sFilename) {

clearLocations();
//qDebug() << "ParserCsv: Starting to parse.";
if (file.open(QIODevice::ReadOnly) && !isBinary(sFilename)) {
if (file.open(QIODevice::ReadOnly)) {
QByteArray ba = file.readAll();

QList<QList<QString> > tokens = tokenize(ba, ',');
Expand Down
2 changes: 1 addition & 1 deletion src/library/parserm3u.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ QList<QString> ParserM3u::parse(const QString& sFilename) {
clearLocations();

QFile file(sFilename);
if (isBinary(sFilename) || !file.open(QIODevice::ReadOnly)) {
if (!file.open(QIODevice::ReadOnly)) {
qWarning()
<< "Failed to open playlist file"
<< sFilename;
Expand Down
3 changes: 1 addition & 2 deletions src/library/parserpls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ QList<QString> ParserPls::parse(const QString& sFilename) {

clearLocations();

if (file.open(QIODevice::ReadOnly) && !isBinary(sFilename)) {

if (file.open(QIODevice::ReadOnly)) {
/* Unfortunately, QT 4.7 does not handle <CR> (=\r or asci value 13) line breaks.
* This is important on OS X where iTunes, e.g., exports M3U playlists using <CR>
* rather that <LF>
Expand Down

0 comments on commit 7411d0d

Please sign in to comment.