Skip to content

Corrects media file timestamps downloaded from Twitter/X.

Notifications You must be signed in to change notification settings

Anub1sR0cks/OrganizeArt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

OrganizeArt.py

This Python script can modify the timestamp of a media file downloaded from Twitter/X. This can assist users who download large batches of pictures (such as artwork, photographs, videos, etc.) and like to organize the typically random filenames by their original upload date & time. This is beneficial to those who enjoy viewing their libraries in a large thumbnail view while being able to sort chronologically.

Usage

python OrganizeArt.py directory

All files in the specified directory named after a valid Twitter ID will have their timestamps replaced. The timestamps are relative to GMT and will display appropriately depending on your system's timezone or locale. The original content of the files themselves will remain untouched.

Before After
Before After

How It Works

The script works by decoding the snowflake ID from the filename's Twitter ID, which is a unique 15-character identifier assigned to each Twitter object. The algorithm for extracting the Unix timestamp is as follows:

  1. Read the Twitter ID from the filename.
  2. Get the snowflake ID by decoding the Twitter ID's base64 string and adding padding if required.
  3. Get the first 16 bytes of the snowflake ID (the Unix timestamp).
  4. Add the constant Twitter epoch to the result, which is 1288834974657 (or Thursday, November 4, 2010 1:42:54.657 AM).

More information about snowflake IDs: https://en.wikipedia.org/wiki/Snowflake_ID

About

Corrects media file timestamps downloaded from Twitter/X.

Topics

Resources

Stars

Watchers

Forks

Languages