1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-09-02 10:24:01 +02:00

Allow resolving file:// directly

This commit is contained in:
Hugo Lindström
2012-12-21 08:44:01 +01:00
parent 1eb01a9074
commit c63fff9981
4 changed files with 30 additions and 11 deletions

View File

@@ -614,11 +614,6 @@ DatabaseImpl::resultFromHint( const Tomahawk::query_ptr& origquery )
if ( s.isNull() ) if ( s.isNull() )
return res; return res;
} }
else if ( url.contains( "file://" ) )
{
s = SourceList::instance()->getLocal();
fileUrl = url;
}
else if ( TomahawkUtils::whitelistedHttpResultHint( url ) || else if ( TomahawkUtils::whitelistedHttpResultHint( url ) ||
TomahawkUtils::whitelistedCustomProtocolResultHint( url ) ) TomahawkUtils::whitelistedCustomProtocolResultHint( url ) )
{ {

View File

@@ -24,6 +24,8 @@
#include <QXmlStreamReader> #include <QXmlStreamReader>
#include "Query.h" #include "Query.h"
#include "utils/NetworkReply.h" #include "utils/NetworkReply.h"
#include <QFileInfo>
#include <QFile>
using namespace Tomahawk; using namespace Tomahawk;
@@ -49,6 +51,15 @@ void
CustomResultHintChecker::handleResultHint() CustomResultHintChecker::handleResultHint()
{ {
if ( url().startsWith( "file:" ) )
{
QFileInfo tmpFile( QUrl::fromUserInput( url() ).toLocalFile() );
if( !tmpFile.exists() )
{
qDebug() << Q_FUNC_INFO << url();
removeHint();
}
}
if ( url().startsWith( "hnhh" ) ) if ( url().startsWith( "hnhh" ) )
{ {
QUrl httpUrl = QUrl::fromUserInput( url() ); QUrl httpUrl = QUrl::fromUserInput( url() );

View File

@@ -31,6 +31,7 @@
/* taglib */ /* taglib */
#include <taglib/fileref.h> #include <taglib/fileref.h>
#include <taglib/tag.h> #include <taglib/tag.h>
#include "filemetadata/taghandlers/tag.h"
using namespace Tomahawk; using namespace Tomahawk;
@@ -77,12 +78,15 @@ M3uLoader::getTags( const QFileInfo& info )
TagLib::FileRef f( encodedName ); TagLib::FileRef f( encodedName );
if( f.isNull() ) if( f.isNull() )
return; return;
TagLib::Tag *tag = f.tag();
Tag* tag = Tag::fromFile( f );
if( !tag ) if( !tag )
return; return;
QString artist = TStringToQString( tag->artist() ).trimmed();
QString album = TStringToQString( tag->album() ).trimmed(); QString artist, album, track;
QString track = TStringToQString( tag->title() ).trimmed(); artist = tag->artist().trimmed();
album = tag->album().trimmed();
track = tag->title().trimmed();
if ( artist.isEmpty() || track.isEmpty() ) if ( artist.isEmpty() || track.isEmpty() )
{ {
@@ -91,12 +95,21 @@ M3uLoader::getTags( const QFileInfo& info )
} }
else else
{ {
qDebug() << Q_FUNC_INFO << artist << track << album;
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 );
if ( !q.isNull() ) if ( !q.isNull() )
{ {
q->setResultHint( "file://" + info.absoluteFilePath() ); q->setResultHint( "file://" + info.absoluteFilePath() );
q->setSaveHTTPResultHint( true ); q->setSaveHTTPResultHint( true );
TagLib::AudioProperties *audioProp = f.audioProperties();
if ( audioProp )
{
q->setDuration( audioProp->length() );
}
q->setComposer( tag->composer() );
q->setAlbumPos( tag->track() );
q->setDiscNumber( tag->discNumber() );
qDebug() << "Adding resulthint" << q->resultHint(); qDebug() << "Adding resulthint" << q->resultHint();
m_tracks << q; m_tracks << q;
} }

View File

@@ -953,7 +953,7 @@ whitelistedHttpResultHint( const QString& url )
bool bool
whitelistedCustomProtocolResultHint( const QString& url ) whitelistedCustomProtocolResultHint( const QString& url )
{ {
return url.startsWith( "hnhh" ); return url.startsWith( "hnhh" ) | url.startsWith( "file:" );
} }
} // ns } // ns