Skip to content

Instantly share code, notes, and snippets.

@tylerhall
Created March 29, 2019 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tylerhall/f19e78829fcd6babb301a6f3c9b90375 to your computer and use it in GitHub Desktop.
Save tylerhall/f19e78829fcd6babb301a6f3c9b90375 to your computer and use it in GitHub Desktop.
<?PHP
$post = trim(file_get_contents('php://input'));
$dict = json_decode($post);
// Only process emails starting with our kids' names since they're the ones with photos/videos. All other service emails should be ignored...
if(substr($dict->Subject, 0, strlen("Kid #1's Name")) == "Kid #1's Name" || substr($dict->Subject, 0, strlen("Kid #2's Name")) == "Kid #2's Name") {
$html = $dict->HtmlBody;
if(preg_match('!href=[\'"](https?://www.domain.com/m/p/[a-zA-Z0-9]+)[\'"]!', $html, $matches) == 1) {
$img_url = $matches[1] . '?d=t';
$img_data = file_get_contents($img_url);
$ts = microtime();
file_put_contents("some-folder/photo-$ts.jpg", $img_data);
}
if(preg_match('!href=[\'"](https?://www.domain.com/m/v/[a-zA-Z0-9]+)[\'"]!', $html, $matches) == 1) {
$video_url = $matches[1] . '?d=t';
$video_data = file_get_contents($video_url);
$ts = microtime();
file_put_contents("some-folder/video-$ts.mp4", $video_data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment