Skip to content

Commit 35defc9

Browse files
committed
added logic to ignore virtual items
1 parent fd81c8f commit 35defc9

File tree

3 files changed

+261
-20
lines changed

3 files changed

+261
-20
lines changed
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Webhooks</title>
5+
</head>
6+
<body>
7+
<div data-role="page" class="page type-interior pluginConfigurationPage smtpConfigurationPage" data-require="emby-select,emby-checkbox,emby-input,emby-button">
8+
9+
10+
<div id="itemTemplate" class="paperList" style="display:none;">
11+
<div class="listItem">
12+
<div class="listItemBody two-line">
13+
<div>
14+
<div class="inputContainer">
15+
<input is="emby-input" type="text" class="txtUrl"/>
16+
<div class="fieldDescription">
17+
Url
18+
</div>
19+
</div>
20+
</div>
21+
<div>
22+
<h3>Events</h3>
23+
<label class="checkboxContainer" style="float:left; width:auto; padding-right:10px">
24+
<input is="emby-checkbox" type="checkbox" class="chkOnPlay" />
25+
<span>Play</span>
26+
</label>
27+
<label class="checkboxContainer" style="float:left; width:auto; padding-right:10px">
28+
<input is="emby-checkbox" type="checkbox" class="chkOnPause" />
29+
<span>Pause</span>
30+
</label>
31+
<label class="checkboxContainer" style="float:left; width:auto; padding-right:10px">
32+
<input is="emby-checkbox" type="checkbox" class="chkOnStop" />
33+
<span>Stop</span>
34+
</label>
35+
<label class="checkboxContainer" style="float:left; width:auto; padding-right:10px">
36+
<input is="emby-checkbox" type="checkbox" class="chkOnResume" />
37+
<span>Resume</span>
38+
</label>
39+
<label class="checkboxContainer" style="float:left; width:auto; padding-right:10px">
40+
<input is="emby-checkbox" type="checkbox" class="chkOnItemAdded" />
41+
<span>Item Added</span>
42+
</label>
43+
44+
45+
</div>
46+
<div>
47+
<h3>Media Types</h3>
48+
<label class="checkboxContainer" style="float:left; width:auto; padding-right:10px">
49+
<input is="emby-checkbox" type="checkbox" class="chkMovies" />
50+
<span>Movies</span>
51+
</label>
52+
<label class="checkboxContainer" style="float:left; width:auto; padding-right:10px">
53+
<input is="emby-checkbox" type="checkbox" class="chkEpisodes" />
54+
<span>TV Shows</span>
55+
</label>
56+
<label class="checkboxContainer" style="float:left; width:auto; padding-right:10px">
57+
<input is="emby-checkbox" type="checkbox" class="chkSongs" />
58+
<span>Music</span>
59+
</label>
60+
</div>
61+
62+
63+
64+
65+
</div>
66+
<button title="Delete" class="btnDeleteDevice paper-icon-button-light removeHook" type="button" is="paper-icon-button-light"><i class="md-icon">delete</i></button>
67+
68+
</div>
69+
</div>
70+
71+
<div data-role="content">
72+
<div class="content-primary">
73+
74+
<form class="smtpConfigurationForm">
75+
76+
<h1 style="display:inline-block;vertical-align:middle;">Webhooks</h1>
77+
<button title="Add" class="raised btnAddDevice submit mini emby-button" id="testNotification"
78+
style="margin-left:1em;" type="button" is="emby-button">
79+
<i class="md-icon">add</i>
80+
<span>Add</span>
81+
</button>
82+
<div id="Hooks">
83+
84+
85+
</div>
86+
87+
88+
<br/>
89+
<div>
90+
<button is="emby-button" type="submit" class="raised button-submit block"><span>Save</span></button>
91+
</div>
92+
93+
</form>
94+
</div>
95+
</div>
96+
97+
<script type="text/javascript">
98+
99+
(function () {
100+
101+
var pluginId = "C55C17A0-0E7E-495B-9A1D-48BAE4D55FB3";
102+
103+
function loadUserConfig(page, userId) {
104+
105+
Dashboard.showLoadingMsg();
106+
107+
ApiClient.getPluginConfiguration(pluginId).then(function (config) {
108+
109+
Dashboard.hideLoadingMsg();
110+
});
111+
}
112+
113+
114+
115+
$('.smtpConfigurationPage').on('pageinit', function (event) {
116+
117+
var page = this;
118+
$(page).on("click", ".removeHook", function removeHook() {
119+
$(this).parent().parent().remove();
120+
});
121+
122+
$('#testNotification', page).on('click', function (event) {
123+
124+
Dashboard.showLoadingMsg();
125+
var a = $('#itemTemplate').clone();
126+
127+
$('#Hooks', page).append(
128+
a
129+
);
130+
$(a).show();
131+
132+
Dashboard.hideLoadingMsg();
133+
134+
135+
});
136+
137+
$('.smtpConfigurationForm', page).on('submit', function (e) {
138+
139+
Dashboard.showLoadingMsg();
140+
var form = this;
141+
142+
var config = { Hooks: [] };
143+
$('#Hooks .listItem', form).each(function (i) {
144+
var a = $(this).find('.txtUrl').first().val();
145+
146+
147+
config.Hooks.push(
148+
{
149+
URL: a,
150+
onPlay: $(this).find('.chkOnPlay').first().checked(),
151+
onPause: $(this).find('.chkOnPause').first().checked(),
152+
onStop: $(this).find('.chkOnStop').first().checked(),
153+
onResume: $(this).find('.chkOnResume').first().checked(),
154+
155+
withMovies: $(this).find('.chkMovies').first().checked(),
156+
withEpisodes: $(this).find('.chkEpisodes').first().checked(),
157+
withSongs: $(this).find('.chkSongs').first().checked(),
158+
onItemAdded: $(this).find('.chkOnItemAdded').first().checked()
159+
160+
}
161+
);
162+
});
163+
164+
console.log(config);
165+
166+
ApiClient.updatePluginConfiguration(pluginId, config).then(
167+
Dashboard.processPluginConfigurationUpdateResult);
168+
return false;
169+
});
170+
171+
172+
173+
}).on('pageshow', function (event) {
174+
175+
Dashboard.showLoadingMsg();
176+
177+
var page = this;
178+
179+
ApiClient.getPluginConfiguration(pluginId).then(function (config) {
180+
for (var i in config.Hooks) {
181+
var a = $('#itemTemplate').clone();
182+
183+
$(a).show();
184+
$('#Hooks', page).append(
185+
a
186+
//'<div class="listItem"><div class="listItemBody">'+
187+
//'<input is="emby-input" type="text" class="txtUrl" label="URL:" value="' + config.Hooks[i].URL +'" /></div>' +
188+
//'<button title="Delete" class="btnDeleteDevice paper-icon-button-light removeHook" type="button" is="paper-icon-button-light"><i class="md-icon">delete</i></button>' +
189+
//'</div>'
190+
);
191+
$(a).find('.txtUrl').first().val(config.Hooks[i].URL || '');
192+
193+
$(a).find('.chkOnPlay').first().checked(config.Hooks[i].onPlay || false);
194+
$(a).find('.chkOnPause').first().checked(config.Hooks[i].onPause || false);
195+
$(a).find('.chkOnStop').first().checked(config.Hooks[i].onStop || false);
196+
$(a).find('.chkOnResume').first().checked(config.Hooks[i].onResume || false);
197+
198+
$(a).find('.chkMovies').first().checked(config.Hooks[i].withMovies || false);
199+
$(a).find('.chkEpisodes').first().checked(config.Hooks[i].withEpisodes || false);
200+
$(a).find('.chkSongs').first().checked(config.Hooks[i].withSongs || false);
201+
$(a).find('.chkOnItemAdded').first().checked(config.Hooks[i].onItemAdded || false);
202+
203+
204+
205+
}
206+
});
207+
208+
Dashboard.hideLoadingMsg();
209+
});
210+
211+
})();
212+
213+
</script>
214+
</div>
215+
</body>
216+
</html>

