1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-19 07:19:42 +01: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" );
if ( acceptedType.testFlag( Playlist ) )
{
if( url.contains( "xspf" ) )
if ( url.contains( "xspf" ) )
return true;
if( url.contains( "m3u" ) )
if ( url.contains( "m3u" ) )
return true;
if( data->data( "text/uri-list" ).contains( "xspf" ) )
if ( data->data( "text/uri-list" ).contains( "xspf" ) )
return true;
if( data->data( "text/uri-list" ).contains( "m3u" ) )
if ( data->data( "text/uri-list" ).contains( "m3u" ) )
return true;
// Not the most elegant
@ -125,10 +124,10 @@ DropJob::acceptsMimeData( const QMimeData* data, DropJob::DropTypes acceptedType
if ( acceptedType.testFlag( Track ) )
{
if( url.contains( "m3u" ) )
if ( url.contains( "m3u" ) )
return true;
if( data->data( "text/uri-list" ).contains( "m3u" ) )
if ( data->data( "text/uri-list" ).contains( "m3u" ) )
return true;
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;
connect( m, SIGNAL( tracks( QList<Tomahawk::query_ptr> ) ), this, SLOT( onTracksAdded( QList< Tomahawk::query_ptr > ) ) );
}
m->parse();
m_queryCount++;
}
@ -556,7 +556,6 @@ DropJob::handleRdioUrls( const QString& urlsRaw )
m_queryCount++;
rdio->setCreatePlaylist( dropAction() == Create );
rdio->parse( urls );
}
@ -785,5 +784,4 @@ DropJob::getTopTen( const QString &artist )
Tomahawk::InfoSystem::InfoSystem::instance()->getInfo( requestData );
m_queryCount++;
}

View File

@ -1,6 +1,7 @@
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
*
* 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
* it under the terms of the GNU General Public License as published by
@ -22,46 +23,55 @@
#include "query.h"
#include "sourcelist.h"
//#include <QtCore/QRegExp>
#include <QtCore/QFileInfo>
#include "playlist.h"
#include "dropjob.h"
#include <QtCore/QFile>
#include <QFileInfo>
#include <QFile>
/* taglib */
#include <taglib/fileref.h>
#include <taglib/tag.h>
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_trackMode( true )
, 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_trackMode( true )
, m_createNewPlaylist( createNewPlaylist )
, m_urls( url )
{
parseM3u( Url );
}
M3uLoader::~M3uLoader()
{
}
void
M3uLoader::parse()
{
foreach ( const QString& url, m_urls )
parseM3u( url );
}
void
M3uLoader::getTags( const QFileInfo& info )
{
QByteArray fileName = QFile::encodeName( info.canonicalFilePath() );
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 );
m_tracks << q;
}
}
void
M3uLoader::parseM3u( const QString& fileLink )
{
@ -94,22 +104,19 @@ M3uLoader::parseM3u( const QString& fileLink )
if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
{
qDebug() << "Error" << file.errorString();
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
if( line.contains("EXT") )
if ( line.contains( "EXT" ) )
continue;
qDebug() << line.simplified();
QFileInfo tmpFile( QUrl::fromUserInput( QString( line.simplified() ) ).toLocalFile() );
if( tmpFile.exists() )
@ -117,21 +124,17 @@ M3uLoader::parseM3u( const QString& fileLink )
else
{
QFileInfo tmpFile( QUrl::fromUserInput( QString( fileInfo.canonicalPath() + "/" + line.simplified() ) ).toLocalFile() );
if( tmpFile.exists() )
if ( tmpFile.exists() )
getTags( tmpFile );
}
}
if( m_tracks.isEmpty() )
if ( m_tracks.isEmpty() )
{
qDebug() << Q_FUNC_INFO << "Coulnt parse M3U!";
tDebug() << Q_FUNC_INFO << "Could not parse M3U!";
return;
}
if ( m_createNewPlaylist )
{
m_playlist = Playlist::create( SourceList::instance()->getLocal(),
@ -143,14 +146,10 @@ M3uLoader::parseM3u( const QString& fileLink )
m_tracks );
connect( m_playlist.data(), SIGNAL( revisionLoaded( Tomahawk::PlaylistRevision ) ), this, SLOT( playlistCreated() ) );
}
else
emit tracks( m_tracks );
m_tracks.clear();
file.deleteLater();
}

View File

@ -1,6 +1,7 @@
/* === 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
* it under the terms of the GNU General Public License as published by
@ -37,11 +38,15 @@ namespace Tomahawk
class DLLEXPORT M3uLoader : public QObject
{
Q_OBJECT
public:
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 QString& url, bool createNewPlaylist = false, QObject* parent = 0 );
explicit M3uLoader( const QStringList& urls, bool createNewPlaylist = false, QObject* parent = 0 );
virtual ~M3uLoader();
public slots:
void parse();
signals:
void track( const Tomahawk::query_ptr& track );
void tracks( const QList< Tomahawk::query_ptr > tracks );
@ -55,7 +60,7 @@ private:
bool m_trackMode;
bool m_createNewPlaylist;
playlist_ptr m_playlist;
QStringList m_urls;
};
}