Created
July 15, 2024 00:44
-
-
Save medeirosT/6af395037bee2eef6144d123916a1c39 to your computer and use it in GitHub Desktop.
Quick and Dirty fotoshare.co downloader script in php
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 | |
function downloadFile($url) { | |
$fileName = basename(parse_url($url, PHP_URL_PATH)); | |
$fileContent = file_get_contents($url); | |
if ($fileContent === false) { | |
echo "...Failed to download file from $url"; | |
return false; | |
} | |
// Save the file in the current directory | |
if (file_put_contents($fileName, $fileContent) !== false) { | |
echo "...File downloaded successfully and saved as $fileName\n"; | |
return true; | |
} else { | |
echo "...Failed to save the file $fileName"; | |
return false; | |
} | |
} | |
if ($argc != 2) { | |
echo "Usage: php get.php <fotoshare.co url>\n"; | |
exit(1); | |
} | |
$album = $argv[1]; | |
echo "fotoshare downloader by MedeirosT\n"; | |
$strip_base_url = "https://fotoshare.co/i/"; | |
$data = file_get_contents($album); | |
// Define the regular expression pattern | |
$pattern = '/data-url="\/i\/([a-zA-Z0-9]+)"/'; | |
// Perform the regex match | |
preg_match_all($pattern, $data, $matches); | |
if ( empty($matches) ){ | |
echo "Could not find any albums... did the website change?\n"; | |
} else { | |
echo "Found albums!\n"; | |
$results = $matches[1]; | |
$counter = 0; | |
foreach ($results as $result){ | |
$counter++; | |
echo "Going for album #" . $counter . "! Wish me luck!\n"; | |
echo "...Trying to find the picture JSON data..."; | |
$url = $strip_base_url . $result; | |
$album_data = file_get_contents($url); | |
$album_json_start = "let sessionImages = "; | |
$json_start_pos = strpos($album_data, $album_json_start, strlen($album_json_start)) + strlen($album_json_start); | |
$album_data = substr($album_data, $json_start_pos); | |
$json_end_pos = strpos($album_data, "}}};"); | |
$album_data = substr($album_data, 0, $json_end_pos) . "}}}" ; | |
$album_data = str_replace("\/","/",$album_data); | |
echo "I think I got it..."; | |
$album_data = json_decode($album_data); | |
if ( $album_data != null ){ | |
echo "Yup! Got it!! Downloading...\n"; | |
foreach ( $album_data as $top_object => $top_value){ | |
foreach ($top_value as $picture_obj => $pic_values){ | |
echo "...Downloading image hash " . $pic_values->hash . "\n"; | |
downloadFile($pic_values->img); | |
} | |
} | |
} else { | |
echo "I didn't find any valid JSON data :<\n"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment