Email new releases via REST api

Third-party modifications and add-ons, Apps and Clients

Moderator: moderators

Email new releases via REST api

Postby CasN » Mon Jun 29, 2020 2:29 pm

Have updated my script which was dedicated to a MySQL database. Now using the REST api so it is usable for all subsonic users, actually for all medie streamers that make use of the subsonic api.
Since I cannot attach the script, it follows below.
So copy the script and save it as "subsonic-mail-new-releases.php", for the rest follow instructions within the script.
Code: Select all
<?php
####################################################################################
# Script to inform your subsonic users about new releases on your subsonic site    #
# Independent from your choice of database, uses the REST api                      #
# Developed by Cas Nuy, www.NUY.info, June 2020                                    #
# Feel free to adjust                                                              #
####################################################################################
# Installation instructions:                                                       #
# Copy this script into the root of your webserver                                 #
# You can run it manually by typing php subsonic-mail-new-releases.php             #
# Even better, setup a Cron-job or Task to run the script automatically            #
####################################################################################
## Definitions                                                                     #
####################################################################################
#
## define the url of your subsonic installation ( including port and with trailing slash )
#
$subsonic   = "http://www.mysubsonic.nl:4040/";
#
## define userid/password for retrieving data (must have admin rights within subsonic
#
$user      =   "admin";
$pwd      =    "password";
#
## define mail settings
## if you add a value for $bcc here, users will not receive an email ( usefull for testing)
#
$bcc       = "";
$from      = "xx@xgmail.com";
$to         = "xx@xgmail.com";
$subject    = "Music-News from my Subsonic site";
#
## define rest version
#
$version   = "1.9.0";
#
## define number of days to look back for new releases
#
$his      = 7;
#
## max albums to check ( no more than 500, limitation of the REST api )
#
$max      = 250;
####################################################################################
## No changes required below thiese lines - No changes required below thiese lines #
####################################################################################
$adjust      = "-".$his." days" ;
$curdate   = date('Y-m-d', strtotime("$adjust"));
$send      = false;
$returnpath = "-f$from" ;
$headers   = "From: $from"."\r\n";
$headers   .= "Return-Path: $from"."\r\n";

// first create url for retrieving users
//  someting like http://subsonic.com:4040/rest/getUsers?v=1.9.0&u=user&p=password&f=xml&c=myapp"
$usr_url    = $subsonic ;
$usr_url   .= "rest/getUsers?v=";
$usr_url   .= $version ;
$usr_url   .= "&u=" ;
$usr_url   .= $user ;
$usr_url   .= "&p=" ;
$usr_url   .= $pwd ;
$usr_url   .= "&f=xml&c=myapp";

// Next create the url for retrieving albumsi
// some thing like http://subsonic.com:4040/rest/getAlbumList2?v=1.9.0&u=user&p=password&f=xml&c=myapp&type=newest&size=50
$album_url    = $subsonic ;
$album_url   .= "rest/getAlbumList2?v=";
$album_url   .= $version ;
$album_url   .= "&u=" ;
$album_url   .= $user ;
$album_url   .= "&p=" ;
$album_url   .= $pwd ;
$album_url   .= "&f=xml&c=myapp&type=newest&size=";
$album_url   .= $max ;

// now we retrieve the xml's and convert those into array's
$usr_xml = simplexml_load_file($usr_url);
$album_xml = simplexml_load_file($album_url);

// create address list as BCC
if ($bcc == ""){
   foreach($usr_xml->users as $list) {
      foreach($list->user as $user) {
         $bcc .=  $user['email']; 
         $bcc .=",";
      }
   }
}

// Add BCC
$headers .= 'BCC: '. $bcc . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1";

// Create the html message
$message    ="<html><body>";
$message    .= $subject." \n\n";
$message   .= "<table><tr>";
$message    .= "<td><b>Genre</td><td><b>Artist</td><td><b>Album</td><td><b>Released</td> <td><b>Date Uploaded</td></tr></b>";

foreach($album_xml->albumList2 as $list) {
   foreach($list->album as $album) {
      $uploaded = substr($album['created'],0,10) ;
      $limit = date( "Y-m-d", strtotime($uploaded));
      if ( $limit > $curdate ){
         $message .= "<tr><td>";
         $message .=  $album['genre'];
         $message .="</td><td>";
         $message .=  $album['artist']; 
         $message .="</td><td>";
         $message .=  $album['name']; 
         $message .="</td><td>";
         $message .=  $album['year']; 
         $message .="</td><td>";
         $message .=  substr($album['created'],0,10). "</td></tr>";
         $send      = true;   
      }
   }
}
$message   .= "</table></body></html>";

// email fields: to, from, subject, and so on, only if there is something to send
if ($send){
   $ok = mail($to, $subject, $message, $headers, $returnpath);
}
return $ok ;
CasN
 
Posts: 35
Joined: Wed Jan 12, 2011 2:24 pm

Re: Email new releases via REST api

Postby Jypy » Mon Oct 26, 2020 8:01 pm

Thank you so much for that!
Jypy
 
Posts: 6
Joined: Thu Mar 15, 2012 9:58 am


Return to Mods, Apps and Clients

Who is online

Users browsing this forum: No registered users and 16 guests