Skip to content

Instantly share code, notes, and snippets.

@pixelchai
Last active April 27, 2021 06:46
Show Gist options
  • Save pixelchai/ddd367395ba2c12431d83bca974ace29 to your computer and use it in GitHub Desktop.
Save pixelchai/ddd367395ba2c12431d83bca974ace29 to your computer and use it in GitHub Desktop.
Script to download all the memories media from Snapchat's 'Download My Data' thing: https://accounts.snapchat.com/accounts/downloadmydata
import json
import requests
from tqdm import tqdm
import os
import traceback
OUTPUT_FOLDER = "media"
def download(media):
try:
ref_url = media["Download Link"]
ext = {
"PHOTO": ".jpg",
"VIDEO": ".mp4"
}[media["Media Type"]]
out_path = os.path.join(OUTPUT_FOLDER, media["Date"].replace(" ", "_").replace(":", "-") + ext)
if not os.path.isfile(out_path):
r = requests.post(ref_url)
if r.status_code == 200:
media_url = r.text
r = requests.get(media_url)
if r.status_code == 200:
with open(out_path, "wb") as f:
f.write(r.content)
else:
print("Media url: {}\nStatus code: {}".format(media_url, r.status_code))
else:
print("Ref url: {}\nStatus code: {}".format(ref_url, r.status_code))
except KeyboardInterrupt:
raise
except:
print("Media failed:\n{}".format(json.dumps(media, indent=4)))
traceback.print_exc()
def main():
os.makedirs(OUTPUT_FOLDER, exist_ok=True)
with open(os.path.join("json", "memories_history.json"), "r") as f:
media_list = json.load(f)["Saved Media"]
try:
for media in tqdm(media_list):
download(media)
except KeyboardInterrupt:
print("Interrupted")
if __name__ == '__main__':
main()
@Tirbo06
Copy link

Tirbo06 commented Apr 27, 2021

Works perfectly thanks for sharing 💯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment