-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_plugin.php
executable file
·167 lines (147 loc) · 6.07 KB
/
main_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
<?php
require_once 'lib/default_dune_plugin.php';
require_once 'lib/utils.php';
require "main_menu.php";
require "games_menu.php";
require "favorite_menu.php";
require "games_search_menu.php";
require "games_quality_menu.php";
require "channels_menu.php";
require "game_play.php";
class TwitchPlugin extends DefaultDunePlugin implements UserInputHandler
{
public function __construct() {}
public $game_name, $stream_name, $img, $status_stream, $stream_chat = "", $install_dir;
public function get_folder_view($media_url, &$plugin_cookies)
{
if (strpos($media_url, "search_games:") === 0) {
$menu = new GameSearchMenu(substr($media_url, 13));
} else if (strpos($media_url, "streams:") === 0) {
$this->stream_name = substr($media_url, 8);
$menu = new GameQuality(substr($media_url, 8));
$jdimg = new Tw_Search_quality($this->stream_name);
$this->img = $jdimg->getIMG();
$this->status_stream = $jdimg->getStatus();
$this->game_name = $jdimg->getGameName();
$this->install_dir = DuneSystem::$properties["install_dir_path"];
shell_exec($this->install_dir . "/bin/irc.sh start " . $this->stream_name);
} else if ($media_url == "games") {
$menu = new GamesMenu();
} else if ($media_url == "channels") {
$menu = new ChannelsMenu();
} else if ($media_url == "favorite") {
$menu = new FavoriteMenu($plugin_cookies->auth_token);
} else if ($media_url == "setup") {
return $this->get_setup_folder_view($media_url, $plugin_cookies);
} else {
$menu = new MainMenu();
}
return $menu->generate_menu();
}
public function get_handler_id()
{
return 'twitch_handler';
}
public function get_next_folder_view($media_url, &$plugin_cookies) {}
public function get_tv_info($media_url, &$plugin_cookies) {}
public function get_tv_stream_url($media_url, &$plugin_cookies) {}
//Play selected stream with selected quality
public function get_vod_info($media_url, &$plugin_cookies)
{
$q = array(
GUI_EVENT_KEY_CLEAR => UserInputHandlerRegistry::create_action($this, 'chat'),
GUI_EVENT_PLAYBACK_GOING_TO_SWITCH => UserInputHandlerRegistry::create_action($this, 'stop_irc'),
GUI_EVENT_PLAYBACK_STOP => UserInputHandlerRegistry::create_action($this, 'stop_irc')
);
if (strpos($media_url, "stream_name:") === 0) {
$stream = new GamePlay(substr($media_url, 12), $this->stream_name, $this->img, $this->status_stream, $this->game_name);
return $stream->generatePlayInfo($q);
}
}
public function get_vod_stream_url($media_url, &$plugin_cookies) {}
public function get_regular_folder_items($media_url, $from_ndx, &$plugin_cookies) {}
public function get_day_epg($channel_id, $day_start_tm_sec, &$plugin_cookies) {}
public function get_tv_playback_url($channel_id, $archive_tm_sec, $protect_code, &$plugin_cookies) {}
public function change_tv_favorites($op_type, $channel_id, &$plugin_cookies) {}
public function handle_user_input(&$user_input, &$plugin_cookies)
{
hd_print('Setup: handle_user_input:');
foreach ($user_input as $key => $value) hd_print(" $key => $value");
if ($user_input->action_type === 'apply') {
$control_id = $user_input->control_id;
$auth_value = $user_input->auth_token;
$name_value = $user_input->username;
if ($control_id === 'btnSave') {
$plugin_cookies->auth_token = $auth_value;
$plugin_cookies->username = $name_value;
}
}
if ($user_input->control_id == "chat") {
$this->stream_chat = file_get_contents("/tmp/tw_irc.log", true);
ControlFactory::add_multiline_label($defs, '', $this->stream_chat, 15);
$attrs['dialog_params'] = array('frame_style' => DIALOG_FRAME_STYLE_GLASS);
$attrs['actions'] = array(GUI_EVENT_TIMER => ActionFactory::close_dialog_and_run(UserInputHandlerRegistry::create_action($this, 'chat')));
$attrs['timer'] = array(GuiTimerDef::delay_ms => 2000);
return ActionFactory::show_dialog("#" . $this->stream_name, $defs, true, 1500, $attrs);
}
if ($user_input->control_id == "stop_irc") {
shell_exec($this->install_dir . "/bin/irc.sh stop");
}
return null;
}
private function get_setup_folder_view($media_url, &$plugin_cookies)
{
$defs = array();
if (isset($plugin_cookies->auth_token) and isset($plugin_cookies->username)) {
$auth_token = $plugin_cookies->auth_token;
$username = $plugin_cookies->username;
} else {
$auth_token = '';
$username = '';
}
ControlFactory::add_text_field(
$defs,
$this,
null,
'auth_token',
'Token from: http://tw.fex.cc/ ',
$auth_token,
0,
0,
0,
true,
500
);
ControlFactory::add_text_field(
$defs,
$this,
null,
'username',
'Login from: twitch.tv ',
$username,
0,
0,
0,
true,
500
);
ControlFactory::add_button(
$defs,
$handler = $this,
$add_params = array(),
$name = 'btnSave',
$title = null,
$caption = 'Save',
$width = 400
);
return array(
PluginFolderView::multiple_views_supported => false,
PluginFolderView::archive => null,
PluginFolderView::view_kind => PLUGIN_FOLDER_VIEW_CONTROLS,
PluginFolderView::data => array(
PluginControlsFolderView::defs => $defs,
PluginControlsFolderView::initial_sel_ndx => -1,
)
);
}
}