Code Monkey home page Code Monkey logo

snapchatmemoriescaptionadder's Introduction

SnapchatMemoriesCaptionAdder

Overview

Adds metadata (captions and timestamps) to your exported Snapchat memories.

Background

Snapchat allows you to save images/videos to their servers with their memories feature. When you export your memories from Snapchat from their accounts website, you get all the memories, but with no metadata and the captions are stored separately!

A series of pictures with useless names

Base Image Overlay Image
Base image with no caption Overlay image with no image

You may then go to an alternate project like ToTheMax's Snapchat-All-Memories-Downloader, which is fantastic! It uses a memories_history.json file to download all memories and add a timestamp, but this technique loses all the captions! They aren't included in memories_history.json :(

{
  "Date": "2020-01-02 23:08:19 UTC",
  "Media Type": "Image",
  "Location": "Latitude, Longitude: 0.0, 0.0",
  "Download Link": "https://app.snapchat.com/dmd/memories?..."
}

So in short, memories_history.json has all the metadata we need, but we need to combine it with the full memory export if we want captions. So this project serves as a bridge between these two methods! We have all the metadata and we have all the memory photos/videos and captions, we just need to combine them. The final result:

Final result

Note the caption is on the image, the file name and metadata has a timestamp! The file's creation date is also set to the correct date.

Install

Note

This project and documentation is not very friendly to non-developers :( If you have questions, I'm happy to try and help if you make a new Github issue. I'm very open to any PRs that want to work on making this more user-friendly (see the Contribution section below!)

This project relies on two major libraries.

  • ffmpeg is "a complete, cross-platform solution to record, convert and stream audio and video." This project uses ffmpeg 6 to overlay the captions onto videos. If you're on Linux, download ffmpeg 6 from your package manager, if you're on MacOS, install ffmpeg@6 from brew, and if you're on Windows, install it from [winget](https://learn.microsoft.com/en-us/windows/package-manager/ winget/) with winget install -e --id Gyan.FFmpeg --version 6.0 (package here).
    • Currently, this project does not work with ffmpeg 7.1+ due to this script using the depreciated scale2ref filter, please see #7 for more information. I plan on fixing this once ffmpeg 7 is available in Fedora Linux.
    • libvips is "a demand-driven, horizontally threaded image processing library. Compared to similar libraries, libvips runs quickly and uses little memory." This project uses it to overlay the captions onto images. If you're on Linux, download it from your package manager, if you're on macOS install it from brew, and if you're on Windows download a compiled version here and add the bin folder to your path.

Finally, this project requires Python to be installed on your computer. Once installed, you can clone this repo and run

python -m pip install -r requirements.txt

to install the Python requirements for the project.

Usage

Note

This project and documentation is not very friendly to non-developers :( If you have questions, I'm happy to try and help if you make a new Github issue. I'm very open to any PRs that want to work on making this more user-friendly (see the Contribution section below!)

First, we need to get our data. Follow Snapchat's instructions to download your data. You'll need to do two separate exports:

  • Check "Include your Memories, Chat Media and Shared Stories" to download all your memories. (Note: this may take up a significant amount of space!) The status of the other checkmarks shouldn't matter, so feel free to export any additional data you'd like. Make sure the date range includes everything you want to export! If you choose to download multiple data packages, merge all the memories folders into one memories folder. This is the only folder you need from the export for this script.

  • Create a second export, without "Include your Memories, Chat Media and Shared Stories" checked, and with "Export JSON files" and "Memories and Other Media" checked. Use the same date range as your first export. This export should take much less time for Snapchat to send to you :) In this data export, make sure you have a json/memories_history.json. This is the metadata for the memories, which is only generated when you don't export your memories.

Now, make a folder in this repo called input and put the memories folder from the first export and the memories_history.json file from the second export into it.

  • Alternatively, you can provide the location of the memories_history.json file with the --memories-history flag and the memories folder with the memories flag, for example python main.py --memories-history test/memories_history.json --memories-folder test/memories --output test_output.

With this folder prepared, you can now run python main.py to run the script! It will create a new folder called output that will hold all memories with timestamps and captions. (Note: this will create a new copy of each photo/video, so make sure you have enough space!) Alternatively, use the --output flag to provide a different location to dump the photos.

If you run into issues, please run the script with the -v or --verbose flag, which will output information on what the script is doing. If that doesn't help you with the issue, open a github issue with that output! You can also use the -vv flag to get logs from ffmpeg/vips.

Some other flags:

  • --image-only will only convert images and not videos!
  • --video-only will only convert videos and not images!
  • --only-one will only convert one video and one image - useful for debugging to see the log of only one conversion, or testing the script before running it on your entire library.

Warning

If your captions are important to you, double check the final result against the photos in the Snapchat app! I found that the memories export did not include overlays/captions from some of my photos in 2017-2018. So check the final photos to make sure captions are there. If they aren't, you may need to download those impacted photos/videos directly from the Snapchat app. The majority of photos were successfully exported with all their captions.

Note: The timezone applied to the photos is set by your computer's local timezone! I'm open to any PRs to improve this (see below), but for a quick hack you can set the default timezone in SnapchatMemoriesCaptionAdder/adder.py in the add_metadata signature.

Thanks

  • @n-katti for fixing issues on Windows and new Snapchat export format (issue #3)
  • @Enricon27 for fixing a problem with the earlier fix :) (issue #3)
  • @autumnesponda for adding location metadata

Contributing

This achieved what I needed it to do, so I don't anticipate adding many more features. I'd be happy to accept PRs for some feaures I didn't implement:

  • Making this much more user friendly. This is currently not accessible to anyone who doesn't have knowledge of installing and using libraries.
    • Bundling libraries with the app
    • Creating a GUI
  • Cleaning the project up :) Introducing python-ffmpeg's async definitely made this functional but messy.
  • Snapchat uses UTC as the timezone for the timestamps. This script takes a guess that your computer's local time zone is the timezone you want the timestamps in. Allowing the user to specify a timezone, or automatically determine the timezone from the photo's location data, would be an improvement.
  • I believe ffmpeg could also do photos, but it's less efficient than VIPS. Adding a fallback to ffmpeg would make installation easier for those who can't easily install VIPS.

License

MIT

snapchatmemoriescaptionadder's People

Contributors

aidandenlinger avatar autumnesponda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

snapchatmemoriescaptionadder's Issues

videos with captions aren't working with ffmpeg 7

hey! so i'm trying to fix my snap memories, i downloaded all the requirements and ran the program and it worked beautifully for all my images. but then it gets to the videos and doesn't work? it just stops after like 10 videos, and i check the output and they're all videos that don't have captions (originally). so those are working, but the videos that are supposed to have captions don't. i redownloaded ffmpeg, and reran the python line to download requirements and it said "requirement is already satified." i'm not sure what i'm doing wrong, maybe i don't have enough ram or something?

Installing Libraries

Downloaded the ffmpeg & vips-dev compiled libraries as I'm on Windows, but I have no idea what to do with them?

Bugged Metadata Video Output

I was able to isolate this bug. It depends upon a handful of bugged videos, around 3 out of 1500.

If the program encounters one of these videos when in the final stages of processing, all other videos saved to output before this encounter have the correct metadata however, any videos encountered after will have no metadata (e.g. timestamp set to present). Additionally, this bugged input video will not be saved to the output folder itself. My three encounters with videos like these seem to be clustered around mid-2020.

Here is the traceback:

Waiting for final videos...
100%|██| 1/1 [00:00<00:00,  8.73it/s]
Traceback (most recent call last):
  File "/Users/jonathanxakellis/Documents/Snapchat/SnapchatMemoriesCaptionAdder/main.py", line 120, in <module>
    main()
  File "/Users/jonathanxakellis/Documents/Snapchat/SnapchatMemoriesCaptionAdder/main.py", line 114, in main
    add_file_creation(path, metadata)
  File "/Users/jonathanxakellis/Documents/Snapchat/SnapchatMemoriesCaptionAdder/SnapchatMemoriesCaptionAdder/adder.py", line 105, in add_file_creation
    assert output.exists()
AssertionError

Originally posted by @jxakellis in #7 (comment)

Does this work on chat media?/User friendly interface

Hi,
I was wondering if this works with chat media to add captions since those are separated into their own photo with a black background separate from the original photo. I'm also not very tech savvy and am confused by a lot of the directions.

Files outputting with no extension and 0 kb size

Hi! This is SUCH a helpful idea. I had downloaded all of my memories using another script, and I realized halfway through that they were missing the caption overlays

Things have been mostly straightforward, but I’ve got a few questions:

  1. I think maybe the file name format that memories are downloaded in has maybe changed since you wrote this? I was getting errors that none of the picture names (taken from the memories_json file) were found in the memories folder. Turns out that the script was trying to match for everything after the YYYY-MM-DD_ in the beginning of the file name. I wrote some code to remove this date from the beginning of the file names, and that at least stopped throwing the warning that pictures could not be found
  2. Now, the main.py runs fine (hangs up on the videos, but I don’t care much about video captions), but the output folder is full with files that have no extension at all and no file size.

Did my fix for #1 cause #2 potentially? And, if so, is there 1) a different way to go about this and 2) separately, a way for video processing to not hang up?

Thank you so much!

Unclear Configurations for Snapchat Data Export

Hi,

When exporting my Snapchat data from the "Download my Data" portal, I was slightly unclear about the required configurations. This is because there are two different options to select to include/exclude Memories. As you only get two data exports from Snapchat every 24 hours, I wanted to ensure I chose the correct options. Attached are the screenshots of what I presume are the proper configurations for the two exports. Let me know if I'm on the right track (and possibly clarify instructions for other future users)

The rest of the guide is straightforward and looks great!

  • Jonathan
Screenshot 2024-06-21 at 12 18 03 PM Screenshot 2024-06-21 at 1 46 44 PM

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.