@@ -105,8 +105,6 @@ bool CLogitechMediaServer::StartHardware()
105
105
106
106
StartHeartbeatThread ();
107
107
108
- ReloadNodes ();
109
-
110
108
// Start worker thread
111
109
m_stoprequested = false ;
112
110
m_thread = boost::shared_ptr<boost::thread>(new boost::thread (boost::bind (&CLogitechMediaServer::Do_Work, this )));
@@ -282,9 +280,12 @@ void CLogitechMediaServer::Do_Node_Work(const LogitechMediaServerNode &Node)
282
280
if (sYear == " 0" ) sYear = " " ;
283
281
if (sYear != " " )
284
282
sYear = " (" + sYear + " )" ;
283
+
284
+ sLabel = sArtist + " - " + sTitle + sYear ;
285
285
}
286
+ else
287
+ sLabel = " (empty playlist)" ;
286
288
287
- sLabel = sArtist + " - " + sTitle + sYear ;
288
289
sStatus = sLabel ;
289
290
}
290
291
}
@@ -308,6 +309,9 @@ void CLogitechMediaServer::Do_Work()
308
309
309
310
_log.Log (LOG_STATUS, " Logitech Media Server: Worker started..." );
310
311
312
+ ReloadNodes ();
313
+ ReloadPlaylists ();
314
+
311
315
while (!m_stoprequested)
312
316
{
313
317
sleep_milliseconds (500 );
@@ -509,26 +513,23 @@ bool CLogitechMediaServer::WriteToHardware(const char *pdata, const unsigned cha
509
513
{
510
514
case light2_sOn:
511
515
case light2_sGroupOn:
512
- SendCommand (itt->ID , " PowerOn" );
513
- return true ;
516
+ return SendCommand (itt->ID , " PowerOn" );
514
517
case light2_sOff:
515
518
case light2_sGroupOff:
516
- SendCommand (itt->ID , " PowerOff" );
517
- return true ;
519
+ return SendCommand (itt->ID , " PowerOff" );
518
520
case gswitch_sPlay:
519
521
SendCommand (itt->ID , " NowPlaying" );
520
- SendCommand (itt->ID , " Play" );
521
- return true ;
522
+ return SendCommand (itt->ID , " Play" );
523
+ case gswitch_sPlayPlaylist:
524
+ sParam = GetPlaylistByRefID (iParam);
525
+ return SendCommand (itt->ID , " PlayPlaylist" , sParam );
522
526
case gswitch_sStop:
523
- SendCommand (itt->ID , " Stop" );
524
- return true ;
527
+ return SendCommand (itt->ID , " Stop" );
525
528
case gswitch_sPause:
526
- SendCommand (itt->ID , " Pause" );
527
- return true ;
529
+ return SendCommand (itt->ID , " Pause" );
528
530
case gswitch_sSetVolume:
529
531
sParam = boost::lexical_cast<std::string>(iParam);
530
- SendCommand (itt->ID , " SetVolume" , sParam );
531
- return true ;
532
+ return SendCommand (itt->ID , " SetVolume" , sParam );
532
533
default :
533
534
return true ;
534
535
}
@@ -576,7 +577,44 @@ void CLogitechMediaServer::ReloadNodes()
576
577
_log.Log (LOG_ERROR, " Logitech Media Server: No player-switches found." );
577
578
}
578
579
579
- void CLogitechMediaServer::SendCommand (const int ID, const std::string &command, const std::string ¶m)
580
+ void CLogitechMediaServer::ReloadPlaylists ()
581
+ {
582
+ m_playlists.clear ();
583
+
584
+ std::string sPostdata = " {\" id\" :1,\" method\" :\" slim.request\" ,\" params\" :[\"\" ,[\" playlists\" ,0,999]]}" ;
585
+ Json::Value root = Query (m_IP, m_Port, sPostdata );
586
+
587
+ int totPlaylists = root[" count" ].asInt ();
588
+ if (totPlaylists > 0 ) {
589
+ _log.Log (LOG_STATUS, " Logitech Media Server: %i playlist(s) found." , totPlaylists);
590
+ for (int ii = 0 ; ii < totPlaylists; ii++)
591
+ {
592
+ LMSPlaylistNode pnode;
593
+
594
+ pnode.ID = root[" playlists_loop" ][ii][" id" ].asInt ();
595
+ pnode.Name = root[" playlists_loop" ][ii][" playlist" ].asString ();
596
+ pnode.refID = pnode.ID % 256 ;
597
+
598
+ m_playlists.push_back (pnode);
599
+ }
600
+ }
601
+ else
602
+ _log.Log (LOG_STATUS, " Logitech Media Server: No playlists found." );
603
+ }
604
+
605
+ std::string CLogitechMediaServer::GetPlaylistByRefID (const int ID)
606
+ {
607
+ std::vector<CLogitechMediaServer::LMSPlaylistNode>::const_iterator itt;
608
+
609
+ for (itt = m_playlists.begin (); itt != m_playlists.end (); ++itt) {
610
+ if (itt->refID == ID) return itt->Name ;
611
+ }
612
+
613
+ _log.Log (LOG_ERROR, " Logitech Media Server: Playlist ID %d not found." , ID);
614
+ return " " ;
615
+ }
616
+
617
+ bool CLogitechMediaServer::SendCommand (const int ID, const std::string &command, const std::string ¶m)
580
618
{
581
619
std::vector<std::vector<std::string> > result;
582
620
std::string sPlayerId = " " ;
@@ -640,6 +678,10 @@ void CLogitechMediaServer::SendCommand(const int ID, const std::string &command,
640
678
else if (command == " Play" ) {
641
679
sLMSCmnd = " \" button\" , \" play.single\" " ;
642
680
}
681
+ else if (command == " PlayPlaylist" ) {
682
+ if (param == " " ) return false ;
683
+ sLMSCmnd = " \" playlist\" , \" play\" , \" " + param + " \" " ;
684
+ }
643
685
else if (command == " Pause" ) {
644
686
sLMSCmnd = " \" button\" , \" pause.single\" " ;
645
687
}
@@ -653,22 +695,51 @@ void CLogitechMediaServer::SendCommand(const int ID, const std::string &command,
653
695
sLMSCmnd = " \" power\" , \" 0\" " ;
654
696
}
655
697
else if (command == " SetVolume" ) {
698
+ if (param == " " ) return false ;
656
699
sLMSCmnd = " \" mixer\" , \" volume\" , \" " + param + " \" " ;
657
700
}
658
701
659
702
if (sLMSCmnd != " " )
660
703
{
661
704
std::string sPostdata = " {\" id\" :1,\" method\" :\" slim.request\" ,\" params\" :[\" " + sPlayerId + " \" ,[" + sLMSCmnd + " ]]}" ;
662
705
Json::Value root = Query (m_IP, m_Port, sPostdata );
706
+
707
+ sPostdata = " {\" id\" :1,\" method\" :\" slim.request\" ,\" params\" :[\" " + sPlayerId + " \" ,[\" status\" ,\" -\" ,1,\" tags:uB\" ]]}" ;
708
+ root = Query (m_IP, m_Port, sPostdata );
709
+
710
+ if (root[" player_connected" ].asString () == " 1" )
711
+ {
712
+ std::string sPower = root[" power" ].asString ();
713
+ std::string sMode = root[" mode" ].asString ();
714
+
715
+ if (command == " Stop" )
716
+ return sMode == " stop" ;
717
+ else if (command == " Pause" )
718
+ return sMode == " pause" ;
719
+ else if (command == " Play" )
720
+ return sMode == " play" ;
721
+ else if (command == " PlayPlaylist" )
722
+ return sMode == " play" ;
723
+ else if (command == " PowerOn" )
724
+ return sPower == " 1" ;
725
+ else if (command == " PowerOff" )
726
+ return sPower == " 0" ;
727
+ else
728
+ return false ;
729
+ }
730
+ else
731
+ return false ;
663
732
}
664
733
else
665
734
{
666
735
_log.Log (LOG_ERROR, " Logitech Media Server: (%s) Command: '%s'. Unknown command." , result[0 ][0 ].c_str (), command.c_str ());
736
+ return false ;
667
737
}
668
738
}
669
739
else
670
740
{
671
741
_log.Log (LOG_ERROR, " Logitech Media Server: (%d) Command: '%s'. Device not found." , ID, command.c_str ());
742
+ return false ;
672
743
}
673
744
}
674
745
@@ -686,6 +757,23 @@ void CLogitechMediaServer::SendText(const std::string &playerIP, const std::stri
686
757
}
687
758
}
688
759
760
+ std::vector<CLogitechMediaServer::LMSPlaylistNode> CLogitechMediaServer::GetPlaylists ()
761
+ {
762
+ return m_playlists;
763
+ }
764
+
765
+ int CLogitechMediaServer::GetPlaylistRefID (const std::string &name)
766
+ {
767
+ std::vector<CLogitechMediaServer::LMSPlaylistNode>::const_iterator itt;
768
+
769
+ for (itt = m_playlists.begin (); itt != m_playlists.end (); ++itt) {
770
+ if (itt->Name == name) return itt->refID ;
771
+ }
772
+
773
+ _log.Log (LOG_ERROR, " Logitech Media Server: Playlist '%s' not found." , name.c_str ());
774
+ return 0 ;
775
+ }
776
+
689
777
// Webserver helpers
690
778
namespace http {
691
779
namespace server {
@@ -757,6 +845,34 @@ namespace http {
757
845
}
758
846
}
759
847
848
+ void CWebServer::Cmd_LMSGetPlaylists (WebEmSession & session, const request& req, Json::Value &root)
849
+ {
850
+ std::string hwid = request::findValue (&req, " idx" );
851
+ if (hwid == " " )
852
+ return ;
853
+ int iHardwareID = atoi (hwid.c_str ());
854
+ CDomoticzHardwareBase *pBaseHardware = m_mainworker.GetHardware (iHardwareID);
855
+ if (pBaseHardware == NULL )
856
+ return ;
857
+ if (pBaseHardware->HwdType != HTYPE_LogitechMediaServer)
858
+ return ;
859
+ CLogitechMediaServer *pHardware = (CLogitechMediaServer*)pBaseHardware;
860
+
861
+ root[" status" ] = " OK" ;
862
+ root[" title" ] = " Cmd_LMSGetPlaylists" ;
863
+
864
+ std::vector<CLogitechMediaServer::LMSPlaylistNode> m_nodes = pHardware->GetPlaylists ();
865
+ std::vector<CLogitechMediaServer::LMSPlaylistNode>::const_iterator itt;
866
+
867
+ int ii = 0 ;
868
+ for (itt = m_nodes.begin (); itt != m_nodes.end (); ++itt) {
869
+ root[" result" ][ii][" id" ] = itt->ID ;
870
+ root[" result" ][ii][" refid" ] = itt->refID ;
871
+ root[" result" ][ii][" Name" ] = itt->Name ;
872
+ ii++;
873
+ }
874
+ }
875
+
760
876
void CWebServer::Cmd_LMSMediaCommand (WebEmSession & session, const request& req, Json::Value &root)
761
877
{
762
878
std::string sIdx = request::findValue (&req, " idx" );
0 commit comments