mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-01 03:40:16 +02:00
Allow dropping iTunes Library
This commit is contained in:
@@ -100,6 +100,7 @@ set( libGuiSources
|
|||||||
utils/SpotifyParser.cpp
|
utils/SpotifyParser.cpp
|
||||||
utils/M3uLoader.cpp
|
utils/M3uLoader.cpp
|
||||||
utils/ItunesParser.cpp
|
utils/ItunesParser.cpp
|
||||||
|
utils/ItunesLoader.cpp
|
||||||
utils/RdioParser.cpp
|
utils/RdioParser.cpp
|
||||||
utils/ShortenedLinkParser.cpp
|
utils/ShortenedLinkParser.cpp
|
||||||
utils/SoundcloudParser.cpp
|
utils/SoundcloudParser.cpp
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#include "utils/SpotifyParser.h"
|
#include "utils/SpotifyParser.h"
|
||||||
#include "utils/ItunesParser.h"
|
#include "utils/ItunesParser.h"
|
||||||
|
#include "utils/ItunesLoader.h"
|
||||||
#include "utils/RdioParser.h"
|
#include "utils/RdioParser.h"
|
||||||
#include "utils/M3uLoader.h"
|
#include "utils/M3uLoader.h"
|
||||||
#include "utils/ShortenedLinkParser.h"
|
#include "utils/ShortenedLinkParser.h"
|
||||||
@@ -114,6 +115,12 @@ 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( "xml" ) && url.contains( "iTunes") )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if ( data->data( "text/uri-list" ).contains( "xml" ) && data->data( "text/uri-list" ).contains( "iTunes") )
|
||||||
|
return true;
|
||||||
|
|
||||||
if ( url.contains( "xspf" ) )
|
if ( url.contains( "xspf" ) )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@@ -204,6 +211,12 @@ DropJob::isDropType( DropJob::DropType desired, const QMimeData* data )
|
|||||||
const QString url = data->data( "text/plain" );
|
const QString url = data->data( "text/plain" );
|
||||||
if ( desired == Playlist )
|
if ( desired == Playlist )
|
||||||
{
|
{
|
||||||
|
if ( url.contains( "xml" ) && url.contains( "iTunes") )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
if ( data->data( "text/uri-list" ).contains( "xml" ) && data->data( "text/uri-list" ).contains( "iTunes") )
|
||||||
|
return true;
|
||||||
|
|
||||||
if( url.contains( "xspf" ) || data->data( "text/uri-list").contains( "xspf" ) )
|
if( url.contains( "xspf" ) || data->data( "text/uri-list").contains( "xspf" ) )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@@ -682,7 +695,12 @@ DropJob::handleAllUrls( const QString& urls )
|
|||||||
void
|
void
|
||||||
DropJob::handleTrackUrls( const QString& urls )
|
DropJob::handleTrackUrls( const QString& urls )
|
||||||
{
|
{
|
||||||
if ( urls.contains( "itunes.apple.com") )
|
|
||||||
|
if ( urls.contains( "xml" ) && urls.contains( "iTunes" ) )
|
||||||
|
{
|
||||||
|
new iTunesLoader( urls, this );
|
||||||
|
}
|
||||||
|
else if ( urls.contains( "itunes.apple.com") )
|
||||||
{
|
{
|
||||||
QStringList tracks = urls.split( QRegExp( "\\s+" ), QString::SkipEmptyParts );
|
QStringList tracks = urls.split( QRegExp( "\\s+" ), QString::SkipEmptyParts );
|
||||||
|
|
||||||
|
103
src/libtomahawk/utils/ItunesLoader.cpp
Normal file
103
src/libtomahawk/utils/ItunesLoader.cpp
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2013, Hugo Lindström <hugolm84@gmail.com>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ItunesLoader.h"
|
||||||
|
#include <QUrl>
|
||||||
|
#include <QSettings>
|
||||||
|
#include "Playlist.h"
|
||||||
|
#include "SourceList.h"
|
||||||
|
|
||||||
|
using namespace Tomahawk;
|
||||||
|
|
||||||
|
ItunesLoader::ItunesLoader( const QString& input, QObject *parent)
|
||||||
|
: QObject(parent)
|
||||||
|
, m_itunesLibFile( input )
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Paths to ItunesLibFile
|
||||||
|
* /Users/username/Music/iTunes/iTunes Library.xml
|
||||||
|
* \Users\username\Music\iTunes\iTunes Library.xml
|
||||||
|
* \Documents and Settings\username\My Documents\My Music\iTunes\iTunes Library.xml
|
||||||
|
* http://support.apple.com/kb/HT1660
|
||||||
|
*/
|
||||||
|
|
||||||
|
QSettings plist( QUrl::fromUserInput( QString( input.simplified() ) ).toLocalFile(), QSettings::NativeFormat);
|
||||||
|
|
||||||
|
m_ignoreFields << "Library" << "Movies" << "TV Shows" << "Music Videos" << "Genius";
|
||||||
|
|
||||||
|
parseTracks( plist.value( "Tracks" ).toMap() );
|
||||||
|
parsePlaylists( plist.value( "Playlists" ).toList() );
|
||||||
|
|
||||||
|
foreach ( const QString& name, m_playlists.keys())
|
||||||
|
{
|
||||||
|
Playlist::create( SourceList::instance()->getLocal(),
|
||||||
|
uuid(),
|
||||||
|
name,
|
||||||
|
"iTunes imported playlist",
|
||||||
|
"",
|
||||||
|
false,
|
||||||
|
m_playlists[ name ] );
|
||||||
|
}
|
||||||
|
|
||||||
|
m_tracks.clear();
|
||||||
|
m_playlists.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ItunesLoader::parseTracks( const QVariantMap& tracks )
|
||||||
|
{
|
||||||
|
foreach ( const QVariant& track, tracks )
|
||||||
|
{
|
||||||
|
QVariantMap trackMap = track.toMap();
|
||||||
|
if ( !trackMap.value( "Track ID" ).isValid() )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const QString artist = trackMap.value( "Artist", "" ).toString();
|
||||||
|
const QString title = trackMap.value( "Name", "" ).toString();
|
||||||
|
const QString album = trackMap.value( "Album", "" ).toString();
|
||||||
|
|
||||||
|
if ( artist.isEmpty() || title.isEmpty() )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
m_tracks.insert( trackMap.value( "Track ID" ).toInt(), Tomahawk::Query::get( artist, title, album ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ItunesLoader::parsePlaylists( const QVariantList& playlists )
|
||||||
|
{
|
||||||
|
foreach ( const QVariant& playlist, playlists )
|
||||||
|
{
|
||||||
|
const QString title = playlist.toMap().value( "Name" ).toString();
|
||||||
|
|
||||||
|
if ( m_ignoreFields.contains( title ) )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
foreach ( const QVariant& items, playlist.toMap() )
|
||||||
|
{
|
||||||
|
if ( items.toMap().value( "Track ID" ).isValid() )
|
||||||
|
{
|
||||||
|
int trackId = items.toMap().value( "Track ID" ).toInt();
|
||||||
|
if ( m_tracks.contains( trackId ) )
|
||||||
|
m_playlists[title] << m_tracks[ trackId ];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
54
src/libtomahawk/utils/ItunesLoader.h
Normal file
54
src/libtomahawk/utils/ItunesLoader.h
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
|
||||||
|
*
|
||||||
|
* Copyright 2013, Hugo Lindström <hugolm84@gmail.com>
|
||||||
|
*
|
||||||
|
* Tomahawk is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Tomahawk is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ITUNESLOADER__
|
||||||
|
#define __ITUNESLOADER__
|
||||||
|
|
||||||
|
|
||||||
|
#include "DllMacro.h"
|
||||||
|
#include "Typedefs.h"
|
||||||
|
#include "Query.h"
|
||||||
|
#include <QMap>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
namespace Tomahawk
|
||||||
|
{
|
||||||
|
|
||||||
|
class DLLEXPORT ItunesLoader : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit ItunesLoader( const QString& input, QObject* parent = 0 );
|
||||||
|
~iTunesLoader(){}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void parseTracks( const QVariantMap& tracks );
|
||||||
|
void parsePlaylists( const QVariantList& playlists );
|
||||||
|
|
||||||
|
QString m_itunesLibFile;
|
||||||
|
QStringList m_ignoreFields;
|
||||||
|
|
||||||
|
QMap< QString, QList<Tomahawk::query_ptr > > m_playlists;
|
||||||
|
QMap< int, Tomahawk::query_ptr > m_tracks;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
Reference in New Issue
Block a user