Created
March 29, 2019 15:46
-
-
Save tylerhall/f19e78829fcd6babb301a6f3c9b90375 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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