add mp4 support
This commit is contained in:
44
__main__.py
44
__main__.py
@@ -2,12 +2,35 @@ import sys
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import json
|
import json
|
||||||
import shutil
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
|
||||||
import piexif
|
import piexif
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
|
def mp4_add_date(input_path: Path, output_path: Path, epoch):
|
||||||
|
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
shutil.copy(input_path, output_path)
|
||||||
|
exif_date = datetime.utcfromtimestamp(epoch).strftime("%Y:%m:%d %H:%M:%S")
|
||||||
|
print(f"{output_path} @ {exif_date}")
|
||||||
|
subprocess.run(
|
||||||
|
["exiftool", f'-CreateDate="{exif_date}"', output_path]
|
||||||
|
).check_returncode()
|
||||||
|
|
||||||
|
|
||||||
|
def jpg_add_date(input_path: Path, output_path: Path, epoch):
|
||||||
|
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
shutil.copy(input_path, output_path)
|
||||||
|
exif_date = datetime.utcfromtimestamp(epoch).strftime("%Y:%m:%d %H:%M:%S")
|
||||||
|
exif_dict = {
|
||||||
|
"0th": {},
|
||||||
|
"Exif": {piexif.ExifIFD.DateTimeOriginal: exif_date},
|
||||||
|
}
|
||||||
|
print(f"{output_path} @ {exif_date}")
|
||||||
|
piexif.insert(piexif.dump(exif_dict), str(output_path))
|
||||||
|
|
||||||
|
|
||||||
def assign(input_dir: Path, output_dir: Path):
|
def assign(input_dir: Path, output_dir: Path):
|
||||||
|
|
||||||
album = input_dir / "your_facebook_activity" / "posts" / "album"
|
album = input_dir / "your_facebook_activity" / "posts" / "album"
|
||||||
@@ -18,8 +41,6 @@ def assign(input_dir: Path, output_dir: Path):
|
|||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
for e in data["photos"]:
|
for e in data["photos"]:
|
||||||
uri = e["uri"]
|
uri = e["uri"]
|
||||||
if not uri.endswith(".jpg"):
|
|
||||||
continue
|
|
||||||
taken_timestamp = (
|
taken_timestamp = (
|
||||||
e.get("media_metadata", {})
|
e.get("media_metadata", {})
|
||||||
.get("photo_metadata", {})
|
.get("photo_metadata", {})
|
||||||
@@ -34,21 +55,14 @@ def assign(input_dir: Path, output_dir: Path):
|
|||||||
epoch = creation_timestamp
|
epoch = creation_timestamp
|
||||||
else:
|
else:
|
||||||
assert False
|
assert False
|
||||||
exif_date = datetime.utcfromtimestamp(epoch).strftime("%Y:%m:%d %H:%M:%S")
|
|
||||||
|
|
||||||
# print(uri, taken_timestamp, creation_timestamp)
|
|
||||||
|
|
||||||
output_path = output_dir / Path("/".join(Path(uri).parts[-2:]))
|
output_path = output_dir / Path("/".join(Path(uri).parts[-2:]))
|
||||||
|
|
||||||
output_path.parent.mkdir(parents=True, exist_ok=True)
|
if uri.endswith(".jpg"):
|
||||||
shutil.copy(input_dir / uri, output_path)
|
jpg_add_date(input_dir / uri, output_path, epoch)
|
||||||
|
elif uri.endswith(".mp4"):
|
||||||
exif_dict = {
|
mp4_add_date(input_dir / uri, output_path, epoch)
|
||||||
"0th": {},
|
else:
|
||||||
"Exif": {piexif.ExifIFD.DateTimeOriginal: exif_date},
|
assert False
|
||||||
}
|
|
||||||
print(f"{output_path} @ {exif_date}")
|
|
||||||
piexif.insert(piexif.dump(exif_dict), str(output_path))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Reference in New Issue
Block a user