Merge pull request #4861 from TheUbuntuGuy/master
Fix Last.fm scrobbling after seek
This commit is contained in:
commit
02069b7c60
@ -436,13 +436,9 @@ void Player::SeekTo(int seconds) {
|
|||||||
qBound(0ll, qint64(seconds) * kNsecPerSec, length_nanosec);
|
qBound(0ll, qint64(seconds) * kNsecPerSec, length_nanosec);
|
||||||
engine_->Seek(nanosec);
|
engine_->Seek(nanosec);
|
||||||
|
|
||||||
// If we seek the track we don't want to submit it to last.fm
|
// If we seek the track we need to move the scrobble point
|
||||||
qLog(Info) << "Track seeked to" << nanosec << "ns - not scrobbling";
|
qLog(Info) << "Track seeked to" << nanosec << "ns - updating scrobble point";
|
||||||
if (app_->playlist_manager()->active()->get_lastfm_status() ==
|
app_->playlist_manager()->active()->UpdateScrobblePoint(nanosec);
|
||||||
Playlist::LastFM_New) {
|
|
||||||
app_->playlist_manager()->active()->set_lastfm_status(
|
|
||||||
Playlist::LastFM_Seeked);
|
|
||||||
}
|
|
||||||
|
|
||||||
emit Seeked(nanosec / 1000);
|
emit Seeked(nanosec / 1000);
|
||||||
}
|
}
|
||||||
|
@ -95,6 +95,9 @@ const char* Playlist::kWriteMetadata = "write_metadata";
|
|||||||
const int Playlist::kUndoStackSize = 20;
|
const int Playlist::kUndoStackSize = 20;
|
||||||
const int Playlist::kUndoItemLimit = 500;
|
const int Playlist::kUndoItemLimit = 500;
|
||||||
|
|
||||||
|
const qint64 Playlist::kMinScrobblePointNsecs = 31ll * kNsecPerSec;
|
||||||
|
const qint64 Playlist::kMaxScrobblePointNsecs = 240ll * kNsecPerSec;
|
||||||
|
|
||||||
Playlist::Playlist(PlaylistBackend* backend, TaskManager* task_manager,
|
Playlist::Playlist(PlaylistBackend* backend, TaskManager* task_manager,
|
||||||
LibraryBackend* library, int id, const QString& special_type,
|
LibraryBackend* library, int id, const QString& special_type,
|
||||||
bool favorite, QObject* parent)
|
bool favorite, QObject* parent)
|
||||||
@ -1705,14 +1708,25 @@ Song Playlist::current_item_metadata() const {
|
|||||||
return current_item()->Metadata();
|
return current_item()->Metadata();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Playlist::UpdateScrobblePoint() {
|
void Playlist::UpdateScrobblePoint(qint64 seek_point_nanosec) {
|
||||||
const qint64 length = current_item_metadata().length_nanosec();
|
const qint64 length = current_item_metadata().length_nanosec();
|
||||||
|
|
||||||
if (length == 0) {
|
if (seek_point_nanosec == 0) {
|
||||||
scrobble_point_ = 240ll * kNsecPerSec; // 4 minutes
|
if (length == 0) {
|
||||||
|
scrobble_point_ = kMaxScrobblePointNsecs; // 4 minutes
|
||||||
|
} else {
|
||||||
|
scrobble_point_ =
|
||||||
|
qBound(kMinScrobblePointNsecs, length / 2, kMaxScrobblePointNsecs);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
scrobble_point_ =
|
if (length == 0) {
|
||||||
qBound(31ll * kNsecPerSec, length / 2, 240ll * kNsecPerSec);
|
// 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);
|
set_lastfm_status(LastFM_New);
|
||||||
|
@ -160,6 +160,9 @@ class Playlist : public QAbstractListModel {
|
|||||||
static const int kUndoStackSize;
|
static const int kUndoStackSize;
|
||||||
static const int kUndoItemLimit;
|
static const int kUndoItemLimit;
|
||||||
|
|
||||||
|
static const qint64 kMinScrobblePointNsecs;
|
||||||
|
static const qint64 kMaxScrobblePointNsecs;
|
||||||
|
|
||||||
static bool CompareItems(int column, Qt::SortOrder order, PlaylistItemPtr a,
|
static bool CompareItems(int column, Qt::SortOrder order, PlaylistItemPtr a,
|
||||||
PlaylistItemPtr b);
|
PlaylistItemPtr b);
|
||||||
|
|
||||||
@ -227,6 +230,7 @@ class Playlist : public QAbstractListModel {
|
|||||||
}
|
}
|
||||||
void set_lastfm_status(LastFMStatus status) { lastfm_status_ = status; }
|
void set_lastfm_status(LastFMStatus status) { lastfm_status_ = status; }
|
||||||
void set_have_incremented_playcount() { have_incremented_playcount_ = true; }
|
void set_have_incremented_playcount() { have_incremented_playcount_ = true; }
|
||||||
|
void UpdateScrobblePoint(qint64 seek_point_nanosec = 0);
|
||||||
|
|
||||||
// Changing the playlist
|
// Changing the playlist
|
||||||
void InsertItems(const PlaylistItemList& items, int pos = -1,
|
void InsertItems(const PlaylistItemList& items, int pos = -1,
|
||||||
@ -351,7 +355,6 @@ signals:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void SetCurrentIsPaused(bool paused);
|
void SetCurrentIsPaused(bool paused);
|
||||||
void UpdateScrobblePoint();
|
|
||||||
int NextVirtualIndex(int i, bool ignore_repeat_track) const;
|
int NextVirtualIndex(int i, bool ignore_repeat_track) const;
|
||||||
int PreviousVirtualIndex(int i, bool ignore_repeat_track) const;
|
int PreviousVirtualIndex(int i, bool ignore_repeat_track) const;
|
||||||
bool FilterContainsVirtualIndex(int i) const;
|
bool FilterContainsVirtualIndex(int i) const;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user