Bug 133030 - Katapult exporting malformed url to Amarok
Summary: Katapult exporting malformed url to Amarok
Status: RESOLVED FIXED
Alias: None
Product: katapult
Classification: Miscellaneous
Component: general (show other bugs)
Version: unspecified
Platform: Ubuntu Linux
: VHI normal
Target Milestone: ---
Assignee: Martin Meredith
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-08-26 16:01 UTC by Gareth Bowen
Modified: 2006-12-25 13:25 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gareth Bowen 2006-08-26 16:01:27 UTC
Version:           0.3.1.2 (using KDE KDE 3.5.3)
Installed from:    Ubuntu Packages
OS:                Linux

When using Katapult to play a media file in Amarok, the URL exported to Amarok begins with a period. This results in the following error from Amarok:

Error Loading Media
No suitable input plugin. This often means that the url's protocol is not supported.
./home/gareth/Music/B/Black Label Society/Mafia/05 - In This River.mp3

If, for example Amarok is given the command:

amarok /home/gareth/Music/B/Black Label Society/Mafia/05 - In This River.mp3

the file plays correctly.
Comment 1 Michele Spagnuolo 2006-09-03 19:55:22 UTC
Confirmed on Kubuntu Dapper, Amarok 1.4.2, and Katapult 0.3.1.2 and last dev (BZR) version.
Comment 2 Tobias G. Pfeiffer 2006-09-06 10:42:41 UTC
For me, the problem appeared only with Amarok 1.4.2, with 1.4.1 it still worked fine.
Comment 3 Michele Spagnuolo 2006-09-06 10:45:49 UTC
Yes, only with Amarok 1.4.2... Please do something in order to fix it!
Comment 4 Michele Spagnuolo 2006-09-06 10:50:56 UTC
The problem appears also with Amarok 1.4.3
Comment 5 Robert Parker 2006-09-06 17:59:28 UTC
Yes, I also have this problem with 1.4.2 and 1.4.3 (of course not installed at the same time)
Comment 6 Martin Meredith 2006-09-15 18:31:00 UTC
It may be exporting a malformed URL - but thats because it gets a malformed URL FROM amarok -

https://launchpad.net/products/katapult/+bug/60136

Comment 7 Stephen Baker 2006-10-12 14:57:39 UTC
Using This is Amarok 1.4.3 and Katapult 0.3.1.3

Not only is there a dot at the beginning, some of the path appears to be missing for me.

Actual track:
/mnt/win_c/Documents and Settings/Stephen/My Documents/My Music/Finger 11 - Awake and Dreaming.mp3

Katapult track: 
./Documents and Settings/Stephen/My Documents/My Music/Finger 11 - Awake and Dreaming.mp3
Comment 8 Neil Skrypuch 2006-10-13 01:14:31 UTC
This is because Amarok's tables have changed, as a result of ATF I believe, Katapult needs to use the device mountpoint appended to the url, for example:

neil@t40-n ~ $ dcop amarok collection query 'select lastmountpoint, url from devices join uniqueid on deviceid = id order by rand() limit 1'
/home
./neil/mp3/Red Hot Chili Peppers - By the Way/Red Hot Chili Peppers - By the Way - 02 - Universally Speaking.mp3

Joining the two columns with a / will give you the correct path. Presumably older versions of Amarok stored the full path in the url, but that isn't the case anymore.
Comment 9 Neil Skrypuch 2006-10-13 03:32:21 UTC
Well, I had a look at the source and found what should be the offending piece of code, but I can't for the life of me figure out why none of my changes to the file are reflected after compiling and running. I threw some debug output into katapult/common/cachedcatalog.cpp just to make sure, and those changes were reflected, so I have no idea why the others weren't.

However, if you look at katapult/plugins/catalogs/amarokcatalog/amarokcatalog.cpp:65 and change the sql there to this:

SELECT a.name, t.title, t.url, i.path, album.name d.lastmountpoint FROM tags t JOIN devices d ON t.deviceid = d.id JOIN artist a ON t.artist = a.id JOIN album ON t.album = album.id LEFT JOIN statistics s ON t.url = s.url LEFT JOIN images i ON (a.name = i.artist AND album.name = i.album) WHERE t.album = album.id AND t.artist = a.id

and then setURL() as d.lastmountpoint . "/" . t.url, it should work.

