From 84ab3456ef9064008f70bf03f57ce7bc5a3df51b Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sat, 23 Nov 2019 01:10:22 +0100 Subject: [PATCH 01/32] added more fields --- mpd.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/mpd.h b/mpd.h index 2842ef9..99399e1 100644 --- a/mpd.h +++ b/mpd.h @@ -5,11 +5,13 @@ class Song { public: Song() {}; Song(struct mpd_song *song); - Song(std::string artist, std::string title, std::string album, int duration) { + Song(std::string artist, std::string title, std::string album, int duration, int track, std::string mpid) { this->artist = artist; this->title = title; this->album = album; this->duration = duration; + this->track = track; + this->mpid = mpid; } std::string getArtist() const { return artist; } @@ -17,9 +19,12 @@ class Song { std::string getAlbum() const { return album; } std::string getAlbumArtist() const { return albumartist; } int getDuration() const { return duration; } + int getTrack() const { return track; } + std::string getMusicBrainzId() const { return mbid; } private: - std::string albumartist, artist, title, album; + std::string albumartist, artist, title, album, mbid; int duration = -1; + int track = -1; }; class CMPD From 8c680ea7fc0251d45cb081271eb3164815ad7658 Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sat, 23 Nov 2019 01:13:09 +0100 Subject: [PATCH 02/32] fix typo --- mpd.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mpd.h b/mpd.h index 99399e1..4c180ec 100644 --- a/mpd.h +++ b/mpd.h @@ -5,13 +5,13 @@ class Song { public: Song() {}; Song(struct mpd_song *song); - Song(std::string artist, std::string title, std::string album, int duration, int track, std::string mpid) { + Song(std::string artist, std::string title, std::string album, int duration, int track, std::string mbid) { this->artist = artist; this->title = title; this->album = album; this->duration = duration; this->track = track; - this->mpid = mpid; + this->mbid = mbid; } std::string getArtist() const { return artist; } From b5f63d7a3600e40d89175328ce16a0d909b8cf70 Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sat, 23 Nov 2019 01:39:40 +0100 Subject: [PATCH 03/32] fix --- audioscrobbler.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/audioscrobbler.cpp b/audioscrobbler.cpp index 5a9cce9..6fec91f 100644 --- a/audioscrobbler.cpp +++ b/audioscrobbler.cpp @@ -108,6 +108,14 @@ std::string CAudioScrobbler::CreateScrobbleMessage(int index, const CacheEntry& msg.AddField("albumArtist", song.getAlbumArtist()); } + if(!song.getMusicBrainzId().empty()) { + msg.AddField("mbid", song.getMusicBrainzId()); + } + + if(!song.getTrack() == -1) { + msg.AddField("trackNumber", song.getTrack()); + } + return msg.GetMessage(); } @@ -236,6 +244,14 @@ bool CAudioScrobbler::SendNowPlaying(const Song& song) msg.AddField("albumArtist", song.getAlbumArtist()); } + if(!song.getMusicBrainzId().empty()) { + msg.AddField("mbid", song.getMusicBrainzId()); + } + + if(!song.getTrack() == -1) { + msg.AddField("trackNumber", song.getTrack()); + } + OpenURL(GetServiceURL(), msg.GetMessage().c_str()); if(_response.find("") != std::string::npos) { From 8db78669622c4134ce63a615ad717aa155b07f29 Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sat, 23 Nov 2019 01:40:59 +0100 Subject: [PATCH 04/32] added new tags --- mpd.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mpd.cpp b/mpd.cpp index 0477f1d..1005ee4 100644 --- a/mpd.cpp +++ b/mpd.cpp @@ -160,5 +160,11 @@ Song::Song(struct mpd_song *song) temp = mpd_song_get_tag(song, MPD_TAG_ALBUM_ARTIST, 0); albumartist = temp ? temp : ""; + temp = mpd_song_get_tag(song, MPD_TAG_TRACK, 0); + track = temp ? temp : -1; + + temp = mpd_song_get_tag(song, MPD_TAG_MUSICBRAINZ_TRACKID , 0); + mbid = temp ? temp : ""; + duration = mpd_song_get_duration(song); } From b6ff530b804236b353a8b5a62c1b051a76d3da2a Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sat, 23 Nov 2019 01:42:41 +0100 Subject: [PATCH 05/32] changed type --- mpd.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mpd.h b/mpd.h index 4c180ec..37fdba2 100644 --- a/mpd.h +++ b/mpd.h @@ -5,7 +5,7 @@ class Song { public: Song() {}; Song(struct mpd_song *song); - Song(std::string artist, std::string title, std::string album, int duration, int track, std::string mbid) { + Song(std::string artist, std::string title, std::string album, int duration, std::string track, std::string mbid) { this->artist = artist; this->title = title; this->album = album; @@ -22,9 +22,8 @@ class Song { int getTrack() const { return track; } std::string getMusicBrainzId() const { return mbid; } private: - std::string albumartist, artist, title, album, mbid; + std::string albumartist, artist, title, album, track,mbid; int duration = -1; - int track = -1; }; class CMPD From c9c2db000f1cd734ecfd220c18c2618bc728eabc Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sat, 23 Nov 2019 01:43:38 +0100 Subject: [PATCH 06/32] type --- audioscrobbler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/audioscrobbler.cpp b/audioscrobbler.cpp index 6fec91f..2e8cb94 100644 --- a/audioscrobbler.cpp +++ b/audioscrobbler.cpp @@ -112,7 +112,7 @@ std::string CAudioScrobbler::CreateScrobbleMessage(int index, const CacheEntry& msg.AddField("mbid", song.getMusicBrainzId()); } - if(!song.getTrack() == -1) { + if(!song.getTrack().empty()) { msg.AddField("trackNumber", song.getTrack()); } @@ -248,7 +248,7 @@ bool CAudioScrobbler::SendNowPlaying(const Song& song) msg.AddField("mbid", song.getMusicBrainzId()); } - if(!song.getTrack() == -1) { + if(!song.getTrack().empty()) { msg.AddField("trackNumber", song.getTrack()); } From 6549268493a696ae44054220dd572ed0674231de Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sat, 23 Nov 2019 01:44:36 +0100 Subject: [PATCH 07/32] bugfix --- mpd.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mpd.h b/mpd.h index 37fdba2..ef82497 100644 --- a/mpd.h +++ b/mpd.h @@ -19,7 +19,7 @@ class Song { std::string getAlbum() const { return album; } std::string getAlbumArtist() const { return albumartist; } int getDuration() const { return duration; } - int getTrack() const { return track; } + std:string getTrack() const { return track; } std::string getMusicBrainzId() const { return mbid; } private: std::string albumartist, artist, title, album, track,mbid; From 94dd43a8d7d12f4981b35fa878365b1075e84c9c Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sat, 23 Nov 2019 01:45:28 +0100 Subject: [PATCH 08/32] bugfix --- mpd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mpd.cpp b/mpd.cpp index 1005ee4..24a2208 100644 --- a/mpd.cpp +++ b/mpd.cpp @@ -161,7 +161,7 @@ Song::Song(struct mpd_song *song) albumartist = temp ? temp : ""; temp = mpd_song_get_tag(song, MPD_TAG_TRACK, 0); - track = temp ? temp : -1; + track = temp ? temp : ""; temp = mpd_song_get_tag(song, MPD_TAG_MUSICBRAINZ_TRACKID , 0); mbid = temp ? temp : ""; From 579842ef08e8dc3f524d3873910f53f34abaaf8c Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sat, 23 Nov 2019 01:46:10 +0100 Subject: [PATCH 09/32] ad --- mpd.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mpd.h b/mpd.h index ef82497..46704cb 100644 --- a/mpd.h +++ b/mpd.h @@ -19,7 +19,7 @@ class Song { std::string getAlbum() const { return album; } std::string getAlbumArtist() const { return albumartist; } int getDuration() const { return duration; } - std:string getTrack() const { return track; } + std::string getTrack() const { return track; } std::string getMusicBrainzId() const { return mbid; } private: std::string albumartist, artist, title, album, track,mbid; From 5e4b13fe2d21ee349e2d6c4a43aec6f594fe5212 Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sat, 23 Nov 2019 01:50:03 +0100 Subject: [PATCH 10/32] added fields --- mpd.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mpd.h b/mpd.h index 46704cb..26dad42 100644 --- a/mpd.h +++ b/mpd.h @@ -5,10 +5,11 @@ class Song { public: Song() {}; Song(struct mpd_song *song); - Song(std::string artist, std::string title, std::string album, int duration, std::string track, std::string mbid) { + Song(std::string artist, std::string title, std::string album, std::string albumartist, int duration, std::string track, std::string mbid) { this->artist = artist; this->title = title; this->album = album; + this->albumartist = albumartist; this->duration = duration; this->track = track; this->mbid = mbid; @@ -22,7 +23,7 @@ class Song { std::string getTrack() const { return track; } std::string getMusicBrainzId() const { return mbid; } private: - std::string albumartist, artist, title, album, track,mbid; + std::string albumartist, artist, title, album, track, mbid; int duration = -1; }; From 79dfff7bb4b5f7bf27283b160b8b3ddedae488bf Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sat, 23 Nov 2019 01:53:29 +0100 Subject: [PATCH 11/32] added new tags to cache --- cache.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cache.cpp b/cache.cpp index 5d8980b..7397619 100644 --- a/cache.cpp +++ b/cache.cpp @@ -86,7 +86,10 @@ std::ofstream& operator <<(std::ofstream& outstream, const CacheEntry& inobj) outstream << song.getArtist() << std::endl << song.getTitle() << std::endl << song.getAlbum() << std::endl - << song.getDuration() << std::endl + << song.getAlbumArtist() << std::endl + << song.getTrack() << std::endl + << song.getMusicBrainzId() << std::endl + << song.getDuration() << std::endl << inobj.getStartTime(); return outstream; @@ -101,13 +104,16 @@ std::ifstream& operator >>(std::ifstream& instream, CacheEntry& outobj) getline(instream, artist); getline(instream, title); getline(instream, album); + getline(instream, albumartist); + getline(instream, track); + getline(instream, mbid); instream >> duration; instream.ignore(1); instream >> starttime; instream.ignore(1); - Song song(artist, title, album, duration); + Song song(artist, title, album, albumartist, duration, track, mbid); outobj = CacheEntry(song, starttime); return instream; From 1555f7dc35c5cf2b4ee46e1fb77b7749c83b7c92 Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sat, 23 Nov 2019 01:54:28 +0100 Subject: [PATCH 12/32] added types --- cache.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cache.cpp b/cache.cpp index 7397619..dc89da1 100644 --- a/cache.cpp +++ b/cache.cpp @@ -97,7 +97,7 @@ std::ofstream& operator <<(std::ofstream& outstream, const CacheEntry& inobj) std::ifstream& operator >>(std::ifstream& instream, CacheEntry& outobj) { - std::string artist, title, album; + std::string artist, title, album, albumartist, track, mbid; int duration; time_t starttime; From 6c4275e8129cd0175d6c2d9c7fc726160cade31a Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sun, 24 Nov 2019 14:42:06 +0100 Subject: [PATCH 13/32] changed indentation --- cache.cpp | 14 +++++++------- mpd.h | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cache.cpp b/cache.cpp index dc89da1..c60f600 100644 --- a/cache.cpp +++ b/cache.cpp @@ -86,10 +86,10 @@ std::ofstream& operator <<(std::ofstream& outstream, const CacheEntry& inobj) outstream << song.getArtist() << std::endl << song.getTitle() << std::endl << song.getAlbum() << std::endl - << song.getAlbumArtist() << std::endl - << song.getTrack() << std::endl - << song.getMusicBrainzId() << std::endl - << song.getDuration() << std::endl + << song.getAlbumArtist() << std::endl + << song.getTrack() << std::endl + << song.getMusicBrainzId() << std::endl + << song.getDuration() << std::endl << inobj.getStartTime(); return outstream; @@ -97,7 +97,7 @@ std::ofstream& operator <<(std::ofstream& outstream, const CacheEntry& inobj) std::ifstream& operator >>(std::ifstream& instream, CacheEntry& outobj) { - std::string artist, title, album, albumartist, track, mbid; + std::string artist, title, album, albumartist, track, mbid; int duration; time_t starttime; @@ -105,8 +105,8 @@ std::ifstream& operator >>(std::ifstream& instream, CacheEntry& outobj) getline(instream, title); getline(instream, album); getline(instream, albumartist); - getline(instream, track); - getline(instream, mbid); + getline(instream, track); + getline(instream, mbid); instream >> duration; instream.ignore(1); diff --git a/mpd.h b/mpd.h index 26dad42..f06d92d 100644 --- a/mpd.h +++ b/mpd.h @@ -5,7 +5,7 @@ class Song { public: Song() {}; Song(struct mpd_song *song); - Song(std::string artist, std::string title, std::string album, std::string albumartist, int duration, std::string track, std::string mbid) { + Song(std::string artist, std::string title, std::string album, std::string albumartist, int duration, std::string track, std::string mbid) { this->artist = artist; this->title = title; this->album = album; @@ -20,10 +20,10 @@ class Song { std::string getAlbum() const { return album; } std::string getAlbumArtist() const { return albumartist; } int getDuration() const { return duration; } - std::string getTrack() const { return track; } + std::string getTrack() const { return track; } std::string getMusicBrainzId() const { return mbid; } private: - std::string albumartist, artist, title, album, track, mbid; + std::string albumartist, artist, title, album, track, mbid; int duration = -1; }; From 1bbf769cb5bccf0db1e6c5e475081b56d138f0aa Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sun, 24 Nov 2019 15:19:16 +0100 Subject: [PATCH 14/32] lets see what this will do --- mpd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mpd.cpp b/mpd.cpp index 24a2208..2d4a98b 100644 --- a/mpd.cpp +++ b/mpd.cpp @@ -5,7 +5,7 @@ CMPD* MPD = 0; void CMPD::SetSong(const Song *song) { _cached = false; - if(song && !song->getArtist().empty() && !song->getTitle().empty()) { + if(song && !song->getArtist().empty() && !song->getTitle().empty() && (_song && (song->getArtist() != _song->getArtist() || song->getTitle() != _song->getTitle())) { _song = *song; _gotsong = true; iprintf("New song: %s - %s", _song.getArtist().c_str(), _song.getTitle().c_str()); From 347ebd04a9d35c222f81c095413270a962772847 Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sun, 24 Nov 2019 15:20:05 +0100 Subject: [PATCH 15/32] fix ) --- mpd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mpd.cpp b/mpd.cpp index 2d4a98b..734b7d1 100644 --- a/mpd.cpp +++ b/mpd.cpp @@ -5,7 +5,7 @@ CMPD* MPD = 0; void CMPD::SetSong(const Song *song) { _cached = false; - if(song && !song->getArtist().empty() && !song->getTitle().empty() && (_song && (song->getArtist() != _song->getArtist() || song->getTitle() != _song->getTitle())) { + if(song && !song->getArtist().empty() && !song->getTitle().empty() && (_song && (song->getArtist() != _song->getArtist() || song->getTitle() != _song->getTitle()))) { _song = *song; _gotsong = true; iprintf("New song: %s - %s", _song.getArtist().c_str(), _song.getTitle().c_str()); From 2c8bff7e39c43cfcd643c71340ffbf844c8c7947 Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sun, 24 Nov 2019 15:21:01 +0100 Subject: [PATCH 16/32] asd --- mpd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mpd.cpp b/mpd.cpp index 734b7d1..544e116 100644 --- a/mpd.cpp +++ b/mpd.cpp @@ -5,7 +5,7 @@ CMPD* MPD = 0; void CMPD::SetSong(const Song *song) { _cached = false; - if(song && !song->getArtist().empty() && !song->getTitle().empty() && (_song && (song->getArtist() != _song->getArtist() || song->getTitle() != _song->getTitle()))) { + if(song && !song->getArtist().empty() && !song->getTitle().empty() && (_song && (song->getArtist() != _song.getArtist() || song->getTitle() != _song.getTitle()))) { _song = *song; _gotsong = true; iprintf("New song: %s - %s", _song.getArtist().c_str(), _song.getTitle().c_str()); From 54a5f5297552c817455bf46d0ed183c1cbee5e2f Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sun, 24 Nov 2019 15:28:51 +0100 Subject: [PATCH 17/32] asd --- mpd.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mpd.cpp b/mpd.cpp index 544e116..82b4b12 100644 --- a/mpd.cpp +++ b/mpd.cpp @@ -5,7 +5,7 @@ CMPD* MPD = 0; void CMPD::SetSong(const Song *song) { _cached = false; - if(song && !song->getArtist().empty() && !song->getTitle().empty() && (_song && (song->getArtist() != _song.getArtist() || song->getTitle() != _song.getTitle()))) { + if(song && !song->getArtist().empty() && !song->getTitle().empty() && (_song != NULL && (song->getArtist() != _song.getArtist() || song->getTitle() != _song.getTitle()))) { _song = *song; _gotsong = true; iprintf("New song: %s - %s", _song.getArtist().c_str(), _song.getTitle().c_str()); @@ -33,6 +33,7 @@ CMPD::CMPD(CConfig *cfg) _gotsong = false; _connected = false; _cached = false; + _song = NULL; _songid = -1; _songpos = -1; From 64bd8dc93e032c32b7a75cbbedab287c82c9714a Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sun, 24 Nov 2019 15:29:53 +0100 Subject: [PATCH 18/32] asd --- mpd.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mpd.cpp b/mpd.cpp index 82b4b12..79d898f 100644 --- a/mpd.cpp +++ b/mpd.cpp @@ -5,7 +5,7 @@ CMPD* MPD = 0; void CMPD::SetSong(const Song *song) { _cached = false; - if(song && !song->getArtist().empty() && !song->getTitle().empty() && (_song != NULL && (song->getArtist() != _song.getArtist() || song->getTitle() != _song.getTitle()))) { + if(song && !song->getArtist().empty() && !song->getTitle().empty() && (_song != Song() && (song->getArtist() != _song.getArtist() || song->getTitle() != _song.getTitle()))) { _song = *song; _gotsong = true; iprintf("New song: %s - %s", _song.getArtist().c_str(), _song.getTitle().c_str()); @@ -33,7 +33,6 @@ CMPD::CMPD(CConfig *cfg) _gotsong = false; _connected = false; _cached = false; - _song = NULL; _songid = -1; _songpos = -1; From 2cb58c5233d1f2334a833c8646ee5a74f6930c45 Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sun, 24 Nov 2019 15:30:42 +0100 Subject: [PATCH 19/32] fix --- mpd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mpd.cpp b/mpd.cpp index 79d898f..e491ccb 100644 --- a/mpd.cpp +++ b/mpd.cpp @@ -5,7 +5,7 @@ CMPD* MPD = 0; void CMPD::SetSong(const Song *song) { _cached = false; - if(song && !song->getArtist().empty() && !song->getTitle().empty() && (_song != Song() && (song->getArtist() != _song.getArtist() || song->getTitle() != _song.getTitle()))) { + if(song && !song->getArtist().empty() && !song->getTitle().empty() && (song->getArtist() != _song.getArtist() || song->getTitle() != _song.getTitle())) { _song = *song; _gotsong = true; iprintf("New song: %s - %s", _song.getArtist().c_str(), _song.getTitle().c_str()); From 9229e4b1c4237d093dc9839c8d57627cce4fd43f Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sun, 24 Nov 2019 15:39:10 +0100 Subject: [PATCH 20/32] nicer code formatting --- mpd.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mpd.cpp b/mpd.cpp index e491ccb..24d4579 100644 --- a/mpd.cpp +++ b/mpd.cpp @@ -5,7 +5,8 @@ CMPD* MPD = 0; void CMPD::SetSong(const Song *song) { _cached = false; - if(song && !song->getArtist().empty() && !song->getTitle().empty() && (song->getArtist() != _song.getArtist() || song->getTitle() != _song.getTitle())) { + if(song && !song->getArtist().empty() && !song->getTitle().empty() && + (song->getArtist() != _song.getArtist() || song->getTitle() != _song.getTitle())) { _song = *song; _gotsong = true; iprintf("New song: %s - %s", _song.getArtist().c_str(), _song.getTitle().c_str()); From 1bc8ca7fe5b099991b94ba6a46601372d052c263 Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sun, 24 Nov 2019 15:48:21 +0100 Subject: [PATCH 21/32] asd --- mpd.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mpd.cpp b/mpd.cpp index 24d4579..89a7fe1 100644 --- a/mpd.cpp +++ b/mpd.cpp @@ -97,7 +97,10 @@ void CMPD::Update() int newsongid = mpd_status_get_song_id(status); int newsongpos = mpd_status_get_elapsed_time(status); int curplaytime = mpd_stats_get_play_time(stats); - // new song (or the same song but from the beginning after it has been played long enough before) + + iprintf("DEBUG: %i - %s - %s", curplaytime, newsongpos, newsongid); + + // new song (or the same song but from the beginning after it has been played long enough before) if(newsongid != _songid || (_song.getDuration() != -1 && _songpos > (_song.getDuration()/2) && newsongpos < _songpos && newsongpos < 10)) { _songid = newsongid; _songpos = newsongpos; @@ -113,7 +116,7 @@ void CMPD::Update() } // song playing - if(newsongpos != _songpos) { + if(newsongpos != _songpos) { _songpos = newsongpos; CheckSubmit(curplaytime); } From c8e5822f29456e59ff9a8f87ed6af56f2c22d2f6 Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sun, 24 Nov 2019 15:48:55 +0100 Subject: [PATCH 22/32] asd --- mpd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mpd.cpp b/mpd.cpp index 89a7fe1..247306e 100644 --- a/mpd.cpp +++ b/mpd.cpp @@ -98,7 +98,7 @@ void CMPD::Update() int newsongpos = mpd_status_get_elapsed_time(status); int curplaytime = mpd_stats_get_play_time(stats); - iprintf("DEBUG: %i - %s - %s", curplaytime, newsongpos, newsongid); + iprintf("DEBUG: %i - %i - %i", curplaytime, newsongpos, newsongid); // new song (or the same song but from the beginning after it has been played long enough before) if(newsongid != _songid || (_song.getDuration() != -1 && _songpos > (_song.getDuration()/2) && newsongpos < _songpos && newsongpos < 10)) { From d618f6db484baa9eb78ae23425c8daf344791439 Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sun, 24 Nov 2019 15:58:07 +0100 Subject: [PATCH 23/32] added comparison operator --- mpd.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/mpd.h b/mpd.h index f06d92d..19a91b9 100644 --- a/mpd.h +++ b/mpd.h @@ -22,6 +22,11 @@ class Song { int getDuration() const { return duration; } std::string getTrack() const { return track; } std::string getMusicBrainzId() const { return mbid; } + bool operator != (const Song &other) const { + return this->getArtist() != other.getArtist() or + this->getAlbum() != other.getAlbum() or + this->getTitle() != other.getTitle(); + } private: std::string albumartist, artist, title, album, track, mbid; int duration = -1; From 1b184ba2963c14e3d17bb8852b8fcb135be6ba41 Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sun, 24 Nov 2019 15:59:06 +0100 Subject: [PATCH 24/32] asd --- mpd.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/mpd.cpp b/mpd.cpp index 247306e..53fb7db 100644 --- a/mpd.cpp +++ b/mpd.cpp @@ -35,6 +35,7 @@ CMPD::CMPD(CConfig *cfg) _connected = false; _cached = false; _songid = -1; + _song = Song(); _songpos = -1; if(Connect()) From f6351e84e828c1ebb21a926a8a4d604890af7f39 Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sun, 24 Nov 2019 16:13:40 +0100 Subject: [PATCH 25/32] asd --- mpd.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/mpd.cpp b/mpd.cpp index 53fb7db..6008ebe 100644 --- a/mpd.cpp +++ b/mpd.cpp @@ -98,19 +98,21 @@ void CMPD::Update() int newsongid = mpd_status_get_song_id(status); int newsongpos = mpd_status_get_elapsed_time(status); int curplaytime = mpd_stats_get_play_time(stats); + mpd_song *song = mpd_run_current_song(_conn); + Song *song_ = song ? new Song(song) : NULL; - iprintf("DEBUG: %i - %i - %i", curplaytime, newsongpos, newsongid); + //iprintf("DEBUG: %i - %i - %i", curplaytime, newsongpos, newsongid); + iprintf("DEBUG (duration): %i", song_->getDuration()); // new song (or the same song but from the beginning after it has been played long enough before) - if(newsongid != _songid || (_song.getDuration() != -1 && _songpos > (_song.getDuration()/2) && newsongpos < _songpos && newsongpos < 10)) { + if(newsongid != _songid || (song_ and _song != *song_) || (_song.getDuration() != -1 && _songpos > (_song.getDuration()/2) && newsongpos < _songpos && newsongpos < 10)) { _songid = newsongid; _songpos = newsongpos; _start = curplaytime; - - mpd_song *song = mpd_run_current_song(_conn); + //_start = 0; + if(song) { GotNewSong(song); - mpd_song_free(song); } else { _song = Song(); } @@ -122,6 +124,11 @@ void CMPD::Update() CheckSubmit(curplaytime); } + if (song) + mpd_song_free(song); + if (song_) + delete song_; + // check for client-to-client messages if(mpd_send_read_messages(_conn)) { mpd_message *msg; From fb08c25e879433fff090b175bc96f70999489012 Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sun, 24 Nov 2019 16:28:27 +0100 Subject: [PATCH 26/32] asd --- mpd.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mpd.cpp b/mpd.cpp index 6008ebe..f26584e 100644 --- a/mpd.cpp +++ b/mpd.cpp @@ -178,5 +178,8 @@ Song::Song(struct mpd_song *song) temp = mpd_song_get_tag(song, MPD_TAG_MUSICBRAINZ_TRACKID , 0); mbid = temp ? temp : ""; - duration = mpd_song_get_duration(song); + mpd_status *status = mpd_run_status(_conn); + //duration = mpd_song_get_duration(song); + duration = mpd_status_get_total_time(status); + mpd_status_free(status); } From 9e0282b4b75d41fb7ef2ae0908c192655de83d98 Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sun, 24 Nov 2019 16:32:08 +0100 Subject: [PATCH 27/32] blah --- mpd.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/mpd.cpp b/mpd.cpp index f26584e..f239b2d 100644 --- a/mpd.cpp +++ b/mpd.cpp @@ -71,9 +71,9 @@ bool CMPD::Connect() return _connected; } -void CMPD::GotNewSong(struct mpd_song *song) +void CMPD::GotNewSong(struct mpd_song *song, int duration) { - Song *s = new Song(song); + Song *s = new Song(song, duration); SetSong(s); delete s; } @@ -98,6 +98,7 @@ void CMPD::Update() int newsongid = mpd_status_get_song_id(status); int newsongpos = mpd_status_get_elapsed_time(status); int curplaytime = mpd_stats_get_play_time(stats); + int duration = mpd_status_get_total_time(status); mpd_song *song = mpd_run_current_song(_conn); Song *song_ = song ? new Song(song) : NULL; @@ -112,7 +113,7 @@ void CMPD::Update() //_start = 0; if(song) { - GotNewSong(song); + GotNewSong(song, duration); } else { _song = Song(); } @@ -156,7 +157,7 @@ void CMPD::Update() } } -Song::Song(struct mpd_song *song) +Song::Song(struct mpd_song *song, int duration) { const char* temp; @@ -178,8 +179,6 @@ Song::Song(struct mpd_song *song) temp = mpd_song_get_tag(song, MPD_TAG_MUSICBRAINZ_TRACKID , 0); mbid = temp ? temp : ""; - mpd_status *status = mpd_run_status(_conn); //duration = mpd_song_get_duration(song); - duration = mpd_status_get_total_time(status); - mpd_status_free(status); + this->duration = duration; } From 4cb4ff031290818f734b9c5f765beeb20344d399 Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sun, 24 Nov 2019 16:34:22 +0100 Subject: [PATCH 28/32] blah --- mpd.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mpd.h b/mpd.h index 19a91b9..42a69b2 100644 --- a/mpd.h +++ b/mpd.h @@ -4,7 +4,7 @@ class Song { public: Song() {}; - Song(struct mpd_song *song); + Song(struct mpd_song *song, int duration); Song(std::string artist, std::string title, std::string album, std::string albumartist, int duration, std::string track, std::string mbid) { this->artist = artist; this->title = title; @@ -46,7 +46,7 @@ class CMPD inline bool isConnected() { return _connected; } private: - void GotNewSong(struct mpd_song *song); + void GotNewSong(struct mpd_song *song, int duration); CConfig *_cfg; mpd_connection *_conn; From 14b05401d1a8451962c0782e480632dff100ad27 Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sun, 24 Nov 2019 16:35:08 +0100 Subject: [PATCH 29/32] blah --- mpd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mpd.cpp b/mpd.cpp index f239b2d..1bee110 100644 --- a/mpd.cpp +++ b/mpd.cpp @@ -100,7 +100,7 @@ void CMPD::Update() int curplaytime = mpd_stats_get_play_time(stats); int duration = mpd_status_get_total_time(status); mpd_song *song = mpd_run_current_song(_conn); - Song *song_ = song ? new Song(song) : NULL; + Song *song_ = song ? new Song(song, duration) : NULL; //iprintf("DEBUG: %i - %i - %i", curplaytime, newsongpos, newsongid); iprintf("DEBUG (duration): %i", song_->getDuration()); From 87c57e6d67851097a52464acd869950134a3a03d Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sun, 24 Nov 2019 16:39:59 +0100 Subject: [PATCH 30/32] blah blah --- mpd.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/mpd.cpp b/mpd.cpp index 1bee110..c0260e5 100644 --- a/mpd.cpp +++ b/mpd.cpp @@ -102,11 +102,23 @@ void CMPD::Update() mpd_song *song = mpd_run_current_song(_conn); Song *song_ = song ? new Song(song, duration) : NULL; + if(duration == 0){ + if (song) + mpd_song_free(song); + if (song_) + delete song_; + mpd_status_free(status); + mpd_stats_free(stats); + return; + } + //iprintf("DEBUG: %i - %i - %i", curplaytime, newsongpos, newsongid); iprintf("DEBUG (duration): %i", song_->getDuration()); // new song (or the same song but from the beginning after it has been played long enough before) - if(newsongid != _songid || (song_ and _song != *song_) || (_song.getDuration() != -1 && _songpos > (_song.getDuration()/2) && newsongpos < _songpos && newsongpos < 10)) { + if(newsongid != _songid || + (song_ and _song != *song_) || + (_song.getDuration() != -1 && _songpos > (_song.getDuration()/2) && newsongpos < _songpos && newsongpos < 10)) { _songid = newsongid; _songpos = newsongpos; _start = curplaytime; From e54637d9f646f9110a5ca3e32dc91b66fe3b3145 Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sun, 24 Nov 2019 16:41:19 +0100 Subject: [PATCH 31/32] removed debug crap --- mpd.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/mpd.cpp b/mpd.cpp index c0260e5..8ec636b 100644 --- a/mpd.cpp +++ b/mpd.cpp @@ -112,8 +112,6 @@ void CMPD::Update() return; } - //iprintf("DEBUG: %i - %i - %i", curplaytime, newsongpos, newsongid); - iprintf("DEBUG (duration): %i", song_->getDuration()); // new song (or the same song but from the beginning after it has been played long enough before) if(newsongid != _songid || From e0341a757dade43bd4377956fa04e3d4ec35db19 Mon Sep 17 00:00:00 2001 From: Loreno Heer Date: Sun, 24 Nov 2019 18:13:09 +0100 Subject: [PATCH 32/32] I don't think this change was necessary --- mpd.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mpd.cpp b/mpd.cpp index 8ec636b..5bad630 100644 --- a/mpd.cpp +++ b/mpd.cpp @@ -5,8 +5,7 @@ CMPD* MPD = 0; void CMPD::SetSong(const Song *song) { _cached = false; - if(song && !song->getArtist().empty() && !song->getTitle().empty() && - (song->getArtist() != _song.getArtist() || song->getTitle() != _song.getTitle())) { + if(song && !song->getArtist().empty() && !song->getTitle().empty()) { _song = *song; _gotsong = true; iprintf("New song: %s - %s", _song.getArtist().c_str(), _song.getTitle().c_str());