Skip to content
Browse files

Move fingerprinting to a different process.

  • Loading branch information...
1 parent b02ee8f commit fc664d1b2da8e8777525e03798b3d0e1444ebe2e @eartle eartle committed Mar 7, 2013
View
3 Last.fm.pro
@@ -5,7 +5,8 @@ SUBDIRS = lib/logger \
lib/listener \
i18n \
app/client \
- app/twiddly
+ app/twiddly \
+ app/fingerprinter
#app/boffin
unix:!mac:SUBDIRS -= app/twiddly
View
2 admin/dist/mac/bundleFrameworks.sh
@@ -155,7 +155,7 @@ echo
echo ======= Copying Qt plugins ===========
mkdir -p "$bundlePath/Contents/plugins"
-plugins="imageformats phonon_backend sqldrivers"
+plugins="imageformats phonon_backend sqldrivers bearer"
for plugin in $plugins; do
if [ -d /Developer/Applications/Qt/plugins/ ]; then
View
12 admin/qmake/3rdparty.pro.inc
@@ -10,13 +10,12 @@ CONFIG( taglib ) {
}
CONFIG( ffmpeg ) {
- DEFINES += FFMPEG_FINGERPRINTING
-
mac {
LIBS += /usr/local/lib/libavcodec.dylib
LIBS += /usr/local/lib/libavformat.dylib
LIBS += /usr/local/lib/libavutil.dylib
LIBS += /usr/local/lib/libswresample.dylib
+ DEFINES += HAVE_SWRESAMPLE
} else {
CONFIG += link_pkgconfig
PKGCONFIG += libavformat libavcodec libavutil
@@ -25,15 +24,6 @@ CONFIG( ffmpeg ) {
DEFINES += HAVE_SWRESAMPLE
}
}
-
- win32:CONFIG(debug, debug|release) {
- # disable fingerprinting on windows debug
- # the pre-built ffmpeg we use is incompatible with debug builds
- # because the crt it links against is incompatible
- PKGCONFIG -= libavformat
- PKGCONFIG -= libswresample
- DEFINES -= FFMPEG_FINGERPRINTING
- }
}
CONFIG( boost ) {
View
24 app/client/Application.cpp
@@ -55,7 +55,6 @@
#include "CommandReciever/CommandReciever.h"
#endif
-#include "Fingerprinter/Fingerprinter.h"
#include "Dialogs/LicensesDialog.h"
#include "MediaDevices/DeviceScrobbler.h"
#include "Services/RadioService.h"
@@ -497,7 +496,6 @@ Application::onTrackStarted( const lastfm::Track& track, const Track& oldTrack )
}
}
-#ifdef FFMPEG_FINGERPRINTING
if ( unicorn::UserSettings().value( "fingerprint", true ).toBool()
#if QT_VERSION >= 0x040800
&& track.url().isLocalFile()
@@ -509,12 +507,26 @@ Application::onTrackStarted( const lastfm::Track& track, const Track& oldTrack )
if ( trackFileInfo.exists()
&& trackFileInfo.isWritable() ) // this stops us fingerprinting CDs (but maybe other things)
{
- Fingerprinter* fingerprinter = new Fingerprinter( track, this );
- connect( fingerprinter, SIGNAL(finished()), fingerprinter, SLOT(deleteLater()) );
- fingerprinter->start();
+ QProcess* fpProcess = new QProcess( this );
+ connect( fpProcess, SIGNAL(finished(int)), fpProcess, SLOT(deleteLater()) );
+
+ QStringList arguments;
+ arguments << User().name();
+ arguments << track.url().toLocalFile();
+ arguments << "--title" << track.title();
+ arguments << "--album" << track.album();
+ arguments << "--artist" << track.artist();
+
+#ifdef Q_OS_WIN
+ QString fpExe = QDir( QCoreApplication::applicationDirPath() ).absoluteFilePath( "fingerprinter.exe" );
+#elif defined( Q_OS_MAC )
+ QString fpExe = QDir( QCoreApplication::applicationDirPath() ).absoluteFilePath( "../Helpers/fingerprinter" );
+#else
+ QString fpExe = QDir( QCoreApplication::applicationDirPath() ).absoluteFilePath( "fingerprinter" );
+#endif
+ fpProcess->start( fpExe, arguments );
}
}
-#endif
m_tray->setToolTip( track.toString() );
View
5 app/client/Settings/ScrobbleSettingsWidget.cpp
@@ -50,12 +50,7 @@ ScrobbleSettingsWidget::ScrobbleSettingsWidget( QWidget* parent )
ui->percentText->setFixedWidth( ui->percentText->fontMetrics().width( "100" ) );
m_initialScrobblePercentage = scrobblePointValue;
-#ifdef FFMPEG_FINGERPRINTING
ui->allowFingerprint->setChecked( userSettings.fingerprinting() );
-#else
- ui->allowFingerprint->setEnabled( false );
- ui->allowFingerprint->setChecked( false );
-#endif
ui->enfocreScrobbleTimeMax->setChecked( userSettings.enforceScrobbleTimeMax() );
ui->scrobblingOn->setChecked( userSettings.scrobblingOn() );
View
7 app/client/client.pro
@@ -103,7 +103,6 @@ SOURCES += \
Dialogs/LicensesDialog.cpp \
Widgets/ScrobblesWidget.cpp \
Widgets/ScrobblesListWidget.cpp \
- Fingerprinter/Fingerprinter.cpp \
Services/AnalyticsService/AnalyticsService.cpp \
Services/AnalyticsService/PersistentCookieJar.cpp \
Settings/CheckFileSystemModel.cpp \
@@ -182,18 +181,12 @@ HEADERS += \
Dialogs/LicensesDialog.h \
Widgets/ScrobblesListWidget.h \
Widgets/ScrobblesWidget.h \
- Fingerprinter/Fingerprinter.h \
Services/AnalyticsService.h \
Services/AnalyticsService/AnalyticsService.h \
Services/AnalyticsService/PersistentCookieJar.h \
Settings/CheckFileSystemModel.h \
Settings/CheckFileSystemView.h
-contains(DEFINES, FFMPEG_FINGERPRINTING) {
- SOURCES += Fingerprinter/LAV_Source.cpp
- HEADERS += Fingerprinter/LAV_Source.h
-}
-
mac:HEADERS += CommandReciever/CommandReciever.h \
MediaKeys/MediaKey.h \
../../lib/3rdparty/SPMediaKeyTap/SPMediaKeyTap.h \
View
89 app/client/Fingerprinter/Fingerprinter.cpp → app/fingerprinter/Fingerprinter.cpp
@@ -29,63 +29,70 @@
#include <lastfm/FingerprintableSource.h>
#include <lastfm/Track.h>
-#ifdef FFMPEG_FINGERPRINTING
#include "LAV_Source.h"
-#endif
-
#include "Fingerprinter.h"
Fingerprinter::Fingerprinter( const lastfm::Track& track, QObject* parent )
- :QThread( parent ), m_track( track )
-{
-}
-
-void
-Fingerprinter::run()
+ :QObject( parent ), m_fp( track ), m_fpSource( 0 )
{
-#ifdef FFMPEG_FINGERPRINTING
- QEventLoop loop;
-
- lastfm::Fingerprint fingerprint( m_track );
-
- if ( fingerprint.id().isNull() )
+ if ( m_fp.id().isNull() )
{
- lastfm::FingerprintableSource* fingerprintableSource = new LAV_Source();
+ m_fpSource = new LAV_Source();
- if ( fingerprintableSource )
+ if ( m_fpSource )
{
try
{
- fingerprint.generate( fingerprintableSource );
-
- QNetworkReply* fingerprintReply = fingerprint.submit();
- connect( fingerprintReply, SIGNAL(finished()), &loop, SLOT(quit()) );
- loop.exec();
-
- fingerprint.decode( fingerprintReply );
-
- qDebug() << "Fingerprint success: " << fingerprint.id();
-
-#ifndef NDEBUG
- // This code will fetch the suggestions from the fingerprint id, one
- // day we might do something with this info, like offer corrections
-
- QNetworkReply* reply = fingerprint.id().getSuggestions();
- connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
- loop.exec();
-
- QMap<float,Track> suggestions = lastfm::FingerprintId::getSuggestions( reply );
-
- qDebug() << suggestions;
-#endif
+ m_fp.generate( m_fpSource );
+ connect( m_fp.submit(), SIGNAL(finished()), SLOT(onFingerprintSubmitted()) );
}
catch ( const lastfm::Fingerprint::Error& error )
{
qWarning() << "Fingerprint error: " << error;
+ qApp->quit();
}
- delete fingerprintableSource;
}
}
-#endif // FFMPEG_FINGERPRINTING
+ else
+ {
+ qDebug() << "Already Fingerprinted: " << m_fp.id();
+
+#ifndef NDEBUG
+ // This code will fetch the suggestions from the fingerprint id, one
+ // day we might do something with this info, like offer corrections
+ connect( m_fp.id().getSuggestions(), SIGNAL(finished()), SLOT(onGotSuggestions()) );
+#else
+ qApp->quit();
+#endif
+ }
+}
+
+Fingerprinter::~Fingerprinter()
+{
+ delete m_fpSource;
+}
+
+void
+Fingerprinter::onFingerprintSubmitted()
+{
+ m_fp.decode( static_cast<QNetworkReply*>( sender() ) );
+ qDebug() << "Fingerprint success: " << m_fp.id();
+
+#ifndef NDEBUG
+ // This code will fetch the suggestions from the fingerprint id, one
+ // day we might do something with this info, like offer corrections
+ connect( m_fp.id().getSuggestions(), SIGNAL(finished()), SLOT(onGotSuggestions()) );
+#else
+ qApp->quit();
+#endif
+
+}
+
+void
+Fingerprinter::onGotSuggestions()
+{
+ QMap<float, Track> suggestions = lastfm::FingerprintId::getSuggestions( static_cast<QNetworkReply*>( sender() ) );
+ qDebug() << suggestions;
+ qApp->quit();
}
View
15 app/client/Fingerprinter/Fingerprinter.h → app/fingerprinter/Fingerprinter.h
@@ -18,20 +18,27 @@
along with liblastfm. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <QThread>
+#include <QObject>
#include <lastfm/Track.h>
+#include <lastfm/Fingerprint.h>
-class Fingerprinter : public QThread
+namespace lastfm { class FingerprintableSource; }
+
+class Fingerprinter : public QObject
{
Q_OBJECT
public:
explicit Fingerprinter( const lastfm::Track& track, QObject* parent = 0 );
+ ~Fingerprinter();
-private:
- void run();
+private slots:
+ void onFingerprintSubmitted();
+ void onGotSuggestions();
private:
+ lastfm::Fingerprint m_fp;
+ lastfm::FingerprintableSource* m_fpSource;
lastfm::Track m_track;
};
View
0 app/client/Fingerprinter/LAV_Source.cpp → app/fingerprinter/LAV_Source.cpp
File renamed without changes.
View
0 app/client/Fingerprinter/LAV_Source.h → app/fingerprinter/LAV_Source.h
File renamed without changes.
View
27 app/fingerprinter/fingerprinter.pro
@@ -0,0 +1,27 @@
+TARGET = fingerprinter
+QT = core network xml sql
+
+CONFIG += lastfm unicorn logger fingerprint ffmpeg
+CONFIG -= app_bundle
+
+include( ../../admin/include.qmake )
+
+# TODO: FIX THIS: I think this means that we can only build bundles
+mac {
+ DESTDIR = "../../_bin/Last.fm Scrobbler.app/Contents/Helpers"
+ QMAKE_POST_LINK += ../../admin/dist/mac/bundleFrameworks.sh \"$$DESTDIR/$$TARGET\"
+}
+
+SOURCES += main.cpp \
+ Fingerprinter.cpp \
+ LAV_Source.cpp
+
+HEADERS += LAV_Source.h \
+ Fingerprinter.h
+
+
+
+
+
+DEFINES += LASTFM_COLLAPSE_NAMESPACE
+
View
64 app/fingerprinter/main.cpp
@@ -0,0 +1,64 @@
+/*
+ Copyright 2013 Last.fm Ltd.
+ - Primarily authored by Michael Coffey
+
+ This file is part of liblastfm.
+
+ liblastfm 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.
+
+ liblastfm 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 liblastfm. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "Fingerprinter.h"
+
+#include "lib/unicorn/UnicornCoreApplication.h"
+
+#include <lastfm/ws.h>
+
+#include <QStringList>
+#include <QCoreApplication>
+#include <QDebug>
+
+// ./fingerprinter <username> <filename> --title <title> --album <album> --artist <artist>
+
+int main(int argc, char *argv[])
+{
+ QtSingleCoreApplication::setApplicationName( "Last.fm Fingerprinter" );
+ QtSingleCoreApplication::setOrganizationName( "Last.fm" );
+
+ unicorn::CoreApplication a(argc, argv);
+
+ qDebug() << a.arguments();
+
+ // create the track from the command line arguments
+ MutableTrack track;
+
+ // argument 1 should always be the filename
+ lastfm::ws::Username = a.arguments().at( 1 );
+ track.setUrl( QUrl::fromLocalFile( a.arguments().at( 2 ) ) );
+
+ int titleIndex = a.arguments().indexOf( "--title" );
+ int albumIndex = a.arguments().indexOf( "--album" );
+ int artistIndex = a.arguments().indexOf( "--artist" );
+
+ if ( titleIndex != -1 ) track.setTitle( a.arguments().at( titleIndex + 1 ) );
+ if ( albumIndex != -1 ) track.setAlbum( a.arguments().at( albumIndex + 1 ) );
+ if ( artistIndex != -1 ) track.setTitle( a.arguments().at( artistIndex + 1 ) );
+
+ Fingerprinter* fingerprinter = new Fingerprinter( track );
+
+ int exitCode = a.exec();
+
+ delete fingerprinter;
+
+ return exitCode;
+}
View
9 app/twiddly/main.cpp
@@ -72,15 +72,6 @@ main( int argc, char** argv )
return 1;
}
-#ifdef Q_OS_MAC
- // We need to tell twiddly where to load the plugins because it
- // loads system ones when not in the /Contents/MacOS directory
- TwiddlyApplication::addLibraryPath( QDir( TwiddlyApplication::applicationDirPath() ).absoluteFilePath( "../plugins" ) );
-#elif defined Q_OS_WIN
- TwiddlyApplication::addLibraryPath( QDir( TwiddlyApplication::applicationDirPath() ).absoluteFilePath( "plugins" ) );
-#endif
-
-
// check we're using a compatible version of the plugin
unicorn::Version compatibleVersion( 6, 0, 5, 4 );
unicorn::Version installedVersion;
View
15 lib/unicorn/UnicornCoreApplication.cpp
@@ -40,6 +40,12 @@ unicorn::CoreApplication::CoreApplication( const QString& id, int& argc, char**
init();
}
+unicorn::CoreApplication::CoreApplication( int& argc, char** argv )
+ : QtSingleCoreApplication( argc, argv )
+{
+ init();
+}
+
void //static
unicorn::CoreApplication::init()
{
@@ -51,6 +57,14 @@ unicorn::CoreApplication::init()
lastfm::ws::ApiKey = QString( API_KEY ).isEmpty() ? "9e89b44de1ff37c5246ad0af18406454" : API_KEY;
lastfm::ws::SharedSecret = QString( API_SECRET ).isEmpty() ? "147320ea9b8930fe196a4231da50ada4" : API_SECRET;
+#ifdef Q_OS_MAC
+ QString pluginsDir = applicationDirPath() + "/../plugins";
+#elif defined Q_OS_WIN
+ QString pluginsDir = applicationDirPath() + "/plugins";
+#endif
+ addLibraryPath( pluginsDir );
+
+
dir::runtimeData().mkpath( "." );
#ifndef WIN32
QFile runtimeDataPerms( dir::runtimeData().absolutePath() );
@@ -71,6 +85,7 @@ unicorn::CoreApplication::init()
qInstallMsgHandler( qMsgHandler );
qDebug() << "Introducing" << applicationName()+' '+applicationVersion();
qDebug() << "Directed by" << lastfm::platform();
+ qDebug() << "Plugin DIR" << pluginsDir;
}
View
1 lib/unicorn/UnicornCoreApplication.h
@@ -38,6 +38,7 @@ namespace unicorn
public:
CoreApplication( const QString& id, int& argc, char** argv );
+ CoreApplication( int& argc, char** argv );
static QFileInfo log()
{

0 comments on commit fc664d1

Please sign in to comment.
Something went wrong with that request. Please try again.