This script pulls photos and videos from an Android device using ADB and
automatically sorts them into organized year/month folders on your
computer.
It collects media from common Android folders (Camera, Instagram, WhatsApp, etc.), extracts the correct date, and moves files into a structured archive.
-
Connects to your Android device via ADB
-
Pulls media from predefined Android folders
-
Automatically detects additional subfolders inside:
/sdcard/Pictures/Gallery/owner -
Extracts the correct date using:
- π· EXIF
DateTimeOriginal(for real camera photos) - π WhatsApp filename patterns (e.g.Β
IMG-20240212-WA0001.jpg) - π File modification date (fallback)
- π· EXIF
-
Sorts files into:
<!-- -->
DESTINATION/
βββ 2023/
β βββ 11/
β βββ 12/
βββ 2024/
βββ 01/
βββ 02/
- Avoids duplicate files\
- Cleans up the temporary folder when finished
- Python 3.8+
- ADB (Android Debug Bridge) installed and available in PATH
- Android device with USB debugging enabled
- Python package:
Pillow
Install Pillow:
pip install pillowCreate a config.py file in the same directory with:
TEMP_FOLDER = "temp_media"
DESTINATION = "sorted_media"TEMP_FOLDERβ where files are temporarily pulledDESTINATIONβ final sorted archive location
The script pulls media from:
/sdcard/DCIM/Camera/sdcard/Movies/Instagram/sdcard/Pictures/Instagram/sdcard/Pictures/Whatsapp/sdcard/Android/media/com.whatsapp/WhatsApp/Media/WhatsApp Images/sdcard/Android/media/com.whatsapp/WhatsApp/Media/WhatsApp Video/sdcard/Pictures/Gallery/owner(including all subfolders)
You can modify BASE_ANDROID_SOURCES inside the script if needed.
- Connect your Android device via USB
- Enable USB debugging
- Verify connection:
adb devices- Run the script:
python pull_and_sort_media.pyThe script determines the file date in this order:
- EXIF metadata (
DateTimeOriginal) - WhatsApp filename date (YYYYMMDD)
- File modification timestamp
This ensures accurate sorting even for shared media.
After sorting is complete, the temporary pull folder is automatically deleted.
If a file already exists in the destination folder, it will be skipped.
- Only processes:
.jpg.jpeg.png.mp4.mov
- Files are moved (not copied) after sorting.
- Designed for personal media archiving and cleanup.