1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-07 14:46:33 +02:00

* Fixed M3U loader not appending tracks to an existing playlist.

This commit is contained in:
Christian Muehlhaeuser
2011-11-28 09:51:20 +01:00
parent 5911b51d05
commit e2336b595d
3 changed files with 45 additions and 43 deletions

View File

@@ -103,19 +103,18 @@ DropJob::acceptsMimeData( const QMimeData* data, DropJob::DropTypes acceptedType
const QString url = data->data( "text/plain" ); const QString url = data->data( "text/plain" );
if ( acceptedType.testFlag( Playlist ) ) if ( acceptedType.testFlag( Playlist ) )
{ {
if( url.contains( "xspf" ) ) if ( url.contains( "xspf" ) )
return true; return true;
if( url.contains( "m3u" ) ) if ( url.contains( "m3u" ) )
return true; return true;
if( data->data( "text/uri-list" ).contains( "xspf" ) ) if ( data->data( "text/uri-list" ).contains( "xspf" ) )
return true; return true;
if( data->data( "text/uri-list" ).contains( "m3u" ) ) if ( data->data( "text/uri-list" ).contains( "m3u" ) )
return true; return true;
// Not the most elegant // Not the most elegant
@@ -125,10 +124,10 @@ DropJob::acceptsMimeData( const QMimeData* data, DropJob::DropTypes acceptedType
if ( acceptedType.testFlag( Track ) ) if ( acceptedType.testFlag( Track ) )
{ {
if( url.contains( "m3u" ) ) if ( url.contains( "m3u" ) )
return true; return true;
if( data->data( "text/uri-list" ).contains( "m3u" ) ) if ( data->data( "text/uri-list" ).contains( "m3u" ) )
return true; return true;
if ( url.contains( "itunes" ) && url.contains( "album" ) ) // YES itunes is fucked up and song links have album/ in the url. if ( url.contains( "itunes" ) && url.contains( "album" ) ) // YES itunes is fucked up and song links have album/ in the url.
@@ -466,6 +465,7 @@ DropJob::handleM3u( const QString& fileUrls )
tDebug() << Q_FUNC_INFO << "Trying to append contents from" << urls; tDebug() << Q_FUNC_INFO << "Trying to append contents from" << urls;
connect( m, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ), this, SLOT( onTracksAdded( QList< Tomahawk::query_ptr > ) ) ); connect( m, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ), this, SLOT( onTracksAdded( QList< Tomahawk::query_ptr > ) ) );
} }
m->parse();
m_queryCount++; m_queryCount++;
} }
@@ -556,7 +556,6 @@ DropJob::handleRdioUrls( const QString& urlsRaw )
m_queryCount++; m_queryCount++;
rdio->setCreatePlaylist( dropAction() == Create ); rdio->setCreatePlaylist( dropAction() == Create );
rdio->parse( urls ); rdio->parse( urls );
} }
@@ -785,5 +784,4 @@ DropJob::getTopTen( const QString &artist )
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData ); Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
m_queryCount++; m_queryCount++;
} }

View File

