-
Notifications
You must be signed in to change notification settings - Fork 1
/
RealDebrid.php
401 lines (331 loc) · 12.9 KB
/
RealDebrid.php
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
<?php
class X_VlcShares_Plugins_RealDebrid extends X_VlcShares_Plugins_Abstract {
const VERSION_CLEAN = '0.1.5';
const VERSION = '0.1.5';
private $hosters = array(
// replace-id => with class
'megavideo' => 'X_VlcShares_Plugins_Helper_Hoster_RealDebridMegavideo',
'megaupload' => 'X_VlcShares_Plugins_Helper_Hoster_RealDebridMegaupload',
'videobb' => 'X_VlcShares_Plugins_Helper_Hoster_RealDebridVideoBB',
'4shared' => 'X_VlcShares_Plugins_Helper_Hoster_RealDebrid4Shared',
'megaporn' => 'X_VlcShares_Plugins_Helper_Hoster_RealDebridMegaporn',
'rapidshare' => 'X_VlcShares_Plugins_Helper_Hoster_RealDebridRapidShare',
'videozer' => 'X_VlcShares_Plugins_Helper_Hoster_RealDebridVideozer',
'hulu' => 'X_VlcShares_Plugins_Helper_Hoster_RealDebridHulu',
'2shared' => 'X_VlcShares_Plugins_Helper_Hoster_RealDebrid2Shared',
'cwtv' => 'X_VlcShares_Plugins_Helper_Hoster_RealDebridCwtv',
'cbs' => 'X_VlcShares_Plugins_Helper_Hoster_RealDebridCbs',
'videoweed' => 'X_VlcShares_Plugins_Helper_Hoster_RealDebridVideoweed',
// generics
'novamov' => array(
'/https?:\/\/(www\.)?nova(mov|up)\.com\/(video|download)\/(?P<ID>[A-Za-z0-9]+)/i',
'http://www.novamov.com/video/%s'
),
'bitshare' => array(
'/https?:\/\/(www\.)?bitshare\.com\/files\/(?P<ID>.+)/i',
'http://www.bitshare.com/files/%s'
),
'filefactory' => array(
'/https?:\/\/(www\.)?filefactory\.com\/file\/(?P<ID>.+)/i',
'http://www.filefactory.com/file/%s'
),
'hotfile' => array(
'/https?:\/\/(www\.)?hotfile\.com\/dl\/(?P<ID>.+)/i',
'https?://www.hotfile.com/dl/%s'
),
'justintv' => array(
'/https?:\/\/(www\.|([a-z]+)\.)?justin\.tv\/(?P<ID>.+)/i',
'http://www.justin.tv/dl/%s'
),
'loadto' => array(
'/https?:\/\/(www\.)?load\.to\/(?P<ID>.+)/i',
'http://www.load.to/%s'
),
'mediafire' => array(
'/https?:\/\/(www\.)?mediafire\.com\/\?(?P<ID>.+)/i',
'http://www.mediafire.com/?%s'
),
'megashares' => array(
'/https?:\/\/(www\.|([a-z]+)\.)?megashares\.com\/(index\.php)?\?(?P<ID>.+)/i',
'http://www.megashares.com/?%s'
),
'netloadin' => array(
'/https?:\/\/(www\.)?netload\.in\/(?P<ID>.+)/i',
'http://www.netload.in/%s'
),
'putlocker' => array(
'/https?:\/\/(www\.)?putlocker\.com\/file\/(?P<ID>.+)/i',
'http://www.putlocker.com/file/%s'
),
'uploadedto' => array(
'/https?:\/\/(www\.)?u((ploaded)|l)?\.to\/(file\/)?(?P<ID>.+)/i',
'http://uploaded.to/file/%s'
),
'wupload' => array(
'/https?:\/\/(www\.)?wupload\.com\/file\/(?P<ID>.+)/i',
'http://www.wupload.com/file/%s'
),
'wattv' => array(
'/https?:\/\/(www\.)?wat\.tv\/video\/(?P<ID>.+)/i',
'http://www.wat.tv/video/%s'
),
'abc' => array(
'/https?:\/\/abc\.go\.com\/watch\/(?P<ID>.+)/i',
'http://abc.go.com/watch/%s'
),
'abc' => array(
'/https?:\/\/abc\.go\.com\/watch\/(?P<ID>.+)/i',
'http://abc.go.com/watch/%s'
),
'sockshare' => array(
'/https\:\/\/((www\.)?)sockshare\.com\/(file|embed)\/(?P<ID>[A-Za-z0-9]+)/i',
'http://www.sockshare.com/file/%s'
),
);
public function __construct() {
$this
// gen_beforeInit must be loaded with low priority, other hosters must be setted first
->setPriority('gen_beforeInit', 99)
->setPriority('getIndexManageLinks')
->setPriority('getModeItems')
->setPriority('preGetSelectionItems')
->setPriority('getSelectionItems')
->setPriority('prepareConfigElement');
}
public function gen_beforeInit(Zend_Controller_Action $controller) {
// translation
$this->helpers()->language()->addTranslation(__CLASS__);
$this->helpers()->registerHelper('realdebrid', new X_VlcShares_Plugins_Helper_RealDebrid(array(
'username' => $this->config('auth.username', ''),
'password' => $this->config('auth.password', ''),
'cache' => $this->config('cache.validity', 24 * 60),
)));
foreach ( $this->hosters as $hId => $hClass ) {
// only if hosters is enabled
if ( $this->config("hosters.$hId.enabled", true) ) {
$pHoster = null;
try {
$pHoster = $this->helpers()->hoster()->getHoster($hId);
$this->helpers()->hoster()->unregisterHoster($hId);
} catch (Exception $e) {
// no problem, wasn't registered
}
$hObj = null;
if ( is_array($hClass) ) {
$hObj = new X_VlcShares_Plugins_Helper_Hoster_RealDebridGeneric("$hId-realdebrid", $hClass[0], $hClass[1] );
} else {
$hObj = new $hClass();
}
// allow to use a standard hoster (if available) for fetch informations
// because it should work better than realdebrid hoster
if ( method_exists($hObj, 'setParentHoster') ) {
$hObj->setParentHoster($pHoster);
}
// register the new one:
// - repleace the old hoster id if there is one (so old links work with new hoster)
// - otherwise register it as a new one (with the right icon), so new links are locked to this hoster
$this->helpers()->hoster()->registerHoster($hObj, ($pHoster === null ? null : $hId ) );
}
}
}
/**
* Allow to choose the stream type (if more than one is available)
*
* @param string $provider
* @param string $location
* @param Zend_Controller_Action $controller
* @return X_Page_ItemList_PItem
*/
public function getModeItems($provider, $location, Zend_Controller_Action $controller) {
// if provider is FileSystem, This isn't needed for sure
if ( X_VlcShares_Plugins::broker()->getPluginClass($provider) == 'X_VlcShares_Plugins_FileSystem' ) {
return;
}
try {
/* @var $realdebridHelper X_VlcShares_Plugins_Helper_RealDebrid */
$realdebridHelper = $this->helpers('realdebrid');
// check if a valid location has been setted
if ( !$realdebridHelper->isValid() ) {
X_Debug::i("Location is not provided by RealDebrid");
return;
}
$lists = new X_Page_ItemList_PItem();
X_Debug::i('Plugin triggered. Location could be provided by RealDebrid');
$urlHelper = $controller->getHelper('url');
$links = $realdebridHelper->getUrls();
if ( count($links) <= 1 ) {
X_Debug::i('Links count is <= 1, no choose needed');
} else {
$selectedIndex = $controller->getRequest()->getParam('realdebrid', 0);
if ( count($links) < $selectedIndex ) {
$selectedIndex = 0;
}
$linkPart = explode('/', $links[$selectedIndex]);
$selectedLink = urldecode(array_pop($linkPart));
$link = new X_Page_Item_PItem($this->getId(), X_Env::_('p_realdebrid_selected', $selectedLink, $links[$selectedIndex]));
$link->setIcon('/images/realdebrid/logo.png')
->setType(X_Page_Item_PItem::TYPE_ELEMENT)
->setLink(array(
'action' => 'selection',
'pid' => $this->getId()
), 'default', false);
$lists->append($link);
}
$link = new X_Page_Item_PItem($this->getId(), X_Env::_('p_realdebrid_regenerate'));
$link->setIcon('/images/realdebrid/logo.png')
->setType(X_Page_Item_PItem::TYPE_ELEMENT)
->setLink(array(
'action' => 'selection',
'pid' => "{$this->getId()}",
"{$this->getId()}:refresh" => 1
), 'default', false);
$lists->append($link);
return $lists;
} catch (Exception $e) {
X_Debug::i("Location is not provided by RealDebrid");
}
}
/**
* Set the header of stream type selection
* @param string $provider
* @param string $location
* @param string $pid
* @param Zend_Controller_Action $controller
* @return X_Page_ItemList_PItem
*/
public function preGetSelectionItems($provider, $location, $pid, Zend_Controller_Action $controller) {
// we want to expose items only if pid is this plugin
if ( $this->getId() != $pid ) return;
X_Debug::i('Plugin triggered');
$urlHelper = $controller->getHelper('url');
$link = new X_Page_Item_PItem($this->getId().'-header', X_Env::_('p_realdebrid_streamselection_title'));
$link->setType(X_Page_Item_PItem::TYPE_ELEMENT)
->setLink(X_Env::completeUrl($urlHelper->url()));
return new X_Page_ItemList_PItem(array($link));
}
/**
* Show the list of valid streams
* @param string $provider
* @param string $location
* @param string $pid
* @param Zend_Controller_Action $controller
* @return X_Page_ItemList_PItem
*/
public function getSelectionItems($provider, $location, $pid, Zend_Controller_Action $controller) {
// we want to expose items only if pid is this plugin
if ( $this->getId() != $pid ) return;
X_Debug::i('Plugin triggered');
$urlHelper = $controller->getHelper('url');
// i try to mark current selected sub based on $this->getId() param
// in $currentSub i get the name of the current profile
$currentStream = $controller->getRequest()->getParam($this->getId(), false);
$return = new X_Page_ItemList_PItem();
try {
/* @var $realdebridHelper X_VlcShares_Plugins_Helper_RealDebrid */
$realdebridHelper = $this->helpers('realdebrid');
// check if a valid location has been setted
if ( !$realdebridHelper->isValid() ) {
X_Debug::i("Try to force location retrieval");
$providerObj = X_VlcShares_Plugins::broker()->getPlugins($provider);
if ( $providerObj instanceof X_VlcShares_Plugins_ResolverInterface ) {
$providerObj->resolveLocation($location);
} elseif (method_exists($providerObj, 'resolveLocation') ) {
// try to check if resolveLocation is there, even if not the interface
$providerObj->resolveLocation($location);
} else {
X_Debug::e("Provider can't be called for location resolving");
return;
}
}
$links = $realdebridHelper->getUrls();
X_Debug::i('Plugin triggered. Location could be provided by RealDebrid');
// if $pid == ID:refresh, only force refresh the link
if ( $controller->getRequest()->getParam("{$this->getId()}:refresh", false) != false ) {
$realdebridHelper->cleanCurrentCacheEntry();
$item = new X_Page_Item_PItem($this->getId(), X_Env::_('p_realdebrid_refreshdone'));
$item->setType(X_Page_Item_PItem::TYPE_ELEMENT)
->setLink(array(
'action' => 'mode',
"{$this->getId()}:refresh" => null,
'pid' => null
), 'default', false);
$return->append($item);
} else {
foreach ($links as $i => $streamlink) {
$linkPart = explode('/', $streamlink);
$label = urldecode(array_pop($linkPart));
$item = new X_Page_Item_PItem($this->getId()."-$i", X_Env::_('p_realdebrid_streamoption', $label, $streamlink));
$item->setType(X_Page_Item_PItem::TYPE_ELEMENT)
->setLink(array(
'action' => 'mode',
$this->getId() => $i == 0 ? null : $i, // unset this plugin selection
'pid' => null
), 'default', false)
->setHighlight(($currentStream == $i));
$return->append($item);
}
}
} catch ( Exception $e) {
X_Debug::f("Location is not provided by RealDebrid, but i'm inside the stream type selection O_o");
}
return $return;
}
/**
* Add the link for -manage-megavideo-
* @param Zend_Controller_Action $this
* @return X_Page_ItemList_ManageLink
*/
public function getIndexManageLinks(Zend_Controller_Action $controller) {
$link = new X_Page_Item_ManageLink($this->getId(), X_Env::_('p_realdebrid_mlink'));
$link->setTitle(X_Env::_('p_realdebrid_managetitle'))
->setIcon('/images/realdebrid/logo.png')
->setLink(array(
'controller' => 'config',
'action' => 'index',
'key' => 'realdebrid'
), 'default', true);
return new X_Page_ItemList_ManageLink(array($link));
}
/**
* Remove cookie.jar if configs change and convert form password to password element
* @param string $section
* @param string $namespace
* @param unknown_type $key
* @param Zend_Form_Element $element
* @param Zend_Form $form
* @param Zend_Controller_Action $controller
*/
public function prepareConfigElement($section, $namespace, $key, Zend_Form_Element $element, Zend_Form $form, Zend_Controller_Action $controller) {
// nothing to do if this isn't the right section
if ( $namespace != $this->getId() ) return;
switch ($key) {
// i have to convert it to a password element
case 'plugins_realdebrid_auth_password':
$password = $form->createElement('password', 'plugins_realdebrid_auth_password', array(
'label' => $element->getLabel(),
'description' => $element->getDescription(),
'renderPassword' => true,
));
$form->plugins_realdebrid_auth_password = $password;
break;
}
// remove cookie.jar if somethings has value
if ( !$form->isErrors() && !is_null($element->getValue()) && $key = 'plugins_realdebrid_auth_password' ) {
// clean cookies
try {
X_Debug::i("Cleaning up cookies in cache");
/* @var $cacheHelper X_VlcShares_Plugins_Helper_Cache */
$cacheHelper = X_VlcShares_Plugins::helpers()->helper('cache');
try {
$cacheHelper->retrieveItem("realdebrid::cookies");
// set expire date to now!
$cacheHelper->storeItem("realdebrid::cookies", '', 0);
} catch (Exception $e) {
// nothing to do
}
} catch (Exception $e) {
X_Debug::w("Cache plugin disabled? O_o");
}
}
}
}