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