-
Notifications
You must be signed in to change notification settings - Fork 14
/
emplexer_plugin.php
executable file
·185 lines (146 loc) · 7.13 KB
/
emplexer_plugin.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
<?php
///////////////////////////////////////////////////////////////////////////
require_once 'lib/default_dune_plugin.php';
require_once 'lib/vod/vod_list_screen.php';
require_once 'lib/vod/vod_series_list_screen.php';
require_once 'lib/vod/abstract_vod.php';
require_once 'lib/vod/movie.php';
require_once 'lib/user_input_handler.php';
require_once 'lib/default_archive.php';
require_once 'lib/utils.php';
require_once 'emplexer_vod.php';
require_once 'emplexer_setup_screen.php';
require_once 'emplexer_config.php';
require_once 'emplexer_section_screen.php';
require_once 'emplexer_root_list.php';
require_once 'emplexer_season_list.php';
require_once 'emplexer_video_list.php';
require_once 'emplexer_movie_list.php';
require_once 'emplexer_archive.php';
require_once 'emplexer_fifo_controller.php';
require_once 'emplexer_popup.php';
require_once 'emplexer_movie_description_screen.php';
require_once 'emplexer_base_channel.php';
require_once 'emplexer_list_video.php';
require_once 'emplexer_secondary_section.php';
require_once 'emplexer_music_list.php';
require_once 'lib/vod/vod_movie_screen.php';
//require_once 'emplexer_smb_setup.php';
//require_once 'emplexer_trasnscode_manager.php';
//implements UserInputHandler
class Emplexer extends DefaultDunePlugin {
function __construct() {
if (CREATE_LOG_FOLDER) {
if (file_exists('/D') && is_dir('/D')) {
if (!file_exists('/D/dune_plugin_logs/')) {
mkdir('/D/dune_plugin_logs/');
hd_print('log_dir created');
}
}
}
$this->vod = new EmplexerVod();
$this->add_screen(new EmplexerSetupScreen());
$this->add_screen(new EmplexerSectionScreen());
$this->add_screen(new EmplexerRootList());
$this->add_screen(new EmplexerSeasonList());
$this->add_screen(new EmplexerVideoList());
$this->add_screen(new EmplexerMovieList());
// $this->add_screen(new EmplexerMovieDescriptionScreen());
$this->add_screen(new VodMovieScreen($this->vod));
$this->add_screen(new EmplexerBaseChannel());
$this->add_screen(new EmplexerListVideo());
$this->add_screen(new EmplexerSecondarySection());
$this->add_screen(new EmplexerMusicList());
// $this->add_screen(new EmplexerSMBSetup());
EmplexerFifoController::getInstance(); // inicia o fifo
}
public function get_handler_id() {
return 'plex_root';
}
public function get_vod_info($media_url_str, &$plugin_cookies) {
// hd_print(print_r(debug_backtrace(), true));
HD::print_backtrace();
$media_url = MediaURL::decode($media_url_str);
hd_print(__METHOD__ . ': ' . print_r($media_url, true));
if ($media_url->screen_id == 'emplexer_base_channel') {
$toPlay = $media_url->video_media_array[$plugin_cookies->channel_selected_index];
return EmplexerBaseChannel::get_vod_info($toPlay);
}
if ($media_url->screen_id == 'vod_movie') {
return $this->vod->get_vod_info($media_url, $plugin_cookies);
// EmplexerVod::get_vod_info($media_url, $plugin_cookies);
}
$handler = $media_url->back_screen_id == EmplexerVideoList::ID ? EmplexerVideoList::ID : EmplexerMovieList::ID;
$params = array('key' => $media_url->key, 'back_screen_id' => $media_url->back_screen_id, 'back_key' => $media_url->back_key, 'back_filter_name' => $media_url->back_filter_name);
$stop_action = UserInputHandlerRegistry::create_action($this->get_screen_by_id($handler), 'stop', $params);
$time_action = UserInputHandlerRegistry::create_action($this->get_screen_by_id($handler), 'time', $params);
$series_array = array();
$series_array[] = array(
PluginVodSeriesInfo::name => $media_url->title,
PluginVodSeriesInfo::playback_url => $media_url->video_url,
// PluginVodSeriesInfo::playback_url => $media_url->librarySectionID == '7' ? $this->getTranscodeSessionPlayList($media_url, $plugin_cookies) : $media_url->video_url,
PluginVodSeriesInfo::playback_url_is_stream_url => true,
);
$toBeReturned = array(
PluginVodInfo::id => $media_url->movie_id,
PluginVodInfo::series => $series_array,
PluginVodInfo::name => $media_url->name,
PluginVodInfo::description => $media_url->summary,
PluginVodInfo::poster_url => $media_url->thumb,
PluginVodInfo::initial_series_ndx => 0,
PluginVodInfo::buffering_ms => 3000,
PluginVodInfo::initial_position_ms => EmplexerVideoList::$viewOffset,
PluginVodInfo::advert_mode => false,
PluginVodInfo::timer => array(GuiTimerDef::delay_ms => 5000),
PluginVodInfo::actions => array(
GUI_EVENT_PLAYBACK_STOP => $stop_action,
GUI_EVENT_TIMER => $time_action
)
);
hd_print(print_r($toBeReturned, true));
return $toBeReturned;
}
// private function getTranscodeSessionPlayList(&$media_url, &$plugin_cookies) {
// $plexIp = $plugin_cookies->plexIp;
// $plexPort = $plugin_cookies->plexPort;
//
// $transcodeVideoUrl = "http://$plexIp:$plexPort" . $media_url->detail_info_key;
// $transcodedPlaylist = TranscodeManager::getInstance($plexIp, $plexPort)->startSession(urlencode($transcodeVideoUrl), $media_url->viewOffset);
// file_put_contents('/tmp/www/plugins/emplexer/video.m3u8', $transcodedPlaylist);
//
// hd_print(__METHOD__ . ':' . print_r($transcodedPlaylist, true));
//
// return 'http://127.0.0.1/plugins/emplexer/video.m3u8';
// }
private function get_right_media_url(MediaURL $media_url, $filter_name) {
$episodes = array('newest', 'recentlyAdded', 'recentlyViewed', 'onDeck');
$season = array('all', 'recentlyViewedShows', 'unwatched');
if (in_array($filter_name, $episodes)) {
return EmplexerVideoList::get_media_url_str($media_url->category_id, $filter_name);
} else {
return EmplexerRootList::get_media_url_str($media_url->category_id, $filter_name);
}
}
private function open_popup_for_filter($current_url, $key) {
$key = (string) $media_url->category_id;
$doc = HD::http_get_document($current_url . '/' . $key);
$pop_up_items = array();
$xml = simplexml_load_string($doc);
foreach ($xml->Directory as $c) {
$key = (string) $c->attributes()->key;
$prompt = (string) $c->attributes()->prompt;
if ($key != 'all' && $key != 'folder' && !$prompt) {
$pop_up_items[] = array(
GuiMenuItemDef::caption => (string) $c->attributes()->title,
GuiMenuItemDef::action => ActionFactory::open_folder($this->get_right_media_url($media_url, $key), $key)
);
}
}
$action = ActionFactory::show_popup_menu($pop_up_items);
}
private function is_filfer($filter_name) {
$filter = array('firstCharacter', 'genre', 'year', 'contentRating', 'folder');
return in_array($filter_name, $filter);
}
}
?>