-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathemplexer_fifo_controller.php
executable file
·126 lines (106 loc) · 4.28 KB
/
emplexer_fifo_controller.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
<?php
class EmplexerFifoController
{
private $fileDescriptor;
private static $instance;
public static function getInstance(){
hd_print(__METHOD__);
if (!isset(self::$instance)){
hd_print(self::$instance);
self::$instance = new EmplexerFifoController();
}
return self::$instance;
}
private function __construct()
{
hd_print(__METHOD__);
$plugin_dir = dirname(__FILE__);
if (!$this->isRuning()){
hd_print("$plugin_dir/bin/emplexer_fifo_controller.sh '$plugin_dir/bin/' >> /D/dune_plugin_logs/fifo.txt 2>/dev/null &");
exec("/bin/sh $plugin_dir/bin/emplexer_fifo_controller.sh '$plugin_dir/bin/' >> /D/dune_plugin_logs/fifo.txt 2>/dev/null &");
}
// hd_print(__METHOD__ . ': iniciado fifo' );
}
public function __destruct()
{
hd_print(__METHOD__);
HD::print_backtrace();
$this->open();
fwrite($this->fileDescriptor, "quit\n");
fclose($this->fileDescriptor);
// hd_print(__METHOD__ . ': já fechei fileDescriptor veja ' .$this->fileDescriptor);
}
public function isRuning(){
hd_print(__METHOD__);
// $pid = shell_exec("pidof emplexer_fifo_controller.sh");
// $ret = isset($pid);
// hd_print(__METHOD__ . ": resultado pid= $pid ret=$ret");
return file_exists("/tmp/emplexer.fifo");
}
private function open(){
hd_print(__METHOD__);
if (is_null($this->fileDescriptor)){
$this->fileDescriptor = fopen('/tmp/emplexer.fifo', 'r+');
stream_set_blocking($this->fileDescriptor, true);
// hd_print(__METHOD__ . 'fileDescriptor : ' . $this->fileDescriptor );
}
}
public function downloadToCache($fileName, $fileUrl){
if (EmplexerConfig::getInstance()->hasPersistFs){
hd_print(__METHOD__);
// fwrite($this->fileDescriptor, "c|$fileName|$fileUrl");
$file_path = "/persistfs/plugins_archive/emplexer/emplexer_default_archive/$fileName";
// $file_path = "/D/emplexer/emplexer_default_archive/$fileName";
if (!file_exists($file_path)){
//$this->open();
// exec("echo 'c|$fileName|$fileUrl' > /tmp/emplexer.fifo");
//fwrite($this->fileDescriptor, "c|$fileName|$fileUrl\n");
//hd_print(__METHOD__ . " Escrevi com c|$fileName|$fileUrl" );
$opts = array(
CURLOPT_BINARYTRANSFER => true,
CURLOPT_HEADER =>false,
);
$doc = HD::http_get_document($fileUrl, $opts);
$file = fopen($file_path, 'x');
fwrite($file, $doc);
fclose($file);
unset($doc);
$doc= null;
}
}
}
public function startPlexNotify($id, $pooling, $url, $timeToMark=DEFAULT_TIME_TO_MARK){
hd_print(__METHOD__);
// s|id do arquivo no plex|tempo do pooling|url base do plex (http://192.168.2.9:32400/)"
$this->open();
fwrite($this->fileDescriptor, "s|$id|$pooling|$url|$timeToMark\n");
// exec("echo 's|$id|$pooling|$url' > /tmp/emplexer.fifo");
// hd_print(__METHOD__ . " Escrevi com s|$id|$pooling|$url" );
}
public function killPlexNotify(){
hd_print(__METHOD__);
$this->open();
// exec("echo 'kill' > /tmp/emplexer.fifo");
fwrite($this->fileDescriptor, "kill\n");
// hd_print(__METHOD__ . " Escrevi com kill" );
}
public function startDefaultPlayBack($url, $startPosition, $plexFileId, $timeToMark=DEFAULT_TIME_TO_MARK, $basePlexURL, $pooling=5)
{
hd_print(__METHOD__);
$command = "p|". urlencode($url) . "|$startPosition|$plexFileId|$pooling|$basePlexURL|$timeToMark\n";
$this->open();
hd_print("iniciando startDefaultPlayBack com paramentros $command");
//exec("/usr/bin/wget \"http://192.168.2.7/cgi-bin/do?cmd=start_file_playback&media_url=nfs%3A%2F%2F192.168.2.9%3A%2Fvolume1%2FAnimes%2FFairy+Tail%2Fs01%2FPUNCH_Fairy_Tail_-_10_HD.mkv\"");
// HD::http_get_document("http://192.168.2.7/cgi-bin/do?cmd=start_file_playback&media_url=nfs%3A%2F%2F192.168.2.9%3A%2Fvolume1%2FAnimes%2FFairy+Tail%2Fs01%2FPUNCH_Fairy_Tail_-_10_HD.mkv");
fwrite($this->fileDescriptor, $command);
}
public function startSetPlayBackPosition($position, &$plugin_cookies, $id, $mark_time=40, $pooling_time=5, $delay=3){
$plugin_dir = dirname(__FILE__);
// plex_notify.sh 32301 5 http://192.168.2.9:32400/ 40
$base_url = 'http://'. $plugin_cookies->plexIp . ':' . $plugin_cookies->plexPort . '/';
$command ="/bin/sh $plugin_dir/bin/setPlayBackPosition.sh $delay $position $plugin_dir $base_url $id $pooling_time $mark_time >> 1 2>/dev/null &";
hd_print("executando comando = $command");
exec($command);
}
}
?>