[Updated] How to: Send email when video is played

Tutorials, tips and tricks.

Moderator: moderators

[Updated] How to: Send email when video is played

Postby nutt318 » Wed May 02, 2012 7:39 pm

EDIT (10/15/2012): I've updated the code a little bit, it should work better than before. This is test on SubSonic ver. 4.7
This tutorial will show you how to modify SubSonic to send an email when a video file is played along with the user and IP address. This is my first one so be nice if there are any errors.

Currently this doesn't work in IE9, if someone knows why I would like to hear.

Edit playAddDownload.jsp (yours may be different but here is mine) - located in C:\subsonic\jetty\2583\webapp\WEB-INF\jsp
Add the following code to the top of the file

Code: Select all
<script>
function sendMail(video, user) {
var xmlhttp;
         if (window.XMLHttpRequest) {
            xmlhttp = new XMLHttpRequest();
         } else {// IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
         }
         xmlhttp.open("GET", "http://www.yourdomain.com/somedirectory/sendemail.php?video="+video+"&user="+user+'&ip=<%= request.getHeader("X-Real-IP") %>', false); // Use this if using a reverse proxy
         xmlhttp.open("GET", "http://www.yourdomain.com/somedirectory/sendemail.php?video="+video+"&user="+user+"&ip=<%= request.getRemoteAddr()) %>", false); // Use this if using a NAT on your firewall
         xmlhttp.send();
}
</script>


Then in the same file look for this chuck of code, around line ~54
Code: Select all
            <a href="${videoUrl}" target="main">


Make it look like this
Code: Select all
            <a href="${videoUrl}" target="main" onclick="sendMail(parentElement.parentElement.getElementsByTagName('span')[2].attributes['title'].value, '${model.user.username}')">


Now hopefully you have a hosting provider that supports .php or you could use your local machine. Create a .php file called sendemail.php and put it on your hosting account like in the above code. In this .php file you will want to put the following code.

Code: Select all
<?php
$videoplaying = $_GET['video'];
$username = $_GET['user'];
$ip = $_GET['ip'];
$to = "youremail@email.com";
$subject = "Video Streaming";
$message = $username . " has just started watching " . $videoplaying . " from IP Address: " . $ip;
$from = "subsonic@yourdomainname.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
Last edited by nutt318 on Wed Oct 17, 2012 6:21 pm, edited 3 times in total.
nutt318
 
Posts: 54
Joined: Thu Dec 09, 2010 9:24 pm

Re: How to: Send email when video is played

Postby GJ51 » Wed May 02, 2012 10:00 pm

Great job getting this figured out. This would be a great feature to incorporate into a future release. It would be nice to be able to select email notifications to the admin or designated user with a range of trigger options based on who/what the admin wants to monitor, perhaps by username, media type, ip address, and whatever else makes sense to ensure that your site isn't being abused or compromised.

I'll link this post to an entry in the feature request section.

EDIT: Please comment in the feature request forum if you have interest. Here's the link:

viewtopic.php?f=3&t=9444
Last edited by GJ51 on Tue Oct 16, 2012 1:38 pm, edited 1 time in total.
Gary J

http://bios-mods.com
http://www.maplegrovepartners.com
http://theaverageguy.tv/category/tagpodcasts/cyberfrontiers/
User avatar
GJ51
 
Posts: 3492
Joined: Wed Oct 20, 2010 11:58 pm
Location: Western New York

Re: [Updated] How to: Send email when video is played

Postby nutt318 » Mon Oct 15, 2012 2:56 pm

Guide has been updated.
nutt318
 
Posts: 54
Joined: Thu Dec 09, 2010 9:24 pm

Re: [Updated] How to: Send email when video is played

Postby qtip920 » Sat Dec 08, 2012 12:17 am

Maybe a dumb question. But does this only work if the user is using IE?
qtip920
 
Posts: 3
Joined: Sat Dec 08, 2012 12:16 am

Re: [Updated] How to: Send email when video is played

Postby nutt318 » Sat Dec 08, 2012 12:23 am

Haven't tested this in a while (currently on my phone) but it should work just fine with Firefox and chrome. IE was having problems. I'll have to retest and post what I find.
nutt318
 
Posts: 54
Joined: Thu Dec 09, 2010 9:24 pm

Re: [Updated] How to: Send email when video is played

Postby qtip920 » Sat Dec 08, 2012 12:35 am

All my users are using Chrome. I've been trying to get this to work. But can't seem to figure it out.
qtip920
 
Posts: 3
Joined: Sat Dec 08, 2012 12:16 am

Re: [Updated] How to: Send email when video is played

Postby nutt318 » Sat Dec 08, 2012 12:42 am

Hmm, I can try to help you out. Do you use gmail, easier to chat instead of post in the forum. PM me you contact if you want.
nutt318
 
Posts: 54
Joined: Thu Dec 09, 2010 9:24 pm

Re: [Updated] How to: Send email when video is played

Postby qtip920 » Sat Dec 08, 2012 4:23 pm

I actually got it working. Thanks for the offer tho and thanks for the awesome mod.
qtip920
 
Posts: 3
Joined: Sat Dec 08, 2012 12:16 am

Re: [Updated] How to: Send email when video is played

Postby gurutech » Sat Dec 15, 2012 3:20 am

How would I code this to use my Gmail account as an SMTP relay? I run SS on my own computer, and my ISP blocks port 25, so I have to use an SMTP relay through my Gmail account to send mail from my computer.

Will this just pick up the settings automatically (use what's built in to my Linux configuration), or is there a setting I need to adjust somewhere?
Image
gurutech
 
Posts: 492
Joined: Sun Jan 15, 2012 9:56 pm


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 24 guests