-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'countplaylist' of https://github.com/jcorporation/MPD
- Loading branch information
Showing
8 changed files
with
130 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
// Copyright The Music Player Daemon Project | ||
|
||
#include "config.h" | ||
#include "LocateUri.hxx" | ||
#include "Length.hxx" | ||
#include "PlaylistAny.hxx" | ||
#include "PlaylistSong.hxx" | ||
#include "SongEnumerator.hxx" | ||
#include "SongPrint.hxx" | ||
#include "song/DetachedSong.hxx" | ||
#include "song/LightSong.hxx" | ||
#include "fs/Traits.hxx" | ||
#include "thread/Mutex.hxx" | ||
#include "Partition.hxx" | ||
#include "Instance.hxx" | ||
|
||
#include <fmt/format.h> | ||
|
||
static SignedSongTime get_duration(const DetachedSong &song) { | ||
const auto duration = song.GetDuration(); | ||
return duration.IsNegative() ? (SignedSongTime)0 : song.GetDuration(); | ||
} | ||
|
||
static void | ||
playlist_provider_length(Response &r, | ||
const SongLoader &loader, | ||
const char *uri, | ||
SongEnumerator &e) noexcept | ||
{ | ||
const auto base_uri = uri != nullptr | ||
? PathTraitsUTF8::GetParent(uri) | ||
: "."; | ||
|
||
std::unique_ptr<DetachedSong> song; | ||
unsigned i = 0; | ||
SignedSongTime playtime = (SignedSongTime)0; | ||
while ((song = e.NextSong()) != nullptr) { | ||
if (playlist_check_translate_song(*song, base_uri, | ||
loader)) | ||
playtime += get_duration(*song); | ||
i++; | ||
} | ||
r.Fmt(FMT_STRING("songs: {}\n"), i); | ||
r.Fmt(FMT_STRING("playtime: {}\n"), playtime.RoundS()); | ||
} | ||
|
||
bool | ||
playlist_file_length(Response &r, Partition &partition, | ||
const SongLoader &loader, | ||
const LocatedUri &uri) | ||
{ | ||
Mutex mutex; | ||
|
||
#ifndef ENABLE_DATABASE | ||
(void)partition; | ||
#endif | ||
|
||
auto playlist = playlist_open_any(uri, | ||
#ifdef ENABLE_DATABASE | ||
partition.instance.storage, | ||
#endif | ||
mutex); | ||
if (playlist == nullptr) | ||
return false; | ||
|
||
playlist_provider_length(r, loader, uri.canonical_uri, *playlist); | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
// Copyright The Music Player Daemon Project | ||
|
||
#ifndef MPD_PLAYLIST__LENGTH_HXX | ||
#define MPD_PLAYLIST__LENGTH_HXX | ||
|
||
#include "client/Response.hxx" | ||
|
||
class SongLoader; | ||
struct Partition; | ||
|
||
/** | ||
* Count the number of songs and their total playtime (seconds) in the | ||
* playlist. | ||
* | ||
* @param uri the URI of the playlist file in UTF-8 encoding | ||
* @return true on success, false if the playlist does not exist | ||
*/ | ||
bool | ||
playlist_file_length(Response &r, Partition &partition, | ||
const SongLoader &loader, | ||
const LocatedUri &uri); | ||
|
||
#endif |