The above sql also has the advantage of working with a MySQL backend as well as SQLite (Katapult currently doesn't work with a MySQL backend for Amarok).
Comment 10 Martin Meredith 2006-10-22 01:39:04 UTC
Fix made - testing - will commit to SVN soon
Comment 11 Martin Meredith 2006-10-31 14:41:34 UTC
SVN commit 600691 by mmeredith:

Added PNGs for o2display

Fixed up amarokcatalog to work with amarok >=1.4.2
BUG: 133030



 M  +216 -62   catalogs/amarokcatalog/amarokcatalog.cpp  
 M  +3 -1      catalogs/amarokcatalog/amarokcatalog.h  
 AM            display/o2display/doublebg.png  
 AM            display/o2display/singlebg.png  


--- trunk/extragear/utils/katapult/plugins/catalogs/amarokcatalog/amarokcatalog.cpp #600690:600691
@@ -1,6 +1,8 @@
 /***************************************************************************
  *   Copyright (C) 2005 by Bastian Holst                                   *
  *   bastianholst@gmx.de                                                   *
+ *   Copyright (C) 2006 by Martin Meredith                                 *
+ *   mez@thekatapult.org.uk                                                *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
  *   it under the terms of the GNU General Public License as published by  *
@@ -45,6 +47,10 @@
 {
 	_minQueryLen = 3;
 	ActionRegistry::self()->registerAction(new ActionPlaySong());
+	_gotCollectionStatus = false;
+	_dynamicCollection = false;
+	checkCollectionType();	
+
 }
 AmarokCatalog::~AmarokCatalog()
 {
@@ -60,76 +66,184 @@
 		setBestMatch(Match());
 		setStatus(0);
 	} else {
-		QStringList queryList;
-		//prepares SQL-queryQRegExp
-		QString sqlQuery("SELECT a.name, t.title, t.url, i.path, album.name FROM tags t, artist a, album LEFT JOIN statistics s ON t.url = s.url LEFT JOIN images i ON (a.name = i.artist AND album.name = i.album) WHERE t.album = album.id AND t.artist = a.id"); // AND 
+
+		if ( _gotCollectionStatus)
+		{
+
+			if (!_dynamicCollection)
+			{
+
+			// Stuff for Amarok < 1.4.2
+
+				QStringList queryList;
+				//prepares SQL-queryQRegExp
+				QString sqlQuery("SELECT a.name, t.title, t.url, i.path, album.name FROM tags t, artist a, album LEFT JOIN statistics s ON t.url = s.url LEFT JOIN images i ON (a.name = i.artist AND album.name = i.album) WHERE t.album = album.id AND t.artist = a.id"); // AND 
 		
-		queryList = QStringList::split ( QString(" "), QString(queryString).replace(QChar(':')," ").replace(QChar('\"'), " ").replace(QChar('\"'), "%") );	
-		for(QStringList::Iterator it = queryList.begin(); it != queryList.end(); ++it) {
-			sqlQuery.append(QString(" AND (t.title LIKE \"%%%1%%\"").arg(*it));
-			sqlQuery.append(QString(" OR a.name LIKE \"%%%1%%\")").arg(*it));
-		}
-		sqlQuery.append(" ORDER BY a.name, t.title, s.percentage DESC");
-		
-		//sending SQL-query to amarok via dcop
-		QByteArray sqlQueryData, replyData;
-		QCString replyType;
-		QDataStream arg(sqlQueryData, IO_WriteOnly);
-		arg << sqlQuery;
-		if (!kapp->dcopClient()->call("amarok", "collection", "query(QString)",
-		     sqlQueryData, replyType, replyData)) {
-			//qDebug("There was some error using DCOP. Perhaps amaroK doesn't run.");
-			newStatus = 0;
-		} else {
-			QDataStream reply(replyData, IO_ReadOnly);
-			if (replyType == "QStringList") {
-				QStringList sqlResult;
-				reply >> sqlResult;
+				queryList = QStringList::split ( QString(" "), QString(queryString).replace(QChar(':')," ").replace(QChar('\"'), " ").replace(QChar('\"'), "%") );	
+				for(QStringList::Iterator it = queryList.begin(); it != queryList.end(); ++it) {
+					sqlQuery.append(QString(" AND (t.title LIKE \"\%%1\%\"").arg(*it));
+					sqlQuery.append(QString(" OR a.name LIKE \"\%%1\%\")").arg(*it));
+				}
+				sqlQuery.append(" ORDER BY a.name, t.title, s.percentage DESC");
 				
-				if(sqlResult.isEmpty()) {
+				//sending SQL-query to ararok via dcop
+				QByteArray sqlQueryData, replyData;
+				QCString replyType;
+				QDataStream arg(sqlQueryData, IO_WriteOnly);
+				arg << sqlQuery;
+				if (!kapp->dcopClient()->call("amarok", "collection", "query(QString)",
+				     sqlQueryData, replyType, replyData)) {
 					newStatus = 0;
 				} else {
-					reset();
-					//Reads information from SQL-Query
-					_result.setArtist(sqlResult[0]);
-					_result.setName(sqlResult[1]);
-					_result.setURL(KURL(sqlResult[2]));
-					_result.setAlbum(sqlResult[4]);
+					QDataStream reply(replyData, IO_ReadOnly);
+					if (replyType == "QStringList") {
+						QStringList sqlResult;
+						reply >> sqlResult;
 					
-					//_result.setIcon(QString());
-					if ( !sqlResult[3].isEmpty() ) {
-						_result.setIcon(sqlResult[3]);
+						if(sqlResult.isEmpty()) {
+							newStatus = 0;
+						} else {
+							reset();
+							//Reads information from SQL-Query
+							_result.setArtist(sqlResult[0]);
+							_result.setName(sqlResult[1]);
+							_result.setURL(KURL(sqlResult[2]));
+							_result.setAlbum(sqlResult[4]);
+						
+							//_result.setIcon(QString());
+							if ( !sqlResult[3].isEmpty() ) {
+								_result.setIcon(sqlResult[3]);
+							}
+							
+							//counts the matched charecters
+							int i = queryString.find( ':' );
+							if ( i != -1 ) {
+								if ( queryString[i+1] != ' ' )
+									queryString.insert(i+1, ' ');
+								if ( queryString[i-1] != ' ' ) 
+									queryString.insert(i, ' ');
+							}
+							queryList = QStringList::split ( " ", queryString );
+							unsigned int matched = 0;
+							for(QStringList::Iterator it = queryList.begin(); it != queryList.end(); ++it) {
+								if(matched < (_result.text().find(*it, matched, false) + (*it).length()))
+									matched = _result.text().find(*it, matched, false) + (*it).length();
+							}
+							setBestMatch(Match(&_result, 100*queryString.length()/_result.text().length(), matched)); 
+					
+							//Checks if there are multiple results
+							if( !sqlResult[5].isEmpty() )
+								newStatus = S_HasResults | S_Multiple;
+							else 
+								newStatus = S_HasResults;
+						}
+					} else {
+						newStatus = 0;
 					}
+				}
+
+			} else {	// Dynamic Collection 
+
+				// Do same as above here again but with dyn collection stuff
+
+				QStringList queryList;
+				//prepares SQL-queryQRegExp
+				QString sqlQuery("SELECT a.name, t.title, t.deviceid, d.lastmountpoint, t.url, i.path, album.name FROM tags t LEFT JOIN statistics s ON t.url = s.url AND t.deviceid = s.deviceid LEFT JOIN artist a ON t.artist = a.id LEFT JOIN album ON t.album = album.id LEFT JOIN images i ON ( a.name = i.artist AND album.name = i.album) LEFT JOIN devices d ON t.deviceid = d.id WHERE 1");
+				queryList = QStringList::split ( QString(" "), QString(queryString).replace(QChar(':')," ").replace(QChar('\"'), " ").replace(QChar('\"'), "%") );
+
+				for(QStringList::Iterator it = queryList.begin(); it != queryList.end(); ++it) {
+
+					sqlQuery.append(QString(" AND (t.title LIKE \"\%%1\%\"").arg(*it));
+					sqlQuery.append(QString(" OR a.name LIKE \"\%%1\%\")").arg(*it));
+				}
+				sqlQuery.append(" ORDER BY a.name, t.title, s.percentage DESC");
+				
+				//sending SQL-query to ararok via dcop
+				QByteArray sqlQueryData, replyData;
+				QCString replyType;
+				QDataStream arg(sqlQueryData, IO_WriteOnly);
+				arg << sqlQuery;
+				if (!kapp->dcopClient()->call("amarok", "collection", "query(QString)",
+				     sqlQueryData, replyType, replyData)) {
+					newStatus = 0;
+				} else {
+					QDataStream reply(replyData, IO_ReadOnly);
+					if (replyType == "QStringList") {
+						QStringList sqlResult;
+						reply >> sqlResult;
 					
-					//counts the matched charecters
-					int i = queryString.find( ':' );
-					if ( i != -1 ) {
-						if ( queryString[i+1] != ' ' )
-							queryString.insert(i+1, ' ');
-						if ( queryString[i-1] != ' ' ) 
-							queryString.insert(i, ' ');
+						if(sqlResult.isEmpty()) {
+							newStatus = 0;
+						} else {
+							reset();
+							//Reads information from SQL-Query
+							_result.setArtist(sqlResult[0]);
+							_result.setName(sqlResult[1]);
+							if (sqlResult[2]!="-1") {
+								KURL absolutePath;
+								absolutePath.setPath( sqlResult[3] );
+								absolutePath.addPath( sqlResult[4] );
+								absolutePath.cleanPath();
+
+								_result.setURL( absolutePath );
+							} else {
+								KURL absolutePath;
+								absolutePath.setPath( "/" );
+								absolutePath.addPath( sqlResult[4] );
+								absolutePath.cleanPath(); 
+
+								_result.setURL( absolutePath );
+							}
+
+							_result.setAlbum(sqlResult[6]);
+						
+							//_result.setIcon(QString());
+							if ( !sqlResult[3].isEmpty() ) {
+								_result.setIcon(sqlResult[5]);
+							}
+							
+							//counts the matched charecters
+							int i = queryString.find( ':' );
+							if ( i != -1 ) {
+								if ( queryString[i+1] != ' ' )
+									queryString.insert(i+1, ' ');
+								if ( queryString[i-1] != ' ' ) 
+									queryString.insert(i, ' ');
+							}
+							queryList = QStringList::split ( " ", queryString );
+							unsigned int matched = 0;
+							for(QStringList::Iterator it = queryList.begin(); it != queryList.end(); ++it) {
+								if(matched < (_result.text().find(*it, matched, false) + (*it).length()))
+									matched = _result.text().find(*it, matched, false) + (*it).length();
+							}
+							setBestMatch(Match(&_result, 100*queryString.length()/_result.text().length(), matched)); 
+					
+							//Checks if there are multiple results
+						 	if( !sqlResult[7].isEmpty() )
+								newStatus = S_HasResults | S_Multiple;
+							else 
+								newStatus = S_HasResults;
+						}
+					} else {
+						newStatus = 0;
 					}
-					queryList = QStringList::split ( " ", queryString );
-					unsigned int matched = 0;
-					for(QStringList::Iterator it = queryList.begin(); it != queryList.end(); ++it) {
-						if(matched < (_result.text().find(*it, matched, false) + (*it).length()))
-							matched = _result.text().find(*it, matched, false) + (*it).length();
-					}
-					setBestMatch(Match(&_result, 100*queryString.length()/_result.text().length(), matched)); 
-					
-					//Checks if there are multiple results
-					if( !sqlResult[5].isEmpty() )
-						newStatus = S_HasResults | S_Multiple;
-					else 
-						newStatus = S_HasResults;
 				}
-			} else {
-				qDebug("DCOP: query returned an unexpected type of reply!");
-				newStatus = 0;
-			}
+
+
+			} //end of >1.4.2 section
+		setStatus(newStatus);
+
+		} else {                //We haven't got the collection status
+
+			checkCollectionType();	
+			reset();
+			setBestMatch(Match());
+			setStatus(0);
 		}
-		setStatus(newStatus);
-	}
+
+
+	} //dont go after this while fixing
+
 }
 
 void AmarokCatalog::reset()
@@ -139,6 +253,48 @@
 	_result.setAlbum(QString::null);
 	_result.setIcon(QString::null);
 }
+
+void AmarokCatalog::checkCollectionType()
+{
+	QString sqlQuery("SELECT COUNT(*) FROM admin WHERE noption = 'Database Devices Version'");
+
+	QByteArray sqlQueryData, replyData;
+	QCString replyType;
+	QDataStream arg(sqlQueryData, IO_WriteOnly);
+	arg << sqlQuery;
+	if (!kapp->dcopClient()->call("amarok", "collection", "query(QString)", sqlQueryData, replyType, replyData))
+	{
+		_gotCollectionStatus = false;
+
+	}
+	else
+	{
+		QDataStream reply(replyData, IO_ReadOnly);
+		if (replyType == "QStringList")
+		{
+			QStringList sqlResult;
+			reply >> sqlResult;
+
+			if (sqlResult[0] == "1")
+			{
+				_dynamicCollection = true;
+
+			}
+			else
+			{
+				_dynamicCollection = false;
+
+			}
+			_gotCollectionStatus = true;
+		}
+		else
+		{
+			_gotCollectionStatus = false;
+		}
+	}
+}
+
+
 /*
 void AmarokCatalog::initialize()
 {
@@ -173,5 +329,3 @@
 {
 	config->writeEntry("MinQueryLen", _minQueryLen);
 }
-
-#include "amarokcatalog.moc"
--- trunk/extragear/utils/katapult/plugins/catalogs/amarokcatalog/amarokcatalog.h #600690:600691
@@ -50,10 +50,12 @@
 protected:
 	void queryChanged();
 	void reset();
+	void checkCollectionType();	
 	
 private:
 	unsigned int _minQueryLen;
-	
+	bool _dynamicCollection;
+	bool _gotCollectionStatus;	
 	Song _result;
 };
 
** trunk/extragear/utils/katapult/plugins/display/o2display/doublebg.png #property svn:mime-type
   + application/octet-stream
** trunk/extragear/utils/katapult/plugins/display/o2display/singlebg.png #property svn:mime-type
   + application/octet-stream
Comment 12 Gehold Bertin 2006-12-25 13:25:33 UTC
I reopend that unfixed bug: http://bugs.kde.org/show_bug.cgi?id=139206