@@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* *
* Copyright 2010-2011, Hugo Lindström <hugolm84@gmail.com> * Copyright 2010-2011, Hugo Lindström <hugolm84@gmail.com>
* Copyright 2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -22,46 +23,55 @@
#include "query.h" #include "query.h"
#include "sourcelist.h" #include "sourcelist.h"
//#include <QtCore/QRegExp>
#include <QtCore/QFileInfo>
#include "playlist.h" #include "playlist.h"
#include "dropjob.h" #include "dropjob.h"
#include <QtCore/QFile>
#include <QFileInfo>
#include <QFile>
/* taglib */ /* taglib */
#include <taglib/fileref.h> #include <taglib/fileref.h>
#include <taglib/tag.h> #include <taglib/tag.h>
using namespace Tomahawk; using namespace Tomahawk;
M3uLoader::M3uLoader( const QStringList& Urls, bool createNewPlaylist, QObject* parent )
: QObject ( parent ) M3uLoader::M3uLoader( const QStringList& urls, bool createNewPlaylist, QObject* parent )
: QObject( parent )
, m_single( false ) , m_single( false )
, m_trackMode( true ) , m_trackMode( true )
, m_createNewPlaylist( createNewPlaylist ) , m_createNewPlaylist( createNewPlaylist )
, m_urls( urls )
{ {
foreach ( const QString& url, Urls )
parseM3u( url );
} }
M3uLoader::M3uLoader( const QString& Url, bool createNewPlaylist, QObject* parent )
: QObject ( parent ) M3uLoader::M3uLoader( const QString& url, bool createNewPlaylist, QObject* parent )
: QObject( parent )
, m_single( false ) , m_single( false )
, m_trackMode( true ) , m_trackMode( true )
, m_createNewPlaylist( createNewPlaylist ) , m_createNewPlaylist( createNewPlaylist )
, m_urls( url )
{ {
parseM3u( Url );
} }
M3uLoader::~M3uLoader() M3uLoader::~M3uLoader()
{ {
} }
void
M3uLoader::parse()
{
foreach ( const QString& url, m_urls )
parseM3u( url );
}
void void
M3uLoader::getTags( const QFileInfo& info ) M3uLoader::getTags( const QFileInfo& info )
{ {
QByteArray fileName = QFile::encodeName( info.canonicalFilePath() ); QByteArray fileName = QFile::encodeName( info.canonicalFilePath() );
const char *encodedName = fileName.constData(); const char *encodedName = fileName.constData();
@@ -83,9 +93,9 @@ M3uLoader::getTags( const QFileInfo& info )
Tomahawk::query_ptr q = Tomahawk::Query::get( artist, track, album, uuid(), !m_createNewPlaylist ); Tomahawk::query_ptr q = Tomahawk::Query::get( artist, track, album, uuid(), !m_createNewPlaylist );
m_tracks << q; m_tracks << q;
} }
} }
void void
M3uLoader::parseM3u( const QString& fileLink ) M3uLoader::parseM3u( const QString& fileLink )
{ {
@@ -94,22 +104,19 @@ M3uLoader::parseM3u( const QString& fileLink )
if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) ) if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
{ {
qDebug() << "Error" << file.errorString(); tDebug() << "Error opening m3u:" << file.errorString();
return; return;
} }
m_title = fileInfo.baseName(); m_title = fileInfo.baseName();
while ( !file.atEnd() ) while ( !file.atEnd() )
{ {
QByteArray line = file.readLine(); QByteArray line = file.readLine();
/// If anyone wants to take on the regex for parsing EXT, go ahead /// 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 /// But the notion that users does not tag by a common rule. that seems hard
if( line.contains("EXT") ) if ( line.contains( "EXT" ) )
continue; continue;
qDebug() << line.simplified();
QFileInfo tmpFile( QUrl::fromUserInput( QString( line.simplified() ) ).toLocalFile() ); QFileInfo tmpFile( QUrl::fromUserInput( QString( line.simplified() ) ).toLocalFile() );
if( tmpFile.exists() ) if( tmpFile.exists() )
@@ -117,21 +124,17 @@ M3uLoader::parseM3u( const QString& fileLink )
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() )
getTags( tmpFile ); getTags( tmpFile );
} }
} }
if ( m_tracks.isEmpty() )
if( m_tracks.isEmpty() )
{ {
tDebug() << Q_FUNC_INFO << "Could not parse M3U!";
qDebug() << Q_FUNC_INFO << "Coulnt parse M3U!";
return; return;
} }
if ( m_createNewPlaylist ) if ( m_createNewPlaylist )
{ {
m_playlist = Playlist::create( SourceList::instance()->getLocal(), m_playlist = Playlist::create( SourceList::instance()->getLocal(),
@@ -143,14 +146,10 @@ M3uLoader::parseM3u( const QString& fileLink )
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();
file.deleteLater(); file.deleteLater();
} }

View File

@@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === /* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
* *
* Copyright 2011-2012, Hugo Lindström <hugolm84@gmail.com> * Copyright 2010-2011, Hugo Lindström <hugolm84@gmail.com>
* Copyright 2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
* *
* Tomahawk is free software: you can redistribute it and/or modify * Tomahawk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@@ -37,11 +38,15 @@ namespace Tomahawk
class DLLEXPORT M3uLoader : public QObject class DLLEXPORT M3uLoader : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit M3uLoader( const QString& trackUrl, bool createNewPlaylist = false, QObject* parent = 0 ); explicit M3uLoader( const QString& url, bool createNewPlaylist = false, QObject* parent = 0 );
explicit M3uLoader( const QStringList& trackUrls, bool createNewPlaylist = false, QObject* parent = 0 ); explicit M3uLoader( const QStringList& urls, bool createNewPlaylist = false, QObject* parent = 0 );
virtual ~M3uLoader(); virtual ~M3uLoader();
public slots:
void parse();
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 );
@@ -55,7 +60,7 @@ private:
bool m_trackMode; bool m_trackMode;
bool m_createNewPlaylist; bool m_createNewPlaylist;
playlist_ptr m_playlist; playlist_ptr m_playlist;
QStringList m_urls;
}; };
} }