snapchat-memories-downloader/notebooks/verify_metadata.ipynb

355 lines
11 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 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/2019-04-05_23-27-17.jpg</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>../downloads/2024-10-23_00-29-09.jpg</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>../downloads/2025-02-16_00-09-41.mp4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>../downloads/2023-03-10_22-11-18.jpg</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>../downloads/2024-02-24_22-18-07.jpg</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>../downloads/2020-10-24_03-27-27.mp4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>../downloads/2020-11-04_04-40-23.mp4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>../downloads/2017-06-09_22-44-18.jpg</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>../downloads/2018-12-26_06-49-23.mp4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>../downloads/2024-07-25_04-57-56.mp4</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" file\n",
"0 ../downloads/2019-04-05_23-27-17.jpg\n",
"1 ../downloads/2024-10-23_00-29-09.jpg\n",
"2 ../downloads/2025-02-16_00-09-41.mp4\n",
"3 ../downloads/2023-03-10_22-11-18.jpg\n",
"4 ../downloads/2024-02-24_22-18-07.jpg\n",
"5 ../downloads/2020-10-24_03-27-27.mp4\n",
"6 ../downloads/2020-11-04_04-40-23.mp4\n",
"7 ../downloads/2017-06-09_22-44-18.jpg\n",
"8 ../downloads/2018-12-26_06-49-23.mp4\n",
"9 ../downloads/2024-07-25_04-57-56.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,\n",
" capture_output=True,\n",
" text=True,\n",
" check=False,\n",
" 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": 7,
"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/2019-04-05_23-27-17.jpg</td>\n",
" <td>2019:04:05 18:27:17</td>\n",
" <td>40 deg 24' 14.76\" N</td>\n",
" <td>104 deg 44' 21.52\" W</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>../downloads/2024-10-23_00-29-09.jpg</td>\n",
" <td>2024:10:22 19:29:09</td>\n",
" <td>44 deg 6' 15.77\" N</td>\n",
" <td>94 deg 13' 10.52\" W</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>../downloads/2025-02-16_00-09-41.mp4</td>\n",
" <td>2025:02:16 00:09:41</td>\n",
" <td>44 deg 21' 17.71\" N</td>\n",
" <td>93 deg 58' 1.20\" W</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>../downloads/2023-03-10_22-11-18.jpg</td>\n",
" <td>2023:03:10 16:11:18</td>\n",
" <td>40 deg 24' 39.13\" N</td>\n",
" <td>104 deg 41' 33.90\" W</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>../downloads/2024-02-24_22-18-07.jpg</td>\n",
" <td>2024:02:24 16:18:07</td>\n",
" <td>40 deg 25' 17.08\" N</td>\n",
" <td>104 deg 45' 22.75\" W</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>../downloads/2020-10-24_03-27-27.mp4</td>\n",
" <td>2020:10:24 03:27:27</td>\n",
" <td>40 deg 24' 37.62\" N</td>\n",
" <td>104 deg 42' 28.73\" W</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>../downloads/2020-11-04_04-40-23.mp4</td>\n",
" <td>2020:11:04 04:40:23</td>\n",
" <td>40 deg 25' 55.63\" N</td>\n",
" <td>104 deg 46' 10.16\" W</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>../downloads/2017-06-09_22-44-18.jpg</td>\n",
" <td>2017:06:09 17:44:18</td>\n",
" <td>39 deg 50' 49.74\" N</td>\n",
" <td>104 deg 40' 29.57\" W</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>../downloads/2018-12-26_06-49-23.mp4</td>\n",
" <td>2018:12:26 06:49:23</td>\n",
" <td>40 deg 25' 56.21\" N</td>\n",
" <td>104 deg 46' 11.24\" W</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>../downloads/2024-07-25_04-57-56.mp4</td>\n",
" <td>2024:07:25 04:57:56</td>\n",
" <td>44 deg 21' 17.17\" N</td>\n",
" <td>93 deg 57' 57.82\" W</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" file createdate \\\n",
"0 ../downloads/2019-04-05_23-27-17.jpg 2019:04:05 18:27:17 \n",
"1 ../downloads/2024-10-23_00-29-09.jpg 2024:10:22 19:29:09 \n",
"2 ../downloads/2025-02-16_00-09-41.mp4 2025:02:16 00:09:41 \n",
"3 ../downloads/2023-03-10_22-11-18.jpg 2023:03:10 16:11:18 \n",
"4 ../downloads/2024-02-24_22-18-07.jpg 2024:02:24 16:18:07 \n",
"5 ../downloads/2020-10-24_03-27-27.mp4 2020:10:24 03:27:27 \n",
"6 ../downloads/2020-11-04_04-40-23.mp4 2020:11:04 04:40:23 \n",
"7 ../downloads/2017-06-09_22-44-18.jpg 2017:06:09 17:44:18 \n",
"8 ../downloads/2018-12-26_06-49-23.mp4 2018:12:26 06:49:23 \n",
"9 ../downloads/2024-07-25_04-57-56.mp4 2024:07:25 04:57:56 \n",
"\n",
" gpslatitude gpslongitude \n",
"0 40 deg 24' 14.76\" N 104 deg 44' 21.52\" W \n",
"1 44 deg 6' 15.77\" N 94 deg 13' 10.52\" W \n",
"2 44 deg 21' 17.71\" N 93 deg 58' 1.20\" W \n",
"3 40 deg 24' 39.13\" N 104 deg 41' 33.90\" W \n",
"4 40 deg 25' 17.08\" N 104 deg 45' 22.75\" W \n",
"5 40 deg 24' 37.62\" N 104 deg 42' 28.73\" W \n",
"6 40 deg 25' 55.63\" N 104 deg 46' 10.16\" W \n",
"7 39 deg 50' 49.74\" N 104 deg 40' 29.57\" W \n",
"8 40 deg 25' 56.21\" N 104 deg 46' 11.24\" W \n",
"9 44 deg 21' 17.17\" N 93 deg 57' 57.82\" W "
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head(10)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"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.13.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}