mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-19 07:19:42 +01:00
Create playlist from M3U
This commit is contained in:
parent
f38f6b2eed
commit
ed306b00f0
@ -21,11 +21,12 @@
|
||||
#include "utils/tomahawkutils.h"
|
||||
#include "query.h"
|
||||
#include "sourcelist.h"
|
||||
#include "jobview/JobStatusView.h"
|
||||
#include "jobview/JobStatusModel.h"
|
||||
#include "viewmanager.h"
|
||||
#include <QtCore/QRegExp>
|
||||
|
||||
//#include <QtCore/QRegExp>
|
||||
#include <QtCore/QFileInfo>
|
||||
#include "playlist.h"
|
||||
|
||||
#include "dropjob.h"
|
||||
#include <QtCore/QFile>
|
||||
/* taglib */
|
||||
#include <taglib/fileref.h>
|
||||
@ -57,7 +58,7 @@ M3uLoader::~M3uLoader()
|
||||
{
|
||||
}
|
||||
|
||||
Tomahawk::query_ptr
|
||||
void
|
||||
M3uLoader::getTags( const QFileInfo& info )
|
||||
{
|
||||
|
||||
@ -74,13 +75,13 @@ M3uLoader::getTags( const QFileInfo& info )
|
||||
if ( artist.isEmpty() || track.isEmpty() )
|
||||
{
|
||||
qDebug() << "Error parsing" << info.fileName();
|
||||
return Tomahawk::query_ptr();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << artist << track << album;
|
||||
Tomahawk::query_ptr q = Tomahawk::Query::get( artist, track, album, uuid(), true );
|
||||
return q;
|
||||
Tomahawk::query_ptr q = Tomahawk::Query::get( artist, track, album, uuid(), !m_createNewPlaylist );
|
||||
m_tracks << q;
|
||||
}
|
||||
|
||||
}
|
||||
@ -97,6 +98,8 @@ M3uLoader::parseM3u( const QString& fileLink )
|
||||
return;
|
||||
}
|
||||
|
||||
m_title = fileInfo.baseName();
|
||||
|
||||
while ( !file.atEnd() )
|
||||
{
|
||||
|
||||
@ -110,23 +113,44 @@ M3uLoader::parseM3u( const QString& fileLink )
|
||||
QFileInfo tmpFile( QUrl::fromUserInput( QString( line.simplified() ) ).toLocalFile() );
|
||||
|
||||
if( tmpFile.exists() )
|
||||
m_tracks << getTags( tmpFile );
|
||||
getTags( tmpFile );
|
||||
else
|
||||
{
|
||||
QFileInfo tmpFile( QUrl::fromUserInput( QString( fileInfo.canonicalPath() + "/" + line.simplified() ) ).toLocalFile() );
|
||||
if( tmpFile.exists() )
|
||||
m_tracks << getTags( tmpFile );
|
||||
getTags( tmpFile );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
if( !m_tracks.isEmpty() )
|
||||
if( m_tracks.isEmpty() )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO << "Emitting tracks!";
|
||||
emit tracks( m_tracks );
|
||||
|
||||
qDebug() << Q_FUNC_INFO << "Coulnt parse M3U!";
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if ( m_createNewPlaylist )
|
||||
{
|
||||
m_playlist = Playlist::create( SourceList::instance()->getLocal(),
|
||||
uuid(),
|
||||
m_title,
|
||||
m_info,
|
||||
m_creator,
|
||||
false,
|
||||
m_tracks );
|
||||
|
||||
connect( m_playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), this, SLOT( playlistCreated() ) );
|
||||
|
||||
}
|
||||
else
|
||||
emit tracks( m_tracks );
|
||||
|
||||
|
||||
m_tracks.clear();
|
||||
file.deleteLater();
|
||||
|
||||
}
|
||||
|
||||
|
@ -19,11 +19,12 @@
|
||||
#ifndef M3U_LOADER_H
|
||||
#define M3U_LOADER_H
|
||||
|
||||
|
||||
#include <QtCore/QFileInfo>
|
||||
#include "dllmacro.h"
|
||||
#include "typedefs.h"
|
||||
#include "query.h"
|
||||
#include "dropjobnotifier.h"
|
||||
#include <QtCore/QFileInfo>
|
||||
#include "playlist.h"
|
||||
#include <QObject>
|
||||
#include <QSet>
|
||||
#include <QtCore/QStringList>
|
||||
@ -40,18 +41,21 @@ public:
|
||||
explicit M3uLoader( const QString& trackUrl, bool createNewPlaylist = false, QObject* parent = 0 );
|
||||
explicit M3uLoader( const QStringList& trackUrls, bool createNewPlaylist = false, QObject* parent = 0 );
|
||||
virtual ~M3uLoader();
|
||||
|
||||
signals:
|
||||
void track( const Tomahawk::query_ptr& track );
|
||||
void tracks( const QList< Tomahawk::query_ptr > tracks );
|
||||
|
||||
private:
|
||||
void parseM3u( const QString& track );
|
||||
Tomahawk::query_ptr getTags( const QFileInfo& info );
|
||||
void getTags( const QFileInfo& info );
|
||||
QList< query_ptr > m_tracks;
|
||||
QString m_title, m_info, m_creator;
|
||||
bool m_single;
|
||||
bool m_trackMode;
|
||||
bool m_createNewPlaylist;
|
||||
playlist_ptr m_playlist;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user