Skip to content
This repository has been archived by the owner on May 3, 2019. It is now read-only.

Commit

Permalink
[Bug] Fix broken soundclound integration
Browse files Browse the repository at this point in the history
Soundclound recently changed their player interface which broke our jquery integration. This commit fix the jquery integration and add a new feature: we are now able to fetch the song art and display it for notifications and for the mpris 2 interface.
  • Loading branch information
ColinDuquesnoy committed Mar 28, 2015
1 parent d154656 commit 7b5ceac
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
36 changes: 32 additions & 4 deletions plugins/soundcloud/soundcloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,13 @@ PlaybackStatus SoundcloudPlugin::playbackStatus()
SongInfo SoundcloudPlugin::currentSongInfo()
{
SongInfo retVal;
retVal.songName = runJavaScript("$('.playbackTitle__link').text()").toString();
retVal.position = runJavaScript("$('.playbackTitle__progress').attr('aria-valuenow')").toFloat() * 1000;
retVal.duration = runJavaScript("$('.playbackTitle__progress').attr('aria-valuemax')").toFloat() * 1000;
retVal.songName = runJavaScript("$('.playbackSoundBadge__title').text()").toString();
QString progress = runJavaScript("$('.playbackTimeline__timePassed').text()").toString();
retVal.position = stringToTime(progress);
QString duration = runJavaScript("$('.playbackTimeline__duration').text()").toString();
retVal.duration = stringToTime(duration);
QString url = runJavaScript("$('.playbackSoundBadge').children(0).children(0).children(0).css('background-image')").toString();
retVal.artUrl = url.left(url.length() - 1).replace("url(", "").replace("t50x50", "t120x120");
#if QT_VERSION >= 0x050000
retVal.songId = QString::number(qt_hash(retVal.songName));
#endif
Expand Down Expand Up @@ -178,7 +182,31 @@ bool SoundcloudPlugin::canGoNext()
bool SoundcloudPlugin::canGoPrevious()
{
return !runJavaScript("$('.skipControl__previous').attr('class')").toString(
).contains("disabled");
).contains("disabled");
}

qlonglong SoundcloudPlugin::stringToTime(const QString &string)
{
QString format;
switch (string.length()) {
case 4:
format = "m:ss";
break;
case 5:
format = "mm:ss";
break;
case 7:
format = "h:mm:ss";
break;
case 8:
format = "hh:mm:ss";
break;
default:
break;
}
QTime time = QTime::fromString(string, format);
int seconds = QTime(0, 0, 0).secsTo(time);
return seconds * 1000000;
}

//---------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions plugins/soundcloud/soundcloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,6 @@ class SoundcloudPlugin:
bool canGoPrevious();

private:
qlonglong stringToTime(const QString& string);
int id;
};

0 comments on commit 7b5ceac

Please sign in to comment.