1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-04 05:07:27 +02:00

Fix for dropping iTunes exported m3u's

This commit is contained in:
Hugo Lindström
2012-12-21 07:52:07 +01:00
parent 47956a1bde
commit 027123ae5d
2 changed files with 55 additions and 32 deletions

View File

@@ -97,36 +97,15 @@ M3uLoader::getTags( const QFileInfo& info )
{ {
q->setResultHint( "file://" + info.absoluteFilePath() ); q->setResultHint( "file://" + info.absoluteFilePath() );
q->setSaveHTTPResultHint( true ); q->setSaveHTTPResultHint( true );
qDebug() << "ADding resulthint" << q->resultHint(); qDebug() << "Adding resulthint" << q->resultHint();
m_tracks << q; m_tracks << q;
} }
} }
} }
void void
M3uLoader::parseM3u( const QString& fileLink ) M3uLoader::parseLine( const QString& line, const QFile& file )
{ {
QFileInfo fileInfo( fileLink );
QFile file( QUrl::fromUserInput( fileLink ).toLocalFile() );
if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
{
tDebug() << "Error opening m3u:" << file.errorString();
return;
}
m_title = fileInfo.baseName();
while ( !file.atEnd() )
{
QByteArray line = file.readLine();
/// If anyone wants to take on the regex for parsing EXT, go ahead
/// But the notion that users does not tag by a common rule. that seems hard
/// So ignore that for now
if ( line.contains( "EXT" ) )
continue;
QFileInfo tmpFile( QUrl::fromUserInput( QString( line.simplified() ) ).toLocalFile() ); QFileInfo tmpFile( QUrl::fromUserInput( QString( line.simplified() ) ).toLocalFile() );
if( tmpFile.exists() ) if( tmpFile.exists() )
@@ -142,14 +121,57 @@ M3uLoader::parseM3u( const QString& fileLink )
getTags( tmpFile ); getTags( tmpFile );
} }
} }
}
void
M3uLoader::parseM3u( const QString& fileLink )
{
QFileInfo fileInfo( fileLink );
QFile file( QUrl::fromUserInput( fileLink ).toLocalFile() );
if ( !file.open( QIODevice::ReadOnly ) )
{
tDebug() << "Error opening m3u:" << file.errorString();
return;
}
m_title = fileInfo.baseName();
QTextStream stream( &file );
QString singleLine;
while ( !stream.atEnd() )
{
QString line = stream.readLine().trimmed();
/// Fallback solution for, (drums) itunes!
singleLine.append(line);
/// If anyone wants to take on the regex for parsing EXT, go ahead
/// But the notion that users does not tag by a common rule. that seems hard
/// So ignore that for now
if ( line.contains( "EXT" ) )
continue;
parseLine( line, file );
} }
if ( m_tracks.isEmpty() ) if ( m_tracks.isEmpty() )
{ {
tDebug() << Q_FUNC_INFO << "Could not parse M3U!"; if ( !singleLine.isEmpty() )
{
QStringList m3uList = singleLine.split("\r");
foreach( const QString& line, m3uList )
parseLine( line, file );
}
if ( m_tracks.isEmpty() )
{
tDebug() << "Could not parse M3U!";
return; return;
} }
}
if ( m_createNewPlaylist ) if ( m_createNewPlaylist )
{ {
@@ -165,7 +187,6 @@ M3uLoader::parseM3u( const QString& fileLink )
} }
else else
emit tracks( m_tracks ); emit tracks( m_tracks );
m_tracks.clear(); m_tracks.clear();
} }

View File

@@ -28,6 +28,7 @@
#include "Playlist.h" #include "Playlist.h"
#include <QObject> #include <QObject>
#include <QSet> #include <QSet>
#include <QFile>
#include <QtCore/QStringList> #include <QtCore/QStringList>
class TrackModel; class TrackModel;
@@ -56,6 +57,7 @@ signals:
private: private:
void parseM3u( const QString& track ); void parseM3u( const QString& track );
void getTags( const QFileInfo& info ); void getTags( const QFileInfo& info );
void parseLine(const QString& line , const QFile &file);
QList< query_ptr > m_tracks; QList< query_ptr > m_tracks;
QString m_title, m_info, m_creator; QString m_title, m_info, m_creator;
bool m_single; bool m_single;