Emby.Webhooks/Emby.Webhooks.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
<ItemGroup>
6161
<EmbeddedResource Include="Configuration\config.html" />
6262
</ItemGroup>
63+
<ItemGroup>
64+
<EmbeddedResource Include="Configuration\config_1.html" />
65+
</ItemGroup>
6366
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
6467
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
6568
Other similar extension points exist, see Microsoft.Common.targets.

Emby.Webhooks/Webhooks.cs

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,23 @@ public void Run()
8484
}
8585

8686
private void ItemAdded(object sender, ItemChangeEventArgs e) {
87-
var iType = _libraryManager.GetContentType(e.Item);
87+
_logger.Debug("Item added event");
88+
_logger.Debug(_jsonSerializer.SerializeToString(e));
89+
90+
var cType = _libraryManager.GetContentType(e.Item);
8891

89-
var hooks = hooksByType(iType).Where(i => i.onItemAdded);
92+
//Only concerned with video and audio files
93+
if (
94+
e.Item.IsVirtualItem == false &&
95+
(e.Item.MediaType == "Video" || e.Item.MediaType == "Audio")
96+
) {
97+
var hooks = hooksByType(cType).Where(h => h.onItemAdded);
9098

91-
if (hooks.Count() > 0)
92-
{
93-
var jsonString = buildJson(e.Item, "media.added");
94-
SendHooks(hooks, jsonString);
99+
if (hooks.Count() > 0)
100+
{
101+
var jsonString = buildJson(e.Item, "media.added");
102+
SendHooks(hooks, jsonString);
103+
}
95104
}
96105
}
97106
private void PlaybackProgress(object sender, PlaybackProgressEventArgs e)
@@ -100,6 +109,9 @@ private void PlaybackProgress(object sender, PlaybackProgressEventArgs e)
100109

101110
if (e.IsPaused & getPauseControl(e.DeviceId).wasPaused == false)
102111
{
112+
_logger.Debug("Playback Paused event");
113+
_logger.Debug(_jsonSerializer.SerializeToString(e));
114+
103115
//Paused Event
104116
getPauseControl(e.DeviceId).wasPaused = true;
105117

@@ -111,6 +123,10 @@ private void PlaybackProgress(object sender, PlaybackProgressEventArgs e)
111123
}
112124
else if (e.IsPaused == false & getPauseControl(e.DeviceId).wasPaused)
113125
{
126+
_logger.Debug("Playback Resume event");
127+
_logger.Debug(_jsonSerializer.SerializeToString(e));
128+
129+
114130
getPauseControl(e.DeviceId).wasPaused = false;
115131

116132
var hooks = hooksByType(iType).Where(i => i.onResume);
@@ -122,6 +138,9 @@ private void PlaybackProgress(object sender, PlaybackProgressEventArgs e)
122138
}
123139
private void PlaybackStart(object sender, PlaybackProgressEventArgs e)
124140
{
141+
_logger.Debug("Playback Start event");
142+
_logger.Debug(_jsonSerializer.SerializeToString(e));
143+
125144
getPauseControl(e.DeviceId).wasPaused = false;
126145

127146
var iType = _libraryManager.GetContentType(e.Item);
@@ -210,21 +229,24 @@ public string buildJson(BaseItem i, string trigger)
210229

211230
public string buildJson (PlaybackProgressEventArgs e, string trigger)
212231
{
232+
// User u = e.Users.FirstOrDefault();
233+
213234
envelope j = new envelope() {
214-
@event = trigger,
215-
216-
Account = new Account() { },
217-
Player = new Player() {
218-
title = e.ClientName,
219-
uuid = e.DeviceId.ToString()
220-
},
221-
Metadata = new Metadata()
222-
{
223-
type = _libraryManager.GetContentType(e.Item),
224-
title = e.Item.Name,
225-
grandparentTitle = e.Item.Parent.Parent.Name,
226-
parentTitle = e.Item.Parent.Name,
227-
guid = e.Item.Id.ToString()
235+
@event = trigger,
236+
237+
Account = new Account() { },
238+
Player = new Player() {
239+
title = e.ClientName,
240+
uuid = e.DeviceId.ToString()
241+
},
242+
Metadata = new Metadata()
243+
{
244+
type = _libraryManager.GetContentType(e.Item),
245+
title = e.Item.Name,
246+
grandparentTitle = e.Item.Parent.Parent.Name,
247+
parentTitle = e.Item.Parent.Name,
248+
guid = e.Item.Id.ToString()
249+
228250
}
229251
};
230252

0 commit comments

Comments
 (0)