forked from PepaRokos/pvr.sledovanitv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.cpp
582 lines (471 loc) · 14.7 KB
/
client.cpp
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
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
/*
* Copyright (C) 2013 Anton Fedchin
* http://github.com/afedchin/xbmc-addon-iptvsimple/
*
* Copyright (C) 2011 Pulse-Eight
* http://www.pulse-eight.com/
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#include "client.h"
#include "p8-platform/util/util.h"
#include "PVRIptvData.h"
#include "xbmc_pvr_dll.h"
#include "libKODI_guilib.h"
#include <iostream>
using namespace std;
using namespace ADDON;
#ifdef TARGET_WINDOWS
#define snprintf _snprintf
#endif
bool m_bCreated = false;
ADDON_STATUS m_CurStatus = ADDON_STATUS_UNKNOWN;
PVRIptvData *m_data = NULL;
bool m_bIsPlaying = false;
PVRIptvChannel m_currentChannel;
PVRIptvRecording m_currentRecording;
/* User adjustable settings are saved here.
* Default values are defined inside client.h
* and exported to the other source files.
*/
std::string g_strUserPath = "";
std::string g_strClientPath = "";
CHelper_libXBMC_addon *XBMC = NULL;
CHelper_libXBMC_pvr *PVR = NULL;
//std::string g_strTvgPath = "";
//std::string g_strM3UPath = "";
//std::string g_strLogoPath = "";
std::string g_strUserName = "";
std::string g_strPassword = "";
bool g_bHdEnabled = true;
//int g_iEPGTimeShift = 0;
//int g_iStartNumber = 1;
//bool g_bTSOverride = true;
//bool g_bCacheM3U = false;
//bool g_bCacheEPG = false;
extern std::string PathCombine(const std::string &strPath, const std::string &strFileName)
{
std::string strResult = strPath;
if (strResult.at(strResult.size() - 1) == '\\' ||
strResult.at(strResult.size() - 1) == '/')
{
strResult.append(strFileName);
}
else
{
strResult.append("/");
strResult.append(strFileName);
}
return strResult;
}
extern std::string GetClientFilePath(const std::string &strFileName)
{
return PathCombine(g_strClientPath, strFileName);
}
extern std::string GetUserFilePath(const std::string &strFileName)
{
return PathCombine(g_strUserPath, strFileName);
}
extern "C" {
void ADDON_ReadSettings(void)
{
char buffer[1024];
//int iPathType = 0;
if (XBMC->GetSetting("userName", &buffer))
{
g_strUserName = buffer;
}
if (XBMC->GetSetting("password", buffer))
{
g_strPassword = buffer;
}
if (!XBMC->GetSetting("enableHd", &g_bHdEnabled))
{
g_bHdEnabled = true;
}
}
ADDON_STATUS ADDON_Create(void* hdl, void* props)
{
if (!hdl || !props)
{
return ADDON_STATUS_UNKNOWN;
}
PVR_PROPERTIES* pvrprops = (PVR_PROPERTIES*)props;
XBMC = new CHelper_libXBMC_addon;
if (!XBMC->RegisterMe(hdl))
{
SAFE_DELETE(XBMC);
return ADDON_STATUS_PERMANENT_FAILURE;
}
PVR = new CHelper_libXBMC_pvr;
if (!PVR->RegisterMe(hdl))
{
SAFE_DELETE(PVR);
SAFE_DELETE(XBMC);
return ADDON_STATUS_PERMANENT_FAILURE;
}
XBMC->Log(LOG_DEBUG, "%s - Creating the PVR sledovanitv.cz add-on", __FUNCTION__);
m_CurStatus = ADDON_STATUS_UNKNOWN;
g_strUserPath = pvrprops->strUserPath;
g_strClientPath = pvrprops->strClientPath;
if (!XBMC->DirectoryExists(g_strUserPath.c_str()))
{
#ifdef TARGET_WINDOWS
CreateDirectory(g_strUserPath.c_str(), NULL);
#else
XBMC->CreateDirectory(g_strUserPath.c_str());
#endif
}
ADDON_ReadSettings();
m_data = new PVRIptvData;
m_CurStatus = ADDON_STATUS_OK;
m_bCreated = true;
return m_CurStatus;
}
ADDON_STATUS ADDON_GetStatus()
{
return m_CurStatus;
}
void ADDON_Destroy()
{
delete m_data;
m_bCreated = false;
m_CurStatus = ADDON_STATUS_UNKNOWN;
}
bool ADDON_HasSettings()
{
return true;
}
ADDON_STATUS ADDON_SetSetting(const char *settingName, const void *settingValue)
{
// reset cache and restart addon
string strFile = GetUserFilePath(M3U_FILE_NAME);
if (XBMC->FileExists(strFile.c_str(), false))
{
#ifdef TARGET_WINDOWS
DeleteFile(strFile.c_str());
#else
XBMC->DeleteFile(strFile.c_str());
#endif
}
strFile = GetUserFilePath(TVG_FILE_NAME);
if (XBMC->FileExists(strFile.c_str(), false))
{
#ifdef TARGET_WINDOWS
DeleteFile(strFile.c_str());
#else
XBMC->DeleteFile(strFile.c_str());
#endif
}
return ADDON_STATUS_NEED_RESTART;
}
void ADDON_Stop()
{
if (m_data != NULL)
{
delete m_data;
m_data = NULL;
}
}
void ADDON_FreeSettings()
{
}
void ADDON_Announce(const char *flag, const char *sender, const char *message, const void *data)
{
}
/***********************************************************
* PVR Client AddOn specific public library functions
***********************************************************/
PVR_ERROR GetAddonCapabilities(PVR_ADDON_CAPABILITIES* pCapabilities)
{
pCapabilities->bSupportsEPG = true;
pCapabilities->bSupportsTV = true;
pCapabilities->bSupportsRadio = true;
pCapabilities->bSupportsChannelGroups = true;
pCapabilities->bSupportsRecordings = true;
pCapabilities->bSupportsTimers = true;
// pCapabilities->bHandlesInputStream = true;
return PVR_ERROR_NO_ERROR;
}
const char *GetBackendName(void)
{
static const char *strBackendName = "Sledovanitv.cz PVR Add-on";
return strBackendName;
}
const char *GetBackendVersion(void)
{
static CStdString strBackendVersion = PVR_CLIENT_VERSION;
return strBackendVersion.c_str();
}
const char *GetConnectionString(void)
{
static CStdString strConnectionString = "connected";
return strConnectionString.c_str();
}
PVR_ERROR GetDriveSpace(long long *iTotal, long long *iUsed)
{
*iTotal = 0;
*iUsed = 0;
return PVR_ERROR_NO_ERROR;
}
PVR_ERROR GetEPGForChannel(ADDON_HANDLE handle, const PVR_CHANNEL &channel, time_t iStart, time_t iEnd)
{
if (m_data)
return m_data->GetEPGForChannel(handle, channel, iStart, iEnd);
return PVR_ERROR_SERVER_ERROR;
}
int GetChannelsAmount(void)
{
if (m_data)
return m_data->GetChannelsAmount();
return -1;
}
PVR_ERROR GetChannels(ADDON_HANDLE handle, bool bRadio)
{
if (m_data)
return m_data->GetChannels(handle, bRadio);
return PVR_ERROR_SERVER_ERROR;
}
void SetStreamPropValue(PVR_NAMED_VALUE *properties, const std::string &strUrl)
{
strncpy(properties[0].strName, PVR_STREAM_PROPERTY_STREAMURL, sizeof(properties[0].strName) - 1);
strncpy(properties[0].strValue, strUrl.c_str(), sizeof(properties[0].strValue) - 1);
}
PVR_ERROR GetChannelStreamProperties(const PVR_CHANNEL* channel, PVR_NAMED_VALUE* properties, unsigned int* iPropertiesCount)
{
if (!channel || !properties || !iPropertiesCount)
return PVR_ERROR_SERVER_ERROR;
if (*iPropertiesCount < 1)
return PVR_ERROR_INVALID_PARAMETERS;
PVRIptvChannel currChannel;
if (m_data && m_data->GetChannel(*channel, currChannel))
{
SetStreamPropValue(properties, currChannel.strStreamURL);
*iPropertiesCount = 1;
return PVR_ERROR_NO_ERROR;
}
return PVR_ERROR_SERVER_ERROR;
}
PVR_ERROR GetRecordingStreamProperties(const PVR_RECORDING* recording, PVR_NAMED_VALUE* properties, unsigned int* iPropertiesCount)
{
if (!recording || !properties || !iPropertiesCount)
return PVR_ERROR_SERVER_ERROR;
if (*iPropertiesCount < 1)
return PVR_ERROR_INVALID_PARAMETERS;
PVRIptvRecording currRecording;
if (m_data && m_data->GetRecording(*recording, currRecording))
{
SetStreamPropValue(properties, m_data->GetRecordingUrl(currRecording.strRecordId));
*iPropertiesCount = 1;
return PVR_ERROR_NO_ERROR;
}
return PVR_ERROR_SERVER_ERROR;
}
int GetCurrentClientChannel(void)
{
return m_currentChannel.iUniqueId;
}
bool SwitchChannel(const PVR_CHANNEL &channel)
{
CloseLiveStream();
return OpenLiveStream(channel);
}
int GetChannelGroupsAmount(void)
{
if (m_data)
return m_data->GetChannelGroupsAmount();
return -1;
}
PVR_ERROR GetChannelGroups(ADDON_HANDLE handle, bool bRadio)
{
if (m_data)
return m_data->GetChannelGroups(handle, bRadio);
return PVR_ERROR_SERVER_ERROR;
}
PVR_ERROR GetChannelGroupMembers(ADDON_HANDLE handle, const PVR_CHANNEL_GROUP &group)
{
if (m_data)
return m_data->GetChannelGroupMembers(handle, group);
return PVR_ERROR_SERVER_ERROR;
}
PVR_ERROR SignalStatus(PVR_SIGNAL_STATUS &signalStatus)
{
snprintf(signalStatus.strAdapterName, sizeof(signalStatus.strAdapterName), "Sledovanitv.cz");
snprintf(signalStatus.strAdapterStatus, sizeof(signalStatus.strAdapterStatus), "OK");
return PVR_ERROR_NO_ERROR;
}
bool CanPauseStream(void) { return true; }
int GetRecordingsAmount(bool deleted)
{
if (m_data)
return m_data->GetRecordingsAmount();
return 0;
}
PVR_ERROR GetRecordings(ADDON_HANDLE handle, bool deleted)
{
if (m_data)
return m_data->GetRecordings(handle);
return PVR_ERROR_SERVER_ERROR;
}
bool OpenRecordedStream(const PVR_RECORDING &recording)
{
if (m_data)
m_data->SetPlaying(true);
m_bIsPlaying = true;
return true;
}
void CloseRecordedStream(void)
{
if (m_data)
m_data->SetPlaying(false);
m_bIsPlaying = false;
}
/** SEEK */
bool CanSeekStream(void)
{
return false;
}
long long SeekRecordedStream(long long iPosition, int iWhence /* = SEEK_SET */)
{
return 0;
}
long long PositionRecordedStream(void)
{
return -1;
}
long long LengthRecordedStream(void)
{
return 0;
}
/** TIMER FUNCTIONS */
int GetTimersAmount(void)
{
if (m_data)
return m_data->GetTimersAmount();
return -1;
}
PVR_ERROR GetTimers(ADDON_HANDLE handle)
{
if (m_data)
return m_data->GetTimers(handle);
return PVR_ERROR_SERVER_ERROR;
}
PVR_ERROR AddTimer(const PVR_TIMER &timer)
{
if (m_data)
return m_data->AddTimer(timer);
return PVR_ERROR_SERVER_ERROR;
}
PVR_ERROR DeleteTimer(const PVR_TIMER &timer, bool bForceDelete)
{
if (m_data)
return m_data->DeleteRecord(timer.iClientIndex);
return PVR_ERROR_SERVER_ERROR;
}
PVR_ERROR DeleteRecording(const PVR_RECORDING &recording)
{
if (m_data)
return m_data->DeleteRecord(recording.strRecordingId);
return PVR_ERROR_SERVER_ERROR;
}
bool IsTimeshifting(void)
{
return true;
}
const char *GetBackendHostname(void)
{
return "sledovanitv.cz";
}
PVR_ERROR IsEPGTagPlayable(const EPG_TAG *pEpgTag, bool *pbPlayable)
{
if (m_data)
return m_data->CanPlayEvent(pEpgTag, pbPlayable);
return PVR_ERROR_SERVER_ERROR;
}
PVR_ERROR IsEPGTagRecordable(const EPG_TAG *pEpgTag, bool *pbRecortable)
{
if (m_data)
return m_data->CanRecordEvent(pEpgTag, pbRecortable);
return PVR_ERROR_SERVER_ERROR;
}
PVR_ERROR GetEPGTagStreamProperties(const EPG_TAG *pTag, PVR_NAMED_VALUE *properties, unsigned int *iPropertiesCount)
{
string url;
if (m_data)
{
url = m_data->GetEventUrl(pTag->iUniqueChannelId, pTag->startTime, pTag->endTime);
}
if (url.empty())
{
return PVR_ERROR_FAILED;
}
SetStreamPropValue(properties, url);
*iPropertiesCount = 1;
return PVR_ERROR_NO_ERROR;
}
/** UNUSED API FUNCTIONS */
const char * GetLiveStreamURL(const PVR_CHANNEL &channel) { return ""; }
PVR_ERROR DialogChannelScan(void) { return PVR_ERROR_NOT_IMPLEMENTED; }
PVR_ERROR CallMenuHook(const PVR_MENUHOOK &menuhook, const PVR_MENUHOOK_DATA &item) { return PVR_ERROR_NOT_IMPLEMENTED; }
PVR_ERROR DeleteChannel(const PVR_CHANNEL &channel) { return PVR_ERROR_NOT_IMPLEMENTED; }
PVR_ERROR RenameChannel(const PVR_CHANNEL &channel) { return PVR_ERROR_NOT_IMPLEMENTED; }
PVR_ERROR MoveChannel(const PVR_CHANNEL &channel) { return PVR_ERROR_NOT_IMPLEMENTED; }
PVR_ERROR DialogChannelSettings(const PVR_CHANNEL &channel) { return PVR_ERROR_NOT_IMPLEMENTED; }
PVR_ERROR DialogAddChannel(const PVR_CHANNEL &channel) { return PVR_ERROR_NOT_IMPLEMENTED; }
PVR_ERROR GetTimerTypes(PVR_TIMER_TYPE types[], int *size) { return PVR_ERROR_NOT_IMPLEMENTED; }
PVR_ERROR OpenDialogChannelScan(void) { return PVR_ERROR_NOT_IMPLEMENTED; }
PVR_ERROR OpenDialogChannelSettings(const PVR_CHANNEL &channel) { return PVR_ERROR_NOT_IMPLEMENTED; }
PVR_ERROR OpenDialogChannelAdd(const PVR_CHANNEL &channel) { return PVR_ERROR_NOT_IMPLEMENTED; }
PVR_ERROR DeleteAllRecordingsFromTrash() { return PVR_ERROR_NOT_IMPLEMENTED; }
PVR_ERROR UndeleteRecording(const PVR_RECORDING& recording) { return PVR_ERROR_NOT_IMPLEMENTED; }
bool OpenLiveStream(const PVR_CHANNEL &channel) { return false; }
void CloseLiveStream(void) {}
int ReadRecordedStream(unsigned char *pBuffer, unsigned int iBufferSize) { return 0; }
void DemuxReset(void) {}
void DemuxFlush(void) {}
int ReadLiveStream(unsigned char *pBuffer, unsigned int iBufferSize) { return 0; }
long long SeekLiveStream(long long iPosition, int iWhence /* = SEEK_SET */) { return -1; }
long long PositionLiveStream(void) { return -1; }
long long LengthLiveStream(void) { return -1; }
PVR_ERROR RenameRecording(const PVR_RECORDING &recording) { return PVR_ERROR_NOT_IMPLEMENTED; }
PVR_ERROR SetRecordingPlayCount(const PVR_RECORDING &recording, int count) { return PVR_ERROR_NOT_IMPLEMENTED; }
PVR_ERROR SetRecordingLastPlayedPosition(const PVR_RECORDING &recording, int lastplayedposition) { return PVR_ERROR_NOT_IMPLEMENTED; }
int GetRecordingLastPlayedPosition(const PVR_RECORDING &recording) { return -1; }
PVR_ERROR GetRecordingEdl(const PVR_RECORDING&, PVR_EDL_ENTRY[], int*) { return PVR_ERROR_NOT_IMPLEMENTED; }
PVR_ERROR UpdateTimer(const PVR_TIMER &timer) { return PVR_ERROR_NOT_IMPLEMENTED; }
void DemuxAbort(void) {}
DemuxPacket* DemuxRead(void) { return NULL; }
unsigned int GetChannelSwitchDelay(void) { return 0; }
void PauseStream(bool bPaused) {}
bool SeekTime(double,bool,double*) { return false; }
void SetSpeed(int) {}
time_t GetPlayingTime() { return 0; }
time_t GetBufferTimeStart() { return 0; }
time_t GetBufferTimeEnd() { return 0; }
void OnSystemSleep() { }
void OnSystemWake() { }
void OnPowerSavingActivated() { }
void OnPowerSavingDeactivated() { }
PVR_ERROR SetEPGTimeFrame(int) { return PVR_ERROR_NOT_IMPLEMENTED; }
bool IsRealTimeStream() { return true; }
PVR_ERROR GetDescrambleInfo(PVR_DESCRAMBLE_INFO*) { return PVR_ERROR_NOT_IMPLEMENTED; }
PVR_ERROR SetRecordingLifetime(const PVR_RECORDING*) { return PVR_ERROR_NOT_IMPLEMENTED; }
PVR_ERROR GetStreamTimes(PVR_STREAM_TIMES*) { return PVR_ERROR_NOT_IMPLEMENTED; }
PVR_ERROR GetStreamProperties(PVR_STREAM_PROPERTIES*) { return PVR_ERROR_NOT_IMPLEMENTED; }
PVR_ERROR GetEPGTagEdl(const EPG_TAG* epgTag, PVR_EDL_ENTRY edl[], int *size) { return PVR_ERROR_NOT_IMPLEMENTED; }
PVR_ERROR GetStreamReadChunkSize(int* chunksize) { return PVR_ERROR_NOT_IMPLEMENTED; }
}