snapchat-memories-downloader/notebooks/verify_metadata.ipynb
2025-12-10 16:25:46 -06:00

352 lines
10 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "cf03ce25",
"metadata": {},
"outputs": [],
"source": [
"import subprocess\n",
"import json\n",
"import csv\n",
"import os\n",
"from pathlib import Path\n",
"import pandas as pd\n",
"import logging"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "326f265c",
"metadata": {},
"outputs": [],
"source": [
"file_directory = Path(\"../downloads\")\n",
"\n",
"files_to_check = [\n",
" p\n",
" for p in file_directory.iterdir()\n",
" if p.is_file() and p.suffix.lower() in [\".jpg\", \".mp4\"]\n",
"]"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "d659da7f",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>file</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>../downloads/2025-03-15_01-17-10.mp4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>../downloads/2025-02-28_18-25-46.mp4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>../downloads/2024-09-09_23-21-56.jpg</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>../downloads/2025-02-18_13-40-28.mp4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>../downloads/2024-10-18_02-04-34.mp4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>../downloads/2025-03-08_06-20-39.mp4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>../downloads/2025-06-28_02-54-42.jpg</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>../downloads/2025-04-13_22-54-57.jpg</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>../downloads/2025-03-04_19-48-15.mp4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>../downloads/2025-04-28_21-29-43.mp4</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" file\n",
"0 ../downloads/2025-03-15_01-17-10.mp4\n",
"1 ../downloads/2025-02-28_18-25-46.mp4\n",
"2 ../downloads/2024-09-09_23-21-56.jpg\n",
"3 ../downloads/2025-02-18_13-40-28.mp4\n",
"4 ../downloads/2024-10-18_02-04-34.mp4\n",
"5 ../downloads/2025-03-08_06-20-39.mp4\n",
"6 ../downloads/2025-06-28_02-54-42.jpg\n",
"7 ../downloads/2025-04-13_22-54-57.jpg\n",
"8 ../downloads/2025-03-04_19-48-15.mp4\n",
"9 ../downloads/2025-04-28_21-29-43.mp4"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"file_df = pd.DataFrame(data=files_to_check, columns=[\"file\"])\n",
"file_df.head(10)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "10071159",
"metadata": {},
"outputs": [],
"source": [
"def get_metadata(row: pd.Series) -> pd.Series:\n",
"\n",
" file_path = row[\"file\"]\n",
" command = [\n",
" \"exiftool\",\n",
" \"-T\",\n",
" \"-createdate\",\n",
" \"-gpslatitude\",\n",
" \"-gpslongitude\",\n",
" # *tags_to_check,\n",
" str(file_path),\n",
" ]\n",
" result = subprocess.run(\n",
" command, capture_output=True, text=True, check=False, timeout=30\n",
" )\n",
" metadata = result.stdout.strip().split(\"\\n\")[0].split(\"\\t\")\n",
"\n",
" if len(metadata) < 3:\n",
" metadata = metadata + [\"-\"] * (3 - len(metadata))\n",
" row[\"createdate\"] = metadata[0]\n",
" row[\"gpslatitude\"] = metadata[1]\n",
" row[\"gpslongitude\"] = metadata[2]\n",
" return row"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "6faafde0",
"metadata": {},
"outputs": [],
"source": [
"df = file_df.apply(get_metadata, axis=1)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "e4389a3e",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>file</th>\n",
" <th>createdate</th>\n",
" <th>gpslatitude</th>\n",
" <th>gpslongitude</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>../downloads/2025-03-15_01-17-10.mp4</td>\n",
" <td>2025:03:15 01:17:29</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>../downloads/2025-02-28_18-25-46.mp4</td>\n",
" <td>2025:02:28 18:26:16</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>../downloads/2024-09-09_23-21-56.jpg</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>../downloads/2025-02-18_13-40-28.mp4</td>\n",
" <td>2025:02:18 13:41:28</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>../downloads/2024-10-18_02-04-34.mp4</td>\n",
" <td>2024:10:18 02:04:52</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>../downloads/2025-03-08_06-20-39.mp4</td>\n",
" <td>2025:03:08 06:21:26</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>../downloads/2025-06-28_02-54-42.jpg</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>../downloads/2025-04-13_22-54-57.jpg</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>../downloads/2025-03-04_19-48-15.mp4</td>\n",
" <td>2025:03:04 19:48:37</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>../downloads/2025-04-28_21-29-43.mp4</td>\n",
" <td>2025:04:28 21:30:00</td>\n",
" <td>-</td>\n",
" <td>-</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" file createdate gpslatitude \\\n",
"0 ../downloads/2025-03-15_01-17-10.mp4 2025:03:15 01:17:29 - \n",
"1 ../downloads/2025-02-28_18-25-46.mp4 2025:02:28 18:26:16 - \n",
"2 ../downloads/2024-09-09_23-21-56.jpg - - \n",
"3 ../downloads/2025-02-18_13-40-28.mp4 2025:02:18 13:41:28 - \n",
"4 ../downloads/2024-10-18_02-04-34.mp4 2024:10:18 02:04:52 - \n",
"5 ../downloads/2025-03-08_06-20-39.mp4 2025:03:08 06:21:26 - \n",
"6 ../downloads/2025-06-28_02-54-42.jpg - - \n",
"7 ../downloads/2025-04-13_22-54-57.jpg - - \n",
"8 ../downloads/2025-03-04_19-48-15.mp4 2025:03:04 19:48:37 - \n",
"9 ../downloads/2025-04-28_21-29-43.mp4 2025:04:28 21:30:00 - \n",
"\n",
" gpslongitude \n",
"0 - \n",
"1 - \n",
"2 - \n",
"3 - \n",
"4 - \n",
"5 - \n",
"6 - \n",
"7 - \n",
"8 - \n",
"9 - "
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head(10)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "66c681e4",
"metadata": {},
"outputs": [],
"source": [
"df.to_csv(\"../temp/filemetadata.csv\", index=False, sep=\"#\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}