add CLI play-playlist option, to play given playlist name.
This commit is contained in:
parent
c536dc88e9
commit
ee72b974bf
@ -60,16 +60,17 @@ const char* CommandlineOptions::kHelpText =
|
|||||||
" -a, --append %22\n"
|
" -a, --append %22\n"
|
||||||
" -l, --load %23\n"
|
" -l, --load %23\n"
|
||||||
" -k, --play-track <n> %24\n"
|
" -k, --play-track <n> %24\n"
|
||||||
|
" -i, --play-playlist <name> %25\n"
|
||||||
"\n"
|
"\n"
|
||||||
"%25:\n"
|
"%26:\n"
|
||||||
" -o, --show-osd %26\n"
|
" -o, --show-osd %27\n"
|
||||||
" -y, --toggle-pretty-osd %27\n"
|
" -y, --toggle-pretty-osd %28\n"
|
||||||
" -g, --language <lang> %28\n"
|
" -g, --language <lang> %29\n"
|
||||||
" --quiet %29\n"
|
" --quiet %30\n"
|
||||||
" --verbose %30\n"
|
" --verbose %31\n"
|
||||||
" --log-levels <levels> %31\n"
|
" --log-levels <levels> %32\n"
|
||||||
" --version %32\n"
|
" --version %33\n"
|
||||||
" -x, --delete-current %33\n";
|
" -x, --delete-current %34\n";
|
||||||
|
|
||||||
const char* CommandlineOptions::kVersionText = "Clementine %1";
|
const char* CommandlineOptions::kVersionText = "Clementine %1";
|
||||||
|
|
||||||
@ -131,6 +132,7 @@ bool CommandlineOptions::Parse() {
|
|||||||
{"append", no_argument, 0, 'a'},
|
{"append", no_argument, 0, 'a'},
|
||||||
{"load", no_argument, 0, 'l'},
|
{"load", no_argument, 0, 'l'},
|
||||||
{"play-track", required_argument, 0, 'k'},
|
{"play-track", required_argument, 0, 'k'},
|
||||||
|
{"play-playlist", required_argument, 0, 'i'},
|
||||||
{"show-osd", no_argument, 0, 'o'},
|
{"show-osd", no_argument, 0, 'o'},
|
||||||
{"toggle-pretty-osd", no_argument, 0, 'y'},
|
{"toggle-pretty-osd", no_argument, 0, 'y'},
|
||||||
{"language", required_argument, 0, 'g'},
|
{"language", required_argument, 0, 'g'},
|
||||||
@ -145,7 +147,7 @@ bool CommandlineOptions::Parse() {
|
|||||||
bool ok = false;
|
bool ok = false;
|
||||||
forever {
|
forever {
|
||||||
int c =
|
int c =
|
||||||
getopt_long(argc_, argv_, "xhptusqrfv:c:alk:oyg:", kOptions, nullptr);
|
getopt_long(argc_, argv_, "xhptusqrfv:c:i:alk:oyg:", kOptions, nullptr);
|
||||||
|
|
||||||
// End of the options
|
// End of the options
|
||||||
if (c == -1) break;
|
if (c == -1) break;
|
||||||
@ -177,7 +179,8 @@ bool CommandlineOptions::Parse() {
|
|||||||
tr("Create a new playlist with files/URLs"),
|
tr("Create a new playlist with files/URLs"),
|
||||||
tr("Append files/URLs to the playlist"),
|
tr("Append files/URLs to the playlist"),
|
||||||
tr("Loads files/URLs, replacing current playlist"),
|
tr("Loads files/URLs, replacing current playlist"),
|
||||||
tr("Play the <n>th track in the playlist"))
|
tr("Play the <n>th track in the playlist"),
|
||||||
|
tr("Play given playlist"))
|
||||||
.arg(tr("Other options"), tr("Display the on-screen-display"),
|
.arg(tr("Other options"), tr("Display the on-screen-display"),
|
||||||
tr("Toggle visibility for the pretty on-screen-display"),
|
tr("Toggle visibility for the pretty on-screen-display"),
|
||||||
tr("Change the language"),
|
tr("Change the language"),
|
||||||
@ -212,6 +215,10 @@ bool CommandlineOptions::Parse() {
|
|||||||
case 'f':
|
case 'f':
|
||||||
player_action_ = Player_Next;
|
player_action_ = Player_Next;
|
||||||
break;
|
break;
|
||||||
|
case 'i':
|
||||||
|
player_action_ = Player_PlayPlaylist;
|
||||||
|
playlist_name_ = QString(optarg);
|
||||||
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
url_list_action_ = UrlList_CreateNew;
|
url_list_action_ = UrlList_CreateNew;
|
||||||
playlist_name_ = QString(optarg);
|
playlist_name_ = QString(optarg);
|
||||||
@ -349,7 +356,7 @@ QDataStream& operator<<(QDataStream& s, const CommandlineOptions& a) {
|
|||||||
s << qint32(a.player_action_) << qint32(a.url_list_action_) << a.set_volume_
|
s << qint32(a.player_action_) << qint32(a.url_list_action_) << a.set_volume_
|
||||||
<< a.volume_modifier_ << a.seek_to_ << a.seek_by_ << a.play_track_at_
|
<< a.volume_modifier_ << a.seek_to_ << a.seek_by_ << a.play_track_at_
|
||||||
<< a.show_osd_ << a.urls_ << a.log_levels_ << a.toggle_pretty_osd_
|
<< a.show_osd_ << a.urls_ << a.log_levels_ << a.toggle_pretty_osd_
|
||||||
<< a.delete_current_track_;
|
<< a.delete_current_track_ << a.playlist_name_;
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
@ -360,7 +367,7 @@ QDataStream& operator>>(QDataStream& s, CommandlineOptions& a) {
|
|||||||
s >> player_action >> url_list_action >> a.set_volume_ >>
|
s >> player_action >> url_list_action >> a.set_volume_ >>
|
||||||
a.volume_modifier_ >> a.seek_to_ >> a.seek_by_ >> a.play_track_at_ >>
|
a.volume_modifier_ >> a.seek_to_ >> a.seek_by_ >> a.play_track_at_ >>
|
||||||
a.show_osd_ >> a.urls_ >> a.log_levels_ >> a.toggle_pretty_osd_ >>
|
a.show_osd_ >> a.urls_ >> a.log_levels_ >> a.toggle_pretty_osd_ >>
|
||||||
a.delete_current_track_;
|
a.delete_current_track_ >> a.playlist_name_;
|
||||||
a.player_action_ = CommandlineOptions::PlayerAction(player_action);
|
a.player_action_ = CommandlineOptions::PlayerAction(player_action);
|
||||||
a.url_list_action_ = CommandlineOptions::UrlListAction(url_list_action);
|
a.url_list_action_ = CommandlineOptions::UrlListAction(url_list_action);
|
||||||
|
|
||||||
|
@ -56,6 +56,7 @@ class CommandlineOptions {
|
|||||||
Player_Next = 6,
|
Player_Next = 6,
|
||||||
Player_RestartOrPrevious = 7,
|
Player_RestartOrPrevious = 7,
|
||||||
Player_StopAfterCurrent = 8,
|
Player_StopAfterCurrent = 8,
|
||||||
|
Player_PlayPlaylist = 9,
|
||||||
};
|
};
|
||||||
|
|
||||||
bool Parse();
|
bool Parse();
|
||||||
|
@ -224,6 +224,34 @@ void Player::NextItem(Engine::TrackChangeFlags change) {
|
|||||||
PlayAt(i, change, false);
|
PlayAt(i, change, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Player::PlayPlaylist(const QString& playlistName) {
|
||||||
|
PlayPlaylistInternal(Engine::Manual, playlistName);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Player::PlayPlaylistInternal(Engine::TrackChangeFlags change,
|
||||||
|
const QString& playlistName) {
|
||||||
|
Playlist* playlist = NULL;
|
||||||
|
for (Playlist* p : app_->playlist_manager()->GetAllPlaylists()) {
|
||||||
|
if (playlistName == app_->playlist_manager()->GetPlaylistName(p->id())) {
|
||||||
|
playlist = p;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (playlist != NULL) {
|
||||||
|
app_->playlist_manager()->SetActivePlaylist(playlist->id());
|
||||||
|
if (playlist->rowCount() == 0) return;
|
||||||
|
|
||||||
|
int i = app_->playlist_manager()->active()->current_row();
|
||||||
|
if (i == -1) i = app_->playlist_manager()->active()->last_played_row();
|
||||||
|
if (i == -1) i = 0;
|
||||||
|
|
||||||
|
PlayAt(i, Engine::First, true);
|
||||||
|
} else {
|
||||||
|
qLog(Warning) << "Playlist '" << playlistName << "' not found.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool Player::HandleStopAfter() {
|
bool Player::HandleStopAfter() {
|
||||||
if (app_->playlist_manager()->active()->stop_after_current()) {
|
if (app_->playlist_manager()->active()->stop_after_current()) {
|
||||||
// Find what the next track would've been, and mark that one as current
|
// Find what the next track would've been, and mark that one as current
|
||||||
|
@ -151,6 +151,7 @@ class Player : public PlayerInterface {
|
|||||||
void RestartOrPrevious();
|
void RestartOrPrevious();
|
||||||
void Next();
|
void Next();
|
||||||
void Previous();
|
void Previous();
|
||||||
|
void PlayPlaylist(const QString& playlistName);
|
||||||
void SetVolume(int value);
|
void SetVolume(int value);
|
||||||
void VolumeUp() { SetVolume(GetVolume() + 5); }
|
void VolumeUp() { SetVolume(GetVolume() + 5); }
|
||||||
void VolumeDown() { SetVolume(GetVolume() - 5); }
|
void VolumeDown() { SetVolume(GetVolume() - 5); }
|
||||||
@ -180,6 +181,8 @@ class Player : public PlayerInterface {
|
|||||||
void PreviousItem(Engine::TrackChangeFlags change);
|
void PreviousItem(Engine::TrackChangeFlags change);
|
||||||
|
|
||||||
void NextInternal(Engine::TrackChangeFlags);
|
void NextInternal(Engine::TrackChangeFlags);
|
||||||
|
void PlayPlaylistInternal(Engine::TrackChangeFlags,
|
||||||
|
const QString& playlistName);
|
||||||
|
|
||||||
void ValidSongRequested(const QUrl&);
|
void ValidSongRequested(const QUrl&);
|
||||||
void InvalidSongRequested(const QUrl&);
|
void InvalidSongRequested(const QUrl&);
|
||||||
|
@ -2246,9 +2246,10 @@ void MainWindow::CommandlineOptionsReceived(const QString& string_options) {
|
|||||||
if (options.is_empty()) {
|
if (options.is_empty()) {
|
||||||
show();
|
show();
|
||||||
activateWindow();
|
activateWindow();
|
||||||
} else
|
} else {
|
||||||
CommandlineOptionsReceived(options);
|
CommandlineOptionsReceived(options);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::CommandlineOptionsReceived(const CommandlineOptions& options) {
|
void MainWindow::CommandlineOptionsReceived(const CommandlineOptions& options) {
|
||||||
qLog(Debug) << "command line options received";
|
qLog(Debug) << "command line options received";
|
||||||
@ -2277,6 +2278,14 @@ void MainWindow::CommandlineOptionsReceived(const CommandlineOptions& options) {
|
|||||||
case CommandlineOptions::Player_Next:
|
case CommandlineOptions::Player_Next:
|
||||||
app_->player()->Next();
|
app_->player()->Next();
|
||||||
break;
|
break;
|
||||||
|
case CommandlineOptions::Player_PlayPlaylist:
|
||||||
|
if (options.playlist_name().isNull() ||
|
||||||
|
options.playlist_name().isEmpty()) {
|
||||||
|
qLog(Error) << "ERROR: playlist name missing";
|
||||||
|
} else {
|
||||||
|
app_->player()->PlayPlaylist(options.playlist_name());
|
||||||
|
}
|
||||||
|
break;
|
||||||
case CommandlineOptions::Player_RestartOrPrevious:
|
case CommandlineOptions::Player_RestartOrPrevious:
|
||||||
app_->player()->RestartOrPrevious();
|
app_->player()->RestartOrPrevious();
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user