Added an played tracklist
This commit is contained in:
@@ -419,9 +419,15 @@ LmsApplication::createHome()
|
||||
});
|
||||
|
||||
// Events from the PlayQueue
|
||||
playqueue->playTrack.connect(explore, &Explore::handleTrackPlayed);
|
||||
playqueue->playTrack.connect([=](Database::IdType trackId)
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(LmsApp->getDboSession());
|
||||
|
||||
LmsApp->getUser()->getPlayedTrackList().modify()->add(trackId);
|
||||
});
|
||||
playqueue->playTrack.connect(explore, &Explore::handleTrackPlayed);
|
||||
playqueue->playTrack.connect(player, &MediaPlayer::playTrack);
|
||||
|
||||
playqueue->playbackStop.connect(player, &MediaPlayer::stop);
|
||||
|
||||
// Events from MediaScanner
|
||||
|
||||
+37
-48
@@ -28,8 +28,7 @@
|
||||
|
||||
#include "utils/Logger.hpp"
|
||||
|
||||
#include "database/Playlist.hpp"
|
||||
#include "database/TrackStats.hpp"
|
||||
#include "database/TrackList.hpp"
|
||||
|
||||
#include "LmsApplication.hpp"
|
||||
|
||||
@@ -63,7 +62,7 @@ PlayQueue::PlayQueue()
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(LmsApp->getDboSession());
|
||||
|
||||
getPlaylist().modify()->shuffle();
|
||||
getTrackList().modify()->shuffle();
|
||||
}
|
||||
_entriesContainer->clear();
|
||||
addSome();
|
||||
@@ -76,15 +75,15 @@ PlayQueue::PlayQueue()
|
||||
|
||||
LmsApp->preQuit().connect([=]
|
||||
{
|
||||
if (_playlistId)
|
||||
if (_tracklistId)
|
||||
{
|
||||
LMS_LOG(UI, DEBUG) << "Removing playlist id " << *_playlistId;
|
||||
LMS_LOG(UI, DEBUG) << "Removing tracklist id " << *_tracklistId;
|
||||
|
||||
Wt::Dbo::Transaction transaction(LmsApp->getDboSession());
|
||||
|
||||
auto playlist = Database::Playlist::getById(LmsApp->getDboSession(), *_playlistId);
|
||||
if (playlist)
|
||||
playlist.remove();
|
||||
auto tracklist = Database::TrackList::getById(LmsApp->getDboSession(), *_tracklistId);
|
||||
if (tracklist)
|
||||
tracklist.remove();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -92,30 +91,26 @@ PlayQueue::PlayQueue()
|
||||
addSome();
|
||||
}
|
||||
|
||||
Database::Playlist::pointer
|
||||
PlayQueue::getPlaylist()
|
||||
Database::TrackList::pointer
|
||||
PlayQueue::getTrackList()
|
||||
{
|
||||
static const std::string currentPlayQueueName = "__current__playqueue__";
|
||||
Database::Playlist::pointer res;
|
||||
Database::TrackList::pointer res;
|
||||
|
||||
if (LmsApp->getUser()->isDemo())
|
||||
{
|
||||
if (!_playlistId)
|
||||
if (!_tracklistId)
|
||||
{
|
||||
res = Database::Playlist::create(LmsApp->getDboSession(), currentPlayQueueName, false, LmsApp->getUser());
|
||||
res = Database::TrackList::create(LmsApp->getDboSession(), currentPlayQueueName, false, LmsApp->getUser());
|
||||
LmsApp->getDboSession().flush();
|
||||
_playlistId = res.id();
|
||||
_tracklistId = res.id();
|
||||
return res;
|
||||
}
|
||||
|
||||
return Database::Playlist::getById(LmsApp->getDboSession(), *_playlistId);
|
||||
return Database::TrackList::getById(LmsApp->getDboSession(), *_tracklistId);
|
||||
}
|
||||
|
||||
res = Database::Playlist::get(LmsApp->getDboSession(), currentPlayQueueName, LmsApp->getUser());
|
||||
if (!res)
|
||||
res = Database::Playlist::create(LmsApp->getDboSession(), currentPlayQueueName, false, LmsApp->getUser());
|
||||
|
||||
return res;
|
||||
return LmsApp->getUser()->getQueuedTrackList();
|
||||
}
|
||||
|
||||
void
|
||||
@@ -123,7 +118,7 @@ PlayQueue::clearTracks()
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(LmsApp->getDboSession());
|
||||
|
||||
getPlaylist().modify()->clear();
|
||||
getTrackList().modify()->clear();
|
||||
_showMore->setHidden(true);
|
||||
_entriesContainer->clear();
|
||||
updateInfo();
|
||||
@@ -146,29 +141,24 @@ PlayQueue::play(std::size_t pos)
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(LmsApp->getDboSession());
|
||||
|
||||
auto playlist = getPlaylist();
|
||||
auto tracklist = getTrackList();
|
||||
|
||||
// If out of range, stop playing
|
||||
if (pos >= playlist->getCount())
|
||||
if (pos >= tracklist->getCount())
|
||||
{
|
||||
stop();
|
||||
return;
|
||||
}
|
||||
|
||||
// If last and radio mode, fill the next song
|
||||
if (_radioMode->checkState() == Wt::CheckState::Checked && pos == playlist->getCount() - 1)
|
||||
if (_radioMode->checkState() == Wt::CheckState::Checked && pos == tracklist->getCount() - 1)
|
||||
addRadioTrack();
|
||||
|
||||
_trackPos = pos;
|
||||
auto track = playlist->getEntry(*_trackPos)->getTrack();
|
||||
auto track = tracklist->getEntry(*_trackPos)->getTrack();
|
||||
|
||||
trackId = track.id();
|
||||
|
||||
auto stats = Database::TrackStats::get(LmsApp->getDboSession(), track, LmsApp->getUser());
|
||||
|
||||
stats.modify()->incPlayCount();
|
||||
stats.modify()->setLastPlayed(Wt::WLocalDateTime::currentServerDateTime().toUTC());
|
||||
|
||||
updateCurrentTrack(true);
|
||||
}
|
||||
|
||||
@@ -204,7 +194,7 @@ PlayQueue::updateInfo()
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(LmsApp->getDboSession());
|
||||
|
||||
_nbTracks->setText(Wt::WString::tr("Lms.PlayQueue.nb-tracks").arg(static_cast<unsigned>(getPlaylist()->getCount())));
|
||||
_nbTracks->setText(Wt::WString::tr("Lms.PlayQueue.nb-tracks").arg(static_cast<unsigned>(getTrackList()->getCount())));
|
||||
}
|
||||
|
||||
void
|
||||
@@ -229,10 +219,10 @@ PlayQueue::enqueueTracks(const std::vector<Database::Track::pointer>& tracks)
|
||||
// Use a "session" playqueue in order to store the current playqueue
|
||||
// so that the user can disconnect and get its playqueue back
|
||||
|
||||
auto playlist = getPlaylist();
|
||||
auto tracklist = getTrackList();
|
||||
|
||||
for (auto track : tracks)
|
||||
Database::PlaylistEntry::create(LmsApp->getDboSession(), track, playlist);
|
||||
Database::TrackListEntry::create(LmsApp->getDboSession(), track, tracklist);
|
||||
|
||||
updateInfo();
|
||||
addSome();
|
||||
@@ -269,14 +259,13 @@ PlayQueue::addSome()
|
||||
{
|
||||
Wt::Dbo::Transaction transaction (LmsApp->getDboSession());
|
||||
|
||||
auto playlist = getPlaylist();
|
||||
auto tracklist = getTrackList();
|
||||
|
||||
bool moreResults;
|
||||
auto playlistEntries = playlist->getEntries(_entriesContainer->count(), 50, moreResults);
|
||||
for (auto playlistEntry : playlistEntries)
|
||||
auto tracklistEntries = tracklist->getEntries(_entriesContainer->count(), 50);
|
||||
for (auto tracklistEntry : tracklistEntries)
|
||||
{
|
||||
auto playlistEntryId = playlistEntry.id();
|
||||
auto track = playlistEntry->getTrack();
|
||||
auto tracklistEntryId = tracklistEntry.id();
|
||||
auto track = tracklistEntry->getTrack();
|
||||
|
||||
Wt::WTemplate* entry = _entriesContainer->addNew<Wt::WTemplate>(Wt::WString::tr("Lms.PlayQueue.template.entry"));
|
||||
|
||||
@@ -310,7 +299,7 @@ PlayQueue::addSome()
|
||||
{
|
||||
Wt::Dbo::Transaction transaction (LmsApp->getDboSession());
|
||||
|
||||
auto entryToRemove = Database::PlaylistEntry::getById(LmsApp->getDboSession(), playlistEntryId);
|
||||
auto entryToRemove = Database::TrackListEntry::getById(LmsApp->getDboSession(), tracklistEntryId);
|
||||
entryToRemove.remove();
|
||||
}
|
||||
|
||||
@@ -328,7 +317,7 @@ PlayQueue::addSome()
|
||||
|
||||
}
|
||||
|
||||
_showMore->setHidden(!moreResults);
|
||||
_showMore->setHidden(static_cast<std::size_t>(_entriesContainer->count()) >= tracklist->getCount());
|
||||
}
|
||||
|
||||
void
|
||||
@@ -337,17 +326,17 @@ PlayQueue::addRadioTrack()
|
||||
auto now = std::chrono::system_clock::now();
|
||||
std::mt19937 randGenerator(std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()).count());
|
||||
|
||||
auto playlist = getPlaylist();
|
||||
auto tracklist = getTrackList();
|
||||
|
||||
std::set<Database::IdType> playlistTrackIds;
|
||||
std::set<Database::IdType> trackIds;
|
||||
{
|
||||
auto ids = playlist->getTrackIds();
|
||||
playlistTrackIds = std::set<Database::IdType>(ids.begin(), ids.end());
|
||||
auto ids = tracklist->getTrackIds();
|
||||
trackIds = std::set<Database::IdType>(ids.begin(), ids.end());
|
||||
}
|
||||
|
||||
// Get all the tracks of the playlist, get the cluster that is mostly used
|
||||
// Get all the tracks of the tracklist, get the cluster that is mostly used
|
||||
// and reuse it to get the next track
|
||||
auto clusters = playlist->getClusters();
|
||||
auto clusters = tracklist->getClusters();
|
||||
if (clusters.empty())
|
||||
return;
|
||||
|
||||
@@ -357,7 +346,7 @@ PlayQueue::addRadioTrack()
|
||||
|
||||
std::set<Database::IdType> candidateTrackIds;
|
||||
std::set_difference(clusterTrackIds.begin(), clusterTrackIds.end(),
|
||||
playlistTrackIds.begin(), playlistTrackIds.end(),
|
||||
trackIds.begin(), trackIds.end(),
|
||||
std::inserter(candidateTrackIds, candidateTrackIds.end()));
|
||||
|
||||
if (candidateTrackIds.empty())
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#include "database/Playlist.hpp"
|
||||
#include "database/TrackList.hpp"
|
||||
#include "database/Track.hpp"
|
||||
|
||||
namespace UserInterface {
|
||||
@@ -53,7 +53,7 @@ class PlayQueue : public Wt::WTemplate
|
||||
Wt::Signal<> playbackStop;
|
||||
|
||||
private:
|
||||
Database::Playlist::pointer getPlaylist();
|
||||
Database::TrackList::pointer getTrackList();
|
||||
|
||||
void clearTracks();
|
||||
void enqueueTracks(const std::vector<Database::Track::pointer>& tracks);
|
||||
@@ -66,7 +66,7 @@ class PlayQueue : public Wt::WTemplate
|
||||
void play(std::size_t pos);
|
||||
void stop();
|
||||
|
||||
boost::optional<Database::IdType> _playlistId;
|
||||
boost::optional<Database::IdType> _tracklistId;
|
||||
Wt::WCheckBox* _radioMode;
|
||||
Wt::WContainerWidget* _entriesContainer;
|
||||
Wt::WTemplate* _showMore;
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include <Wt/WText.h>
|
||||
|
||||
#include "database/Artist.hpp"
|
||||
#include "database/Setting.hpp"
|
||||
|
||||
#include "utils/Logger.hpp"
|
||||
#include "utils/Utils.hpp"
|
||||
|
||||
@@ -25,8 +25,7 @@
|
||||
#include <Wt/WTemplate.h>
|
||||
|
||||
#include "database/Artist.hpp"
|
||||
#include "database/Setting.hpp"
|
||||
#include "database/TrackStats.hpp"
|
||||
#include "database/TrackList.hpp"
|
||||
|
||||
#include "utils/Logger.hpp"
|
||||
#include "utils/Utils.hpp"
|
||||
@@ -80,7 +79,6 @@ Artists::Artists(Filters* filters)
|
||||
refresh();
|
||||
refreshMostPlayed();
|
||||
refreshRecentlyAdded();
|
||||
refreshRecentlyPlayed();
|
||||
|
||||
filters->updated().connect(this, &Artists::refresh);
|
||||
}
|
||||
@@ -97,22 +95,11 @@ Artists::refreshRecentlyAdded()
|
||||
addCompactEntries(_recentlyAddedContainer, artists);
|
||||
}
|
||||
|
||||
void
|
||||
Artists::refreshRecentlyPlayed()
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(LmsApp->getDboSession());
|
||||
auto artists = TrackStats::getLastPlayedArtists(LmsApp->getDboSession(), LmsApp->getUser(), 5);
|
||||
|
||||
_recentlyPlayedContainer->clear();
|
||||
addCompactEntries(_recentlyPlayedContainer, artists);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Artists::refreshMostPlayed()
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(LmsApp->getDboSession());
|
||||
auto artists = TrackStats::getMostPlayedArtists(LmsApp->getDboSession(), LmsApp->getUser(), 5);
|
||||
auto artists = LmsApp->getUser()->getPlayedTrackList()->getTopArtists(5);
|
||||
|
||||
_mostPlayedContainer->clear();
|
||||
addCompactEntries(_mostPlayedContainer, artists);
|
||||
|
||||
@@ -39,7 +39,6 @@ class Artists : public Wt::WTemplate
|
||||
Wt::Signal<Database::IdType> artistPlay;
|
||||
|
||||
void refreshRecentlyAdded();
|
||||
void refreshRecentlyPlayed();
|
||||
void refreshMostPlayed();
|
||||
|
||||
private:
|
||||
|
||||
@@ -113,10 +113,7 @@ Explore::Explore()
|
||||
_trackPlayed.connect([=]
|
||||
{
|
||||
artists_raw->refreshMostPlayed();
|
||||
artists_raw->refreshRecentlyPlayed();
|
||||
releases_raw->refreshMostPlayed();
|
||||
releases_raw->refreshRecentlyPlayed();
|
||||
|
||||
});
|
||||
|
||||
auto tracks = std::make_unique<Tracks>(_filters);
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include <Wt/WTemplate.h>
|
||||
|
||||
#include "database/Release.hpp"
|
||||
#include "database/TrackStats.hpp"
|
||||
#include "database/TrackList.hpp"
|
||||
|
||||
#include "utils/Logger.hpp"
|
||||
#include "utils/Utils.hpp"
|
||||
@@ -96,7 +96,6 @@ _filters(filters)
|
||||
}));
|
||||
|
||||
refreshRecentlyAdded();
|
||||
refreshRecentlyPlayed();
|
||||
refreshMostPlayed();
|
||||
refresh();
|
||||
|
||||
@@ -106,8 +105,6 @@ _filters(filters)
|
||||
void
|
||||
Releases::refreshRecentlyAdded()
|
||||
{
|
||||
LMS_LOG(UI, DEBUG) << "Refreshing recently added releases";
|
||||
|
||||
auto after = Wt::WLocalDateTime::currentServerDateTime().toUTC().addMonths(-1);
|
||||
|
||||
Wt::Dbo::Transaction transaction(LmsApp->getDboSession());
|
||||
@@ -118,27 +115,12 @@ Releases::refreshRecentlyAdded()
|
||||
addCompactEntries(_recentlyAddedContainer, releases);
|
||||
}
|
||||
|
||||
void
|
||||
Releases::refreshRecentlyPlayed()
|
||||
{
|
||||
LMS_LOG(UI, DEBUG) << "Refreshing recently played releases";
|
||||
|
||||
Wt::Dbo::Transaction transaction(LmsApp->getDboSession());
|
||||
|
||||
auto releases = TrackStats::getLastPlayedReleases(LmsApp->getDboSession(), LmsApp->getUser(), 5);
|
||||
|
||||
_recentlyPlayedContainer->clear();
|
||||
addCompactEntries(_recentlyPlayedContainer, releases);
|
||||
}
|
||||
|
||||
void
|
||||
Releases::refreshMostPlayed()
|
||||
{
|
||||
LMS_LOG(UI, DEBUG) << "Refreshing most played releases";
|
||||
|
||||
Wt::Dbo::Transaction transaction(LmsApp->getDboSession());
|
||||
|
||||
auto releases = TrackStats::getMostPlayedReleases(LmsApp->getDboSession(), LmsApp->getUser(), 5);
|
||||
auto releases = LmsApp->getUser()->getPlayedTrackList()->getTopReleases(5);
|
||||
|
||||
_mostPlayedContainer->clear();
|
||||
addCompactEntries(_mostPlayedContainer, releases);
|
||||
|
||||
@@ -39,7 +39,6 @@ class Releases : public Wt::WTemplate
|
||||
Wt::Signal<Database::IdType> releasePlay;
|
||||
|
||||
void refreshRecentlyAdded();
|
||||
void refreshRecentlyPlayed();
|
||||
void refreshMostPlayed();
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user