Encode song details into URL for all services

This commit is contained in:
craig.p.drummond
2013-07-16 18:31:19 +00:00
committed by craig.p.drummond
parent f51a6f2fb9
commit 045bf0d5ac
7 changed files with 50 additions and 47 deletions

View File

@@ -50,7 +50,7 @@
#include "utils.h"
#include "cuefile.h"
#include "mpdconnection.h"
#include "soundcloudservice.h"
#include "onlineservice.h"
#include <QDebug>
static bool debugEnabled=false;
@@ -249,7 +249,7 @@ Song MPDParseUtils::parseSong(const QByteArray &data, bool isPlayQueue)
if (!song.file.isEmpty()) {
if (song.isStream()) {
if (!song.isCantataStream()) {
if (!SoundCloudService::decode(song)) {
if (!OnlineService::decode(song)) {
QString name=getAndRemoveStreamName(song.file);
if (!name.isEmpty()) {
song.name=name;

View File

@@ -298,7 +298,7 @@ Song JamendoService::fixPath(const Song &orig) const
s.file.replace("id=%1", "id="+orig.file);
s.file+=FMT_MP3==format ? QLatin1String("mp31") : QLatin1String("ogg2");
s.genre=FMT_MP3==format ? QLatin1String("mp3") : QLatin1String("ogg");
return s;
return encode(s);
}
static const QLatin1String constMp3Format("mp3");

View File

@@ -126,7 +126,7 @@ void MagnatuneService::createLoader()
Song MagnatuneService::fixPath(const Song &orig) const
{
if (MB_None==membership) {
return orig;
return encode(orig);
}
Song s=orig;
@@ -150,7 +150,7 @@ Song MagnatuneService::fixPath(const Song &orig) const
// if (MB_Download==membership) {
// s.genre=downloadTypeStr(download);
// }
return s;
return encode(s);
}
QString MagnatuneService::membershipStr(MemberShip f, bool trans)

View File

@@ -176,6 +176,47 @@ void OnlineMusicLoader::progressReport(const QString &str, int prog)
}
}
static const QString constUrlGuard=QLatin1String("#{Cantata}");
static const QString constDeliminator=QLatin1String("<@>");
Song OnlineService::encode(const Song &song)
{
Song encoded=song;
encoded.file=song.file+constUrlGuard+
song.artist+constDeliminator+
song.title+constDeliminator+
song.genre+constDeliminator+
QString::number(song.time)+constDeliminator+
QString::number(song.year)+constDeliminator+
QString::number(song.track);
return encoded;
}
bool OnlineService::decode(Song &song)
{
if (!song.file.startsWith(QLatin1String("http://"))) {
return false;
}
int pos=song.file.indexOf(constUrlGuard);
if (pos>0) {
QStringList parts=song.file.mid(pos+constUrlGuard.length()+1).split(constDeliminator);
if (parts.length()>=6) {
song.artist=parts.at(0);
song.title=parts.at(1);
song.genre=parts.at(2);
song.time=parts.at(3).toUInt();
song.year=parts.at(4).toUInt();
song.track=parts.at(5).toUInt();
song.fillEmptyFields();
song.file=song.file.left(pos);
return true;
}
}
return false;
}
void OnlineService::destroy()
{
stopLoader();

View File

@@ -95,6 +95,9 @@ class OnlineService : public MusicLibraryItemRoot, public QObject
Q_OBJECT
public:
static Song encode(const Song &song);
static bool decode(Song &song);
OnlineService(OnlineServicesModel *m, const QString &name)
: MusicLibraryItemRoot(name, false)
, model(m)

View File

@@ -35,42 +35,6 @@ const QLatin1String SoundCloudService::constName("SoundCloud");
static const QString constApiKey=QLatin1String("0cb23dce473528973ce74815bd36a334");
static const QString constHost=QLatin1String("api.soundcloud.com");
static const QString constUrl=QLatin1String("https://")+constHost+QLatin1Char('/');
static const QString constUrlGuard=QLatin1String("#{SoundCloud}");
static const QString constDeliminator=QLatin1String("<@>");
bool SoundCloudService::decode(Song &song)
{
if (!song.file.startsWith(QLatin1String("http://")+constHost)) {
return false;
}
int pos=song.file.indexOf(constUrlGuard);
if (pos>0) {
QStringList parts=song.file.mid(pos+constUrlGuard.length()+1).split(constDeliminator);
if (parts.length()>=5) {
song.artist=parts.at(0);
song.title=parts.at(1);
song.genre=parts.at(2);
song.time=parts.at(3).toUInt();
song.year=parts.at(4).toUInt();
song.fillEmptyFields();
song.file=song.file.left(pos);
return true;
}
}
return false;
}
QString SoundCloudService::encode(const Song &song)
{
return song.file+constUrlGuard+
song.artist+constDeliminator+
song.title+constDeliminator+
song.genre+constDeliminator+
QString::number(song.time)+constDeliminator+
QString::number(song.year);
}
SoundCloudService::SoundCloudService(OnlineServicesModel *m)
: OnlineService(m, constName)
@@ -82,9 +46,7 @@ SoundCloudService::SoundCloudService(OnlineServicesModel *m)
Song SoundCloudService::fixPath(const Song &orig) const
{
Song s=orig;
s.file=encode(s);
return s;
return encode(orig);
}
void SoundCloudService::clear()

View File

@@ -34,9 +34,6 @@ class SoundCloudService : public OnlineService
public:
static const QLatin1String constName;
static bool decode(Song &song);
static QString encode(const Song &song);
SoundCloudService(OnlineServicesModel *m);
~SoundCloudService() { cancelAll(); }