1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
|
#include "ControlServer.h"
#include "SubscriptionManager.h"
#include "plex.h"
#include "plexOsd.h"
#include "services.h"
#include "tokendefinitions.h"
#include <Poco/Net/SSLManager.h>
#include <Poco/SharedPtr.h>
#include <Poco/Net/Context.h>
#include <Poco/Net/AcceptCertificateHandler.h>
#include <Poco/Net/ConsoleCertificateHandler.h>
//////////////////////////////////////////////////////////////////////////////
// cPlugin
//////////////////////////////////////////////////////////////////////////////
volatile bool cMyPlugin::CalledFromCode = false;
#ifdef SKINDESIGNER
bool cMyPlugin::bSkindesigner = false;
#endif
plexclient::Video cMyPlugin::CurrentVideo;
bool cMyPlugin::PlayingFile = false;
/**
** Initialize any member variables here.
**
** @note DON'T DO ANYTHING ELSE THAT MAY HAVE SIDE EFFECTS, REQUIRE GLOBAL
** VDR OBJECTS TO EXIST OR PRODUCE ANY OUTPUT!
*/
cMyPlugin::cMyPlugin(void)
{
}
/**
** Clean up after yourself!
*/
cMyPlugin::~cMyPlugin(void)
{
plexclient::plexgdm::GetInstance().stopRegistration();
plexclient::ControlServer::GetInstance().Stop();
}
/**
** Return plugin version number.
**
** @returns version number as constant string.
*/
const char *cMyPlugin::Version(void)
{
return VERSION;
}
/**
** Return plugin short description.
**
** @returns short description as constant string.
*/
const char *cMyPlugin::Description(void)
{
return DESCRIPTION;
}
bool cMyPlugin::Start(void)
{
#ifdef SKINDESIGNER
m_pPlugStruct = new skindesignerapi::cPluginStructure();
m_pPlugStruct->name = "plex";
m_pPlugStruct->libskindesignerAPIVersion = LIBSKINDESIGNERAPIVERSION;
m_pPlugStruct->RegisterRootView("root.xml");
skindesignerapi::cTokenContainer *tkBackground = new skindesignerapi::cTokenContainer();
cPlexSdOsd::DefineTokens(eViewElementsRoot::background, tkBackground);
m_pPlugStruct->RegisterViewElement((int)eViews::rootView, (int)eViewElementsRoot::background, "background", tkBackground);
skindesignerapi::cTokenContainer *tkHeader = new skindesignerapi::cTokenContainer();
cPlexSdOsd::DefineTokens(eViewElementsRoot::header, tkHeader);
m_pPlugStruct->RegisterViewElement((int)eViews::rootView, (int)eViewElementsRoot::header, "header", tkHeader);
skindesignerapi::cTokenContainer *tkFooter = new skindesignerapi::cTokenContainer();
cPlexSdOsd::DefineTokens(eViewElementsRoot::footer, tkFooter);
m_pPlugStruct->RegisterViewElement((int)eViews::rootView, (int)eViewElementsRoot::footer, "footer", tkFooter);
skindesignerapi::cTokenContainer *tkInfopane = new skindesignerapi::cTokenContainer();
cPlexSdOsd::DefineTokens(eViewElementsRoot::infopane, tkInfopane);
m_pPlugStruct->RegisterViewElement((int)eViews::rootView, (int)eViewElementsRoot::infopane, "infopane", tkInfopane);
skindesignerapi::cTokenContainer *tkWatch = new skindesignerapi::cTokenContainer();
cPlexSdOsd::DefineTokens(eViewElementsRoot::watch, tkWatch);
m_pPlugStruct->RegisterViewElement((int)eViews::rootView, (int)eViewElementsRoot::watch, "time", tkWatch);
skindesignerapi::cTokenContainer *tkMessage = new skindesignerapi::cTokenContainer();
cPlexSdOsd::DefineTokens(eViewElementsRoot::message, tkMessage);
m_pPlugStruct->RegisterViewElement((int)eViews::rootView, (int)eViewElementsRoot::message, "message", tkMessage);
skindesignerapi::cTokenContainer *tkScrollbar = new skindesignerapi::cTokenContainer();
cPlexSdOsd::DefineTokens(eViewElementsRoot::scrollbar, tkScrollbar);
m_pPlugStruct->RegisterViewElement((int)eViews::rootView, (int)eViewElementsRoot::scrollbar, "scrollbar", tkScrollbar);
skindesignerapi::cTokenContainer *tkGridCover = new skindesignerapi::cTokenContainer();
skindesignerapi::cTokenContainer *tkGridDetail = new skindesignerapi::cTokenContainer();
skindesignerapi::cTokenContainer *tkGridList = new skindesignerapi::cTokenContainer();
cPlexSdOsd::DefineGridTokens(tkGridCover);
cPlexSdOsd::DefineGridTokens(tkGridDetail);
cPlexSdOsd::DefineGridTokens(tkGridList);
m_pPlugStruct->RegisterViewGrid((int)eViews::rootView, (int)eViewGrids::cover, "coverbrowser", tkGridCover);
m_pPlugStruct->RegisterViewGrid((int)eViews::rootView, (int)eViewGrids::detail, "detailbrowser", tkGridDetail);
m_pPlugStruct->RegisterViewGrid((int)eViews::rootView, (int)eViewGrids::list, "listbrowser", tkGridList);
// DetailsView
m_pPlugStruct->RegisterSubView((int)eViews::detailView, "detail.xml");
skindesignerapi::cTokenContainer *tkBackgroundDetail = new skindesignerapi::cTokenContainer();
cPlexSdOsd::DefineDetailsTokens(eViewElementsDetail::background, tkBackgroundDetail);
m_pPlugStruct->RegisterViewElement((int)eViews::detailView, (int)eViewElementsDetail::background, "background", tkBackgroundDetail);
skindesignerapi::cTokenContainer *tkDetailInfo = new skindesignerapi::cTokenContainer();
cPlexSdOsd::DefineDetailsTokens(eViewElementsDetail::info, tkDetailInfo);
m_pPlugStruct->RegisterViewElement((int)eViews::detailView, (int)eViewElementsDetail::info, "info", tkDetailInfo);
skindesignerapi::cTokenContainer *tkDetailFooter = new skindesignerapi::cTokenContainer();
cPlexSdOsd::DefineDetailsTokens(eViewElementsDetail::footer, tkDetailFooter);
m_pPlugStruct->RegisterViewElement((int)eViews::detailView, (int)eViewElementsDetail::footer, "footer", tkDetailFooter);
skindesignerapi::cTokenContainer *tkDetailScrollbar = new skindesignerapi::cTokenContainer();
cPlexSdOsd::DefineDetailsTokens(eViewElementsDetail::scrollbar, tkDetailScrollbar);
m_pPlugStruct->RegisterViewElement((int)eViews::detailView, (int)eViewElementsDetail::scrollbar, "scrollbar", tkDetailScrollbar);
skindesignerapi::cTokenContainer *tkDetailMessage = new skindesignerapi::cTokenContainer();
cPlexSdOsd::DefineDetailsTokens(eViewElementsDetail::message, tkDetailMessage);
m_pPlugStruct->RegisterViewElement((int)eViews::detailView, (int)eViewElementsDetail::message, "message", tkDetailMessage);
skindesignerapi::cTokenContainer *tkDetailExtraGrid = new skindesignerapi::cTokenContainer();
cPlexSdOsd::DefineGridTokens(tkDetailExtraGrid);
m_pPlugStruct->RegisterViewGrid((int)eViews::detailView, (int)eViewDetailViewGrids::extras, "extragrid", tkDetailExtraGrid);
if (!skindesignerapi::SkindesignerAPI::RegisterPlugin(m_pPlugStruct)) {
esyslog("[plex]: skindesigner not available");
bSkindesigner = false;
} else {
dsyslog("[plex]: successfully registered at skindesigner, id %d", m_pPlugStruct->id);
m_pTestOsd = new cPlexSdOsd(m_pPlugStruct);
bSkindesigner = true;
}
#endif
return true;
}
/**
** Start any background activities the plugin shall perform.
*/
bool cMyPlugin::Initialize(void)
{
// Initialize SSL
{
using namespace Poco;
using namespace Poco::Net;
using Poco::Net::SSLManager;
using Poco::Net::Context;
using Poco::Net::AcceptCertificateHandler;
using Poco::Net::PrivateKeyPassphraseHandler;
using Poco::Net::InvalidCertificateHandler;
using Poco::Net::ConsoleCertificateHandler;
//SharedPtr<PrivateKeyPassphraseHandler> pConsoleHandler = new PrivateKeyPassphraseHandler;
SharedPtr<InvalidCertificateHandler> pInvalidCertHandler = new AcceptCertificateHandler(false);
Context::Ptr pContext = new Poco::Net::Context(
Context::CLIENT_USE, "", "", "", Context::VERIFY_NONE, // VERIFY_NONE...?!
9, false, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
SSLManager::instance().initializeClient(NULL, pInvalidCertHandler, pContext);
}
// First Startup? Save UUID
SetupStore("UUID", Config::GetInstance().GetUUID().c_str());
plexclient::plexgdm::GetInstance().clientDetails(Config::GetInstance().GetUUID(), Config::GetInstance().GetHostname(), "3200", DESCRIPTION, VERSION);
plexclient::plexgdm::GetInstance().Start();
plexclient::ControlServer::GetInstance().Start();
return true;
}
/**
** Create main menu entry.
*/
const char *cMyPlugin::MainMenuEntry(void)
{
return Config::GetInstance().HideMainMenuEntry ? NULL : MAINMENUENTRY;
}
/**
** Perform the action when selected from the main VDR menu.
*/
cOsdObject *cMyPlugin::MainMenuAction(void)
{
//dsyslog("[plex]%s:\n", __FUNCTION__);
#ifdef SKINDESIGNER
if(bSkindesigner && m_pTestOsd->SdSupport()) return new cPlexSdOsd(m_pPlugStruct);
else return cPlexMenu::ProcessMenu();
#else
return cPlexMenu::ProcessMenu();
#endif
}
/**
** Called for every plugin once during every cycle of VDR's main program
** loop.
*/
void cMyPlugin::MainThreadHook(void)
{
// dsyslog("[plex]%s:\n", __FUNCTION__);
// Start Tasks, e.g. Play Video
if(plexclient::ActionManager::GetInstance().IsAction()) {
PlayFile(plexclient::ActionManager::GetInstance().GetAction());
}
}
/**
** Return our setup menu.
*/
cMenuSetupPage *cMyPlugin::SetupMenu(void)
{
//dsyslog("[plex]%s:\n", __FUNCTION__);
return new cMyMenuSetupPage;
}
/**
** Parse setup parameters
**
** @param name paramter name (case sensetive)
** @param value value as string
**
** @returns true if the parameter is supported.
*/
bool cMyPlugin::SetupParse(const char *name, const char *value)
{
//dsyslog("[plex]%s: '%s' = '%s'\n", __FUNCTION__, name, value);
return Config::GetInstance().Parse(name, value);
}
/**
** Play a file.
**
** @param filename path and file name
*/
void cMyPlugin::PlayFile(plexclient::Video Vid)
{
if(Vid.m_iMyPlayOffset == 0 && Vid.m_lViewoffset > 0 ) {
cString message = cString::sprintf(tr("To start from %ld minutes, press Ok."), Vid.m_lViewoffset / 60000);
eKeys response = Skins.Message(eMessageType::mtInfo, message, 5);
if(response == kOk) {
Vid.m_iMyPlayOffset = Vid.m_lViewoffset/1000;
}
}
cPlugin* mpvPlugin = cPluginManager::GetPlugin("mpv");
if(Config::GetInstance().UseMpv && mpvPlugin) {
CurrentVideo = Vid;
cMyPlugin::PlayingFile = true;
Mpv_PlayFile req;
Mpv_SetTitle reqTitle;
char* file;
if(Config::GetInstance().UsePlexAccount && Vid.m_pServer->IsLocal() == false) {
file = (char*)plexclient::Plexservice::GetUniversalTranscodeUrl(&Vid, Vid.m_iMyPlayOffset, NULL, true).c_str();
}
else {
file = (char*)(Vid.m_pServer->GetUri() + Vid.m_Media.m_sPartKey).c_str();
}
req.Filename = file;
mpvPlugin->Service(MPV_PLAY_FILE, &req);
reqTitle.Title = (char*)Vid.GetTitle().c_str();
mpvPlugin->Service(MPV_SET_TITLE, &reqTitle);
// Set "StartAt" for mpv player
Mpv_Seek seekData;
seekData.SeekAbsolute = Vid.m_iMyPlayOffset;
seekData.SeekRelative = 0;
mpvPlugin->Service(MPV_SEEK, &seekData);
return;
} else if (Config::GetInstance().UseMpv) {
isyslog("Can't find mpv %s, playing directly.", mpvPlugin ? "service" : "plugin");
}
isyslog("[plex]: play file '%s'\n", Vid.m_sKey.c_str());
cControl* control = cHlsPlayerControl::Create(Vid);
if(control) {
cControl::Launch(control);
}
}
VDRPLUGINCREATOR(cMyPlugin); // Don't touch this!
|