Merge pull request #4861 from TheUbuntuGuy/master

Fix Last.fm scrobbling after seek
This commit is contained in:
John Maguire 2015-05-18 18:28:34 +01:00
commit 02069b7c60
3 changed files with 26 additions and 13 deletions

View File

@ -436,13 +436,9 @@ void Player::SeekTo(int seconds) {
qBound(0ll, qint64(seconds) * kNsecPerSec, length_nanosec);
engine_->Seek(nanosec);
// If we seek the track we don't want to submit it to last.fm
qLog(Info) << "Track seeked to" << nanosec << "ns - not scrobbling";
if (app_->playlist_manager()->active()->get_lastfm_status() ==
Playlist::LastFM_New) {
app_->playlist_manager()->active()->set_lastfm_status(
Playlist::LastFM_Seeked);
}
// If we seek the track we need to move the scrobble point
qLog(Info) << "Track seeked to" << nanosec << "ns - updating scrobble point";
app_->playlist_manager()->active()->UpdateScrobblePoint(nanosec);
emit Seeked(nanosec / 1000);
}

View File

@ -95,6 +95,9 @@ const char* Playlist::kWriteMetadata = "write_metadata";
const int Playlist::kUndoStackSize = 20;
const int Playlist::kUndoItemLimit = 500;
const qint64 Playlist::kMinScrobblePointNsecs = 31ll * kNsecPerSec;
const qint64 Playlist::kMaxScrobblePointNsecs = 240ll * kNsecPerSec;
Playlist::Playlist(PlaylistBackend* backend, TaskManager* task_manager,
LibraryBackend* library, int id, const QString& special_type,
bool favorite, QObject* parent)
@ -1705,14 +1708,25 @@ Song Playlist::current_item_metadata() const {
return current_item()->Metadata();
}
void Playlist::UpdateScrobblePoint() {
void Playlist::UpdateScrobblePoint(qint64 seek_point_nanosec) {
const qint64 length = current_item_metadata().length_nanosec();
if (length == 0) {
scrobble_point_ = 240ll * kNsecPerSec; // 4 minutes
if (seek_point_nanosec == 0) {
if (length == 0) {
scrobble_point_ = kMaxScrobblePointNsecs; // 4 minutes
} else {
scrobble_point_ =
qBound(kMinScrobblePointNsecs, length / 2, kMaxScrobblePointNsecs);
}
} else {
scrobble_point_ =
qBound(31ll * kNsecPerSec, length / 2, 240ll * kNsecPerSec);
if (length == 0) {
// current time + 4 minutes
scrobble_point_ = seek_point_nanosec + kMaxScrobblePointNsecs;
} else {
scrobble_point_ = qBound(seek_point_nanosec + kMinScrobblePointNsecs,
seek_point_nanosec + (length / 2),
seek_point_nanosec + kMaxScrobblePointNsecs);
}
}
set_lastfm_status(LastFM_New);

View File

@ -160,6 +160,9 @@ class Playlist : public QAbstractListModel {
static const int kUndoStackSize;
static const int kUndoItemLimit;
static const qint64 kMinScrobblePointNsecs;
static const qint64 kMaxScrobblePointNsecs;
static bool CompareItems(int column, Qt::SortOrder order, PlaylistItemPtr a,
PlaylistItemPtr b);
@ -227,6 +230,7 @@ class Playlist : public QAbstractListModel {
}
void set_lastfm_status(LastFMStatus status) { lastfm_status_ = status; }
void set_have_incremented_playcount() { have_incremented_playcount_ = true; }
void UpdateScrobblePoint(qint64 seek_point_nanosec = 0);
// Changing the playlist
void InsertItems(const PlaylistItemList& items, int pos = -1,
@ -351,7 +355,6 @@ signals:
private:
void SetCurrentIsPaused(bool paused);
void UpdateScrobblePoint();
int NextVirtualIndex(int i, bool ignore_repeat_track) const;
int PreviousVirtualIndex(int i, bool ignore_repeat_track) const;
bool FilterContainsVirtualIndex(int i) const;