Skip to content

Instantly share code, notes, and snippets.

@AlbertoEAF
Created February 19, 2022 20:01
Show Gist options
  • Select an option

  • Save AlbertoEAF/e42d1b00dd16fb5fcf3b3cf8b43b4d86 to your computer and use it in GitHub Desktop.

Select an option

Save AlbertoEAF/e42d1b00dd16fb5fcf3b3cf8b43b4d86 to your computer and use it in GitHub Desktop.
Fixes the modification dates of mp3's downloaded from Xiaomi's soundrecorder app.
# Author: Alberto Ferreira
# Date: 2022
# License: Free for public use. Use at your own risk.
#
# About:
#
# If you download mp3s from Xiaomi Cloud in the sound recorder app, their dates will show up as
# the date of download instead of the date shown in the app.
#
# This script fixes the mp3 modification dates to match the correct dates stored and visible in the app.
#
# Usage:
#
# 1. Download Xiaomi's soundrecorder mp3's to a folder on your computer.
# 2. Get Xiaomi's soundrecorder app db table "records" to a CSV on that same folder.
# 3. Put this script in the same folder and run it without arguments.
#
#
# Tip: How to get the CSV using Windows 10+/Linux?
#
# 1. Install Android Studio (to have the "adb" application) and WSL (to run some Linux commands later)
# 2. In the command line go to folder C:/Users/«Your_username»/AppData/Local/Android/Sdk/platform-tools
# 3. Run `adb backup com.android.soundrecorder -f soundrecorder_backup.ab` to copy the app data to your PC.
# 4. Using WSL go to the same folder and extract that archive by running:
# `( printf "\x1f\x8b\x08\x00\x00\x00\x00\x00" ; tail -c +25 soundrecorder_backup.ab ) | tar xfvz -`
# 5. Use an app like DBeaver to open the SQLite db in apps/com.android.soundrecorder/db/record.db
# and export the "records" table to a CSV file.
import os
import glob
import pandas as pd
filenames = glob.glob("*.mp3")
csv_filename = glob.glob("*.csv")[0] # Assume a single CSV of the db in the mp3's folder.
print(f"Found {len(filenames)} files to rename.")
print(f"Found app db file with names and creation dates: {csv_filename}")
db_records_table = pd.read_csv(csv_filename)
db_info = db_records_table.set_index("file_name").to_dict("index")
for filename in filenames:
date_s = int(db_info[filename]["create_time"] / 1000) # Convert from ms to seconds.
print(f"Updating file modification date: '{filename}'")
print("\t", int(os.stat(filename).st_mtime), " -> ", date_s)
os.utime(filename, (date_s, date_s))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment