1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-04 13:17:34 +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,12 +97,31 @@ 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
M3uLoader::parseLine( const QString& line, const QFile& file )
{
QFileInfo tmpFile( QUrl::fromUserInput( QString( line.simplified() ) ).toLocalFile() );
if( tmpFile.exists() )
{
getTags( tmpFile );
}
else
{
QUrl fileUrl = QUrl::fromUserInput( QString( QFileInfo(file).canonicalPath() + "/" + line.simplified() ) );
QFileInfo tmpFile( fileUrl.toLocalFile() );
if ( tmpFile.exists() )
{
getTags( tmpFile );
}
}
}
void void
M3uLoader::parseM3u( const QString& fileLink ) M3uLoader::parseM3u( const QString& fileLink )
@@ -110,7 +129,7 @@ M3uLoader::parseM3u( const QString& fileLink )
QFileInfo fileInfo( fileLink ); QFileInfo fileInfo( fileLink );
QFile file( QUrl::fromUserInput( fileLink ).toLocalFile() ); QFile file( QUrl::fromUserInput( fileLink ).toLocalFile() );
if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) ) if ( !file.open( QIODevice::ReadOnly ) )
{ {
tDebug() << "Error opening m3u:" << file.errorString(); tDebug() << "Error opening m3u:" << file.errorString();
return; return;
@@ -118,54 +137,56 @@ M3uLoader::parseM3u( const QString& fileLink )
m_title = fileInfo.baseName(); m_title = fileInfo.baseName();
while ( !file.atEnd() ) QTextStream stream( &file );
QString singleLine;
while ( !stream.atEnd() )
{ {
QByteArray line = file.readLine(); QString line = stream.readLine().trimmed();
/// 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() ); /// Fallback solution for, (drums) itunes!
singleLine.append(line);
if( tmpFile.exists() ) /// 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
getTags( tmpFile ); /// So ignore that for now
} if ( line.contains( "EXT" ) )
else continue;
{
QUrl fileUrl = QUrl::fromUserInput( QString( QFileInfo(file).canonicalPath() + "/" + line.simplified() ) ); parseLine( line, file );
QFileInfo tmpFile( fileUrl.toLocalFile() );
if ( tmpFile.exists() )
{
getTags( tmpFile );
}
}
} }
if ( m_tracks.isEmpty() ) if ( m_tracks.isEmpty() )
{ {
tDebug() << Q_FUNC_INFO << "Could not parse M3U!"; if ( !singleLine.isEmpty() )
return; {
QStringList m3uList = singleLine.split("\r");
foreach( const QString& line, m3uList )
parseLine( line, file );
}
if ( m_tracks.isEmpty() )
{
tDebug() << "Could not parse M3U!";
return;
}
} }
if ( m_createNewPlaylist ) if ( m_createNewPlaylist )
{ {
m_playlist = Playlist::create( SourceList::instance()->getLocal(), m_playlist = Playlist::create( SourceList::instance()->getLocal(),
uuid(), uuid(),
m_title, m_title,
m_info, m_info,
m_creator, m_creator,
false, false,
m_tracks ); m_tracks );
connect( m_playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), this, SLOT( playlistCreated() ) ); connect( m_playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), this, SLOT( playlistCreated() ) );
} }
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;