Last active
July 27, 2022 13:23
-
-
Save opsec-warehouse/3bd6b0207b50909c72c87339160bdb7d to your computer and use it in GitHub Desktop.
Download ALL Snapchat Memories
This file contains hidden or 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
#! /usr/bin/env python | |
""" SnapSaver - Presented by OpSec WareHouse (https://opsec.sh) """ | |
""" DISCLAIMER: THIS IS A FREE SOFTWARE PROVIDED AS-IS. PLEASE GIVE CREDIT IF YOU SHARE THIS DOCUMENT """ | |
import os, sys, json, time, requests, argparse, colorama | |
""" | |
USAGE INSTRUCTIONS | |
Requirements: | |
- Grab a backup of all your Snapchat data (works for banned accounts (up to 30 days post-deletion) as well) from here => https://accounts.snapchat.com/accounts/downloadmydata | |
- Install Python 3 w/ the modules Colorama, Argparse, and Requests (pip -m install colorama, argparse, requests) | |
Instructions: | |
= Preparing 4 Download | |
- Decompress the downloaded (.zip) file containing your Snapchat backup to any directory you wish (make a note of this location) | |
- Confirm you have Python 3+ installed by typing "python --version" (or "python3 --version" if you previously had Py2 installed) | |
- Should this command result in an error, please reinstall Python 3 and make sure "Add to PATH" is selected when installing | |
- Download this script (save as download_memories.py) anywhere you'd like (make a note of this location as well) | |
- Launch command prompt or teminal and change the working directory to the location you saved the .py file to (ex: "cd path/to/file") | |
- Validate all dependencies are met and that everything works by typing "python ./download_memories.py --help" | |
= Downloading Memories | |
- Navigate the folder containing the decompressed files you acquired from Snapchat, folder name should be similar to "mydata_1241642089169" | |
- Search for the file called "memories_history.json", and get a full copy of that filepath (ex: C:/Users/user/Documents/mydata_1241642089169/json/memories_history.json) | |
- Finally, execute the final command "python download_memories.py --memories <path_to_json_file>" | |
- You can also drag and drop the json file from the file explorer to the command line interface to make this step easier | |
- Execute the script and let it do it's job! You'll see a success message when it's complete. | |
= Troubleshooting (worst case scenario execute with '--verbose' flag and send output to [email protected]) | |
- "File 'FILE_URL' download failed, re-trying.." | |
- Copy the file url the program outputs, and open a new CLI session in the same CWD. | |
- Re-execute this script with the '--manual' and '--verbose' flags (ex: python download_memories.py --verbose --manual "FILE_URL") | |
- Hanging Terminal | |
- Exit session smoothly by using Control C (^C); wait a few minutes; re-execute. | |
""" | |
argsToParse = argparse.ArgumentParser(description="SnapSaver (by OpSec WareHouse) - Download ALL Snapchat Memories") | |
switchArgGroup = argsToParse.add_argument_group("[switches]") | |
switchArgGroup.add_argument("-v", "--verbose", action="store_true", help="stdout DEBUG responses") | |
optionArgGroup = argsToParse.add_argument_group("[options]") | |
optionArgGroup.add_argument("-m", "--memories", help="JSON datasheet containing download links") | |
optionArgGroup.add_argument("--manual", help="Manually download file by entering the 'Download Link'") | |
argParsedObj = argsToParse.parse_args() | |
# Text Coloring Properties | |
if "win" in sys.platform.lower(): colorama.init() # support for windows | |
def print_success(string): print(f'{colorama.Fore.GREEN}{colorama.Style.BRIGHT}[+] ' + string + f'{colorama.Style.RESET_ALL}') | |
def print_warning(string): print(f'{colorama.Fore.YELLOW}[=] ' + string + f'{colorama.Style.RESET_ALL}') | |
def print_info(string): print(f'{colorama.Fore.CYAN}[i] ' + string + f'{colorama.Style.RESET_ALL}') | |
def print_error(string): print(f'{colorama.Fore.RED}[-] ' + string + f'{colorama.Style.RESET_ALL}'); sys.exit(0) | |
def print_debug(string): | |
if argParsedObj.verbose: print(f'{colorama.Fore.MAGENTA}[#] ' + string + f'{colorama.Style.RESET_ALL}') | |
def addDL2DB(tarFile): | |
pass | |
def downloadSnapMemory(tarURL): | |
try: | |
genDownloadLink = requests.post(tarURL) | |
if genDownloadLink.status_code == 200: | |
assetFileName_ = genDownloadLink.text[genDownloadLink.text.find('.com') + 4:genDownloadLink.text.find('?')].split('/') | |
assetFileName = assetFileName_[len(assetFileName_) - 1] | |
assetContents = requests.get(genDownloadLink.text) | |
elif genDownloadLink.status_code == 403: print_error("Failed to acquire direct asset download location - you must download all memories within 7 days of downloading your Snapchat data.") | |
elif genDownloadLink.status_code == 500: | |
print_warning("File download failed for an unknown reason. Please download it manually by using 'python download_memories.py --manual LINK' =>\n----------\n{0}\n----------\n".format(tarURL)) | |
return True | |
else: | |
print_debug("Unknown error - restarting download..\nHTTP Response => {0} - {1}".format(str(genDownloadLink.status_code), genDownloadLink.reason)) | |
time.sleep(5) | |
downloadSnapMemory(tarURL) | |
print_info("Downloading '{0}'..".format(assetFileName)) | |
os.makedirs("downloaded_memories/", exist_ok = True) | |
if os.path.exists("downloaded_memories/" + assetFileName): print_warning("File '{0}' already exists.. skipping download.".format("downloaded_memories/" + assetFileName)) | |
else: | |
with open("downloaded_memories/" + assetFileName, "wb") as dataAssetStream: | |
for dataChunk in assetContents.iter_content(chunk_size=256): | |
if dataChunk: | |
dataAssetStream.write(dataChunk) | |
addDL2DB(assetFileName) | |
except Exception as e: | |
print_debug("RAW ERROR => '{0}'".format(e)) | |
print_warning("File '{0}' download failed, re-trying..".format(tarURL)) | |
time.sleep(10) | |
downloadSnapMemory(tarURL) | |
if __name__ == '__main__': | |
print_success("Welcome to SnapSaver - Presented by OpSec WareHouse (https://opsec.sh)") | |
if argParsedObj.manual != None: | |
print_debug("Manually downloading file from designated download link => '{0}'".format(argParsedObj.manual)) | |
downloadSnapMemory(argParsedObj.manual) | |
if argParsedObj.memories != None: | |
print_info("Downloading Saved Snapchat Memories...") | |
if os.path.exists(argParsedObj.memories): | |
print_debug("Chosen filepath '{0}' does indeed exist.".format(argParsedObj.memories)) | |
try: | |
with open(argParsedObj.memories, "r") as memoryBackupFile: | |
memoryBackupObj = json.loads(memoryBackupFile.read()) | |
print_debug("Loaded filepath into JSON object. Looping through download now..\n") | |
for dataSet in memoryBackupObj["Saved Media"]: | |
downloadSnapMemory(dataSet["Download Link"]) | |
print_success("Entire Memory Backup Complete! Visit https://opsec.sh for more goodies :)") | |
except requests.exceptions.MissingSchema: print_error("Failed to acquire direct asset download location - you must download all memories within 7 days of downloading your Snapchat data.") | |
except json.decoder.JSONDecodeError: print_error("Failed to decode JSON data. Either '{0}' is corrupted or it's not the correct file.".format(argParsedObj.memories)) | |
except KeyboardInterrupt: print_error("Stopping download early, have a great d4y!") | |
else: print_error("Chosen filepath '{0}' does not exist.".format(argParsedObj.memories)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment