summaryrefslogtreecommitdiff
path: root/plex.cpp
blob: d4b303025ec724bc615ac1374e8e0bfb9aeec4e3 (plain)
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
#include "ControlServer.h"
#include "SubscriptionManager.h"
#include "plex.h"
#include "plexOsd.h"
#include "plexSdOsd.h"
#include "pictureCache.h"
#include "services.h"
#include "sdDisplayReplay.h"

#include <libskindesignerapi/skindesignerapi.h>

//////////////////////////////////////////////////////////////////////////////
//	cPlugin
//////////////////////////////////////////////////////////////////////////////

volatile bool cMyPlugin::CalledFromCode = false;
bool cMyPlugin::bSkindesigner = 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)
{
	m_pSdCheck = NULL;
}

/**
**	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)
{
	skindesignerapi::cPluginStructure reg;
	reg.name = "plex";
	reg.libskindesignerAPIVersion = LIBSKINDESIGNERAPIVERSION;

	reg.SetView(viRootView, "root.xml");
	reg.SetViewGrid(eViews::viRootView, eViewGrids::vgCover, "coverbrowser");
	reg.SetViewGrid(eViews::viRootView, eViewGrids::vgList, "listbrowser");
	reg.SetViewGrid(eViews::viRootView, eViewGrids::vgDetail, "detailbrowser");
	reg.SetViewElement(viRootView, verHeader, "header");
	reg.SetViewElement(viRootView, verBackground, "background");
	reg.SetViewElement(viRootView, verInfopane, "infopane");
	reg.SetViewElement(viRootView, verFooter, "footer");
	reg.SetViewElement(viRootView, verWatch, "time");
	reg.SetViewElement(viRootView, verMessage, "message");
	reg.SetViewElement(viRootView, verScrollbar, "scrollbar");
	
	reg.SetView(viReplay, "replay.xml");
	reg.SetViewElement(viReplay, cSdDisplayReplay::eElements::Info, "info");
	reg.SetViewElement(viReplay, cSdDisplayReplay::eElements::Replay, "replay");
	/*
		reg.SetSubView(viRootView, viDetailView, "detail.xml");
		reg.SetViewElement(viDetailView, vedBackground, "background");
		reg.SetViewElement(viDetailView, vedHeader, "header");
		reg.SetViewElement(viDetailView, vedFooter, "footer");
	*/
	
	//reg.SetMenu(meRoot, "streamselect.xml");
	if (skindesignerapi::SkindesignerAPI::RegisterPlugin(&reg)) {
		m_pSdCheck = new cPlexSdOsd();
		cMyPlugin::bSkindesigner = m_pSdCheck->SdSupport();
	} else {
		esyslog("[plex]: %s skindesigner not available", __FUNCTION__);
	}
	return true;
}

/**
**	Start any background activities the plugin shall perform.
*/
bool cMyPlugin::Initialize(void)
{
	// 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();
	cPictureCache::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__);
	if(m_pSdCheck && m_pSdCheck->SdSupport()) return new cPlexSdOsd();
	else return cPlexMenu::ProcessMenu();
}

/**
**	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)
{
	cPlugin* mpvPlugin = cPluginManager::GetPlugin("mpv");

	if(Config::GetInstance().UseMpv && mpvPlugin) {
		Mpv_StartPlayService_v1_0_t req;
		char* file = (char*)(Vid.m_pServer->GetUri() + Vid.m_Media.m_sPartKey).c_str();
		req.Filename = file;
		req.Title = (char*)Vid.GetTitle().c_str();
		//req.Title = &Vid.GetTitle().c_str();
		mpvPlugin->Service(MPV_START_PLAY_SERVICE, &req);
		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());
	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;
		}
	}
	cControl* control = cHlsPlayerControl::Create(Vid);
	if(control) {
		cControl::Launch(control);
	}
}

VDRPLUGINCREATOR(cMyPlugin);		// Don't touch this!